Changeset 1211
- Timestamp:
- 07/06/08 13:48:28 (2 months ago)
- Files:
-
- trunk/descent.core/src/descent/internal/codeassist/EvaluationResult.java (modified) (1 diff)
- trunk/descent.core/src/descent/internal/compiler/lookup/LazyAggregateDeclaration.java (modified) (1 diff)
- trunk/descent.core/src/descent/internal/compiler/lookup/ModuleBuilder.java (modified) (2 diffs)
- trunk/descent.core/src/descent/internal/compiler/parser/AssignExp.java (modified) (1 diff)
- trunk/descent.core/src/descent/internal/formatter/CodeFormatterVisitor.java (modified) (1 diff)
- trunk/descent.ui/src/descent/internal/ui/text/java/DdocMacroCompletionProposal.java (modified) (4 diffs)
- trunk/descent.ui/src/descent/internal/ui/text/java/SmartSemicolonAutoEditStrategy.java (modified) (2 diffs)
- trunk/descent.ui/src/descent/internal/ui/text/template/contentassist/TemplateProposal.java (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/descent.core/src/descent/internal/codeassist/EvaluationResult.java
r1198 r1211 31 31 if (i != 0) { 32 32 sb.append(", "); 33 if (results[i].getKind() == IEvaluationResult.ARRAY) { 34 sb.append("\n "); 35 } 33 36 } 34 37 sb.append(results[i]); trunk/descent.core/src/descent/internal/compiler/lookup/LazyAggregateDeclaration.java
r1207 r1211 48 48 } 49 49 50 if (result.hasMixinDeclaration || result.hasStaticIf ) {50 if (result.hasMixinDeclaration || result.hasStaticIf || result.hasAnon) { 51 51 cancelLazyness = true; 52 52 lazy.members(new Dsymbols()); trunk/descent.core/src/descent/internal/compiler/lookup/ModuleBuilder.java
r1203 r1211 806 806 public boolean hasStaticIf; 807 807 public boolean hasMixinDeclaration; 808 public boolean hasAnon; 808 809 } 809 810 … … 905 906 // Anonymous: it must be an enum, at the top level there 906 907 // isn't a use for an annonymous class, template, etc. 907 IType type = (IType) child; 908 if (type.isEnum()) { 909 Dsymbol sym = fillEnum(lazy.getModule(), symbols, type); 910 sym.addMember(lazy.getSemanticScope(), lazy.asScopeDsymbol(), 0, context); 911 lazy.runMissingSemantic(sym, context); 912 result.hasAnonEnum = true; 908 if (child instanceof IType) { 909 IType type = (IType) child; 910 if (type.isEnum()) { 911 Dsymbol sym = fillEnum(lazy.getModule(), symbols, type); 912 sym.addMember(lazy.getSemanticScope(), lazy.asScopeDsymbol(), 0, context); 913 lazy.runMissingSemantic(sym, context); 914 result.hasAnonEnum = true; 915 } else { 916 result.hasAnon = true; 917 } 918 } else { 919 result.hasAnon = true; 913 920 } 914 921 } else { trunk/descent.core/src/descent/internal/compiler/parser/AssignExp.java
r1201 r1211 189 189 e = new CallExp(loc, e1, e2); 190 190 e = e.semantic(sc, context); 191 192 if (e instanceof CallExp) { 193 CallExp callExp = (CallExp) e; 194 if (callExp.e1 instanceof DotVarExp) { 195 DotVarExp dve = (DotVarExp) callExp.e1; 196 sourceE1.setResolvedSymbol(dve.var); 197 } else if (callExp.e1 instanceof VarExp) { 198 VarExp dve = (VarExp) callExp.e1; 199 sourceE1.setResolvedSymbol(dve.var); 200 } 201 } 202 191 203 return e; 192 204 } trunk/descent.core/src/descent/internal/formatter/CodeFormatterVisitor.java
r1198 r1211 2973 2973 { 2974 2974 int statementsLength = statements.size(); 2975 if (statementsLength == 0) 2975 if (statementsLength == 0) { 2976 scribe.printComment(); 2976 2977 return; 2978 } 2977 2979 else if (statementsLength == 1) { 2978 2980 if (statements.get(0) instanceof BreakStatement && unIndentAtBreak) trunk/descent.ui/src/descent/internal/ui/text/java/DdocMacroCompletionProposal.java
r891 r1211 1 1 package descent.internal.ui.text.java; 2 2 3 import org.eclipse.jface.dialogs.MessageDialog; 4 import org.eclipse.jface.text.BadLocationException; 3 5 import org.eclipse.jface.text.DefaultInformationControl; 6 import org.eclipse.jface.text.IDocument; 4 7 import org.eclipse.jface.text.IInformationControl; 5 8 import org.eclipse.jface.text.IInformationControlCreator; 9 import org.eclipse.jface.text.IRegion; 6 10 import org.eclipse.jface.text.ITextViewer; 11 import org.eclipse.jface.text.link.LinkedModeModel; 12 import org.eclipse.jface.text.link.LinkedModeUI; 13 import org.eclipse.jface.text.link.LinkedPosition; 14 import org.eclipse.jface.text.link.LinkedPositionGroup; 7 15 import org.eclipse.swt.SWT; 16 import org.eclipse.swt.graphics.Point; 8 17 import org.eclipse.swt.widgets.Shell; 18 import org.eclipse.ui.IEditorPart; 19 import org.eclipse.ui.texteditor.link.EditorLinkedModeUI; 9 20 10 21 import descent.core.CompletionProposal; 22 import descent.internal.ui.JavaPlugin; 23 import descent.internal.ui.javaeditor.EditorHighlightingSynchronizer; 24 import descent.internal.ui.javaeditor.JavaEditor; 11 25 import descent.internal.ui.text.TextPresenter; 12 26 import descent.internal.ui.text.java.hover.AbstractReusableInformationControlCreator; … … 14 28 15 29 public class DdocMacroCompletionProposal extends LazyJavaCompletionProposal { 30 31 private int fMaxNumberOfParameters; 32 private boolean fParametersHasPlus; 33 private boolean fParametersHasZero; 34 private boolean fParametersComputed; 35 private int[] fParameterOffsets; 36 37 private IRegion fSelectedRegion; // initialized by apply() 16 38 17 39 public DdocMacroCompletionProposal(CompletionProposal proposal, JavaContentAssistInvocationContext context) { … … 20 42 21 43 @Override 44 public void apply(IDocument document, char trigger, int offset) { 45 super.apply(document, trigger, offset); 46 47 int baseOffset= getReplacementOffset(); 48 String replacement= getReplacementString(); 49 50 if (hasParameters()) { 51 try { 52 LinkedModeModel model= new LinkedModeModel(); 53 for (int i= 0; i != fParameterOffsets.length; i++) { 54 LinkedPositionGroup group= new LinkedPositionGroup(); 55 group.addPosition(new LinkedPosition(document, baseOffset + fParameterOffsets[i], 2, LinkedPositionGroup.NO_STOP)); 56 model.addGroup(group); 57 } 58 59 model.forceInstall(); 60 JavaEditor editor= getJavaEditor(); 61 if (editor != null) { 62 model.addLinkingListener(new EditorHighlightingSynchronizer(editor)); 63 } 64 65 LinkedModeUI ui= new EditorLinkedModeUI(model, getTextViewer()); 66 ui.setExitPosition(getTextViewer(), baseOffset + replacement.length(), 0, Integer.MAX_VALUE); 67 ui.setExitPolicy(new ExitPolicy(')', document)); 68 ui.setDoContextInfo(true); 69 ui.setCyclingMode(LinkedModeUI.CYCLE_WHEN_NO_PARENT); 70 ui.enter(); 71 72 fSelectedRegion= ui.getSelectedRegion(); 73 74 } catch (BadLocationException e) { 75 JavaPlugin.log(e); 76 openErrorDialog(e); 77 } 78 } 79 } 80 81 @Override 22 82 protected String computeReplacementString() { 83 String str = super.computeReplacementString(); 84 if (str.length() > 0 && str.charAt(0) == '$') { 85 computeParameters(); 86 87 StringBuilder sb = new StringBuilder(); 88 sb.append('$'); 89 sb.append('('); 90 sb.append(str.substring(1)); 91 92 if (hasParameters()) { 93 // If we have parameters, don't care about $0 94 if (fMaxNumberOfParameters > 0) { 95 // If it's $1 $+, we want two positions 96 if (fParametersHasPlus && fMaxNumberOfParameters == 1) { 97 fParameterOffsets = new int[2]; 98 sb.append(' '); 99 fParameterOffsets[0] = sb.length(); 100 sb.append('$'); 101 sb.append('1'); 102 sb.append(','); 103 sb.append(' '); 104 fParameterOffsets[1] = sb.length(); 105 sb.append('$'); 106 sb.append('+'); 107 } else { 108 fParameterOffsets = new int[fMaxNumberOfParameters]; 109 sb.append(' '); 110 for (int i = 1; i <= fMaxNumberOfParameters; i++) { 111 if (i != 1) { 112 sb.append(','); 113 sb.append(' '); 114 } 115 fParameterOffsets[i - 1] = sb.length(); 116 sb.append('$'); 117 sb.append(i); 118 } 119 } 120 } else { 121 // Just $0 122 fParameterOffsets = new int[1]; 123 sb.append(' '); 124 fParameterOffsets[0] = sb.length(); 125 sb.append('$'); 126 sb.append('0'); 127 } 128 } 129 130 sb.append(')'); 131 return sb.toString(); 132 } 23 133 return super.computeReplacementString() + "()"; //$NON-NLS-1$ 24 134 } 25 135 136 private boolean hasParameters() { 137 computeParameters(); 138 return fMaxNumberOfParameters != 0 || fParametersHasPlus || fParametersHasZero; 139 } 140 141 private void computeParameters() { 142 if (fParametersComputed) { 143 return; 144 } 145 fParametersComputed = true; 146 147 fMaxNumberOfParameters = 0; 148 char[] completion = fProposal.getName(); 149 for (int i = 0; i < completion.length; i++) { 150 char c = completion[i]; 151 if (c == '$' && i < completion.length - 1) { 152 i++; 153 c = completion[i]; 154 int val = c - '0'; 155 if (val == 0) { 156 fParametersHasZero = true; 157 } else if (val > 0 && val <= 9) { 158 if (val > fMaxNumberOfParameters) { 159 fMaxNumberOfParameters = val; 160 } 161 } else if (c == '+') { 162 fParametersHasPlus = true; 163 } 164 } 165 } 166 } 167 168 private boolean containsPlaceholders(String completion) { 169 return completion.matches(".*\\$(\\d).*"); 170 } 171 26 172 @Override 27 173 public void apply(ITextViewer viewer, char trigger, int stateMask, int offset) { … … 38 184 }; 39 185 } 186 187 /** 188 * Returns the currently active java editor, or <code>null</code> if it 189 * cannot be determined. 190 * 191 * @return the currently active java editor, or <code>null</code> 192 */ 193 private JavaEditor getJavaEditor() { 194 IEditorPart part= JavaPlugin.getActivePage().getActiveEditor(); 195 if (part instanceof JavaEditor) 196 return (JavaEditor) part; 197 else 198 return null; 199 } 200 201 private void openErrorDialog(BadLocationException e) { 202 Shell shell= getTextViewer().getTextWidget().getShell(); 203 MessageDialog.openError(shell, JavaTextMessages.ExperimentalProposal_error_msg, e.getMessage()); 204 } 205 206 @Override 207 public Point getSelection(IDocument document) { 208 if (fSelectedRegion == null) 209 return new Point(getReplacementOffset(), 0); 210 211 return new Point(fSelectedRegion.getOffset(), fSelectedRegion.getLength()); 212 } 40 213 41 214 } trunk/descent.ui/src/descent/internal/ui/text/java/SmartSemicolonAutoEditStrategy.java
r210 r1211 280 280 } else if (character == SEMICHAR) { 281 281 282 if (isForStatement(text, offset) ) {283 insertPos= -1; // don't do anything in for statements, as semis are vital part of these282 if (isForStatement(text, offset) || isForeachStatement(text, offset)) { 283 insertPos= -1; // don't do anything in for or foreach statements, as semis are vital part of these 284 284 } else { 285 285 int nextPartitionPos= nextPartitionOrLineEnd(document, line, offset, partitioning); … … 1004 1004 return false; 1005 1005 } 1006 1007 /** 1008 * Determines whether the current line contains a for statement. 1009 * Algorithm: any "for" word in the line is a positive, "for" contained in a string literal will 1010 * produce a false positive. 1011 * 1012 * @param line the line where the change is being made 1013 * @param offset the position of the caret 1014 * @return <code>true</code> if <code>line</code> contains <code>for</code>, <code>false</code> otherwise 1015 */ 1016 private static boolean isForeachStatement(String line, int offset) { 1017 /* searching for (^|\s)foreach(\s|$) */ 1018 int forPos= line.indexOf("foreach"); //$NON-NLS-1$ 1019 if (forPos != -1) { 1020 if ((forPos == 0 || !Character.isJavaIdentifierPart(line.charAt(forPos - 1))) && (line.length() == forPos + 7 || !Character.isJavaIdentifierPart(line.charAt(forPos + 7)))) 1021 return true; 1022 } 1023 return false; 1024 } 1006 1025 1007 1026 /** trunk/descent.ui/src/descent/internal/ui/text/template/contentassist/TemplateProposal.java
r212 r1211 249 249 fSelectedRegion= fRegion; 250 250 } 251 251 252 252 } 253 253
