private static boolean addOverridenMethods( IMethodBinding overridingMethod, ITypeBinding superType, Set<IMethodBinding> results) { for (IMethodBinding methodFromType : superType.getDeclaredMethods()) { if (overridingMethod.overrides(methodFromType) && !results.add(methodFromType)) { // type has already been visited return true; } } return false; }
public static Set<String> getMethodSignatures(final ITypeBinding objType) throws JavaModelException { Set<String> methods = new TreeSet<String>(); for(IMethodBinding m: objType.getDeclaredMethods() ) { methods.add( getSig(m) ); } return methods; }
private List<String> getExistingConstructorSignatures() { List<String> existing= new ArrayList<>(); IMethodBinding[] methods= fType.getDeclaredMethods(); for (int index= 0; index < methods.length; index++) { if (methods[index].isConstructor()) { StringBuilder buffer= new StringBuilder(); createSignature(methods[index], buffer, null); existing.add(buffer.toString()); } } return existing; }
private Map<String, IMethodBinding> toElementsMap(IAnnotationBinding annotBinding) { if (annotBinding == null) { return Collections.emptyMap(); } ITypeBinding annotationType = annotBinding.getAnnotationType(); IMethodBinding[] elements = annotationType.getDeclaredMethods(); Map<String, IMethodBinding> results = new HashMap<String, IMethodBinding>(); for (IMethodBinding element : elements) { results.put(element.getName(), element); } return results; }
private List getExistingConstructorSignatures() { List existing= new ArrayList(); IMethodBinding[] methods= fType.getDeclaredMethods(); for (int index= 0; index < methods.length; index++) { if (methods[index].isConstructor()) { StringBuffer buffer= new StringBuffer(); createSignature(methods[index], buffer, null); existing.add(buffer.toString()); } } return existing; }
private List<String> getExistingConstructorSignatures() { List<String> existing= new ArrayList<>(); IMethodBinding[] methods= fType.getDeclaredMethods(); for (int index= 0; index < methods.length; index++) { if (methods[index].isConstructor()) { StringBuffer buffer= new StringBuffer(); createSignature(methods[index], buffer, null); existing.add(buffer.toString()); } } return existing; }
private boolean annotatesDeclaredMethods(ITypeBinding type) { IMethodBinding[] declaredMethods= type.getDeclaredMethods(); for (int i= 0; i < declaredMethods.length; i++) { IMethodBinding curr= declaredMethods[i]; if (annotates(curr.getAnnotations())) { return true; } } return false; }
private static IBinding resolveSuperclassConstructor(ITypeBinding superClassDeclaration, IMethodBinding constructor) { IMethodBinding[] methods= superClassDeclaration.getDeclaredMethods(); for (int i= 0; i < methods.length; i++) { IMethodBinding method= methods[i]; if (method.isConstructor() && constructor.isSubsignature(method)) return method; } return null; }
private static IBinding resolveSuperclassConstructor(ITypeBinding superClassDeclaration, IMethodBinding constructor) { IMethodBinding[] methods= superClassDeclaration.getDeclaredMethods(); for (int i= 0; i < methods.length; i++) { IMethodBinding method= methods[i]; if (method.isConstructor() && constructor.isSubsignature(method)) return method; } return null; }
private boolean isValidEventAddListener(MethodDeclaration addListener) { if (1 != addListener.parameters().size()) return false; final ITypeBinding type = getFirstParameterType(addListener); if (!type.isInterface()) return false; return type.getDeclaredMethods().length == 1; }
private static boolean hasFieldWithName(ITypeBinding typeBinding, String name) { IMethodBinding[] methods= typeBinding.getDeclaredMethods(); for (int i= 0; i < methods.length; i++) { if (methods[i].getName().equals(name)) { return true; } } ITypeBinding superclass= typeBinding.getSuperclass(); if (superclass != null) { return hasMethodWithName(superclass, name); } return false; }
private static boolean hasFieldWithName(ITypeBinding typeBinding, String name) { IMethodBinding[] methods= typeBinding.getDeclaredMethods(); for (int i= 0; i < methods.length; i++) { if (methods[i].getName().equals(name)) { return true; } } ITypeBinding superclass= typeBinding.getSuperclass(); if (superclass != null) { return hasMethodWithName(superclass, name); } return false; }
private boolean canUseAssertNotEquals(final ImportDeclaration node) { final ITypeBinding typeBinding = resolveTypeBinding(node); if (hasType(typeBinding, "org.testng.Assert")) { for (IMethodBinding mb : typeBinding.getDeclaredMethods()) { if (mb.toString().contains("assertNotEquals")) { return true; } } } return false; }
private static boolean hasFieldWithName(ITypeBinding typeBinding, String name) { IMethodBinding[] methods= typeBinding.getDeclaredMethods(); for (int i= 0; i < methods.length; i++) { if (methods[i].getName().equals(name)) { return true; } } ITypeBinding superclass= typeBinding.getSuperclass(); if (superclass != null) { return hasMethodWithName(superclass, name); } return false; }
private static IMethodBinding findDefaultCtor(ITypeBinding superClass) { for (IMethodBinding met : superClass.getDeclaredMethods()) { if (met.isConstructor() && met.getParameterTypes().length == 0) return met; } Assertions.UNREACHABLE("Couldn't find default ctor"); return null; }
public ToStringInfo(ITypeBinding typeBinding) { IMethodBinding[] declaredMethods= typeBinding.getDeclaredMethods(); for (int i= 0; i < declaredMethods.length; i++) { if (declaredMethods[i].getName().equals(METHODNAME_TO_STRING) && declaredMethods[i].getParameterTypes().length == 0) { this.foundToString= true; if (Modifier.isFinal(declaredMethods[i].getModifiers())) this.foundFinalToString= true; } } } }
private IBinding[] getDeclaredBinding(ITypeBinding typeBinding, FqnType fqnType, ASTNode node) { switch (fqnType) { case METHOD: return typeBinding.getDeclaredMethods(); case FIELD: return typeBinding.getDeclaredFields(); case TYPE: return typeBinding.getDeclaredTypes(); default: throw new NotImplementedException(node, fqnType); } }
public ToStringInfo(ITypeBinding typeBinding) { IMethodBinding[] declaredMethods= typeBinding.getDeclaredMethods(); for (int i= 0; i < declaredMethods.length; i++) { if (declaredMethods[i].getName().equals(METHODNAME_TO_STRING) && declaredMethods[i].getParameterTypes().length == 0) { this.foundToString= true; if (Modifier.isFinal(declaredMethods[i].getModifiers())) this.foundFinalToString= true; } } } }
public boolean annotatesAtLeastOneMethod(ITypeBinding type) { while (type != null) { IMethodBinding[] declaredMethods = type.getDeclaredMethods(); for (IMethodBinding curr : declaredMethods) { if (annotates(curr.getAnnotations())) { return true; } } type = type.getSuperclass(); } return false; } }
private static void getOverridableMethods(AST ast, ITypeBinding superBinding, List<IMethodBinding> allMethods) { IMethodBinding[] methods= superBinding.getDeclaredMethods(); for (int offset= 0; offset < methods.length; offset++) { final int modifiers= methods[offset].getModifiers(); if (!methods[offset].isConstructor() && !Modifier.isStatic(modifiers) && !Modifier.isPrivate(modifiers)) { if (findOverridingMethod(methods[offset], allMethods) == null) allMethods.add(methods[offset]); } } ITypeBinding[] superInterfaces= superBinding.getInterfaces(); for (int index= 0; index < superInterfaces.length; index++) { getOverridableMethods(ast, superInterfaces[index], allMethods); } }