Changeset 1148

Show
Ignore:
Timestamp:
05/01/08 13:29:14 (8 months ago)
Author:
asterite
Message:

More small improvements. Hack for a horrible problem.

Files:

Legend:

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

    r1146 r1148  
    130130 *     | "|"  // interface 
    131131 *     | "E"  // enum 
    132  *     | "/"  // variable 
     132 *     | "¡"  // variable 
    133133 *     | "="  // alias 
    134134 *     | "T"  // typedef 
     
    485485    /** 
    486486     * Character constant indicating a variable in a signature. 
    487      * Value is <code>'/'</code>. 
    488      */ 
    489     public static final char C_VARIABLE                                 = '/'; 
     487     * Value is <code>'¡'</code>. 
     488     */ 
     489    public static final char C_VARIABLE                                 = '¡'; 
    490490     
    491491    /** 
  • trunk/descent.core/src/descent/internal/codeassist/CompletionEngine.java

    r1147 r1148  
    225225    } 
    226226     
     227    char[] parenthesis = { '(', ')' }; 
     228     
    227229    IJavaProject javaProject; 
    228230    CompletionParser parser; 
     
    720722        } 
    721723         
    722         nameEnvironment.findCompilationUnits(fqnBeforeCursor, this); 
     724        if (fqnBeforeCursor.length > 0) { 
     725            nameEnvironment.findCompilationUnits(fqnBeforeCursor, this); 
     726        } 
    723727    } 
    724728     
     
    10361040            // Also suggest packages 
    10371041            isCompletingPackage = true; 
    1038             nameEnvironment.findCompilationUnits(currentName, this); 
     1042            if (currentName.length > 0) { 
     1043                nameEnvironment.findCompilationUnits(currentName, this); 
     1044            } 
    10391045             
    10401046            // And top level declarations 
    1041             nameEnvironment.findPrefixDeclarations(currentName, false, options.camelCaseMatch, this); 
     1047            if (currentName.length > 0) { 
     1048                nameEnvironment.findPrefixDeclarations(currentName, false, options.camelCaseMatch, this); 
     1049            } 
    10421050             
    10431051            // Show constructors and opCalls 
     
    11881196        // Also suggest packages 
    11891197        isCompletingPackage = true; 
    1190         nameEnvironment.findCompilationUnits(currentName, this); 
     1198        if (currentName.length > 0) { 
     1199            nameEnvironment.findCompilationUnits(currentName, this); 
     1200        } 
    11911201         
    11921202        // And top level declarations 
    1193         nameEnvironment.findPrefixDeclarations(currentName, false, options.camelCaseMatch, this); 
     1203        if (currentName.length > 0) { 
     1204            nameEnvironment.findPrefixDeclarations(currentName, false, options.camelCaseMatch, this); 
     1205        } 
    11941206    } 
    11951207     
     
    11991211        if (node.dot == -1) { 
    12001212            currentName = computePrefixAndSourceRange(node); 
     1213            isBetweenMethodName = node.resolvedSymbol != null; 
    12011214             
    12021215            if (rootScope == null) { 
     
    12081221            // Also suggest packages 
    12091222            isCompletingPackage = true; 
    1210             nameEnvironment.findCompilationUnits(currentName, this); 
     1223             
     1224            if (currentName.length > 0) { 
     1225                nameEnvironment.findCompilationUnits(currentName, this); 
     1226            } 
    12111227             
    12121228            // And top level declarations 
    1213             nameEnvironment.findPrefixDeclarations(currentName, false, options.camelCaseMatch, this); 
     1229            if (currentName.length > 0) { 
     1230                nameEnvironment.findPrefixDeclarations(currentName, false, options.camelCaseMatch, this); 
     1231            } 
    12141232             
    12151233            // Show constructors and opCalls 
     
    15681586         
    15691587        isCompletingPackage = true; 
    1570         nameEnvironment.findCompilationUnits(fqn, this); 
     1588        if (fqn.length > 0) { 
     1589            nameEnvironment.findCompilationUnits(fqn, this); 
     1590        } 
    15711591    } 
    15721592 
     
    16671687            proposal.setCompletion(CharOperation.NO_CHAR); 
    16681688        } else { 
    1669             if (!isBetweenMethodName && parser.completionTokenEnd == this.actualCompletionPosition) { 
    1670                 proposal.setCompletion(CharOperation.concat(currentName, "()".toCharArray())); 
    1671             } else { 
    1672                 proposal.setCompletion(currentName); 
    1673             } 
     1689            handleMethodCompletion(proposal, currentName); 
    16741690        } 
    16751691         
     
    23052321                            handleContextInfo(func, funcNameIsOpCall, proposal); 
    23062322                        } else { 
    2307                             if (!isBetweenMethodName && parser.completionTokenEnd == this.actualCompletionPosition) { 
    2308                                 proposal.setCompletion(CharOperation.concat(currentName, "()".toCharArray())); 
    2309                             } else { 
    2310                                 proposal.setCompletion(currentName); 
    2311                             } 
     2323                            handleMethodCompletion(proposal, currentName); 
    23122324                        } 
    23132325                    } else { 
     
    23162328                            handleContextInfo(func, funcNameIsOpCall, proposal); 
    23172329                        } else { 
    2318                             if (!isBetweenMethodName && parser.completionTokenEnd == this.actualCompletionPosition) { 
    2319                                 proposal.setCompletion(CharOperation.concat(ident, "()".toCharArray())); 
    2320                             } else { 
    2321                                 proposal.setCompletion(ident); 
    2322                             } 
     2330                            handleMethodCompletion(proposal, ident);                             
    23232331                        } 
    23242332                    } 
     
    23512359    } 
    23522360     
     2361    private void handleMethodCompletion(CompletionProposal proposal, char[] ident) { 
     2362        if (isBetweenMethodName) { 
     2363            if (parser.completionToken != null && parser.completionTokenEnd == actualCompletionPosition) { 
     2364                proposal.setCompletion(CharOperation.concat(ident, parenthesis)); 
     2365            } else { 
     2366                proposal.setCompletion(ident); 
     2367            } 
     2368        } else { 
     2369            proposal.setCompletion(CharOperation.concat(ident, parenthesis)); 
     2370        } 
     2371    } 
     2372 
    23532373    private void handleContextInfo(FuncDeclaration func, boolean funcNameIsOpCall, CompletionProposal proposal) { 
    23542374        proposal.setCompletion(CharOperation.NO_CHAR); 
     
    31473167        relevance += R_METHOD; 
    31483168         
    3149         proposal.setCompletion(CharOperation.concat(fullName, "".toCharArray())); 
     3169        handleMethodCompletion(proposal, fullName); 
    31503170         
    31513171        proposal.setName(name); 
  • trunk/descent.core/src/descent/internal/compiler/parser/ASTNodeEncoder.java

    r1141 r1148  
    1111public class ASTNodeEncoder { 
    1212     
    13 // private final static char INTEGER_EXP = '='
    14 // private final static char IDENTIFIER_EXP = '?'
     13   private char[] nastyChar = { '/' }
     14   private char[] nastyCharSoltuion = { '*', '!', '_', '!', '*' }
    1515     
    1616    private Parser parser; 
     
    2929    } 
    3030     
     31    // TODO horrible hack: the indexer may get consufed if the expression has 
     32    // the '/' character in it, so replace it with some very improbable 
     33    // string, and then replace it back later 
     34     
     35    private char[] encoderForIndexer(char[] value) { 
     36        if (CharOperation.indexOf('/', value) != -1) { 
     37            return CharOperation.replace(value, nastyChar, nastyCharSoltuion); 
     38        } else { 
     39            return value; 
     40        } 
     41    } 
     42     
     43    private char[] decodeForIndexer(char[] value) { 
     44        if (CharOperation.indexOf(nastyCharSoltuion, value, false) != -1) { 
     45            return CharOperation.replace(value, nastyCharSoltuion, nastyChar); 
     46        } else { 
     47            return value; 
     48        } 
     49    } 
     50     
    3151    public char[] encodeExpression(Expression value) { 
    3252        if (value == null) { 
     
    3454        } 
    3555         
    36         // Optimize for IntegerExp and IdentifierExp, which are the most common cases 
    37 //      if (value instanceof IntegerExp) { 
    38 //          StringBuilder sb = new StringBuilder(); 
    39 //          sb.append(INTEGER_EXP); 
    40 //          sb.append(((IntegerExp) value).value.toString()); 
    41 //          return sb.toString().toCharArray(); 
    42 //      } else if (value instanceof IdentifierExp) { 
    43 //          StringBuilder sb = new StringBuilder(); 
    44 //          sb.append(IDENTIFIER_EXP); 
    45 //          sb.append(((IdentifierExp) value).ident); 
    46 //          return sb.toString().toCharArray(); 
    47 //      } else { 
    48             return value.toString().toCharArray(); 
    49 //      } 
     56        char[] result = value.toString().toCharArray(); 
     57        return encoderForIndexer(result); 
    5058    } 
    5159     
     
    5563        } 
    5664         
    57         // Optimize for IntegerExp and IdentifierExp, which are the most common cases 
    58 //      if (value[0] == INTEGER_EXP) { 
    59 //          return new IntegerExp(Loc.ZERO, new integer_t(new BigInteger(new String(value, 1, value.length - 1)))); 
    60 //      } else if (value[0] == IDENTIFIER_EXP) { 
    61 //          return new IdentifierExp(CharOperation.subarray(value, 1, value.length)); 
    62 //      } 
     65        value = decodeForIndexer(value); 
    6366         
    6467        return initParser(value).parseExpression(); 
     
    7477        } 
    7578         
    76         return init.toString().toCharArray(); 
     79        char[] result = init.toString().toCharArray(); 
     80        return encoderForIndexer(result); 
    7781    } 
    7882     
     
    8892        } 
    8993         
    90         // Optimize for IntegerExp and IdentifierExp, which are the most common cases 
    91 //      if (value[0] == INTEGER_EXP || value[0] == IDENTIFIER_EXP) { 
    92 //          return new ExpInitializer(Loc.ZERO, decodeExpression(value)); 
    93 //      } 
     94        value = decodeForIndexer(value); 
    9495 
    9596        return initParser(value).parseInitializer(); 
  • trunk/descent.core/src/descent/internal/compiler/parser/ISignatureConstants.java

    r1092 r1148  
    1313    char ENUM = 'E'; 
    1414    char ENUM_MEMBER = '~'; 
    15     char VARIABLE = '/'; 
     15    char VARIABLE = '¡'; 
    1616    char ALIAS = '='; 
    1717    char TYPEDEF = 'T'; 
  • trunk/descent.core/src/descent/internal/core/search/matching/FieldPattern.java

    r1145 r1148  
    167167        this.declarationStart = -1; 
    168168    } else { 
    169         slash = CharOperation.indexOf(SEPARATOR, key, start); 
    170         // TODO optimize this 
    171         this.declarationStart = Integer.parseInt(new String(CharOperation.subarray(key, start, slash))); 
     169        this.declarationStart = 0; 
     170        for (; key[start] != SEPARATOR; start++) { 
     171            declarationStart = 10 * declarationStart + (key[start] - '0'); 
     172        } 
     173        slash = start; 
    172174    } 
    173175 
  • trunk/descent.core/src/descent/internal/core/search/matching/MethodPattern.java

    r1132 r1148  
    166166        this.declarationStart = -1; 
    167167    } else { 
    168         slash = CharOperation.indexOf(SEPARATOR, key, start); 
    169         // TODO optimize this 
    170         this.declarationStart = Integer.parseInt(new String(CharOperation.subarray(key, start, slash))); 
     168        this.declarationStart = 0; 
     169        for (; key[start] != SEPARATOR; start++) { 
     170            declarationStart = 10 * declarationStart + (key[start] - '0'); 
     171        } 
     172        slash = start; 
    171173    } 
    172174     
  • trunk/descent.core/src/descent/internal/core/search/matching/TypeDeclarationPattern.java

    r1132 r1148  
    198198        this.declarationStart = -1; 
    199199    } else { 
    200         slash = CharOperation.indexOf(SEPARATOR, key, start); 
    201         // TODO optimize this 
    202         this.declarationStart = Integer.parseInt(new String(CharOperation.subarray(key, start, slash))); 
     200        this.declarationStart = 0; 
     201        for (; key[start] != SEPARATOR; start++) { 
     202            declarationStart = 10 * declarationStart + (key[start] - '0'); 
     203        } 
     204        slash = start; 
    203205    } 
    204206 
  • trunk/descent.ui/src/descent/internal/ui/text/java/LazyJavaMethodCompletionProposal.java

    r1147 r1148  
    116116         
    117117        if (!hasParameters() || !hasArgumentList()) { 
    118             setCursorPosition(replacement.length() + (getVariadic() != IMethod.VARARGS_NO ? 1 : 2)); 
    119 //          if (replacement.length() > 0) { 
    120 //              return replacement + "()"; //$NON-NLS-1$ 
    121 //          } else { 
     118            if (fProposal.getCompletion().length > 0 && fProposal.getCompletion()[fProposal.getCompletion().length - 1] == ')') { 
     119                return replacement + "()"; //$NON-NLS-1$ 
     120            } else { 
     121                boolean variadic = getVariadic() != IMethod.VARARGS_NO; 
     122                setCursorPosition(replacement.length() + (variadic ? 1 : 2)); 
    122123                return replacement; 
    123 //            } 
     124          } 
    124125        } 
    125126         
     
    377378            } else { 
    378379                // Before the last ) 
    379                 fSelectedRegion= new Region(baseOffset + replacement.length() + offsetAdded - (getVariadic() != IMethod.VARARGS_NO ? 1 : 0), 0); 
     380                fSelectedRegion= new Region(baseOffset + replacement.length() + offsetAdded - (replacement.endsWith(")") && getVariadic() != IMethod.VARARGS_NO ? 1 : 0), 0); //$NON-NLS-1$ 
    380381            } 
    381382