List of usage examples for org.eclipse.jdt.core.compiler CharOperation concat
public static final char[] concat(char prefix, char[] array, char suffix)
From source file:com.codenvy.ide.ext.java.server.core.search.SearchPattern.java
License:Open Source License
/** * Returns a search pattern based on a given Java element. * The pattern is used to trigger the appropriate search, and can be parameterized as follows: * * @param element the Java element the search pattern is based on * @param limitTo determines the nature of the expected matches * <ul>/*from w ww . j a v a2 s.c o m*/ * <li>{@link IJavaSearchConstants#DECLARATIONS DECLARATIONS}: will search declarations matching * with the corresponding element. In case the element is a method, declarations of matching * methods in sub-types will also be found, allowing to find declarations of abstract methods, etc. * Some additional flags may be specified while searching declaration: * <ul> * <li>{@link IJavaSearchConstants#IGNORE_DECLARING_TYPE IGNORE_DECLARING_TYPE}: declaring type will be ignored * during the search.<br> * For example using following test case: * <pre> * class A { A method() { return null; } } * class B extends A { B method() { return null; } } * class C { A method() { return null; } } * </pre> * search for <code>method</code> declaration with this flag * will return 2 matches: in A and in C * </li> * <li>{@link IJavaSearchConstants#IGNORE_RETURN_TYPE IGNORE_RETURN_TYPE}: return type will be ignored * during the search.<br> * Using same example, search for <code>method</code> declaration with this flag * will return 2 matches: in A and in B. * </li> * </ul> * Note that these two flags may be combined and both declaring and return types can be ignored * during the search. Then, using same example, search for <code>method</code> declaration * with these 2 flags will return 3 matches: in A, in B and in C * </li> * <li>{@link IJavaSearchConstants#REFERENCES REFERENCES}: will search references to the given element.</li> * <li>{@link IJavaSearchConstants#ALL_OCCURRENCES ALL_OCCURRENCES}: will search for either declarations or * references as specified above. * </li> * <li>All other fine grain constants defined in the <b>limitTo</b> category * of the {@link IJavaSearchConstants} are also accepted nature: * <table border=0> * <tr> * <th align=left>Fine grain constant * <th align=left>Meaning * <tr> * <td>{@link IJavaSearchConstants#FIELD_DECLARATION_TYPE_REFERENCE FIELD_DECLARATION_TYPE_REFERENCE} * <td>Return only type references used as the type of a field declaration. * <tr> * <td>{@link IJavaSearchConstants#LOCAL_VARIABLE_DECLARATION_TYPE_REFERENCE LOCAL_VARIABLE_DECLARATION_TYPE_REFERENCE} * <td>Return only type references used as the type of a local variable declaration. * <tr> * <td>{@link IJavaSearchConstants#PARAMETER_DECLARATION_TYPE_REFERENCE PARAMETER_DECLARATION_TYPE_REFERENCE} * <td>Return only type references used as the type of a method parameter declaration. * <tr> * <td>{@link IJavaSearchConstants#SUPERTYPE_TYPE_REFERENCE SUPERTYPE_TYPE_REFERENCE} * <td>Return only type references used as a super type or as a super interface. * <tr> * <td>{@link IJavaSearchConstants#THROWS_CLAUSE_TYPE_REFERENCE THROWS_CLAUSE_TYPE_REFERENCE} * <td>Return only type references used in a throws clause. * <tr> * <td>{@link IJavaSearchConstants#CAST_TYPE_REFERENCE CAST_TYPE_REFERENCE} * <td>Return only type references used in a cast expression. * <tr> * <td>{@link IJavaSearchConstants#CATCH_TYPE_REFERENCE CATCH_TYPE_REFERENCE} * <td>Return only type references used in a catch header. * <tr> * <td>{@link IJavaSearchConstants#CLASS_INSTANCE_CREATION_TYPE_REFERENCE CLASS_INSTANCE_CREATION_TYPE_REFERENCE} * <td>Return only type references used in class instance creation. * <tr> * <td>{@link IJavaSearchConstants#RETURN_TYPE_REFERENCE RETURN_TYPE_REFERENCE} * <td>Return only type references used as a method return type. * <tr> * <td>{@link IJavaSearchConstants#IMPORT_DECLARATION_TYPE_REFERENCE IMPORT_DECLARATION_TYPE_REFERENCE} * <td>Return only type references used in an import declaration. * <tr> * <td>{@link IJavaSearchConstants#ANNOTATION_TYPE_REFERENCE ANNOTATION_TYPE_REFERENCE} * <td>Return only type references used as an annotation. * <tr> * <td>{@link IJavaSearchConstants#TYPE_ARGUMENT_TYPE_REFERENCE TYPE_ARGUMENT_TYPE_REFERENCE} * <td>Return only type references used as a type argument in a parameterized type or a parameterized method. * <tr> * <td>{@link IJavaSearchConstants#TYPE_VARIABLE_BOUND_TYPE_REFERENCE TYPE_VARIABLE_BOUND_TYPE_REFERENCE} * <td>Return only type references used as a type variable bound. * <tr> * <td>{@link IJavaSearchConstants#WILDCARD_BOUND_TYPE_REFERENCE WILDCARD_BOUND_TYPE_REFERENCE} * <td>Return only type references used as a wildcard bound. * <tr> * <td>{@link IJavaSearchConstants#INSTANCEOF_TYPE_REFERENCE INSTANCEOF_TYPE_REFERENCE} * <td>Return only type references used as a type of an <code>instanceof</code> expression. * <tr> * <td>{@link IJavaSearchConstants#SUPER_REFERENCE SUPER_REFERENCE} * <td>Return only super field accesses or super method invocations (e.g. using the <code>super</code> qualifier). * <tr> * <td>{@link IJavaSearchConstants#QUALIFIED_REFERENCE QUALIFIED_REFERENCE} * <td>Return only qualified field accesses or qualified method invocations. * <tr> * <td>{@link IJavaSearchConstants#THIS_REFERENCE THIS_REFERENCE} * <td>Return only primary field accesses or primary method invocations (e.g. using the <code>this</code> qualifier). * <tr> * <td>{@link IJavaSearchConstants#IMPLICIT_THIS_REFERENCE IMPLICIT_THIS_REFERENCE} * <td>Return only field accesses or method invocations without any qualification. * </table> * </li> * </ul> * @param matchRule one of the following match rules: * <ul> * <li>{@link #R_EXACT_MATCH}</li> * <li>{@link #R_PREFIX_MATCH}</li> * <li>{@link #R_PATTERN_MATCH}</li> * <li>{@link #R_CAMELCASE_MATCH}</li> * <li>{@link #R_CAMELCASE_SAME_PART_COUNT_MATCH}</li> * </ul> * , which may be also combined with one of the following flags: * <ul> * <li>{@link #R_CASE_SENSITIVE}</li> * <li>{@link #R_ERASURE_MATCH}</li> * <li>{@link #R_EQUIVALENT_MATCH}</li> * </ul> * For example, * <ul> * <li>{@link #R_EXACT_MATCH} | {@link #R_CASE_SENSITIVE}: if an exact * and case sensitive match is requested,</li> * <li>{@link #R_PREFIX_MATCH} if a case insensitive prefix match is requested</li> * <li>{@link #R_EXACT_MATCH} | {@link #R_ERASURE_MATCH}: if a case * insensitive and erasure match is requested.</li> * </ul> * Note that {@link #R_ERASURE_MATCH} or {@link #R_EQUIVALENT_MATCH} has no effect * on non-generic types/methods search. * <p> * Note also that default behavior for generic types/methods search is to find exact matches. * @return a search pattern for a Java element or <code>null</code> if the given element is ill-formed * @since 3.1 */ public static SearchPattern createPattern(IJavaElement element, int limitTo, int matchRule) { SearchPattern searchPattern = null; int lastDot; boolean ignoreDeclaringType = false; boolean ignoreReturnType = false; int maskedLimitTo = limitTo & ~(IJavaSearchConstants.IGNORE_DECLARING_TYPE + IJavaSearchConstants.IGNORE_RETURN_TYPE); if (maskedLimitTo == IJavaSearchConstants.DECLARATIONS || maskedLimitTo == IJavaSearchConstants.ALL_OCCURRENCES) { ignoreDeclaringType = (limitTo & IJavaSearchConstants.IGNORE_DECLARING_TYPE) != 0; ignoreReturnType = (limitTo & IJavaSearchConstants.IGNORE_RETURN_TYPE) != 0; } if ((matchRule = validateMatchRule(null, matchRule)) == -1) { return null; } char[] declaringSimpleName = null; char[] declaringQualification = null; switch (element.getElementType()) { case IJavaElement.FIELD: IField field = (IField) element; if (!ignoreDeclaringType) { IType declaringClass = field.getDeclaringType(); declaringSimpleName = declaringClass.getElementName().toCharArray(); declaringQualification = declaringClass.getPackageFragment().getElementName().toCharArray(); char[][] enclosingNames = enclosingTypeNames(declaringClass); if (enclosingNames.length > 0) { declaringQualification = CharOperation.concat(declaringQualification, CharOperation.concatWith(enclosingNames, '.'), '.'); } } char[] name = field.getElementName().toCharArray(); char[] typeSimpleName = null; char[] typeQualification = null; String typeSignature = null; if (!ignoreReturnType) { try { typeSignature = field.getTypeSignature(); char[] signature = typeSignature.toCharArray(); char[] typeErasure = Signature.toCharArray(Signature.getTypeErasure(signature)); CharOperation.replace(typeErasure, '$', '.'); if ((lastDot = CharOperation.lastIndexOf('.', typeErasure)) == -1) { typeSimpleName = typeErasure; } else { typeSimpleName = CharOperation.subarray(typeErasure, lastDot + 1, typeErasure.length); typeQualification = CharOperation.subarray(typeErasure, 0, lastDot); if (!field.isBinary()) { // prefix with a '*' as the full qualification could be bigger (because of an import) typeQualification = CharOperation.concat(IIndexConstants.ONE_STAR, typeQualification); } } } catch (JavaModelException e) { return null; } } // Create field pattern searchPattern = new FieldPattern(name, declaringQualification, declaringSimpleName, typeQualification, typeSimpleName, typeSignature, limitTo, matchRule); break; case IJavaElement.IMPORT_DECLARATION: String elementName = element.getElementName(); lastDot = elementName.lastIndexOf('.'); if (lastDot == -1) return null; // invalid import declaration IImportDeclaration importDecl = (IImportDeclaration) element; if (importDecl.isOnDemand()) { searchPattern = createPackagePattern(elementName.substring(0, lastDot), maskedLimitTo, matchRule); } else { searchPattern = createTypePattern(elementName.substring(lastDot + 1).toCharArray(), elementName.substring(0, lastDot).toCharArray(), null, null, null, maskedLimitTo, matchRule); } break; case IJavaElement.LOCAL_VARIABLE: LocalVariable localVar = (LocalVariable) element; searchPattern = new LocalVariablePattern(localVar, limitTo, matchRule); break; case IJavaElement.TYPE_PARAMETER: ITypeParameter typeParam = (ITypeParameter) element; boolean findParamDeclarations = true; boolean findParamReferences = true; switch (maskedLimitTo) { case IJavaSearchConstants.DECLARATIONS: findParamReferences = false; break; case IJavaSearchConstants.REFERENCES: findParamDeclarations = false; break; } searchPattern = new TypeParameterPattern(findParamDeclarations, findParamReferences, typeParam, matchRule); break; case IJavaElement.METHOD: IMethod method = (IMethod) element; boolean isConstructor; try { isConstructor = method.isConstructor(); } catch (JavaModelException e) { return null; } IType declaringClass = method.getDeclaringType(); if (ignoreDeclaringType) { if (isConstructor) declaringSimpleName = declaringClass.getElementName().toCharArray(); } else { declaringSimpleName = declaringClass.getElementName().toCharArray(); declaringQualification = declaringClass.getPackageFragment().getElementName().toCharArray(); char[][] enclosingNames = enclosingTypeNames(declaringClass); if (enclosingNames.length > 0) { declaringQualification = CharOperation.concat(declaringQualification, CharOperation.concatWith(enclosingNames, '.'), '.'); } } char[] selector = method.getElementName().toCharArray(); char[] returnSimpleName = null; char[] returnQualification = null; String returnSignature = null; if (!ignoreReturnType) { try { returnSignature = method.getReturnType(); char[] signature = returnSignature.toCharArray(); char[] returnErasure = Signature.toCharArray(Signature.getTypeErasure(signature)); CharOperation.replace(returnErasure, '$', '.'); if ((lastDot = CharOperation.lastIndexOf('.', returnErasure)) == -1) { returnSimpleName = returnErasure; } else { returnSimpleName = CharOperation.subarray(returnErasure, lastDot + 1, returnErasure.length); returnQualification = CharOperation.subarray(returnErasure, 0, lastDot); if (!method.isBinary()) { // prefix with a '*' as the full qualification could be bigger (because of an import) CharOperation.concat(IIndexConstants.ONE_STAR, returnQualification); } } } catch (JavaModelException e) { return null; } } String[] parameterTypes = method.getParameterTypes(); int paramCount = parameterTypes.length; char[][] parameterSimpleNames = new char[paramCount][]; char[][] parameterQualifications = new char[paramCount][]; String[] parameterSignatures = new String[paramCount]; for (int i = 0; i < paramCount; i++) { parameterSignatures[i] = parameterTypes[i]; char[] signature = parameterSignatures[i].toCharArray(); char[] paramErasure = Signature.toCharArray(Signature.getTypeErasure(signature)); CharOperation.replace(paramErasure, '$', '.'); if ((lastDot = CharOperation.lastIndexOf('.', paramErasure)) == -1) { parameterSimpleNames[i] = paramErasure; parameterQualifications[i] = null; } else { parameterSimpleNames[i] = CharOperation.subarray(paramErasure, lastDot + 1, paramErasure.length); parameterQualifications[i] = CharOperation.subarray(paramErasure, 0, lastDot); if (!method.isBinary()) { // prefix with a '*' as the full qualification could be bigger (because of an import) CharOperation.concat(IIndexConstants.ONE_STAR, parameterQualifications[i]); } } } // Create method/constructor pattern if (isConstructor) { searchPattern = new ConstructorPattern(declaringSimpleName, declaringQualification, parameterQualifications, parameterSimpleNames, parameterSignatures, method, limitTo, matchRule); } else { searchPattern = new MethodPattern(selector, declaringQualification, declaringSimpleName, returnQualification, returnSimpleName, returnSignature, parameterQualifications, parameterSimpleNames, parameterSignatures, method, limitTo, matchRule); } break; case IJavaElement.TYPE: IType type = (IType) element; searchPattern = createTypePattern(type.getElementName().toCharArray(), type.getPackageFragment().getElementName().toCharArray(), ignoreDeclaringType ? null : enclosingTypeNames(type), null, type, maskedLimitTo, matchRule); break; case IJavaElement.PACKAGE_DECLARATION: case IJavaElement.PACKAGE_FRAGMENT: searchPattern = createPackagePattern(element.getElementName(), maskedLimitTo, matchRule); break; } if (searchPattern != null) MatchLocator.setFocus(searchPattern, element); return searchPattern; }
From source file:com.codenvy.ide.ext.java.server.internal.codeassist.impl.Engine.java
License:Open Source License
protected boolean mustQualifyType(char[] packageName, char[] typeName, char[] enclosingTypeNames, int modifiers) { // If there are no types defined into the current CU yet. if (this.unitScope == null) return true; if (!this.importCachesInitialized) { initializeImportCaches();//from w w w .ja v a2 s. c om } for (int i = 0; i < this.importCacheCount; i++) { char[][] importName = this.importsCache[i]; if (CharOperation.equals(typeName, importName[0])) { char[] fullyQualifiedTypeName = enclosingTypeNames == null || enclosingTypeNames.length == 0 ? CharOperation.concat(packageName, typeName, '.') : CharOperation.concat(CharOperation.concat(packageName, enclosingTypeNames, '.'), typeName, '.'); return !CharOperation.equals(fullyQualifiedTypeName, importName[1]); } } if ((enclosingTypeNames == null || enclosingTypeNames.length == 0) && CharOperation.equals(this.currentPackageName, packageName)) return false; char[] fullyQualifiedEnclosingTypeName = null; for (int i = 0; i < this.onDemandImportCacheCount; i++) { ImportBinding importBinding = this.onDemandImportsCache[i]; Binding resolvedImport = importBinding.resolvedImport; char[][] importName = importBinding.compoundName; char[] importFlatName = CharOperation.concatWith(importName, '.'); boolean isFound = false; // resolvedImport is a ReferenceBindng or a PackageBinding if (resolvedImport instanceof ReferenceBinding) { if (enclosingTypeNames != null && enclosingTypeNames.length != 0) { if (fullyQualifiedEnclosingTypeName == null) { fullyQualifiedEnclosingTypeName = CharOperation.concat(packageName, enclosingTypeNames, '.'); } if (CharOperation.equals(fullyQualifiedEnclosingTypeName, importFlatName)) { if (importBinding.isStatic()) { isFound = (modifiers & ClassFileConstants.AccStatic) != 0; } else { isFound = true; } } } } else { if (enclosingTypeNames == null || enclosingTypeNames.length == 0) { if (CharOperation.equals(packageName, importFlatName)) { if (importBinding.isStatic()) { isFound = (modifiers & ClassFileConstants.AccStatic) != 0; } else { isFound = true; } } } } // find potential conflict with another import if (isFound) { for (int j = 0; j < this.onDemandImportCacheCount; j++) { if (i != j) { ImportBinding conflictingImportBinding = this.onDemandImportsCache[j]; if (conflictingImportBinding.resolvedImport instanceof ReferenceBinding) { ReferenceBinding refBinding = (ReferenceBinding) conflictingImportBinding.resolvedImport; if (refBinding.getMemberType(typeName) != null) { return true; } } else { char[] conflictingImportName = CharOperation .concatWith(conflictingImportBinding.compoundName, '.'); if (this.nameEnvironment.nameLookup.findType(String.valueOf(typeName), String.valueOf(conflictingImportName), false, NameLookup.ACCEPT_ALL, false/*don't check restrictions*/) != null) { return true; } } } } return false; } } return true; }
From source file:com.codenvy.ide.ext.java.server.internal.codeassist.SelectionEngine.java
License:Open Source License
public void acceptType(char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames, int modifiers, AccessRestriction accessRestriction) { char[] typeName = enclosingTypeNames == null ? simpleTypeName : CharOperation.concat(CharOperation.concatWith(enclosingTypeNames, '.'), simpleTypeName, '.'); if (CharOperation.equals(simpleTypeName, this.selectedIdentifier)) { char[] flatEnclosingTypeNames = enclosingTypeNames == null || enclosingTypeNames.length == 0 ? null : CharOperation.concatWith(enclosingTypeNames, '.'); if (mustQualifyType(packageName, simpleTypeName, flatEnclosingTypeNames, modifiers)) { int length = 0; int kind = modifiers & (ClassFileConstants.AccInterface | ClassFileConstants.AccEnum | ClassFileConstants.AccAnnotation); switch (kind) { case ClassFileConstants.AccAnnotation: case ClassFileConstants.AccAnnotation | ClassFileConstants.AccInterface: char[][] acceptedAnnotation = new char[2][]; acceptedAnnotation[0] = packageName; acceptedAnnotation[1] = typeName; if (this.acceptedAnnotations == null) { this.acceptedAnnotations = new char[10][][]; this.acceptedAnnotationsModifiers = new int[10]; this.acceptedAnnotationsCount = 0; }//from w w w .j a va 2s. co m length = this.acceptedAnnotations.length; if (length == this.acceptedAnnotationsCount) { int newLength = (length + 1) * 2; System.arraycopy(this.acceptedAnnotations, 0, this.acceptedAnnotations = new char[newLength][][], 0, length); System.arraycopy(this.acceptedAnnotationsModifiers, 0, this.acceptedAnnotationsModifiers = new int[newLength], 0, length); } this.acceptedAnnotationsModifiers[this.acceptedAnnotationsCount] = modifiers; this.acceptedAnnotations[this.acceptedAnnotationsCount++] = acceptedAnnotation; break; case ClassFileConstants.AccEnum: char[][] acceptedEnum = new char[2][]; acceptedEnum[0] = packageName; acceptedEnum[1] = typeName; if (this.acceptedEnums == null) { this.acceptedEnums = new char[10][][]; this.acceptedEnumsModifiers = new int[10]; this.acceptedEnumsCount = 0; } length = this.acceptedEnums.length; if (length == this.acceptedEnumsCount) { int newLength = (length + 1) * 2; System.arraycopy(this.acceptedEnums, 0, this.acceptedEnums = new char[newLength][][], 0, length); System.arraycopy(this.acceptedEnumsModifiers, 0, this.acceptedEnumsModifiers = new int[newLength], 0, length); } this.acceptedEnumsModifiers[this.acceptedEnumsCount] = modifiers; this.acceptedEnums[this.acceptedEnumsCount++] = acceptedEnum; break; case ClassFileConstants.AccInterface: char[][] acceptedInterface = new char[2][]; acceptedInterface[0] = packageName; acceptedInterface[1] = typeName; if (this.acceptedInterfaces == null) { this.acceptedInterfaces = new char[10][][]; this.acceptedInterfacesModifiers = new int[10]; this.acceptedInterfacesCount = 0; } length = this.acceptedInterfaces.length; if (length == this.acceptedInterfacesCount) { int newLength = (length + 1) * 2; System.arraycopy(this.acceptedInterfaces, 0, this.acceptedInterfaces = new char[newLength][][], 0, length); System.arraycopy(this.acceptedInterfacesModifiers, 0, this.acceptedInterfacesModifiers = new int[newLength], 0, length); } this.acceptedInterfacesModifiers[this.acceptedInterfacesCount] = modifiers; this.acceptedInterfaces[this.acceptedInterfacesCount++] = acceptedInterface; break; default: char[][] acceptedClass = new char[2][]; acceptedClass[0] = packageName; acceptedClass[1] = typeName; if (this.acceptedClasses == null) { this.acceptedClasses = new char[10][][]; this.acceptedClassesModifiers = new int[10]; this.acceptedClassesCount = 0; } length = this.acceptedClasses.length; if (length == this.acceptedClassesCount) { int newLength = (length + 1) * 2; System.arraycopy(this.acceptedClasses, 0, this.acceptedClasses = new char[newLength][][], 0, length); System.arraycopy(this.acceptedClassesModifiers, 0, this.acceptedClassesModifiers = new int[newLength], 0, length); } this.acceptedClassesModifiers[this.acceptedClassesCount] = modifiers; this.acceptedClasses[this.acceptedClassesCount++] = acceptedClass; break; } } else { this.noProposal = false; this.requestor.acceptType(packageName, typeName, modifiers, false, null, this.actualSelectionStart, this.actualSelectionEnd); this.acceptedAnswer = true; } } }
From source file:com.codenvy.ide.ext.java.server.internal.codeassist.SelectionEngine.java
License:Open Source License
private boolean selectDeclaration(TypeDeclaration typeDeclaration, char[] assistIdentifier, char[] packageName) { if (typeDeclaration.name == assistIdentifier) { char[] qualifiedSourceName = null; TypeDeclaration enclosingType = typeDeclaration; while (enclosingType != null) { qualifiedSourceName = CharOperation.concat(enclosingType.name, qualifiedSourceName, '.'); enclosingType = enclosingType.enclosingType; }// w w w . j a v a 2 s. c o m char[] uniqueKey = typeDeclaration.binding != null ? typeDeclaration.binding.computeUniqueKey() : null; this.requestor.acceptType(packageName, qualifiedSourceName, typeDeclaration.modifiers, true, uniqueKey, this.actualSelectionStart, this.actualSelectionEnd); this.noProposal = false; return true; } TypeDeclaration[] memberTypes = typeDeclaration.memberTypes; for (int i = 0, length = memberTypes == null ? 0 : memberTypes.length; i < length; i++) { if (selectDeclaration(memberTypes[i], assistIdentifier, packageName)) return true; } FieldDeclaration[] fields = typeDeclaration.fields; for (int i = 0, length = fields == null ? 0 : fields.length; i < length; i++) { if (fields[i].name == assistIdentifier) { char[] qualifiedSourceName = null; TypeDeclaration enclosingType = typeDeclaration; while (enclosingType != null) { qualifiedSourceName = CharOperation.concat(enclosingType.name, qualifiedSourceName, '.'); enclosingType = enclosingType.enclosingType; } FieldDeclaration field = fields[i]; this.requestor.acceptField(packageName, qualifiedSourceName, field.name, true, field.binding != null ? field.binding.computeUniqueKey() : null, this.actualSelectionStart, this.actualSelectionEnd); this.noProposal = false; return true; } } AbstractMethodDeclaration[] methods = typeDeclaration.methods; for (int i = 0, length = methods == null ? 0 : methods.length; i < length; i++) { AbstractMethodDeclaration method = methods[i]; if (method.selector == assistIdentifier) { char[] qualifiedSourceName = null; TypeDeclaration enclosingType = typeDeclaration; while (enclosingType != null) { qualifiedSourceName = CharOperation.concat(enclosingType.name, qualifiedSourceName, '.'); enclosingType = enclosingType.enclosingType; } this.requestor.acceptMethod(packageName, qualifiedSourceName, null, // SelectionRequestor does not need of declaring type signature for method declaration method.selector, null, // SelectionRequestor does not need of parameters type for method declaration null, // SelectionRequestor does not need of parameters type for method declaration null, // SelectionRequestor does not need of parameters type for method declaration null, // SelectionRequestor does not need of type parameters name for method declaration null, // SelectionRequestor does not need of type parameters bounds for method declaration method.isConstructor(), true, method.binding != null ? method.binding.computeUniqueKey() : null, this.actualSelectionStart, this.actualSelectionEnd); this.noProposal = false; return true; } TypeParameter[] methodTypeParameters = method.typeParameters(); for (int j = 0, length2 = methodTypeParameters == null ? 0 : methodTypeParameters.length; j < length2; j++) { TypeParameter methodTypeParameter = methodTypeParameters[j]; if (methodTypeParameter.name == assistIdentifier) { char[] qualifiedSourceName = null; TypeDeclaration enclosingType = typeDeclaration; while (enclosingType != null) { qualifiedSourceName = CharOperation.concat(enclosingType.name, qualifiedSourceName, '.'); enclosingType = enclosingType.enclosingType; } this.requestor.acceptMethodTypeParameter(packageName, qualifiedSourceName, method.selector, method.sourceStart, method.sourceEnd, methodTypeParameter.name, true, this.actualSelectionStart, this.actualSelectionEnd); this.noProposal = false; return true; } } } TypeParameter[] typeParameters = typeDeclaration.typeParameters; for (int i = 0, length = typeParameters == null ? 0 : typeParameters.length; i < length; i++) { TypeParameter typeParameter = typeParameters[i]; if (typeParameter.name == assistIdentifier) { char[] qualifiedSourceName = null; TypeDeclaration enclosingType = typeDeclaration; while (enclosingType != null) { qualifiedSourceName = CharOperation.concat(enclosingType.name, qualifiedSourceName, '.'); enclosingType = enclosingType.enclosingType; } this.requestor.acceptTypeParameter(packageName, qualifiedSourceName, typeParameter.name, true, this.actualSelectionStart, this.actualSelectionEnd); this.noProposal = false; return true; } } return false; }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.ConstructorPattern.java
License:Open Source License
public ConstructorPattern(char[] declaringSimpleName, char[] declaringQualification, char[][] parameterQualifications, char[][] parameterSimpleNames, int limitTo, int matchRule) { this(matchRule); this.fineGrain = limitTo & FINE_GRAIN_MASK; if (this.fineGrain == 0) { switch (limitTo) { case IJavaSearchConstants.DECLARATIONS: this.findReferences = false; break; case IJavaSearchConstants.REFERENCES: this.findDeclarations = false; break; case IJavaSearchConstants.ALL_OCCURRENCES: break; }/*from w w w .jav a2 s .c om*/ } else { this.findDeclarations = false; } this.declaringQualification = this.isCaseSensitive ? declaringQualification : CharOperation.toLowerCase(declaringQualification); this.declaringSimpleName = (this.isCaseSensitive || this.isCamelCase) ? declaringSimpleName : CharOperation.toLowerCase(declaringSimpleName); if (parameterSimpleNames != null) { this.parameterCount = parameterSimpleNames.length; boolean synthetic = this.parameterCount > 0 && declaringQualification != null && CharOperation.equals( CharOperation.concat(parameterQualifications[0], parameterSimpleNames[0], '.'), declaringQualification); int offset = 0; if (synthetic) { // skip first synthetic parameter this.parameterCount--; offset++; } this.parameterQualifications = new char[this.parameterCount][]; this.parameterSimpleNames = new char[this.parameterCount][]; for (int i = 0; i < this.parameterCount; i++) { this.parameterQualifications[i] = this.isCaseSensitive ? parameterQualifications[i + offset] : CharOperation.toLowerCase(parameterQualifications[i + offset]); this.parameterSimpleNames[i] = this.isCaseSensitive ? parameterSimpleNames[i + offset] : CharOperation.toLowerCase(parameterSimpleNames[i + offset]); } } else { this.parameterCount = -1; } this.mustResolve = mustResolve(); }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.FieldLocator.java
License:Open Source License
public int match(ASTNode node, MatchingNodeSet nodeSet) { int declarationsLevel = IMPOSSIBLE_MATCH; if (this.pattern.findReferences) { if (node instanceof ImportReference) { // With static import, we can have static field reference in import reference ImportReference importRef = (ImportReference) node; int length = importRef.tokens.length - 1; if (importRef.isStatic() && ((importRef.bits & ASTNode.OnDemand) == 0) && matchesName(this.pattern.name, importRef.tokens[length])) { char[][] compoundName = new char[length][]; System.arraycopy(importRef.tokens, 0, compoundName, 0, length); FieldPattern fieldPattern = (FieldPattern) this.pattern; char[] declaringType = CharOperation.concat(fieldPattern.declaringQualification, fieldPattern.declaringSimpleName, '.'); if (matchesName(declaringType, CharOperation.concatWith(compoundName, '.'))) { declarationsLevel = this.pattern.mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH; }/* w w w .j av a2 s .c o m*/ } } } return nodeSet.addMatch(node, declarationsLevel); }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.MethodLocator.java
License:Open Source License
public int match(ASTNode node, MatchingNodeSet nodeSet) { int declarationsLevel = IMPOSSIBLE_MATCH; if (this.pattern.findReferences) { if (node instanceof ImportReference) { // With static import, we can have static method reference in import reference ImportReference importRef = (ImportReference) node; int length = importRef.tokens.length - 1; if (importRef.isStatic() && ((importRef.bits & ASTNode.OnDemand) == 0) && matchesName(this.pattern.selector, importRef.tokens[length])) { char[][] compoundName = new char[length][]; System.arraycopy(importRef.tokens, 0, compoundName, 0, length); char[] declaringType = CharOperation.concat(this.pattern.declaringQualification, this.pattern.declaringSimpleName, '.'); if (matchesName(declaringType, CharOperation.concatWith(compoundName, '.'))) { declarationsLevel = this.pattern.mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH; }//from www . j ava2 s .c o m } } } return nodeSet.addMatch(node, declarationsLevel); }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.MethodPattern.java
License:Open Source License
public EntryResult[] queryIn(Index index) throws IOException { char[] key = this.selector; // can be null int matchRule = getMatchRule(); switch (getMatchMode()) { case R_EXACT_MATCH: if (this.selector != null && this.parameterCount >= 0 && !this.varargs) key = createIndexKey(this.selector, this.parameterCount); else { // do a prefix query with the selector matchRule &= ~R_EXACT_MATCH; matchRule |= R_PREFIX_MATCH; }/*w w w.j a v a 2 s.c o m*/ break; case R_PREFIX_MATCH: // do a prefix query with the selector break; case R_PATTERN_MATCH: if (this.parameterCount >= 0 && !this.varargs) key = createIndexKey(this.selector == null ? ONE_STAR : this.selector, this.parameterCount); else if (this.selector != null && this.selector[this.selector.length - 1] != '*') key = CharOperation.concat(this.selector, ONE_STAR, SEPARATOR); // else do a pattern query with just the selector break; case R_REGEXP_MATCH: // TODO (frederic) implement regular expression match break; case R_CAMELCASE_MATCH: case R_CAMELCASE_SAME_PART_COUNT_MATCH: // do a prefix query with the selector break; } return index.query(getIndexCategories(), key, matchRule); // match rule is irrelevant when the key is null }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.MultiTypeDeclarationPattern.java
License:Open Source License
public EntryResult[] queryIn(Index index) throws IOException { if (this.simpleNames == null) { // if no simple names then return all possible ones from index return index.query(getIndexCategories(), null, -1); // match rule is irrelevant when the key is null }/* ww w . j a va 2 s . c om*/ int count = -1; int numOfNames = this.simpleNames.length; EntryResult[][] allResults = numOfNames > 1 ? new EntryResult[numOfNames][] : null; for (int i = 0; i < numOfNames; i++) { char[] key = this.simpleNames[i]; int matchRule = getMatchRule(); switch (getMatchMode()) { case R_PREFIX_MATCH: // do a prefix query with the simpleName break; case R_EXACT_MATCH: // do a prefix query with the simpleName matchRule &= ~R_EXACT_MATCH; matchRule |= R_PREFIX_MATCH; key = CharOperation.append(key, SEPARATOR); break; case R_PATTERN_MATCH: if (key[key.length - 1] != '*') key = CharOperation.concat(key, ONE_STAR, SEPARATOR); break; case R_REGEXP_MATCH: // TODO (frederic) implement regular expression match break; case R_CAMELCASE_MATCH: case R_CAMELCASE_SAME_PART_COUNT_MATCH: // do a prefix query with the simpleName break; } EntryResult[] entries = index.query(getIndexCategories(), key, matchRule); // match rule is irrelevant when the key is null if (entries != null) { if (allResults == null) return entries; allResults[++count] = entries; } } if (count == -1) return null; int total = 0; for (int i = 0; i <= count; i++) total += allResults[i].length; EntryResult[] allEntries = new EntryResult[total]; int next = 0; for (int i = 0; i <= count; i++) { EntryResult[] entries = allResults[i]; System.arraycopy(entries, 0, allEntries, next, entries.length); next += entries.length; } return allEntries; }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.PatternLocator.java
License:Open Source License
public static char[] qualifiedPattern(char[] simpleNamePattern, char[] qualificationPattern) { // NOTE: if case insensitive search then simpleNamePattern & qualificationPattern are assumed to be lowercase if (simpleNamePattern == null) { if (qualificationPattern == null) return null; return CharOperation.concat(qualificationPattern, ONE_STAR, '.'); } else {/*from ww w. ja v a 2 s.c o m*/ return qualificationPattern == null ? CharOperation.concat(ONE_STAR, simpleNamePattern) : CharOperation.concat(qualificationPattern, simpleNamePattern, '.'); } }