Search in sources :

Example 6 with ITypeHierarchy

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;
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) MethodOverrideTester(org.eclipse.jdt.internal.corext.util.MethodOverrideTester) ArrayList(java.util.ArrayList) IType(org.eclipse.jdt.core.IType) ITypeHierarchy(org.eclipse.jdt.core.ITypeHierarchy) IMethod(org.eclipse.jdt.core.IMethod)

Example 7 with ITypeHierarchy

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);
}
Also used : ITypeHierarchy(org.eclipse.jdt.core.ITypeHierarchy) MethodOverrideTester(org.eclipse.jdt.internal.corext.util.MethodOverrideTester) IMethod(org.eclipse.jdt.core.IMethod) IType(org.eclipse.jdt.core.IType)

Example 8 with ITypeHierarchy

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;
}
Also used : JarEntryType(org.eclipse.che.ide.ext.java.shared.JarEntry.JarEntryType) IType(org.eclipse.jdt.core.IType) Type(org.eclipse.che.ide.ext.java.shared.dto.model.Type) ITypeHierarchy(org.eclipse.jdt.core.ITypeHierarchy) ArrayList(java.util.ArrayList) IType(org.eclipse.jdt.core.IType)

Example 9 with ITypeHierarchy

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);
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ITypeHierarchy(org.eclipse.jdt.core.ITypeHierarchy) IType(org.eclipse.jdt.core.IType) Type(org.eclipse.che.ide.ext.java.shared.dto.model.Type) IType(org.eclipse.jdt.core.IType)

Example 10 with ITypeHierarchy

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;
}
Also used : ITypeHierarchy(org.eclipse.jdt.core.ITypeHierarchy) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) IType(org.eclipse.jdt.core.IType)

Aggregations

ITypeHierarchy (org.eclipse.jdt.core.ITypeHierarchy)37 IType (org.eclipse.jdt.core.IType)25 IMethod (org.eclipse.jdt.core.IMethod)14 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)11 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)8 ArrayList (java.util.ArrayList)6 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)5 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)4 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)4 ModifierKeyword (org.eclipse.jdt.core.dom.Modifier.ModifierKeyword)4 MethodOverrideTester (org.eclipse.jdt.internal.corext.util.MethodOverrideTester)4 Type (org.eclipse.che.ide.ext.java.shared.dto.model.Type)3 JavaModelException (org.eclipse.jdt.core.JavaModelException)3 HashSet (java.util.HashSet)2 LinkedList (java.util.LinkedList)2 IJavaElement (org.eclipse.jdt.core.IJavaElement)2 MethodDeclaration (org.eclipse.jdt.core.dom.MethodDeclaration)2 RefactoringStatusContext (org.eclipse.ltk.core.refactoring.RefactoringStatusContext)2 HashMap (java.util.HashMap)1 List (java.util.List)1