/** * Tests if this type is private to it's source file. A public type declared within a private type * is considered private. */ public static boolean isPrivateInnerType(ITypeBinding type) { if (isPrivate(type) || type.isLocal() || type.isAnonymous()) { return true; } ITypeBinding declaringClass = type.getDeclaringClass(); if (declaringClass != null) { return isPrivateInnerType(declaringClass); } return false; }
public static String bestNameableType(ITypeBinding type) { { String result_ = fqTypeName(type); if (result_ != null) return removeTypeParam(result_); } if (type.isCapture() || type.isWildcardType() || type.isTypeVariable()) { return bestNameableType(type.getErasure()); } // Find an interface or superclass being implemented. // For anonymous class, there can only be one. BUT for // local class, things are super f-ed up... if (type.isAnonymous()) { // any interfaces? if (type.getInterfaces().length > 0) { String result = fqTypeName(type.getInterfaces()[0]); assert (result != null); return removeTypeParam(result); } else { String result = fqTypeName(type.getSuperclass()); assert (result != null); return removeTypeParam(result); } } if (type.isLocal()) { // We can only make sense of this is there is just one // superclass+inferface. if (type.getInterfaces().length == 0) { // EASY! String result = fqTypeName(type.getSuperclass()); assert (result != null); return removeTypeParam(result); } else { // Well, maybe superclass is object? if (type.getSuperclass().getQualifiedName().equals(Object.class.getName())) { String result = fqTypeName(type.getInterfaces()[0]); assert (result != null); return removeTypeParam(result); } else { // Otherwise, return the superclass, I guess, but print a warning: String result = fqTypeName(type.getSuperclass()); assert (result != null); System.err.println("Local class has multiple supertypes..." + type.getBinaryName()); return removeTypeParam(result); } } } return Utilities.impossible(); }
/** * Adds the specified method binding to the search results. * * @param calledMethodBinding * @param node */ protected void addMethodCall(IMethodBinding calledMethodBinding, ASTNode node) { try { if (calledMethodBinding != null) { fProgressMonitor.worked(1); ITypeBinding calledTypeBinding = calledMethodBinding.getDeclaringClass(); IType calledType = null; if (!calledTypeBinding.isAnonymous()) { calledType = (IType) calledTypeBinding.getJavaElement(); } else { if (!"java.lang.Object" .equals(calledTypeBinding.getSuperclass().getQualifiedName())) { // $NON-NLS-1$ calledType = (IType) calledTypeBinding.getSuperclass().getJavaElement(); } else { calledType = (IType) calledTypeBinding.getInterfaces()[0].getJavaElement(); } } IMethod calledMethod = findIncludingSupertypes(calledMethodBinding, calledType, fProgressMonitor); IMember referencedMember = null; if (calledMethod == null) { if (calledMethodBinding.isConstructor() && calledMethodBinding.getParameterTypes().length == 0) { referencedMember = calledType; } } else { if (calledType.isInterface()) { calledMethod = findImplementingMethods(calledMethod); } if (!isIgnoredBySearchScope(calledMethod)) { referencedMember = calledMethod; } } final int position = node.getStartPosition(); final int number = fCompilationUnit.getLineNumber(position); fSearchResults.addMember( fMember, referencedMember, position, position + node.getLength(), number < 1 ? 1 : number); } } catch (JavaModelException jme) { JavaPlugin.log(jme); } }