Changeset 1192

Show
Ignore:
Timestamp:
06/20/08 23:19:43 (2 months ago)
Author:
asterite
Message:

Implemented autocompletion for selective imports. Now some autocompletions just write out the name of it, without arguments: that is the case for selective imports and function pointers (if you write &foo and autocomplete, and foo has arguments, it won't write them anymore :-))

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/descent.core/src/descent/core/CompletionProposal.java

    r1131 r1192  
    19921992    } 
    19931993     
     1994    /** 
     1995     * Returns whether the proposal is intended to be written with 
     1996     * arguments or just the name of the proposal. 
     1997     */ 
     1998    @Override 
     1999    public boolean wantArguments() { 
     2000        return super.wantArguments(); 
     2001    } 
     2002     
    19942003    @Override 
    19952004    public String toString() { 
  • trunk/descent.core/src/descent/internal/codeassist/CompletionEngine.java

    r1189 r1192  
    269269    boolean isCompletingSuperCall = false; 
    270270    boolean isBetweenMethodName = false; 
     271    boolean wantArguments = true; 
    271272     
    272273    Scope rootScope; 
     
    444445                    !requestor.isIgnored(CompletionProposal.COMPILATION_UNIT_REF)) { 
    445446                CompletionOnImport node = (CompletionOnImport) assistNode; 
    446                 completeImport(node); 
     447                if (node.isSelective) { 
     448                    completeSelectiveImport(node); 
     449                } else { 
     450                    completeImport(node); 
     451                } 
    447452            } else if (assistNode instanceof CompletionOnArgumentName) { 
    448453                CompletionOnArgumentName node = (CompletionOnArgumentName) assistNode; 
     
    708713    } 
    709714     
     715    private void completeSelectiveImport(CompletionOnImport node) throws JavaModelException { 
     716        doSemantic(); 
     717         
     718        if (node.mod != null) { 
     719            if (node.selectiveName == null) { 
     720                this.startPosition = actualCompletionPosition; 
     721                this.endPosition = actualCompletionPosition; 
     722                this.currentName = CharOperation.NO_CHAR; 
     723            } else { 
     724                this.currentName = computePrefixAndSourceRange(node.selectiveName); 
     725            } 
     726            this.wantArguments = false; 
     727            suggestMembers(node.mod.members, false, new HashtableOfCharArrayAndObject(), INCLUDE_TYPES | INCLUDE_VARIABLES | INCLUDE_FUNCTIONS); 
     728        } 
     729    } 
     730     
    710731    private void completeImport(CompletionOnImport node) { 
    711732        char[] fqn = node.getFQN(); 
     
    23932414                                    CompletionProposal.METHOD_REF,  
    23942415                                this.actualCompletionPosition, func); 
     2416                     
     2417                    if (parser.isInAddrExp) { 
     2418                        proposal.wantArguments = false; 
     2419                    } 
    23952420                     
    23962421                    if (constructor || opCall) { 
     
    30113036        proposal.nameLookup = this.nameEnvironment.nameLookup; 
    30123037        proposal.completionEngine = this; 
     3038        proposal.wantArguments = this.wantArguments; 
    30133039        return proposal; 
    30143040    } 
     
    32393265         
    32403266        CompletionProposal proposal = this.createProposal(CompletionProposal.METHOD_REF, this.actualCompletionPosition, null); 
     3267         
     3268        if (parser.isInAddrExp) { 
     3269            proposal.wantArguments = false; 
     3270        } 
    32413271         
    32423272        int relevance = computeBaseRelevance(); 
     
    33073337                    return R_EXPECTED_TYPE; 
    33083338                } 
     3339            } else if (expectedType instanceof TypeDelegate) { 
     3340                if (type.covariant(expectedType.next, semanticContext) == 1) { 
     3341                    return R_EXPECTED_TYPE; 
     3342                } 
    33093343            } 
    33103344             
     
    33323366        } 
    33333367         
    3334         if (signature.length > 0 &&  
    3335                 (signature[0] == Signature.C_D_LINKAGE || signature[0] == Signature.C_C_LINKAGE || 
    3336                         signature[0] == Signature.C_CPP_LINKAGE || signature[0] == Signature.C_PASCAL_LINKAGE || 
    3337                         signature[0] == Signature.C_WINDOWS_LINKAGE)) { 
     3368        boolean isFunctionSignature = isFunctionSignature(signature); 
     3369         
     3370        if (CharOperation.equals(signature, expectedTypeSignature) || 
     3371                (expectedTypeSignature.length > 0 && expectedTypeSignature[0] == Signature.C_DELEGATE 
     3372                        && isFunctionSignature 
     3373                        && CharOperation.equals(signature, expectedTypeSignature, 1, expectedTypeSignature.length))) { 
     3374            return R_EXACT_EXPECTED_TYPE; 
     3375        } 
     3376         
     3377        if (isFunctionSignature) { 
    33383378            return computeRelevanceForExpectedType(Signature.getReturnType(signature)); 
    3339         } 
    3340          
    3341         if (CharOperation.equals(expectedTypeSignature, signature)) { 
    3342             return R_EXACT_EXPECTED_TYPE; 
    33433379        } 
    33443380         
     
    33723408    } 
    33733409 
     3410    private boolean isFunctionSignature(char[] signature) { 
     3411        return signature.length > 0 && signature[0] == Signature.C_D_LINKAGE || signature[0] == Signature.C_C_LINKAGE || 
     3412                signature[0] == Signature.C_CPP_LINKAGE || signature[0] == Signature.C_PASCAL_LINKAGE || 
     3413                signature[0] == Signature.C_WINDOWS_LINKAGE; 
     3414    } 
     3415 
    33743416    private boolean isImported(char[] fullyQualifiedName) { 
     3417        // This module is "imported" 
     3418        if (CharOperation.equals(fullyQualifiedName, this.sourceUnitFqn)) { 
     3419            return true; 
     3420        } 
     3421         
    33753422        if (module.aimports != null) { 
    33763423            for(Object sym : module.aimports) { 
  • trunk/descent.core/src/descent/internal/codeassist/InternalCompletionProposal.java

    r1131 r1192  
    5454    protected int declarationStart = -1; 
    5555    protected boolean isAlias; // Whether the proposal is an alias for another symbol 
     56    protected boolean wantArguments; // Whether the proposal is intended to be completed with arguments or just the name 
    5657     
    5758    protected char[][] createDefaultParameterNames(int length) { 
     
    167168    } 
    168169     
    169      
    170170    protected char[][] getParameterTypeNames() { 
    171171        return this.parameterTypeNames; 
    172172    } 
    173173     
     174    protected boolean wantArguments() { 
     175        return this.wantArguments; 
     176    } 
     177     
    174178    protected void setDeclarationPackageName(char[] declarationPackageName) { 
    175179        this.declarationPackageName = declarationPackageName; 
  • trunk/descent.core/src/descent/internal/codeassist/complete/CompletionOnImport.java

    r855 r1192  
    2626     
    2727    public int completePosition; 
     28    public boolean isSelective; 
     29    public IdentifierExp selectiveName; 
    2830 
    2931    public CompletionOnImport(Loc loc, Identifiers packages, IdentifierExp id, IdentifierExp aliasId, boolean isstatic, int completePosition) { 
  • trunk/descent.core/src/descent/internal/codeassist/complete/CompletionParser.java

    r1173 r1192  
    8686    public boolean inNewExp; 
    8787    public boolean isInExp; 
     88    public boolean isInAddrExp; 
    8889     
    8990    public char[] completionToken; 
     
    202203            return super.newImport(loc, packages, module, aliasid, isstatic); 
    203204        } 
     205    } 
     206     
     207    @Override 
     208    protected Import addImportAlias(Import s, IdentifierExp name, IdentifierExp alias) { 
     209        super.addImportAlias(s, name, alias); 
     210         
     211        if (alias != null  && alias.start <= cursorLocation && cursorLocation <= alias.start + alias.length) { 
     212            wantAssist = false; 
     213            wantKeywords = false; 
     214            return s; 
     215        } 
     216         
     217        if (prevToken.ptr <= cursorLocation && cursorLocation <= token.ptr) { 
     218            CompletionOnImport coi = new CompletionOnImport(s.loc, s.packages, s.id, s.aliasId, s.isstatic, cursorLocation); 
     219            if (name != null && name.start <= cursorLocation && cursorLocation <= name.start + name.length) { 
     220                coi.selectiveName = name; 
     221            } 
     222            coi.isSelective = true; 
     223            assistNode = coi; 
     224            wantKeywords = false; 
     225            return coi; 
     226        } 
     227         
     228        return s; 
    204229    } 
    205230 
     
    691716        } 
    692717        return super.newCondExp(loc, e, e1, e2); 
     718    } 
     719     
     720    @Override 
     721    protected Expression newAddrExp(Loc loc, Expression e) { 
     722        if (e == assistNode) { 
     723            isInAddrExp = true; 
     724        } 
     725        return super.newAddrExp(loc, e); 
    693726    } 
    694727     
  • trunk/descent.core/src/descent/internal/compiler/SourceElementParser.java

    r1173 r1192  
    524524        } 
    525525         
    526         requestor.enterConstructor(info); 
     526        if (node.isCtorDeclaration() == null && 
     527                node.isDtorDeclaration() == null && 
     528                node.isNewDeclaration() == null && 
     529                node.isDeleteDeclaration() == null && 
     530                node.isPostBlitDeclaration() == null) { 
     531            requestor.enterMethod(info); 
     532        } else { 
     533            requestor.enterConstructor(info); 
     534        } 
    527535        return true; 
    528536    } 
  • trunk/descent.core/src/descent/internal/compiler/parser/Parser.java

    r1173 r1192  
    22232223 
    22242224                // First, look ahead to see if it is a TypeParameter or a 
    2225                 // ValueParameter¿ 
     2225                // ValueParameterᅵ 
    22262226                 
    22272227                t = peek(token); 
     
    25952595                s.preComments = lastComments; 
    25962596                s.first = prev == null; 
    2597                 decldefs.add(s); 
     2597                //decldefs.add(s); 
    25982598                if (prev == null) { 
    25992599                    s.firstStart = start; 
     
    26132613 
    26142614                        if (token.value != TOKidentifier) { 
    2615                             parsingErrorInsertTokenAfter(prevToken, "Identifier"); 
     2615                            // Signal an empty alias added 
     2616                            s = addImportAlias(s, null, null); 
     2617                             
     2618                            parsingErrorInsertTokenAfter(prevToken, "Identifier");                           
     2619                             
     2620                            decldefs.add(s); 
    26162621                            break; 
    26172622                        } 
     
    26222627                            nextToken(); 
    26232628                            if (token.value != TOKidentifier) { 
     2629                                // Signal an empty alias added 
     2630                                s = addImportAlias(s, newIdentifierExp(), null); 
     2631                                 
    26242632                                parsingErrorInsertTokenAfter(prevToken, "Identifier"); 
     2633                                 
     2634                                decldefs.add(s); 
    26252635                                break; 
    26262636                            } 
     
    26312641                            alias = null; 
    26322642                        } 
    2633                         s.addAlias(name, alias); 
     2643                        s = addImportAlias(s, name, alias); 
     2644                        decldefs.add(s); 
    26342645                        s.setSourceRange(sStart, prevToken.ptr + prevToken.sourceLen - sStart); 
    26352646                    } while (token.value == TOKcomma); 
    26362647                    break; // no comma-separated imports of this form 
    26372648                } else { 
     2649                    decldefs.add(s); 
    26382650                    s.setSourceRange(sStart, prevToken.ptr + prevToken.sourceLen - sStart); 
    26392651                } 
     
    26522664    } 
    26532665     
     2666     
     2667 
    26542668    public Type parseType() { 
    26552669        return parseType(null, null); 
     
    66106624            nextToken(); 
    66116625            e = parseUnaryExp(); 
    6612             e = new AddrExp(loc(), e); 
     6626            e = newAddrExp(loc(), e); 
    66136627            break; 
    66146628 
     
    68326846 
    68336847        return e; 
    6834     } 
     6848    }   
    68356849 
    68366850    private void parsePrimaryExp_case_delegate(Expression[] e, TOK save, boolean isEmptySyntax) { 
     
    78957909    } 
    78967910     
     7911    protected Expression newAddrExp(Loc loc, Expression e) { 
     7912        return new AddrExp(loc, e); 
     7913    } 
     7914     
    78977915    protected VarDeclaration newVarDeclaration(Loc loc, Type type, IdentifierExp ident, Initializer init) { 
    78987916        return new VarDeclaration(loc, type, ident, init); 
     
    79337951    protected AggregateDeclaration endAggregateDeclaration(AggregateDeclaration a) { 
    79347952        return a; 
     7953    } 
     7954     
     7955    protected Import addImportAlias(Import s, IdentifierExp name, IdentifierExp alias) { 
     7956        if (name != null && alias != null) { 
     7957            s.addAlias(name, alias); 
     7958        } 
     7959        return s; 
    79357960    } 
    79367961     
  • trunk/descent.ui/src/descent/internal/ui/text/java/ExperimentalFunctionCallProposal.java

    r1132 r1192  
    8787     */ 
    8888    protected String computeReplacementString() { 
     89        if (!fProposal.wantArguments()) { 
     90            return new String(fProposal.getName()); 
     91        } 
    8992         
    90         if (!hasParameters() || !hasArgumentList()) 
     93        if (!hasParameters() || !hasArgumentList()) { 
    9194            return super.computeReplacementString(); 
     95        } 
    9296         
    9397        char[][] parameterTypes= Signature.getParameterTypes(fProposal.getTypeSignature()); 
  • trunk/descent.ui/src/descent/internal/ui/text/java/ExperimentalMethodProposal.java

    r1132 r1192  
    8686     */ 
    8787    protected String computeReplacementString() { 
     88        if (!fProposal.wantArguments()) { 
     89            return new String(fProposal.getName()); 
     90        } 
    8891         
    89         if (!hasParameters() || !hasArgumentList()) 
     92        if (!hasParameters() || !hasArgumentList()) { 
    9093            return super.computeReplacementString(); 
     94        } 
    9195         
    9296        char[][] parameterNames= fProposal.findParameterNames(null); 
  • trunk/descent.ui/src/descent/internal/ui/text/java/ExperimentalTemplateProposal.java

    r1132 r1192  
    8686     */ 
    8787    protected String computeReplacementString() { 
    88          
    89         if (!hasParameters() || !hasArgumentList()) 
    90             return super.computeReplacementString(); 
    91          
    92         char[][] parameterNames= fProposal.findTemplateParameterNames(null); 
    93         int count= parameterNames.length; 
    94         fArgumentOffsets= new int[count]; 
    95         fArgumentLengths= new int[count]; 
    96         StringBuffer buffer= new StringBuffer(String.valueOf(fProposal.getName())); 
    97          
    98         FormatterPrefs prefs= getFormatterPrefs(); 
    99         if (prefs.beforeOpeningParen) 
    100             buffer.append(SPACE); 
    101         buffer.append(EXCLAMATION); 
    102         buffer.append(LPAREN); 
    103          
    104         setCursorPosition(buffer.length()); 
    105          
    106         if (prefs.afterOpeningParen) 
    107             buffer.append(SPACE); 
    108          
    109         for (int i= 0; i != count; i++) { 
    110             if (i != 0) { 
    111                 if (prefs.beforeFunctionComma) 
    112                     buffer.append(SPACE); 
    113                 buffer.append(COMMA); 
    114                 if (prefs.afterFunctionComma) 
    115                     buffer.append(SPACE); 
     88        try { 
     89            if (!hasParameters() || !hasArgumentList()) 
     90                return super.computeReplacementString(); 
     91             
     92            char[][] parameterNames= fProposal.findTemplateParameterNames(null); 
     93            int count= parameterNames.length; 
     94            fArgumentOffsets= new int[count]; 
     95            fArgumentLengths= new int[count]; 
     96            StringBuffer buffer= new StringBuffer(String.valueOf(fProposal.getName())); 
     97             
     98            FormatterPrefs prefs= getFormatterPrefs(); 
     99            if (prefs.beforeOpeningParen) 
     100                buffer.append(SPACE); 
     101            buffer.append(EXCLAMATION); 
     102            buffer.append(LPAREN); 
     103             
     104            setCursorPosition(buffer.length()); 
     105             
     106            if (prefs.afterOpeningParen) 
     107                buffer.append(SPACE); 
     108             
     109            for (int i= 0; i != count; i++) { 
     110                if (i != 0) { 
     111                    if (prefs.beforeFunctionComma) 
     112                        buffer.append(SPACE); 
     113                    buffer.append(COMMA); 
     114                    if (prefs.afterFunctionComma) 
     115                        buffer.append(SPACE); 
     116                } 
     117                 
     118                fArgumentOffsets[i]= buffer.length(); 
     119                buffer.append(parameterNames[i]); 
     120                fArgumentLengths[i]= parameterNames[i].length; 
    116121            } 
    117122             
    118             fArgumentOffsets[i]= buffer.length(); 
    119             buffer.append(parameterNames[i]); 
    120             fArgumentLengths[i]= parameterNames[i].length; 
     123            if (prefs.beforeFunctionClosingParen) 
     124                buffer.append(SPACE); 
     125     
     126            buffer.append(RPAREN); 
     127     
     128            return buffer.toString(); 
     129        } finally { 
     130            if (!fProposal.wantArguments()) { 
     131                setCursorPosition(fProposal.getName().length); 
     132                return new String(fProposal.getName()); 
     133            } 
    121134        } 
    122          
    123         if (prefs.beforeFunctionClosingParen) 
    124             buffer.append(SPACE); 
    125  
    126         buffer.append(RPAREN); 
    127  
    128         return buffer.toString(); 
    129135    } 
    130136 
  • trunk/descent.ui/src/descent/internal/ui/text/java/ExperimentalTemplatedFunctionProposal.java

    r1132 r1192  
    9292     */ 
    9393    protected String computeReplacementString() { 
     94        try{ 
     95            if (!hasParameters() || !hasArgumentList()) { 
     96                return super.computeReplacementString(); 
     97            } 
    9498         
    95         if (!hasParameters() || !hasArgumentList()) 
    96             return super.computeReplacementString(); 
    97          
    98         char[][] tempParameterNames= fProposal.findTemplateParameterNames(null); 
    99         int tempCount= tempParameterNames.length; 
    100         fTempArgumentOffsets= new int[tempCount]; 
    101         fTempArgumentLengths= new int[tempCount]; 
    102          
    103         char[][] parameterNames= fProposal.findParameterNames(null); 
    104         int count= parameterNames.length; 
    105         fArgumentOffsets= new int[count]; 
    106         fArgumentLengths= new int[count]; 
    107          
    108         StringBuffer buffer= new StringBuffer(String.valueOf(fProposal.getName())); 
    109          
    110         FormatterPrefs prefs= getFormatterPrefs(); 
    111         if (prefs.beforeOpeningParen) 
    112             buffer.append(SPACE); 
    113         buffer.append(EXCLAMATION); 
    114         buffer.append(LPAREN); 
    115          
    116         if (tempCount > 0) { 
    117             setCursorPosition(buffer.length()); 
     99            char[][] tempParameterNames= fProposal.findTemplateParameterNames(null); 
     100            int tempCount= tempParameterNames.length; 
     101            fTempArgumentOffsets= new int[tempCount]; 
     102            fTempArgumentLengths= new int[tempCount]; 
     103             
     104            char[][] parameterNames= fProposal.findParameterNames(null); 
     105            int count= parameterNames.length; 
     106            fArgumentOffsets= new int[count]; 
     107            fArgumentLengths= new int[count]; 
     108             
     109            StringBuffer buffer= new StringBuffer(String.valueOf(fProposal.getName())); 
     110             
     111            FormatterPrefs prefs= getFormatterPrefs(); 
     112            if (prefs.beforeOpeningParen) 
     113                buffer.append(SPACE); 
     114            buffer.append(EXCLAMATION); 
     115            buffer.append(LPAREN); 
     116             
     117            if (tempCount > 0) { 
     118                setCursorPosition(buffer.length()); 
     119            } 
     120             
     121            if (prefs.afterOpeningParen) 
     122                buffer.append(SPACE); 
     123             
     124            for (int i= 0; i != tempCount; i++) { 
     125                if (i != 0) { 
     126                    if (prefs.beforeFunctionComma) 
     127                        buffer.append(SPACE); 
     128                    buffer.append(COMMA); 
     129                    if (prefs.afterFunctionComma) 
     130                        buffer.append(SPACE); 
     131                } 
     132                 
     133                fTempArgumentOffsets[i]= buffer.length(); 
     134                buffer.append(tempParameterNames[i]); 
     135                fTempArgumentLengths[i]= tempParameterNames[i].length; 
     136            } 
     137             
     138            if (prefs.beforeFunctionClosingParen) 
     139                buffer.append(SPACE); 
     140     
     141            buffer.append(RPAREN); 
     142             
     143            buffer.append(LPAREN); 
     144             
     145            if (tempCount == 0) { 
     146                setCursorPosition(buffer.length()); 
     147            } 
     148             
     149            if (prefs.afterOpeningParen) 
     150                buffer.append(SPACE); 
     151             
     152            for (int i= 0; i != count; i++) { 
     153                if (i != 0) { 
     154                    if (prefs.beforeFunctionComma) 
     155                        buffer.append(SPACE); 
     156                    buffer.append(COMMA); 
     157                    if (prefs.afterFunctionComma) 
     158                        buffer.append(SPACE); 
     159                } 
     160                 
     161                fArgumentOffsets[i]= buffer.length(); 
     162                buffer.append(parameterNames[i]); 
     163                fArgumentLengths[i]= parameterNames[i].length; 
     164            } 
     165             
     166            buffer.append(RPAREN); 
     167     
     168            return buffer.toString(); 
     169        } finally { 
     170            if (!fProposal.wantArguments()) { 
     171                setCursorPosition(fProposal.getName().length); 
     172                return new String(fProposal.getName()); 
     173            } 
    118174        } 
    119          
    120         if (prefs.afterOpeningParen) 
    121             buffer.append(SPACE); 
    122          
    123         for (int i= 0; i != tempCount; i++) { 
    124             if (i != 0) { 
    125                 if (prefs.beforeFunctionComma) 
    126                     buffer.append(SPACE); 
    127                 buffer.append(COMMA); 
    128                 if (prefs.afterFunctionComma) 
    129                     buffer.append(SPACE); 
    130             } 
    131              
    132             fTempArgumentOffsets[i]= buffer.length(); 
    133             buffer.append(tempParameterNames[i]); 
    134             fTempArgumentLengths[i]= tempParameterNames[i].length; 
    135         } 
    136          
    137         if (prefs.beforeFunctionClosingParen) 
    138             buffer.append(SPACE); 
    139  
    140         buffer.append(RPAREN); 
    141          
    142         buffer.append(LPAREN); 
    143          
    144         if (tempCount == 0) { 
    145             setCursorPosition(buffer.length()); 
    146         } 
    147          
    148         if (prefs.afterOpeningParen) 
    149             buffer.append(SPACE); 
    150          
    151         for (int i= 0; i != count; i++) { 
    152             if (i != 0) { 
    153                 if (prefs.beforeFunctionComma) 
    154                     buffer.append(SPACE); 
    155                 buffer.append(COMMA); 
    156                 if (prefs.afterFunctionComma) 
    157                     buffer.append(SPACE); 
    158             } 
    159              
    160             fArgumentOffsets[i]= buffer.length(); 
    161             buffer.append(parameterNames[i]); 
    162             fArgumentLengths[i]= parameterNames[i].length; 
    163         } 
    164          
    165         buffer.append(RPAREN); 
    166  
    167         return buffer.toString(); 
    168175    } 
    169176 
  • trunk/descent.ui/src/descent/internal/ui/text/java/JavaMethodCompletionProposal.java

    r1132 r1192  
    193193     */ 
    194194    protected String computeReplacementString() { 
    195         if (!hasArgumentList()) 
     195        if (!fProposal.wantArguments()) { 
     196            return new String(fProposal.getName()); 
     197        } 
     198         
     199        if (!hasArgumentList()) { 
    196200            return super.computeReplacementString(); 
     201        } 
    197202         
    198203        // we're inserting a method plus the argument list - respect formatter preferences 
  • trunk/descent.ui/src/descent/internal/ui/text/java/JavaTemplateCompletionProposal.java

    r1126 r1192  
    139139     */ 
    140140    protected String computeReplacementString() { 
    141         if (!hasArgumentList()) 
    142             return super.computeReplacementString(); 
    143          
    144         // we're inserting a method plus the argument list - respect formatter preferences 
    145         StringBuffer buffer= new StringBuffer(); 
    146         buffer.append(fProposal.getName()); 
    147  
    148         FormatterPrefs prefs= getFormatterPrefs(); 
    149         if (prefs.beforeOpeningParen) 
    150             buffer.append(SPACE); 
    151         buffer.append(EXCLAMATION); 
    152         buffer.append(LPAREN); 
    153          
    154         if (hasParameters()) { 
    155             setCursorPosition(buffer.length()); 
     141        try { 
     142            if (!hasArgumentList()) { 
     143                return super.computeReplacementString(); 
     144            } 
    156145             
    157             if (prefs.afterOpeningParen) 
     146            // we're inserting a method plus the argument list - respect formatter preferences 
     147            StringBuffer buffer= new StringBuffer(); 
     148            buffer.append(fProposal.getName()); 
     149     
     150            FormatterPrefs prefs= getFormatterPrefs(); 
     151            if (prefs.beforeOpeningParen) 
    158152                buffer.append(SPACE); 
     153            buffer.append(EXCLAMATION); 
     154            buffer.append(LPAREN); 
    159155             
    160  
    161             // don't add the trailing space, but let the user type it in himself - typing the closing paren will exit 
    162 //          if (prefs.beforeClosingParen) 
    163 //              buffer.append(SPACE); 
    164         } else { 
    165             if (prefs.inEmptyList) 
    166                 buffer.append(SPACE); 
    167         } 
    168  
    169         buffer.append(RPAREN); 
    170  
    171         return buffer.toString(); 
     156            if (hasParameters()) { 
     157                setCursorPosition(buffer.length()); 
     158                 
     159                if (prefs.afterOpeningParen) 
     160                    buffer.append(SPACE); 
     161                 
     162     
     163                // don't add the trailing space, but let the user type it in himself - typing the closing paren will exit 
     164    //          if (prefs.beforeClosingParen) 
     165    //              buffer.append(SPACE); 
     166            } else { 
     167                if (prefs.inEmptyList) 
     168                    buffer.append(SPACE); 
     169            } 
     170     
     171            buffer.append(RPAREN); 
     172     
     173            return buffer.toString(); 
     174        } finally { 
     175            if (!fProposal.wantArguments()) { 
     176                setCursorPosition(fProposal.getName().length); 
     177                return new String(fProposal.getName()); 
     178            } 
     179        } 
    172180    } 
    173181     
  • trunk/descent.ui/src/descent/internal/ui/text/java/JavaTemplatedFunctionCompletionProposal.java

    r1126 r1192  
    153153     */ 
    154154    protected String computeReplacementString() { 
    155         if (!hasArgumentList()) 
    156             return super.computeReplacementString(); 
    157          
    158         // we're inserting a method plus the argument list - respect formatter preferences 
    159         StringBuffer buffer= new StringBuffer(); 
    160         buffer.append(fProposal.getName()); 
    161  
    162         FormatterPrefs prefs= getFormatterPrefs(); 
    163         if (prefs.beforeOpeningParen) 
    164             buffer.append(SPACE); 
    165         buffer.append(EXCLAMATION); 
    166         buffer.append(LPAREN); 
    167          
    168         if (hasTemplateParameters()) { 
    169             setCursorPosition(buffer.length()); 
     155        try { 
     156            if (!hasArgumentList()) { 
     157                return super.computeReplacementString(); 
     158            } 
    170159             
    171             if (prefs.afterOpeningParen) 
     160            // we're inserting a method plus the argument list - respect formatter preferences 
     161            StringBuffer buffer= new StringBuffer(); 
     162            buffer.append(fProposal.getName()); 
     163     
     164            FormatterPrefs prefs= getFormatterPrefs(); 
     165            if (prefs.beforeOpeningParen) 
    172166                buffer.append(SPACE); 
     167            buffer.append(EXCLAMATION); 
     168            buffer.append(LPAREN); 
    173169             
    174  
    175             // don't add the trailing space, but let the user type it in himself - typing the closing paren will exit 
    176 //          if (prefs.beforeClosingParen) 
    177 //              buffer.append(SPACE); 
    178         } else { 
    179             if (prefs.inEmptyList) 
    180                 buffer.append(SPACE); 
    181         } 
    182         buffer.append(RPAREN); 
    183          
    184         buffer.append(LPAREN); 
    185         if (hasParameters()) { 
    186             if (!hasTemplateParameters()) { 
     170            if (hasTemplateParameters()) { 
    187171                setCursorPosition(buffer.length()); 
    188             } 
     172                 
     173                if (prefs.afterOpeningParen) 
     174                    buffer.append(SPACE); 
     175                 
     176     
     177                // don't add the trailing space, but let the user type it in himself - typing the closing paren will exit 
     178    //          if (prefs.beforeClosingParen) 
     179    //              buffer.append(SPACE); 
     180            } else { 
     181                if (prefs.inEmptyList) 
     182                    buffer.append(SPACE); 
     183            } 
     184            buffer.append(RPAREN); 
    189185             
    190             if (prefs.afterOpeningParen) 
    191                 buffer.append(SPACE); 
    192              
    193  
    194             // don't add the trailing space, but let the user type it in himself - typing the closing paren will exit 
    195 //          if (prefs.beforeClosingParen) 
    196 //              buffer.append(SPACE); 
    197         } else { 
    198             if (prefs.inEmptyList) 
    199                 buffer.append(SPACE); 
    200         } 
    201         buffer.append(RPAREN); 
    202  
    203         return buffer.toString(); 
     186            buffer.append(LPAREN); 
     187            if (hasParameters()) { 
     188                if (!hasTemplateParameters()) { 
     189                    setCursorPosition(buffer.length()); 
     190                } 
     191                 
     192                if (prefs.afterOpeningParen) 
     193                    buffer.append(SPACE); 
     194                 
     195     
     196                // don't add the trailing space, but let the user type it in himself - typing the closing paren will exit 
     197    //          if (prefs.beforeClosingParen) 
     198    //              buffer.append(SPACE); 
     199            } else { 
     200                if (prefs.inEmptyList) 
     201                    buffer.append(SPACE); 
     202            } 
     203            buffer.append(RPAREN); 
     204     
     205            return buffer.toString(); 
     206        } finally { 
     207            if (!fProposal.wantArguments()) { 
     208                setCursorPosition(fProposal.getName().length); 
     209                return new String(fProposal.getName()); 
     210            } 
     211        } 
    204212    } 
    205213