public static Collection<IMethodBinding> getOverriddenMethod(IMethodBinding met) { HashMap<ITypeBinding, IMethodBinding> overridden = new HashMap<>(); if (met == null) return null; getMethodInClassOrSuperclass(met, met.getDeclaringClass(), true, overridden); if (overridden.size() == 0) return null; return overridden.values(); }
private static ITypeBinding getDeclaringTypeBinding(IBinding accessBinding) { if (accessBinding instanceof IMethodBinding) { return ((IMethodBinding) accessBinding).getDeclaringClass(); } else if (accessBinding instanceof IVariableBinding) { return ((IVariableBinding) accessBinding).getDeclaringClass(); } return null; }
/** * Returns a set made of all the method bindings which are overridden by the provided method binding. * * @param overridingMethod the overriding method binding * @return a set made of all the method bindings which are overridden by the provided method binding */ public static Set<IMethodBinding> getOverridenMethods(IMethodBinding overridingMethod) { final Set<IMethodBinding> results = new HashSet<IMethodBinding>(); findOverridenMethods(overridingMethod, results, overridingMethod.getDeclaringClass()); return results; }
private ITypeBinding resolveTypeBinding(final ImportDeclaration node) { IBinding resolveBinding = node.resolveBinding(); if (resolveBinding instanceof ITypeBinding) { return (ITypeBinding) resolveBinding; } else if (resolveBinding instanceof IMethodBinding) { return ((IMethodBinding) resolveBinding).getDeclaringClass(); } return null; }
private static Set<ITypeBinding> getDeclaringSuperTypes(IMethodBinding methodBinding) { ITypeBinding[] allSuperTypes= Bindings.getAllSuperTypes(methodBinding.getDeclaringClass()); Set<ITypeBinding> result= new HashSet<>(); for (int i= 0; i < allSuperTypes.length; i++) { ITypeBinding type= allSuperTypes[i]; if (findMethod(methodBinding, type) != null) result.add(type); } return result; }
private static Set getDeclaringSuperTypes(IMethodBinding methodBinding) { ITypeBinding[] allSuperTypes= Bindings.getAllSuperTypes(methodBinding.getDeclaringClass()); Set result= new HashSet(); for (int i= 0; i < allSuperTypes.length; i++) { ITypeBinding type= allSuperTypes[i]; if (findMethod(methodBinding, type) != null) result.add(type); } return result; }
private boolean declaredInSamePackage(final IMethodBinding methodBinding1, final IMethodBinding methodBinding2) { final ITypeBinding declaringClass1 = methodBinding1.getDeclaringClass(); final ITypeBinding declaringClass2 = methodBinding2.getDeclaringClass(); return declaringClass1.getPackage().equals(declaringClass2.getPackage()); }
private static IMethodBinding findMethod(IMethodBinding methodBinding, ITypeBinding type) { if (methodBinding.getDeclaringClass().equals(type)) return methodBinding; return Bindings.findOverriddenMethodInType(type, methodBinding); }
private IMethod getMethod(IMethodBinding calledMethodBinding) throws JavaModelException { if (calledMethodBinding == null) { return null; } ITypeBinding calledTypeBinding = calledMethodBinding.getDeclaringClass(); IType calledType = (IType) calledTypeBinding.getJavaElement(); return Bindings.findMethod(calledMethodBinding, calledType); }
public static String getMethodSignature(IMethodBinding binding, boolean inOtherCU) { StringBuffer buf= new StringBuffer(); if (inOtherCU && !binding.isConstructor()) { buf.append(binding.getDeclaringClass().getTypeDeclaration().getName()).append('.'); // simple type name } return BindingLabelProvider.getBindingLabel(binding, BindingLabelProvider.DEFAULT_TEXTFLAGS); }
private ITypeBinding getExpressionType(MethodInvocation invocation) { Expression expression= invocation.getExpression(); ITypeBinding typeBinding= null; if (expression == null) { typeBinding= invocation.resolveMethodBinding().getDeclaringClass(); } else { typeBinding= expression.resolveTypeBinding(); } Assert.isNotNull(typeBinding, "Type binding of target expression may not be null"); //$NON-NLS-1$ return typeBinding; }
public ReturnTypeVariable2 makeDeclaredReturnTypeVariable(IMethodBinding methodBinding, ICompilationUnit cu) { if (methodBinding == null) return null; ReturnTypeVariable2 cv= makeReturnTypeVariable(methodBinding); if (cv == null) return null; cv.setCompilationUnit(cu); if (methodBinding.getDeclaringClass().isLocal()) fCuScopedConstraintVariables.add(cv); return cv; }
public ITypeBinding getReceiverType() { Expression expression= Invocations.getExpression(invocation); if (expression != null) { return expression.resolveTypeBinding(); } IMethodBinding method= Invocations.resolveBinding(invocation); if (method != null) { return method.getDeclaringClass(); } 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 static boolean isInterfaceOrAnnotationMember(IBinding binding) { ITypeBinding declaringType= null; if (binding instanceof IVariableBinding) { declaringType= ((IVariableBinding) binding).getDeclaringClass(); } else if (binding instanceof IMethodBinding) { declaringType= ((IMethodBinding) binding).getDeclaringClass(); } else if (binding instanceof ITypeBinding) { declaringType= ((ITypeBinding) binding).getDeclaringClass(); } return declaringType != null && (declaringType.isInterface() || declaringType.isAnnotation()); }
private static ITypeBinding getDeclaringClassBinding(SimpleName memberName) { IBinding binding= memberName.resolveBinding(); if (binding instanceof IMethodBinding) return ((IMethodBinding) binding).getDeclaringClass(); if (binding instanceof IVariableBinding) return ((IVariableBinding) binding).getDeclaringClass(); if (binding instanceof ITypeBinding) return ((ITypeBinding) binding).getDeclaringClass(); Assert.isTrue(false); return null; }
private IJavaSearchScope createSearchScope(IMethod ctor, IMethodBinding binding) throws JavaModelException { if (ctor != null) { return RefactoringScopeFactory.create(ctor); } else { ITypeBinding type= Bindings.getTopLevelType(binding.getDeclaringClass()); return RefactoringScopeFactory.create(type.getJavaElement()); } }
@Override public boolean visit(MethodInvocation node) { IMethodBinding binding = node.resolveMethodBinding(); if (binding != null && !JdtFlags.isStatic(binding) && node.getExpression() == null && Bindings.isSuperType(binding.getDeclaringClass(), fFunctionalInterface, false)) { throw new AbortSearchException(); } return true; } }
@Override public boolean visit(MethodInvocation node) { IMethodBinding binding= node.resolveMethodBinding(); if (binding != null && !JdtFlags.isStatic(binding) && node.getExpression() == null && Bindings.isSuperType(binding.getDeclaringClass(), fFunctionalInterface, false)) throw new AbortSearchException(); return true; } }
public static boolean isVisibleInHierarchy(IMethodBinding member, IPackageBinding pack) { int otherflags= member.getModifiers(); ITypeBinding declaringType= member.getDeclaringClass(); if (Modifier.isPublic(otherflags) || Modifier.isProtected(otherflags) || (declaringType != null && declaringType.isInterface())) { return true; } else if (Modifier.isPrivate(otherflags)) { return false; } return declaringType != null && pack == declaringType.getPackage(); }