Changeset 874
- Timestamp:
- 10/22/07 17:58:09 (1 year ago)
- Files:
-
- trunk/descent.core/src/descent/internal/codeassist/CompletionEngine.java (modified) (2 diffs)
- trunk/descent.core/src/descent/internal/codeassist/complete/CompletionParser.java (modified) (5 diffs)
- trunk/descent.core/src/descent/internal/compiler/SourceElementParser.java (modified) (1 diff)
- trunk/descent.core/src/descent/internal/compiler/parser/Parser.java (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/descent.core/src/descent/internal/codeassist/CompletionEngine.java
r870 r874 151 151 CharOperation.replace(sourceUnitFqn, '/', '.'); 152 152 153 CompletionParserparser = new CompletionParser(AST.D2, source);153 parser = new CompletionParser(AST.D2, source); 154 154 parser.filename = this.fileName; 155 155 parser.cursorLocation = completionPosition; … … 381 381 382 382 private void completeVersionCondition(CompletionOnVersionCondition node) { 383 // TODO For now, suggest the predefined versions. Later, visit the file384 // to see what other versions the user used, and also use the385 // versions defined in the UI (which doesn't exist yet)386 383 char[] name = node.ident == null ? CharOperation.NO_CHAR : node.ident; 387 384 this.startPosition = this.actualCompletionPosition - name.length; 388 385 this.endPosition = this.actualCompletionPosition; 386 387 // Suggest the versions found in the source file 388 HashtableOfCharArrayAndObject versions = parser.versions; 389 if (versions == null) { 390 versions = new HashtableOfCharArrayAndObject(); 391 } 392 393 // And also the predefined 389 394 for(char[] predefined : VersionCondition.resevered) { 390 if (CharOperation.prefixEquals(name, predefined, false) && !CharOperation.equals(name, predefined)) { 395 versions.put(predefined, this); 396 } 397 398 for(char[] id : versions.keys()) { 399 if (id == null) { 400 continue; 401 } 402 403 if (CharOperation.prefixEquals(name, id, false) && !CharOperation.equals(name, id)) { 391 404 CompletionProposal proposal = this.createProposal(CompletionProposal.KEYWORD, this.actualCompletionPosition); 392 proposal.setName( predefined);393 proposal.setCompletion( predefined);405 proposal.setName(id); 406 proposal.setCompletion(id); 394 407 proposal.setReplaceRange(this.startPosition - this.offset, this.endPosition - this.offset); 395 408 CompletionEngine.this.requestor.accept(proposal); trunk/descent.core/src/descent/internal/codeassist/complete/CompletionParser.java
r871 r874 12 12 import descent.internal.compiler.parser.Expression; 13 13 import descent.internal.compiler.parser.GotoStatement; 14 import descent.internal.compiler.parser.HashtableOfCharArrayAndObject; 14 15 import descent.internal.compiler.parser.IdentifierExp; 15 16 import descent.internal.compiler.parser.Identifiers; … … 21 22 import descent.internal.compiler.parser.TOK; 22 23 import descent.internal.compiler.parser.Type; 24 import descent.internal.compiler.parser.Version; 23 25 import descent.internal.compiler.parser.VersionCondition; 26 import descent.internal.compiler.parser.VersionSymbol; 24 27 25 28 public class CompletionParser extends Parser { … … 29 32 private List<ICompletionOnKeyword> keywordCompletions; 30 33 private boolean includeExpectations = true; 34 35 // Versions found in the source file: useful for suggesting a 36 // version identifier in a CompletionOnVersionCondition 37 public HashtableOfCharArrayAndObject versions; 31 38 32 39 public CompletionParser(int apiLevel, char[] source) { … … 154 161 @Override 155 162 protected VersionCondition newVersionCondition(Module module, Loc loc, long level, char[] id) { 156 if (inCompletion() && level == 1 && !(id != null && id.length == 1 && id[0] == '1')) { 163 boolean isId = level == 1 && !(id != null && id.length == 1 && id[0] == '1'); 164 if (isId && id != null) { 165 if (versions == null) { 166 versions = new HashtableOfCharArrayAndObject(); 167 } 168 versions.put(id, this); 169 } 170 171 if (inCompletion() && isId) { 157 172 includeExpectations = false; 158 173 … … 164 179 } 165 180 181 @Override 182 protected VersionSymbol newVersionSymbol(Loc loc, IdentifierExp id, Version version) { 183 if (id != null && id.ident != null) { 184 if (versions == null) { 185 versions = new HashtableOfCharArrayAndObject(); 186 } 187 versions.put(id.ident, this); 188 } 189 return super.newVersionSymbol(loc, id, version); 190 } 191 166 192 private boolean inCompletion() { 167 193 return prevToken.ptr + prevToken.sourceLen <= cursorLocation && cursorLocation <= token.ptr + token.sourceLen trunk/descent.core/src/descent/internal/compiler/SourceElementParser.java
r829 r874 998 998 999 999 public void endVisit(Import node) { 1000 if (!node.first) { 1001 return; 1002 } 1003 1000 1004 popLevelInAttribDeclarationStack(); 1001 1005 } trunk/descent.core/src/descent/internal/compiler/parser/Parser.java
r870 r874 1063 1063 idTokenLength = token.sourceLen; 1064 1064 1065 nextToken(); 1065 nextToken(); 1066 1066 c = newVersionCondition(module, loc, level, id); 1067 1067 check(TOKrparen); … … 1070 1070 1071 1071 c = newVersionCondition(module, loc, level, id); 1072 nextToken(); 1072 1073 // For improved syntax error recovery 1074 if (token.value != TOKrparen) { 1075 nextToken(); 1076 } 1077 nextToken(); 1073 1078 } 1074 1079 } else { … … 6740 6745 return new VersionSymbol(loc, token.intValue.longValue(), newVersionForCurrentToken()); 6741 6746 } else if (token.value == TOKidentifier) { 6742 return new VersionSymbol(loc, newIdentifierExp(), newVersionForCurrentToken());6747 return newVersionSymbol(loc, newIdentifierExp(), newVersionForCurrentToken()); 6743 6748 } else { 6744 6749 throw new RuntimeException("Can't happen"); 6745 6750 } 6746 6751 } 6747 6752 6748 6753 private VoidInitializer newVoidInitializerForToken(Token token) { 6749 6754 VoidInitializer voidInitializer = new VoidInitializer(loc); … … 6995 7000 } 6996 7001 7002 protected VersionSymbol newVersionSymbol(Loc loc, IdentifierExp id, Version version) { 7003 return new VersionSymbol(loc, id, version); 7004 } 7005 6997 7006 /** 6998 7007 * The parser expects the current token to be
