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; }
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; }
/** * Finds the method specified by <code>methodName</code> and <code>parameters</code> in * the type hierarchy denoted by the given type. 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 methodName The name of the method to find * @param parameters The parameter types of the method to find. If <code>null</code> is passed, only the name is matched and parameters are ignored. * @return the method binding representing the method */ public static IMethodBinding findMethodInHierarchy(ITypeBinding type, String methodName, ITypeBinding[] parameters) { IMethodBinding method= findMethodInType(type, methodName, parameters); if (method != null) return method; ITypeBinding superClass= type.getSuperclass(); if (superClass != null) { method= findMethodInHierarchy(superClass, methodName, parameters); if (method != null) return method; } ITypeBinding[] interfaces= type.getInterfaces(); for (int i= 0; i < interfaces.length; i++) { method= findMethodInHierarchy(interfaces[i], methodName, parameters); if (method != null) return method; } return null; }
private boolean needsNoSuperCall(ITypeBinding typeBinding, String name, ITypeBinding[] parameters) { Assert.isNotNull(typeBinding); IMethodBinding binding= Bindings.findMethodInHierarchy(typeBinding.getSuperclass(), name, parameters); if (binding != null && !Modifier.isAbstract(binding.getModifiers())) { ITypeBinding declaring= binding.getDeclaringClass(); return declaring.getQualifiedName().equals(JAVA_LANG_OBJECT); } return true; }
private boolean needsNoSuperCall(ITypeBinding typeBinding, String name, ITypeBinding[] parameters) { Assert.isNotNull(typeBinding); IMethodBinding binding= Bindings.findMethodInHierarchy(typeBinding.getSuperclass(), name, parameters); if (binding != null && !Modifier.isAbstract(binding.getModifiers())) { ITypeBinding declaring= binding.getDeclaringClass(); return declaring.getQualifiedName().equals(JAVA_LANG_OBJECT); } return true; }
/** * 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); }
/** * 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); }
@Override public boolean visit(VariableDeclarationExpression node) { if (node.getLocationInParent() == TryStatement.RESOURCES_PROPERTY) { Type type= node.getType(); ITypeBinding resourceTypeBinding= type.resolveBinding(); if (resourceTypeBinding != null) { IMethodBinding methodBinding= Bindings.findMethodInHierarchy(resourceTypeBinding, "close", new ITypeBinding[0]); //$NON-NLS-1$ if (methodBinding != null) { addExceptions(methodBinding.getExceptionTypes(), node.getAST()); } } } return super.visit(node); }
@Override public boolean visit(VariableDeclarationExpression node) { if (node.getLocationInParent() == TryStatement.RESOURCES_PROPERTY) { Type type = node.getType(); ITypeBinding resourceTypeBinding = type.resolveBinding(); if (resourceTypeBinding != null) { IMethodBinding methodBinding = Bindings.findMethodInHierarchy(resourceTypeBinding, "close", new ITypeBinding[0]); //$NON-NLS-1$ if (methodBinding != null) { addExceptions(methodBinding.getExceptionTypes(), node.getAST()); } } } return super.visit(node); }
@Override public boolean visit(VariableDeclarationExpression node) { if (node.getLocationInParent() == TryStatement.RESOURCES2_PROPERTY) { Type type= node.getType(); ITypeBinding resourceTypeBinding= type.resolveBinding(); if (resourceTypeBinding != null) { IMethodBinding methodBinding= Bindings.findMethodInHierarchy(resourceTypeBinding, "close", new ITypeBinding[0]); //$NON-NLS-1$ if (methodBinding != null) { addExceptions(methodBinding.getExceptionTypes(), node.getAST()); } } } return super.visit(node); }
private static IMethodBinding findGetter(ProposalParameter context) { ITypeBinding returnType= context.variableBinding.getType(); String getterName= GetterSetterUtil.getGetterName(context.variableBinding, context.compilationUnit.getJavaProject(), null, isBoolean(context)); ITypeBinding declaringType= context.variableBinding.getDeclaringClass(); IMethodBinding getter= Bindings.findMethodInHierarchy(declaringType, getterName, new ITypeBinding[0]); if (getter != null && getter.getReturnType().isAssignmentCompatible(returnType) && Modifier.isStatic(getter.getModifiers()) == Modifier.isStatic(context.variableBinding.getModifiers())) return getter; return null; }
private static IMethodBinding findGetter(ProposalParameter context) { ITypeBinding returnType = context.variableBinding.getType(); String getterName = GetterSetterUtil.getGetterName(context.variableBinding, context.compilationUnit.getJavaProject(), null, isBoolean(context)); ITypeBinding declaringType = context.variableBinding.getDeclaringClass(); if (declaringType == null) { return null; } IMethodBinding getter = Bindings.findMethodInHierarchy(declaringType, getterName, new ITypeBinding[0]); if (getter != null && getter.getReturnType().isAssignmentCompatible(returnType) && Modifier.isStatic(getter.getModifiers()) == Modifier.isStatic(context.variableBinding.getModifiers())) { return getter; } return null; }
private static IMethodBinding findGetter(ProposalParameter context) { ITypeBinding returnType= context.variableBinding.getType(); String getterName= GetterSetterUtil.getGetterName(context.variableBinding, context.compilationUnit.getJavaProject(), null, isBoolean(context)); ITypeBinding declaringType= context.variableBinding.getDeclaringClass(); if (declaringType == null) return null; IMethodBinding getter= Bindings.findMethodInHierarchy(declaringType, getterName, new ITypeBinding[0]); if (getter != null && getter.getReturnType().isAssignmentCompatible(returnType) && Modifier.isStatic(getter.getModifiers()) == Modifier.isStatic(context.variableBinding.getModifiers())) return getter; return null; }
private static IMethodBinding findGetter(ProposalParameter context) { ITypeBinding returnType= context.variableBinding.getType(); String getterName= GetterSetterUtil.getGetterName(context.variableBinding, context.compilationUnit.getJavaProject(), null, isBoolean(context)); ITypeBinding declaringType= context.variableBinding.getDeclaringClass(); if (declaringType == null) return null; IMethodBinding getter= Bindings.findMethodInHierarchy(declaringType, getterName, new ITypeBinding[0]); if (getter != null && getter.getReturnType().isAssignmentCompatible(returnType) && Modifier.isStatic(getter.getModifiers()) == Modifier.isStatic(context.variableBinding.getModifiers())) return getter; return null; }
if (Bindings.findMethodInHierarchy(castType, accessSelector.getIdentifier(), paramTypes) == null) { return false; IMethodBinding res= Bindings.findMethodInHierarchy(castType, accessSelector.getIdentifier(), paramTypes); if (res != null) { AST ast= expression.getAST();
if (Bindings.findMethodInHierarchy(castType, accessSelector.getIdentifier(), paramTypes) == null) { return false; IMethodBinding res= Bindings.findMethodInHierarchy(castType, accessSelector.getIdentifier(), paramTypes); if (res != null) { AST ast= expression.getAST();
for (int i2= 0; i2 < highestAndSupers.length; i2++) { if (highestAndSupers[i2].isEqualTo(currentAndSupers[i1]) && (Bindings.findMethodInHierarchy(highestAndSupers[i2], fTargetMethodBinding.getName(), fTargetMethodBinding.getParameterTypes()) != null)) { foundBinding= highestAndSupers[i2]; break;
public static void checkMethodInHierarchy(ITypeBinding type, String methodName, ITypeBinding returnType, ITypeBinding[] parameters, RefactoringStatus result, boolean reUseMethod) { IMethodBinding method= Bindings.findMethodInHierarchy(type, methodName, parameters); if (method != null) { boolean returnTypeClash= false;
/** * Generates the initializer for an iterator based <code>for</code> loop, which declares and * initializes the variable to loop over. * * @param rewrite the instance of {@link ASTRewrite} * @param loopVariableName the proposed name of the loop variable * @return a {@link VariableDeclarationExpression} to use as initializer */ private VariableDeclarationExpression getIteratorBasedForInitializer(ASTRewrite rewrite, SimpleName loopVariableName) { AST ast= rewrite.getAST(); IMethodBinding iteratorMethodBinding= Bindings.findMethodInHierarchy(fExpressionType, "iterator", new ITypeBinding[] {}); //$NON-NLS-1$ // initializing fragment VariableDeclarationFragment varDeclarationFragment= ast.newVariableDeclarationFragment(); varDeclarationFragment.setName(loopVariableName); MethodInvocation iteratorExpression= ast.newMethodInvocation(); iteratorExpression.setName(ast.newSimpleName(iteratorMethodBinding.getName())); iteratorExpression.setExpression((Expression) rewrite.createCopyTarget(fCurrentExpression)); varDeclarationFragment.setInitializer(iteratorExpression); // declaration VariableDeclarationExpression varDeclarationExpression= ast.newVariableDeclarationExpression(varDeclarationFragment); varDeclarationExpression.setType(getImportRewrite().addImport(iteratorMethodBinding.getReturnType(), ast, new ContextSensitiveImportRewriteContext(fCurrentStatement, getImportRewrite()))); return varDeclarationExpression; }
/** * Generates the initializer for an iterator based <code>for</code> loop, which declares and * initializes the variable to loop over. * * @param rewrite the instance of {@link ASTRewrite} * @param loopVariableName the proposed name of the loop variable * @return a {@link VariableDeclarationExpression} to use as initializer */ private VariableDeclarationExpression getIteratorBasedForInitializer(ASTRewrite rewrite, SimpleName loopVariableName) { AST ast= rewrite.getAST(); IMethodBinding iteratorMethodBinding= Bindings.findMethodInHierarchy(fExpressionType, "iterator", new ITypeBinding[] {}); //$NON-NLS-1$ // initializing fragment VariableDeclarationFragment varDeclarationFragment= ast.newVariableDeclarationFragment(); varDeclarationFragment.setName(loopVariableName); MethodInvocation iteratorExpression= ast.newMethodInvocation(); iteratorExpression.setName(ast.newSimpleName(iteratorMethodBinding.getName())); iteratorExpression.setExpression((Expression) rewrite.createCopyTarget(fCurrentExpression)); varDeclarationFragment.setInitializer(iteratorExpression); // declaration VariableDeclarationExpression varDeclarationExpression= ast.newVariableDeclarationExpression(varDeclarationFragment); varDeclarationExpression.setType(getImportRewrite().addImport(iteratorMethodBinding.getReturnType(), ast, new ContextSensitiveImportRewriteContext(fCurrentStatement, getImportRewrite()), TypeLocation.LOCAL_VARIABLE)); return varDeclarationExpression; }