List of usage examples for org.eclipse.jdt.internal.compiler.lookup ReferenceBinding getMethods
@Override public MethodBinding[] getMethods(char[] selector)
From source file:com.android.tools.lint.psi.EcjPsiBinaryClass.java
License:Apache License
@NonNull @Override//from w w w . j av a 2 s . c o m public PsiMethod[] getConstructors() { if (mBinding instanceof ReferenceBinding) { ReferenceBinding cls = (ReferenceBinding) mBinding; MethodBinding[] methods = cls.getMethods(TypeConstants.INIT); if (methods != null) { int count = methods.length; List<EcjPsiBinaryMethod> result = Lists.newArrayListWithExpectedSize(count); for (MethodBinding method : methods) { if (method.isConstructor()) { result.add(new EcjPsiBinaryMethod(mManager, method)); } } return result.toArray(PsiMethod.EMPTY_ARRAY); } } return PsiMethod.EMPTY_ARRAY; }
From source file:com.android.tools.lint.psi.EcjPsiBinaryClass.java
License:Apache License
@NonNull private PsiMethod[] findMethods(@Nullable String name, boolean includeInherited, boolean includeConstructors) { if (mBinding instanceof ReferenceBinding) { ReferenceBinding cls = (ReferenceBinding) mBinding; if (includeInherited) { List<EcjPsiBinaryMethod> result = null; while (cls != null) { MethodBinding[] methods = name != null ? cls.getMethods(name.toCharArray()) : cls.methods(); if (methods != null) { int count = methods.length; if (count > 0) { if (result == null) { result = Lists.newArrayListWithExpectedSize(count); }/*from w w w. j av a 2s . c o m*/ for (MethodBinding method : methods) { if ((method.modifiers & Modifier.PRIVATE) != 0 && cls != mBinding) { // Ignore parent methods that are private continue; } if (includeConstructors || !method.isConstructor()) { // See if this method looks like it's masked boolean masked = false; for (PsiMethod m : result) { MethodBinding mb = ((EcjPsiBinaryMethod) m).getBinding(); if (mb.areParameterErasuresEqual(method)) { masked = true; break; } } if (masked) { continue; } result.add(new EcjPsiBinaryMethod(mManager, method)); } } } } cls = cls.superclass(); } return result != null ? result.toArray(PsiMethod.EMPTY_ARRAY) : PsiMethod.EMPTY_ARRAY; } else { MethodBinding[] methods = name != null ? cls.getMethods(name.toCharArray()) : cls.methods(); if (methods != null) { int count = methods.length; List<EcjPsiBinaryMethod> result = Lists.newArrayListWithExpectedSize(count); for (MethodBinding method : methods) { if (includeConstructors || !method.isConstructor()) { result.add(new EcjPsiBinaryMethod(mManager, method)); } } return result.toArray(PsiMethod.EMPTY_ARRAY); } } } return PsiMethod.EMPTY_ARRAY; }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.MatchLocator.java
License:Open Source License
private MethodBinding getMethodBinding0(MethodPattern methodPattern) { if (this.unitScope == null) return null; // Try to get binding from cache Binding binding = (Binding) this.bindings.get(methodPattern); if (binding != null) { if (binding instanceof MethodBinding && binding.isValidBinding()) return (MethodBinding) binding; return null; }//from ww w.j a va2 s .c o m // Get binding from unit scope char[] typeName = PatternLocator.qualifiedPattern(methodPattern.declaringSimpleName, methodPattern.declaringQualification); if (typeName == null) { if (methodPattern.declaringType == null) return null; typeName = methodPattern.declaringType.getFullyQualifiedName().toCharArray(); } TypeBinding declaringTypeBinding = getType(typeName, typeName); if (declaringTypeBinding != null) { if (declaringTypeBinding.isArrayType()) { declaringTypeBinding = declaringTypeBinding.leafComponentType(); } if (!declaringTypeBinding.isBaseType()) { char[][] parameterTypes = methodPattern.parameterSimpleNames; if (parameterTypes == null) return null; int paramTypeslength = parameterTypes.length; ReferenceBinding referenceBinding = (ReferenceBinding) declaringTypeBinding; MethodBinding[] methods = referenceBinding.getMethods(methodPattern.selector); int methodsLength = methods.length; TypeVariableBinding[] refTypeVariables = referenceBinding.typeVariables(); int typeVarLength = refTypeVariables == null ? 0 : refTypeVariables.length; for (int i = 0; i < methodsLength; i++) { TypeBinding[] methodParameters = methods[i].parameters; int paramLength = methodParameters == null ? 0 : methodParameters.length; TypeVariableBinding[] methodTypeVariables = methods[i].typeVariables; int methTypeVarLength = methodTypeVariables == null ? 0 : methodTypeVariables.length; boolean found = false; if (methodParameters != null && paramLength == paramTypeslength) { for (int p = 0; p < paramLength; p++) { if (CharOperation.equals(methodParameters[p].sourceName(), parameterTypes[p])) { // param erasure match found = true; } else { // type variable found = false; if (refTypeVariables != null) { for (int v = 0; v < typeVarLength; v++) { if (!CharOperation.equals(refTypeVariables[v].sourceName, parameterTypes[p])) { found = false; break; } found = true; } } if (!found && methodTypeVariables != null) { for (int v = 0; v < methTypeVarLength; v++) { if (!CharOperation.equals(methodTypeVariables[v].sourceName, parameterTypes[p])) { found = false; break; } found = true; } } if (!found) break; } } } if (found) { this.bindings.put(methodPattern, methods[i]); return methods[i]; } } } } this.bindings.put(methodPattern, new ProblemMethodBinding(methodPattern.selector, null, ProblemReasons.NotFound)); return null; }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.MethodLocator.java
License:Open Source License
private MethodBinding getMethodBinding(ReferenceBinding type, char[] methodName, TypeBinding[] argumentTypes) { MethodBinding[] methods = type.getMethods(methodName); MethodBinding method = null;//from w ww .j a v a 2s . com methodsLoop: for (int i = 0, length = methods.length; i < length; i++) { method = methods[i]; TypeBinding[] parameters = method.parameters; if (argumentTypes.length == parameters.length) { for (int j = 0, l = parameters.length; j < l; j++) { if (parameters[j].erasure() != argumentTypes[j].erasure()) { continue methodsLoop; } } return method; } } return null; }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.MethodLocator.java
License:Open Source License
private boolean matchOverriddenMethod(ReferenceBinding type, MethodBinding method, MethodBinding matchMethod) { if (type == null || this.pattern.selector == null) return false; // matches superclass if (!type.isInterface() && !CharOperation.equals(type.compoundName, TypeConstants.JAVA_LANG_OBJECT)) { ReferenceBinding superClass = type.superclass(); if (superClass.isParameterizedType()) { MethodBinding[] methods = superClass.getMethods(this.pattern.selector); int length = methods.length; for (int i = 0; i < length; i++) { if (methods[i].areParametersEqual(method)) { if (matchMethod == null) { if (methodParametersEqualsPattern(methods[i].original())) return true; } else { if (methods[i].original().areParametersEqual(matchMethod)) return true; }//from w w w . j a v a 2 s. c o m } } } if (matchOverriddenMethod(superClass, method, matchMethod)) { return true; } } // matches interfaces ReferenceBinding[] interfaces = type.superInterfaces(); if (interfaces == null) return false; int iLength = interfaces.length; for (int i = 0; i < iLength; i++) { if (interfaces[i].isParameterizedType()) { MethodBinding[] methods = interfaces[i].getMethods(this.pattern.selector); int length = methods.length; for (int j = 0; j < length; j++) { if (methods[j].areParametersEqual(method)) { if (matchMethod == null) { if (methodParametersEqualsPattern(methods[j].original())) return true; } else { if (methods[j].original().areParametersEqual(matchMethod)) return true; } } } } if (matchOverriddenMethod(interfaces[i], method, matchMethod)) { return true; } } return false; }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.MethodLocator.java
License:Open Source License
private boolean resolveLevelAsSuperInvocation(ReferenceBinding type, TypeBinding[] argumentTypes, char[][][] superTypeNames, boolean methodAlreadyVerified) { char[][] compoundName = type.compoundName; for (int i = 0, max = superTypeNames.length; i < max; i++) { if (CharOperation.equals(superTypeNames[i], compoundName)) { // need to verify if the type implements the pattern method if (methodAlreadyVerified) return true; // already verified before enter into this method (see resolveLevel(MessageSend)) MethodBinding[] methods = type.getMethods(this.pattern.selector); for (int j = 0, length = methods.length; j < length; j++) { MethodBinding method = methods[j]; TypeBinding[] parameters = method.parameters; if (argumentTypes.length == parameters.length) { boolean found = true; for (int k = 0, l = parameters.length; k < l; k++) { if (parameters[k].erasure() != argumentTypes[k].erasure()) { found = false; break; }//from w ww . ja va 2s . c o m } if (found) { return true; } } } break; } } // If the given type is an interface then a common super interface may be found // in a parallel branch of the super hierarchy, so we need to verify all super interfaces. // If it's a class then there's only one possible branch for the hierarchy and // this branch has been already verified by the test above if (type.isInterface()) { ReferenceBinding[] interfaces = type.superInterfaces(); if (interfaces == null) return false; for (int i = 0; i < interfaces.length; i++) { if (resolveLevelAsSuperInvocation(interfaces[i], argumentTypes, superTypeNames, false)) { return true; } } } return false; }
From source file:org.eclipse.che.jdt.internal.core.search.matching.MethodLocator.java
License:Open Source License
private MethodBinding getMethodBinding(ReferenceBinding type, char[] methodName, TypeBinding[] argumentTypes) { MethodBinding[] methods = type.getMethods(methodName); MethodBinding method = null;//from w w w. j a v a 2 s. c o m methodsLoop: for (int i = 0, length = methods.length; i < length; i++) { method = methods[i]; TypeBinding[] parameters = method.parameters; if (argumentTypes.length == parameters.length) { for (int j = 0, l = parameters.length; j < l; j++) { if (TypeBinding.notEquals(parameters[j].erasure(), argumentTypes[j].erasure())) { continue methodsLoop; } } return method; } } return null; }
From source file:org.eclipse.che.jdt.internal.core.search.matching.MethodLocator.java
License:Open Source License
private boolean resolveLevelAsSuperInvocation(ReferenceBinding type, TypeBinding[] argumentTypes, char[][][] superTypeNames, boolean methodAlreadyVerified) { char[][] compoundName = type.compoundName; for (int i = 0, max = superTypeNames.length; i < max; i++) { if (CharOperation.equals(superTypeNames[i], compoundName)) { // need to verify if the type implements the pattern method if (methodAlreadyVerified) return true; // already verified before enter into this method (see resolveLevel(MessageSend)) MethodBinding[] methods = type.getMethods(this.pattern.selector); for (int j = 0, length = methods.length; j < length; j++) { MethodBinding method = methods[j]; TypeBinding[] parameters = method.parameters; if (argumentTypes.length == parameters.length) { boolean found = true; for (int k = 0, l = parameters.length; k < l; k++) { if (TypeBinding.notEquals(parameters[k].erasure(), argumentTypes[k].erasure())) { found = false; break; }//from w ww . ja v a2s . c om } if (found) { return true; } } } break; } } // If the given type is an interface then a common super interface may be found // in a parallel branch of the super hierarchy, so we need to verify all super interfaces. // If it's a class then there's only one possible branch for the hierarchy and // this branch has been already verified by the test above if (type.isInterface()) { ReferenceBinding[] interfaces = type.superInterfaces(); if (interfaces == null) return false; for (int i = 0; i < interfaces.length; i++) { if (resolveLevelAsSuperInvocation(interfaces[i], argumentTypes, superTypeNames, false)) { return true; } } } return false; }
From source file:org.eclipse.jdt.internal.compiler.lookup.MethodVerifier15.java
License:Open Source License
void checkForNameClash(MethodBinding currentMethod, MethodBinding inheritedMethod) { // sent from checkMethods() to compare a current method and an inherited method that are not 'equal' // error cases: // abstract class AA<E extends Comparable> { abstract void test(E element); } // class A extends AA<Integer> { public void test(Integer i) {} } // public class B extends A { public void test(Comparable i) {} } // interface I<E extends Comparable> { void test(E element); } // class A implements I<Integer> { public void test(Integer i) {} } // public class B extends A { public void test(Comparable i) {} } // abstract class Y implements EqualityComparable<Integer>, Equivalent<String> { // public boolean equalTo(Integer other) { return true; } // }//ww w. j a va 2 s. c o m // interface Equivalent<T> { boolean equalTo(T other); } // interface EqualityComparable<T> { boolean equalTo(T other); } // class Y implements EqualityComparable, Equivalent<String>{ // public boolean equalTo(String other) { return true; } // public boolean equalTo(Object other) { return true; } // } // interface Equivalent<T> { boolean equalTo(T other); } // interface EqualityComparable { boolean equalTo(Object other); } // class A<T extends Number> { void m(T t) {} } // class B<S extends Integer> extends A<S> { void m(S t) {}} // class D extends B<Integer> { void m(Number t) {} void m(Integer t) {} } // inheritedMethods does not include I.test since A has a valid implementation // interface I<E extends Comparable<E>> { void test(E element); } // class A implements I<Integer> { public void test(Integer i) {} } // class B extends A { public void test(Comparable i) {} } if (inheritedMethod.isStatic()) return; if (!detectNameClash(currentMethod, inheritedMethod, false)) { // check up the hierarchy for skipped inherited methods TypeBinding[] currentParams = currentMethod.parameters; TypeBinding[] inheritedParams = inheritedMethod.parameters; int length = currentParams.length; if (length != inheritedParams.length) return; // no match for (int i = 0; i < length; i++) if (currentParams[i] != inheritedParams[i]) if (currentParams[i].isBaseType() != inheritedParams[i].isBaseType() || !inheritedParams[i].isCompatibleWith(currentParams[i])) return; // no chance that another inherited method's bridge method can collide ReferenceBinding[] interfacesToVisit = null; int nextPosition = 0; ReferenceBinding superType = inheritedMethod.declaringClass; ReferenceBinding[] itsInterfaces = superType.superInterfaces(); if (itsInterfaces != Binding.NO_SUPERINTERFACES) { nextPosition = itsInterfaces.length; interfacesToVisit = itsInterfaces; } superType = superType.superclass(); // now start with its superclass while (superType != null && superType.isValidBinding()) { MethodBinding[] methods = superType.getMethods(currentMethod.selector); for (int m = 0, n = methods.length; m < n; m++) { MethodBinding substitute = computeSubstituteMethod(methods[m], currentMethod); if (substitute != null && !isSubstituteParameterSubsignature(currentMethod, substitute) && detectNameClash(currentMethod, substitute, true)) return; } if ((itsInterfaces = superType.superInterfaces()) != Binding.NO_SUPERINTERFACES) { if (interfacesToVisit == null) { interfacesToVisit = itsInterfaces; nextPosition = interfacesToVisit.length; } else { int itsLength = itsInterfaces.length; if (nextPosition + itsLength >= interfacesToVisit.length) System.arraycopy(interfacesToVisit, 0, interfacesToVisit = new ReferenceBinding[nextPosition + itsLength + 5], 0, nextPosition); nextInterface: for (int a = 0; a < itsLength; a++) { ReferenceBinding next = itsInterfaces[a]; for (int b = 0; b < nextPosition; b++) if (next == interfacesToVisit[b]) continue nextInterface; interfacesToVisit[nextPosition++] = next; } } } superType = superType.superclass(); } for (int i = 0; i < nextPosition; i++) { superType = interfacesToVisit[i]; if (superType.isValidBinding()) { MethodBinding[] methods = superType.getMethods(currentMethod.selector); for (int m = 0, n = methods.length; m < n; m++) { MethodBinding substitute = computeSubstituteMethod(methods[m], currentMethod); if (substitute != null && !isSubstituteParameterSubsignature(currentMethod, substitute) && detectNameClash(currentMethod, substitute, true)) return; } if ((itsInterfaces = superType.superInterfaces()) != Binding.NO_SUPERINTERFACES) { int itsLength = itsInterfaces.length; if (nextPosition + itsLength >= interfacesToVisit.length) System.arraycopy(interfacesToVisit, 0, interfacesToVisit = new ReferenceBinding[nextPosition + itsLength + 5], 0, nextPosition); nextInterface: for (int a = 0; a < itsLength; a++) { ReferenceBinding next = itsInterfaces[a]; for (int b = 0; b < nextPosition; b++) if (next == interfacesToVisit[b]) continue nextInterface; interfacesToVisit[nextPosition++] = next; } } } } } }
From source file:org.eclipse.jdt.internal.compiler.lookup.Scope.java
License:Open Source License
protected void findMethodInSuperInterfaces(ReferenceBinding currentType, char[] selector, ObjectVector found, InvocationSite invocationSite) { ReferenceBinding[] itsInterfaces = currentType.superInterfaces(); if (itsInterfaces != null && itsInterfaces != Binding.NO_SUPERINTERFACES) { ReferenceBinding[] interfacesToVisit = itsInterfaces; int nextPosition = interfacesToVisit.length; for (int i = 0; i < nextPosition; i++) { currentType = interfacesToVisit[i]; compilationUnitScope().recordTypeReference(currentType); currentType = (ReferenceBinding) currentType.capture(this, invocationSite == null ? 0 : invocationSite.sourceEnd()); MethodBinding[] currentMethods = currentType.getMethods(selector); if (currentMethods.length > 0) { int foundSize = found.size; if (foundSize > 0) { // its possible to walk the same superinterface from different classes in the hierarchy next: for (int c = 0, l = currentMethods.length; c < l; c++) { MethodBinding current = currentMethods[c]; for (int f = 0; f < foundSize; f++) if (current == found.elementAt(f)) continue next; found.add(current); }//from w w w . j a v a2s . co m } else { found.addAll(currentMethods); } } if ((itsInterfaces = currentType.superInterfaces()) != null && itsInterfaces != Binding.NO_SUPERINTERFACES) { int itsLength = itsInterfaces.length; if (nextPosition + itsLength >= interfacesToVisit.length) System.arraycopy(interfacesToVisit, 0, interfacesToVisit = new ReferenceBinding[nextPosition + itsLength + 5], 0, nextPosition); nextInterface: for (int a = 0; a < itsLength; a++) { ReferenceBinding next = itsInterfaces[a]; for (int b = 0; b < nextPosition; b++) if (next == interfacesToVisit[b]) continue nextInterface; interfacesToVisit[nextPosition++] = next; } } } } }