List of usage examples for org.eclipse.jdt.internal.compiler.lookup ReferenceBinding getExactMethod
public MethodBinding getExactMethod(char[] selector, TypeBinding[] argumentTypes, CompilationUnitScope refScope)
From source file:org.eclipse.jdt.internal.compiler.lookup.Scope.java
License:Open Source License
public MethodBinding findExactMethod(ReferenceBinding receiverType, char[] selector, TypeBinding[] argumentTypes, InvocationSite invocationSite) { CompilationUnitScope unitScope = compilationUnitScope(); unitScope.recordTypeReferences(argumentTypes); MethodBinding exactMethod = receiverType.getExactMethod(selector, argumentTypes, unitScope); if (exactMethod != null && exactMethod.typeVariables == Binding.NO_TYPE_VARIABLES && !exactMethod.isBridge()) { // in >= 1.5 mode, ensure the exactMatch did not match raw types if (compilerOptions().sourceLevel >= ClassFileConstants.JDK1_5) for (int i = argumentTypes.length; --i >= 0;) if (isPossibleSubtypeOfRawType(argumentTypes[i])) return null; // must find both methods for this case: <S extends A> void foo() {} and <N extends B> N foo() { return null; } // or find an inherited method when the exact match is to a bridge method unitScope.recordTypeReferences(exactMethod.thrownExceptions); if (exactMethod.isAbstract() && exactMethod.thrownExceptions != Binding.NO_EXCEPTIONS) return null; // may need to merge exceptions with interface method // special treatment for Object.getClass() in 1.5 mode (substitute parameterized return type) if (receiverType.isInterface() || exactMethod.canBeSeenBy(receiverType, invocationSite, this)) { if (argumentTypes == Binding.NO_PARAMETERS && CharOperation.equals(selector, TypeConstants.GETCLASS) && exactMethod.returnType.isParameterizedType()/*1.5*/) { return environment().createGetClassMethod(receiverType, exactMethod, this); }// w ww . ja va 2 s . c om // targeting a generic method could find an exact match with variable return type if (invocationSite.genericTypeArguments() != null) { exactMethod = computeCompatibleMethod(exactMethod, argumentTypes, invocationSite); } return exactMethod; } } return null; }
From source file:org.eclipse.jdt.internal.compiler.lookup.Scope.java
License:Open Source License
public MethodBinding findMethodForArray(ArrayBinding receiverType, char[] selector, TypeBinding[] argumentTypes, InvocationSite invocationSite) { TypeBinding leafType = receiverType.leafComponentType(); if (leafType instanceof ReferenceBinding) { if (!((ReferenceBinding) leafType).canBeSeenBy(this)) return new ProblemMethodBinding(selector, Binding.NO_PARAMETERS, (ReferenceBinding) leafType, ProblemReasons.ReceiverTypeNotVisible); }/*from w w w .j ava2s . c o m*/ ReferenceBinding object = getJavaLangObject(); MethodBinding methodBinding = object.getExactMethod(selector, argumentTypes, null); if (methodBinding != null) { // handle the method clone() specially... cannot be protected or throw exceptions if (argumentTypes == Binding.NO_PARAMETERS) { switch (selector[0]) { case 'c': if (CharOperation.equals(selector, TypeConstants.CLONE)) { return environment().computeArrayClone(methodBinding); } break; case 'g': if (CharOperation.equals(selector, TypeConstants.GETCLASS) && methodBinding.returnType.isParameterizedType()/*1.5*/) { return environment().createGetClassMethod(receiverType, methodBinding, this); } break; } } if (methodBinding.canBeSeenBy(receiverType, invocationSite, this)) return methodBinding; } methodBinding = findMethod(object, selector, argumentTypes, invocationSite); if (methodBinding == null) return new ProblemMethodBinding(selector, argumentTypes, ProblemReasons.NotFound); return methodBinding; }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.control.Dependencies.java
License:Open Source License
private static void checkMissingMethods(ReferenceBinding roleBinding, TypeDeclaration roleDecl) { if (roleBinding.isClass() && ((roleBinding.tagBits & TagBits.AnnotationInstantiation) != 0)) { InstantiationPolicy instantiationPolicy = RoleModel.getInstantiationPolicy(roleBinding); if (!instantiationPolicy.isAlways()) return; ClassScope scope = roleDecl.scope; boolean missing = false; MethodBinding equals = roleBinding.getExactMethod(TypeConstants.EQUALS, new TypeBinding[] { scope.getJavaLangObject() }, scope.compilationUnitScope()); if (equals == null || !equals.isValidBinding() || TypeBinding.notEquals(equals.declaringClass, roleBinding)) { missing = true;/*w ww . j a v a 2 s . com*/ } else { MethodBinding hashCode = roleBinding.getExactMethod(TypeConstants.HASHCODE, Binding.NO_PARAMETERS, scope.compilationUnitScope()); if (hashCode == null || !hashCode.isValidBinding() || TypeBinding.notEquals(hashCode.declaringClass, roleBinding)) missing = true; } if (missing) { scope.problemReporter().missingEqualsHashCodeWithInstantation(scope.referenceContext, instantiationPolicy); } } // copied abstract methods are not yet checked for callout inference (which is normally triggered from checkMethods()) if (roleBinding.isClass() && roleDecl.methods != null) { for (AbstractMethodDeclaration method : roleDecl.methods) { if (((method.modifiers & ClassFileConstants.AccAbstract) != 0) && method.isCopied) { // inheriting abstract method in non-abstract role may require callout inference: CalloutImplementor coi = new CalloutImplementor(roleDecl.getRoleModel()); MethodDeclaration callout = coi.generateInferredCallout(roleDecl, method.binding); if (callout != null) roleDecl.scope.problemReporter().addingInferredCalloutForInherited(roleDecl, method.binding, callout); } } } }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.control.Dependencies.java
License:Open Source License
private static boolean establishLateElementsCopied(RoleModel model) { boolean success = true; TypeDeclaration roleDecl = model.getAst(); if (roleDecl != null) { success = CopyInheritance.copyLocalTypes(model); if (!roleDecl.isInterface()) { if (roleDecl.methods != null) for (AbstractMethodDeclaration method : roleDecl.methods) if (method.isGenerated && method.model != null) method.model.generateStatements(); if (model.isBound()) { MethodBinding unimplementedGetBase = model.getInheritedUnimplementedGetBase(); if (unimplementedGetBase != null) { ReferenceBinding classBinding = model.getClassPartBinding(); if (classBinding != null && !classBinding.isBinaryBinding()) { MethodBinding getBaseMethod = classBinding.getExactMethod(IOTConstants._OT_GETBASE, Binding.NO_PARAMETERS, null); SourceTypeBinding classSourceType = (SourceTypeBinding) classBinding; classSourceType.addSyntheticBridgeMethod(unimplementedGetBase, getBaseMethod); }/* w w w.ja va 2 s . com*/ } } } } model.setState(STATE_LATE_ELEMENTS_COPIED); return success; }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.lookup.SyntheticBaseCallSurrogate.java
License:Open Source License
/** Is the callin method bound in the given role class? */ public static boolean isCallinMethodBoundIn(MethodBinding callinMethod, ReferenceBinding roleClass) { if (TypeBinding.notEquals(callinMethod.declaringClass, roleClass)) { callinMethod = roleClass.getExactMethod(callinMethod.selector, callinMethod.parameters, null); if (callinMethod == null) return false; }/*from ww w.j av a2 s . c o m*/ if (roleClass.callinCallouts != null) for (CallinCalloutBinding mapping : roleClass.callinCallouts) if (mapping._roleMethodBinding == callinMethod) return true; return false; }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.model.MethodModel.java
License:Open Source License
public static boolean isOverriding(MethodBinding methodBinding, CompilationUnitScope scope) { if (!methodBinding.declaringClass.isBinaryBinding()) { Dependencies.ensureBindingState(methodBinding.declaringClass, ITranslationStates.STATE_METHODS_VERIFIED); return methodBinding.isOverriding(); }/*from w ww. j a v a2s . c o m*/ ReferenceBinding currentClass = methodBinding.declaringClass.superclass(); while (currentClass != null) { MethodBinding candidate = currentClass.getExactMethod(methodBinding.selector, methodBinding.parameters, scope); if (candidate != null && candidate.isValidBinding()) return true; currentClass = currentClass.superclass(); } return false; }