use of org.eclipse.jdt.core.ITypeHierarchy in project che by eclipse.
the class JavadocContentAccess2 method createSuperMethodReferences.
private static StringBuffer createSuperMethodReferences(final IMethod method, String urlPrefix) throws JavaModelException {
IType type = method.getDeclaringType();
ITypeHierarchy hierarchy = SuperTypeHierarchyCache.getTypeHierarchy(type);
final MethodOverrideTester tester = SuperTypeHierarchyCache.getMethodOverrideTester(type);
final ArrayList<IMethod> superInterfaceMethods = new ArrayList<IMethod>();
final IMethod[] superClassMethod = { null };
new InheritDocVisitor() {
@Override
public Object visit(IType currType) throws JavaModelException {
IMethod overridden = tester.findOverriddenMethodInType(currType, method);
if (overridden == null)
return InheritDocVisitor.CONTINUE;
if (currType.isInterface())
superInterfaceMethods.add(overridden);
else
superClassMethod[0] = overridden;
return STOP_BRANCH;
}
}.visitInheritDoc(type, hierarchy);
boolean hasSuperInterfaceMethods = superInterfaceMethods.size() != 0;
if (!hasSuperInterfaceMethods && superClassMethod[0] == null)
return null;
StringBuffer buf = new StringBuffer();
//$NON-NLS-1$
buf.append("<div>");
if (hasSuperInterfaceMethods) {
//$NON-NLS-1$
buf.append("<b>");
buf.append(JavaDocMessages.JavaDoc2HTMLTextReader_specified_by_section);
//$NON-NLS-1$
buf.append("</b> ");
for (Iterator<IMethod> iter = superInterfaceMethods.iterator(); iter.hasNext(); ) {
IMethod overridden = iter.next();
buf.append(createMethodInTypeLinks(overridden, urlPrefix));
if (iter.hasNext())
buf.append(JavaElementLabels.COMMA_STRING);
}
}
if (superClassMethod[0] != null) {
if (hasSuperInterfaceMethods)
buf.append(JavaElementLabels.COMMA_STRING);
//$NON-NLS-1$
buf.append("<b>");
buf.append(JavaDocMessages.JavaDoc2HTMLTextReader_overrides_section);
//$NON-NLS-1$
buf.append("</b> ");
buf.append(createMethodInTypeLinks(superClassMethod[0], urlPrefix));
}
//$NON-NLS-1$
buf.append("</div>");
return buf;
}
use of org.eclipse.jdt.core.ITypeHierarchy in project che by eclipse.
the class JavadocContentAccess2 method findAttachedDocInHierarchy.
/**
* Finds the first available attached Javadoc in the hierarchy of the given method.
*
* @param method
* the method
* @return the inherited Javadoc from the Javadoc attachment, or <code>null</code> if none
* @throws org.eclipse.jdt.core.JavaModelException
* unexpected problem
*/
private static String findAttachedDocInHierarchy(final IMethod method) throws JavaModelException {
IType type = method.getDeclaringType();
ITypeHierarchy hierarchy = SuperTypeHierarchyCache.getTypeHierarchy(type);
final MethodOverrideTester tester = SuperTypeHierarchyCache.getMethodOverrideTester(type);
return (String) new InheritDocVisitor() {
@Override
public Object visit(IType currType) throws JavaModelException {
IMethod overridden = tester.findOverriddenMethodInType(currType, method);
if (overridden == null)
return InheritDocVisitor.CONTINUE;
if (overridden.getOpenable().getBuffer() == null) {
// only if no source available
//TODO: BaseURL for method can be wrong for attached Javadoc from overridden
// (e.g. when overridden is from rt.jar). Fix would be to add baseURL here.
String attachedJavadoc = overridden.getAttachedJavadoc(null);
if (attachedJavadoc != null)
return attachedJavadoc;
}
return CONTINUE;
}
}.visitInheritDoc(type, hierarchy);
}
use of org.eclipse.jdt.core.ITypeHierarchy in project che by eclipse.
the class JavaNavigation method calculateSuperTypes.
private List<Type> calculateSuperTypes(IType type) throws JavaModelException {
List<Type> superTypes = new ArrayList<>();
ITypeHierarchy superTypeHierarchy = SuperTypeHierarchyCache.getTypeHierarchy(type);
if (superTypeHierarchy != null) {
IType[] superITypes = superTypeHierarchy.getAllSupertypes(type);
for (IType iType : superITypes) {
superTypes.add(convertToDTOType(iType));
}
}
return superTypes;
}
use of org.eclipse.jdt.core.ITypeHierarchy in project che by eclipse.
the class JavaTypeHierarchy method findSubTypes.
private void findSubTypes(IJavaElement element, List<Type> implementations) throws JavaModelException {
IType type = (IType) element;
ITypeHierarchy typeHierarchy = type.newTypeHierarchy(new NullProgressMonitor());
IType[] implTypes = typeHierarchy.getAllSubtypes(type);
for (IType implType : implTypes) {
Type dto = convertToTypeDTO(implType);
implementations.add(dto);
}
}
use of org.eclipse.jdt.core.ITypeHierarchy in project che by eclipse.
the class RippleMethodFinder2 method getCachedHierarchy.
private ITypeHierarchy getCachedHierarchy(IType type, WorkingCopyOwner owner, IProgressMonitor monitor) throws JavaModelException {
IType rep = fUnionFind.find(type);
if (rep != null) {
Collection<IType> collection = fRootReps.get(rep);
for (Iterator<IType> iter = collection.iterator(); iter.hasNext(); ) {
IType root = iter.next();
ITypeHierarchy hierarchy = fRootHierarchies.get(root);
if (hierarchy == null) {
hierarchy = root.newTypeHierarchy(owner, new SubProgressMonitor(monitor, 1));
fRootHierarchies.put(root, hierarchy);
}
if (hierarchy.contains(type))
return hierarchy;
}
}
return null;
}
Aggregations