Java Code Examples for org.eclipse.jdt.core.ITypeHierarchy#getAllSupertypes()

The following examples show how to use org.eclipse.jdt.core.ITypeHierarchy#getAllSupertypes() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JavadocContentAccess.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
private static Reader findDocInHierarchy(IMethod method, boolean useAttachedJavadoc) throws JavaModelException {
	/*
	 * Catch ExternalJavaProject in which case
	 * no hierarchy can be built.
	 */
	if (!method.getJavaProject().exists()) {
		return null;
	}

	IType type= method.getDeclaringType();
	ITypeHierarchy hierarchy= type.newSupertypeHierarchy(null);

	MethodOverrideTester tester= new MethodOverrideTester(type, hierarchy);

	IType[] superTypes= hierarchy.getAllSupertypes(type);
	for (IType curr : superTypes) {
		IMethod overridden= tester.findOverriddenMethodInType(curr, method);
		if (overridden != null) {
			Reader reader = getHTMLContentReader(overridden, false, useAttachedJavadoc);
			if (reader != null) {
				return reader;
			}
		}
	}
	return null;
}
 
Example 2
Source File: ContentAssistHistory.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Remembers the selection of a right hand side type (proposal type) for a certain left hand side (expected
 * type) in content assist.
 *
 * @param lhs the left hand side / expected type
 * @param rhs the selected right hand side
 */
public void remember(IType lhs, IType rhs) {
	Assert.isLegal(lhs != null);
	Assert.isLegal(rhs != null);

	try {
		if (!isCacheableRHS(rhs))
			return;
		ITypeHierarchy hierarchy= rhs.newSupertypeHierarchy(getProgressMonitor());
		if (hierarchy.contains(lhs)) {
			// TODO remember for every member of the LHS hierarchy or not? Yes for now.
			IType[] allLHSides= hierarchy.getAllSupertypes(lhs);
			String rhsQualifiedName= rhs.getFullyQualifiedName();
			for (int i= 0; i < allLHSides.length; i++)
				rememberInternal(allLHSides[i], rhsQualifiedName);
			rememberInternal(lhs, rhsQualifiedName);
		}
	} catch (JavaModelException x) {
		JavaPlugin.log(x);
	}
}
 
Example 3
Source File: CompilationUnitCompletion.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns <code>true</code> if <code>subTypeSignature</code>
 * describes a type which is a true sub type of the type described by
 * <code>superTypeSignature</code>.
 *
 * @param subTypeSignature the potential subtype's signature
 * @param superTypeSignature the potential supertype's signature
 * @return <code>true</code> if the inheritance relationship holds
 */
private boolean isTrueSubtypeOf(String subTypeSignature, String superTypeSignature) {
	// try cheap test first
	if (subTypeSignature.equals(superTypeSignature))
		return true;

	if (SignatureUtil.isJavaLangObject(subTypeSignature))
		return false; // Object has no super types

	if (Signature.getTypeSignatureKind(subTypeSignature) != Signature.BASE_TYPE_SIGNATURE && SignatureUtil.isJavaLangObject(superTypeSignature))
		return true;

	IJavaProject project= fUnit.getJavaProject();

	try {

		if ((Signature.getTypeSignatureKind(subTypeSignature) & (Signature.TYPE_VARIABLE_SIGNATURE | Signature.CLASS_TYPE_SIGNATURE)) == 0)
			return false;
		IType subType= project.findType(SignatureUtil.stripSignatureToFQN(subTypeSignature));
		if (subType == null)
			return false;

		if ((Signature.getTypeSignatureKind(superTypeSignature) & (Signature.TYPE_VARIABLE_SIGNATURE | Signature.CLASS_TYPE_SIGNATURE)) == 0)
			return false;
		IType superType= project.findType(SignatureUtil.stripSignatureToFQN(superTypeSignature));
		if (superType == null)
			return false;

		ITypeHierarchy hierarchy= subType.newSupertypeHierarchy(null);
		IType[] types= hierarchy.getAllSupertypes(subType);

		for (int i= 0; i < types.length; i++)
			if (types[i].equals(superType))
				return true;
	} catch (JavaModelException e) {
		// ignore and return false
	}

	return false;
}
 
Example 4
Source File: JavadocContentAccess.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static Reader findDocInHierarchy(IMethod method, boolean isHTML, boolean useAttachedJavadoc) throws JavaModelException {
	/*
	 * Catch ExternalJavaProject in which case
	 * no hierarchy can be built.
	 */
	if (!method.getJavaProject().exists())
		return null;

	IType type= method.getDeclaringType();
	ITypeHierarchy hierarchy= type.newSupertypeHierarchy(null);

	MethodOverrideTester tester= new MethodOverrideTester(type, hierarchy);

	IType[] superTypes= hierarchy.getAllSupertypes(type);
	for (int i= 0; i < superTypes.length; i++) {
		IType curr= superTypes[i];
		IMethod overridden= tester.findOverriddenMethodInType(curr, method);
		if (overridden != null) {
			Reader reader;
			if (isHTML)
				reader= getHTMLContentReader(overridden, false, useAttachedJavadoc);
			else
				reader= getContentReader(overridden, false);
			if (reader != null)
				return reader;
		}
	}
	return null;
}
 
Example 5
Source File: MethodsContentProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public Object[] getElements(Object element) {
	if (element instanceof IType) {
		IType type= (IType)element;

		List<Object> res= new ArrayList<Object>();
		try {
			ITypeHierarchy hierarchy= fHierarchyLifeCycle.getHierarchy();
			if (fShowInheritedMethods && hierarchy != null) {
				IType[] allSupertypes= hierarchy.getAllSupertypes(type);
				// sort in from last to first: elements with same name
				// will show up in hierarchy order
				for (int i= allSupertypes.length - 1; i >= 0; i--) {
					IType superType= allSupertypes[i];
					if (superType.exists()) {
						addAll(superType.getMethods(), res);
						addAll(superType.getInitializers(), res);
						addAll(superType.getFields(), res);
					}
				}
			}
			if (type.exists()) {
				addAll(type.getMethods(), res);
				addAll(type.getInitializers(), res);
				addAll(type.getFields(), res);
			}
		} catch (JavaModelException e) {
			JavaPlugin.log(e);
		}
		return res.toArray();
	}
	return NO_ELEMENTS;
}
 
Example 6
Source File: JavaOutlineInformationControl.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public Object[] getChildren(Object element) {
	if (fShowOnlyMainType) {
		if (element instanceof ITypeRoot) {
			element= ((ITypeRoot)element).findPrimaryType();
		}

		if (element == null)
			return NO_CHILDREN;
	}

	if (fShowInheritedMembers && element instanceof IType) {
		IType type= (IType)element;
		if (type.getDeclaringType() == null || type.equals(fInitiallySelectedType)) {
			ITypeHierarchy th= getSuperTypeHierarchy(type);
			if (th != null) {
				List<Object> children= new ArrayList<Object>();
				IType[] superClasses= th.getAllSupertypes(type);
				children.addAll(Arrays.asList(super.getChildren(type)));
				for (int i= 0, scLength= superClasses.length; i < scLength; i++)
					children.addAll(Arrays.asList(super.getChildren(superClasses[i])));
				return children.toArray();
			}
		}
	}
	return super.getChildren(element);
}
 
Example 7
Source File: JavaOutlineInformationControl.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private IJavaElement[] getInputForCategories() {
	if (fInput == null)
		return new IJavaElement[0];

	if (fOutlineContentProvider.isShowingInheritedMembers()) {
		IJavaElement p= fInput;
		if (p instanceof ITypeRoot) {
			p= ((ITypeRoot)p).findPrimaryType();
		}
		while (p != null && !(p instanceof IType)) {
			p= p.getParent();
		}
		if (!(p instanceof IType))
			return new IJavaElement[] {fInput};

		ITypeHierarchy hierarchy= getSuperTypeHierarchy((IType)p);
		if (hierarchy == null)
			return new IJavaElement[] {fInput};

		IType[] supertypes= hierarchy.getAllSupertypes((IType)p);
		IJavaElement[] result= new IJavaElement[supertypes.length + 1];
		result[0]= fInput;
		System.arraycopy(supertypes, 0, result, 1, supertypes.length);
		return result;
	} else {
		return new IJavaElement[] {fInput};
	}
}