private boolean needsNoSuperCall(ITypeBinding typeBinding, String name, ITypeBinding[] parameters) { Assert.isNotNull(typeBinding); IMethodBinding binding= Bindings.findMethodInHierarchy(typeBinding.getSuperclass(), name, parameters); if (binding != null) { ITypeBinding declaring= binding.getDeclaringClass(); return declaring.getQualifiedName().equals(JAVA_LANG_OBJECT); } return true; }
/** * Finds the field specified by <code>fieldName</code> in * the type hierarchy denoted by the given type. Returns <code>null</code> if no such field * exists. If the field is defined in more than one super type only the first match is * returned. First the super class is examined and then the implemented interfaces. * @param type The type to search the field in * @param fieldName The name of the field to find * @return the variable binding representing the field */ public static IVariableBinding findFieldInHierarchy(ITypeBinding type, String fieldName) { IVariableBinding field= findFieldInType(type, fieldName); if (field != null) return field; ITypeBinding superClass= type.getSuperclass(); if (superClass != null) { field= findFieldInHierarchy(superClass, fieldName); if (field != null) return field; } ITypeBinding[] interfaces= type.getInterfaces(); for (int i= 0; i < interfaces.length; i++) { field= findFieldInHierarchy(interfaces[i], fieldName); if (field != null) // no private fields in interfaces return field; } return null; }
private static IMethodBinding findAnnotationMember(Annotation annotation, String name) { ITypeBinding annotBinding= annotation.resolveTypeBinding(); if (annotBinding != null) { return Bindings.findMethodInType(annotBinding, name, (String[]) null); } return null; }
private static boolean containsASuperType(ITypeBinding type, Set declaringSuperTypes) { for (Iterator iter= declaringSuperTypes.iterator(); iter.hasNext();) { ITypeBinding maybeSuperType= (ITypeBinding) iter.next(); if (! Bindings.equals(maybeSuperType, type) && Bindings.isSuperType(maybeSuperType, type)) return true; } return false; }
public static IMethodBinding findMethodInType(final ITypeBinding type, final String name, final ITypeBinding[] paramTypes) { IMethodBinding origMethod; if (type.isInterface()) { origMethod = Bindings.findMethodInHierarchy(type, name, paramTypes); } else { origMethod = Bindings.findMethodInType(type, name, paramTypes); } return origMethod; }
private static int getNeededVisibility(ASTNode currNode, ITypeBinding targetType) { ITypeBinding currNodeBinding= Bindings.getBindingOfParentType(currNode); if (currNodeBinding == null) { // import return Modifier.PUBLIC; } if (Bindings.isSuperType(targetType, currNodeBinding)) { return Modifier.PROTECTED; } if (currNodeBinding.getPackage().getKey().equals(targetType.getPackage().getKey())) { return 0; } return Modifier.PUBLIC; }
ITypeBinding binding= Bindings.getBindingOfParentType(declaration); if (binding == null) { return; IMethodBinding overridden= null; if (methodBinding != null) { overridden= Bindings.findOverriddenMethod(methodBinding, true); String typeQualifiedName= Bindings.getTypeQualifiedName(binding); String[] typeParamNames; if (declaration instanceof TypeDeclaration) {
if (Bindings.findMethodInHierarchy(castType, accessSelector.getIdentifier(), paramTypes) == null) { return false; } else if (Bindings.findFieldInHierarchy(castType, accessSelector.getIdentifier()) == null) { return false; IMethodBinding res= Bindings.findMethodInHierarchy(castType, accessSelector.getIdentifier(), paramTypes); if (res != null) { AST ast= expression.getAST();
return; ITypeBinding typeBinding= Bindings.getBindingOfParentType(selectedNode); if (typeBinding == null) { return; IVariableBinding fieldBinding= Bindings.findFieldInHierarchy(typeBinding, binding.getName()); if (fieldBinding == null || fieldBinding.getDeclaringClass() != typeBinding && Modifier.isPrivate(fieldBinding.getModifiers())) { return;
public static ITypeBinding guessBindingForReference(ASTNode node) { return Bindings.normalizeTypeBinding(getPossibleReferenceBinding(node)); }
return Signature.toString(candidate).equals(Bindings.getFullyQualifiedName(type)); } else { String[][] qualifiedCandidates= scope.resolveType(Signature.toString(candidate)); return false; String packageName= type.getPackage().isUnnamed() ? "" : type.getPackage().getName(); //$NON-NLS-1$ String typeName= getTypeQualifiedName(type); for (int i= 0; i < qualifiedCandidates.length; i++) { String[] qualifiedCandidate= qualifiedCandidates[i];
if (Bindings.equals(fTarget, binding)) if (fAnonymousClass > 0) { final ThisExpression target= ast.newThisExpression(); ITypeBinding enclosingType= ASTNodes.getEnclosingType(node); if (enclosingType != null) { IVariableBinding fieldInHierarchy= Bindings.findFieldInHierarchy(enclosingType, node.getIdentifier()); if (fieldInHierarchy != null) { targetType= enclosingType; if (Bindings.isSuperType(targetType, method.getDeclaringClass(), false)) { if (JdtFlags.isStatic(variable)) rewrite.replace(node, ast.newQualifiedName(ASTNodeFactory.newName(ast, fTargetRewrite.getImportRewrite().addImport(targetType)), ast.newSimpleName(node.getFullyQualifiedName())), null);
private static boolean isDeclaredException(ITypeBinding curr, ITypeBinding[] declared) { for (int i= 0; i < declared.length; i++) { if (Bindings.isSuperType(declared[i], curr)) { return true; } } return false; }
/** * Extracts the type parameter of the variable contained in fCurrentExpression or the elements * type to iterate over an array using <code>foreach</code>. * * @param ast the current {@link AST} instance * @return the {@link ITypeBinding} of the elements to iterate over */ private ITypeBinding extractType(AST ast) { if (fExpressionType.isArray()) { return Bindings.normalizeForDeclarationUse(fExpressionType.getComponentType(), ast); } // extract elements type directly out of the bindings IMethodBinding iteratorMethodBinding= Bindings.findMethodInHierarchy(fExpressionType, "iterator", new ITypeBinding[] {}); //$NON-NLS-1$ IMethodBinding iteratorNextMethodBinding= Bindings.findMethodInHierarchy(iteratorMethodBinding.getReturnType(), "next", new ITypeBinding[] {}); //$NON-NLS-1$ ITypeBinding currentElementBinding= iteratorNextMethodBinding.getReturnType(); return Bindings.normalizeForDeclarationUse(currentElementBinding, ast); }
private static IMethodBinding findMethod(IMethodBinding methodBinding, ITypeBinding type) { if (methodBinding.getDeclaringClass().equals(type)) return methodBinding; return Bindings.findOverriddenMethodInType(type, methodBinding); }
private static boolean contains(Collection<ITypeBinding> c, ITypeBinding binding){ for (Iterator<ITypeBinding> it=c.iterator(); it.hasNext(); ){ ITypeBinding b = it.next(); if (Bindings.equals(b, binding)) return true; } return false; }
final String name= Bindings.getTypeQualifiedName(binding); if (binding.isWildcardType()) {
/** * Finds a method in the hierarchy of <code>type</code> that is overridden by <code>binding</code>. * Returns <code>null</code> if no such method exists. If the method is defined in more than one super type only the first match is * returned. First the super class is examined and then the implemented interfaces. * @param type The type to search the method in * @param binding The method that overrides * @return the method binding overridden the method */ public static IMethodBinding findOverriddenMethodInHierarchy(ITypeBinding type, IMethodBinding binding) { IMethodBinding method= findOverriddenMethodInType(type, binding); if (method != null) return method; ITypeBinding superClass= type.getSuperclass(); if (superClass != null) { method= findOverriddenMethodInHierarchy(superClass, binding); if (method != null) return method; } ITypeBinding[] interfaces= type.getInterfaces(); for (int i= 0; i < interfaces.length; i++) { method= findOverriddenMethodInHierarchy(interfaces[i], binding); if (method != null) return method; } return null; }
private void addConstraintsForOverriding(IMethodBinding methodBinding, ConstraintVariable2 returnTypeCv, ConstraintVariable2[] parameterTypeCvs) { boolean hasParameterElementCvs= false; for (int i= 0; i < parameterTypeCvs.length; i++) if (parameterTypeCvs[i] != null) hasParameterElementCvs= true; if (returnTypeCv == null && ! hasParameterElementCvs) return; ITypeBinding[] allSuperTypes= Bindings.getAllSuperTypes(methodBinding.getDeclaringClass()); for (int i= 0; i < allSuperTypes.length; i++) { ITypeBinding superType= allSuperTypes[i]; IMethodBinding superMethod= Bindings.findOverriddenMethodInType(superType, methodBinding); if (superMethod == null) continue; for (int p= 0; p < parameterTypeCvs.length; p++) { if (parameterTypeCvs[p] == null) continue; ParameterTypeVariable2 parameterTypeCv= fTCModel.makeParameterTypeVariable(superMethod, p); fTCModel.createElementEqualsConstraints(parameterTypeCv, parameterTypeCvs[p]); } if (returnTypeCv != null) { ReturnTypeVariable2 superMethodReturnTypeCv= fTCModel.makeReturnTypeVariable(superMethod); fTCModel.createElementEqualsConstraints(superMethodReturnTypeCv, returnTypeCv); } } }
ITypeBinding parentTypeBinding= Bindings.getBindingOfParentTypeContext(selector); if (parentTypeBinding != null) { ITypeBinding binding= getQualifier(selector);