Changeset 874

Show
Ignore:
Timestamp:
10/22/07 17:58:09 (1 year ago)
Author:
asterite
Message:

- Fixed a bug relating multiple imports.
- Now versions already used or defined (version(X) { }, version = X;) in the file are used in the completion on version.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/descent.core/src/descent/internal/codeassist/CompletionEngine.java

    r870 r874  
    151151            CharOperation.replace(sourceUnitFqn, '/', '.'); 
    152152             
    153             CompletionParser parser = new CompletionParser(AST.D2, source); 
     153            parser = new CompletionParser(AST.D2, source); 
    154154            parser.filename = this.fileName; 
    155155            parser.cursorLocation = completionPosition; 
     
    381381     
    382382    private void completeVersionCondition(CompletionOnVersionCondition node) { 
    383         // TODO For now, suggest the predefined versions. Later, visit the file 
    384         // to see what other versions the user used, and also use the 
    385         // versions defined in the UI (which doesn't exist yet) 
    386383        char[] name = node.ident == null ? CharOperation.NO_CHAR : node.ident; 
    387384        this.startPosition = this.actualCompletionPosition - name.length; 
    388385        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 
    389394        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)) { 
    391404                CompletionProposal proposal = this.createProposal(CompletionProposal.KEYWORD, this.actualCompletionPosition); 
    392                 proposal.setName(predefined); 
    393                 proposal.setCompletion(predefined); 
     405                proposal.setName(id); 
     406                proposal.setCompletion(id); 
    394407                proposal.setReplaceRange(this.startPosition - this.offset, this.endPosition - this.offset); 
    395408                CompletionEngine.this.requestor.accept(proposal); 
  • trunk/descent.core/src/descent/internal/codeassist/complete/CompletionParser.java

    r871 r874  
    1212import descent.internal.compiler.parser.Expression; 
    1313import descent.internal.compiler.parser.GotoStatement; 
     14import descent.internal.compiler.parser.HashtableOfCharArrayAndObject; 
    1415import descent.internal.compiler.parser.IdentifierExp; 
    1516import descent.internal.compiler.parser.Identifiers; 
     
    2122import descent.internal.compiler.parser.TOK; 
    2223import descent.internal.compiler.parser.Type; 
     24import descent.internal.compiler.parser.Version; 
    2325import descent.internal.compiler.parser.VersionCondition; 
     26import descent.internal.compiler.parser.VersionSymbol; 
    2427 
    2528public class CompletionParser extends Parser { 
     
    2932    private List<ICompletionOnKeyword> keywordCompletions; 
    3033    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; 
    3138 
    3239    public CompletionParser(int apiLevel, char[] source) { 
     
    154161    @Override 
    155162    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) { 
    157172            includeExpectations = false; 
    158173             
     
    164179    } 
    165180     
     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     
    166192    private boolean inCompletion() { 
    167193        return prevToken.ptr + prevToken.sourceLen <= cursorLocation && cursorLocation <= token.ptr + token.sourceLen 
  • trunk/descent.core/src/descent/internal/compiler/SourceElementParser.java

    r829 r874  
    998998     
    999999    public void endVisit(Import node) { 
     1000        if (!node.first) { 
     1001            return; 
     1002        } 
     1003         
    10001004        popLevelInAttribDeclarationStack(); 
    10011005    } 
  • trunk/descent.core/src/descent/internal/compiler/parser/Parser.java

    r870 r874  
    10631063                idTokenLength = token.sourceLen; 
    10641064                 
    1065                 nextToken();            
     1065                nextToken(); 
    10661066                c = newVersionCondition(module, loc, level, id); 
    10671067                check(TOKrparen);                
     
    10701070                 
    10711071                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(); 
    10731078            }            
    10741079        } else { 
     
    67406745            return new VersionSymbol(loc, token.intValue.longValue(), newVersionForCurrentToken()); 
    67416746        } else if (token.value == TOKidentifier) { 
    6742             return new VersionSymbol(loc, newIdentifierExp(), newVersionForCurrentToken()); 
     6747            return newVersionSymbol(loc, newIdentifierExp(), newVersionForCurrentToken()); 
    67436748        } else { 
    67446749            throw new RuntimeException("Can't happen"); 
    67456750        } 
    67466751    } 
    6747      
     6752 
    67486753    private VoidInitializer newVoidInitializerForToken(Token token) { 
    67496754        VoidInitializer voidInitializer = new VoidInitializer(loc); 
     
    69957000    } 
    69967001     
     7002    protected VersionSymbol newVersionSymbol(Loc loc, IdentifierExp id, Version version) { 
     7003        return new VersionSymbol(loc, id, version); 
     7004    } 
     7005     
    69977006    /** 
    69987007     * The parser expects the current token to be