Search in sources :

Example 16 with ITypeHierarchy

use of org.eclipse.jdt.core.ITypeHierarchy in project che by eclipse.

the class IntroduceIndirectionRefactoring method updateTargetVisibility.

private RefactoringStatus updateTargetVisibility(IProgressMonitor monitor) throws JavaModelException, CoreException {
    RefactoringStatus result = new RefactoringStatus();
    // Adjust the visibility of the method and of the referenced type. Note that
    // the target method may not be in the target type; and in this case, the type
    // of the target method does not need a visibility adjustment.
    // This method is called after all other changes have been
    // created. Changes induced by this method will be attached to those changes.
    result.merge(adjustVisibility((IType) fIntermediaryFirstParameterType.getJavaElement(), fIntermediaryType, monitor));
    if (result.hasError())
        // binary
        return result;
    ModifierKeyword neededVisibility = getNeededVisibility(fTargetMethod, fIntermediaryType);
    if (neededVisibility != null) {
        result.merge(adjustVisibility(fTargetMethod, neededVisibility, monitor));
        if (result.hasError())
            // binary
            return result;
        // Need to adjust the overridden methods of the target method.
        ITypeHierarchy hierarchy = fTargetMethod.getDeclaringType().newTypeHierarchy(null);
        MethodOverrideTester tester = new MethodOverrideTester(fTargetMethod.getDeclaringType(), hierarchy);
        IType[] subtypes = hierarchy.getAllSubtypes(fTargetMethod.getDeclaringType());
        for (int i = 0; i < subtypes.length; i++) {
            IMethod method = tester.findOverridingMethodInType(subtypes[i], fTargetMethod);
            if (method != null && method.exists()) {
                result.merge(adjustVisibility(method, neededVisibility, monitor));
                if (monitor.isCanceled())
                    throw new OperationCanceledException();
                if (result.hasError())
                    // binary
                    return result;
            }
        }
    }
    return result;
}
Also used : ITypeHierarchy(org.eclipse.jdt.core.ITypeHierarchy) ModifierKeyword(org.eclipse.jdt.core.dom.Modifier.ModifierKeyword) MethodOverrideTester(org.eclipse.jdt.internal.corext.util.MethodOverrideTester) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) IMethod(org.eclipse.jdt.core.IMethod) IType(org.eclipse.jdt.core.IType)

Example 17 with ITypeHierarchy

use of org.eclipse.jdt.core.ITypeHierarchy in project che by eclipse.

the class InlineMethodRefactoring method checkOverridden.

private void checkOverridden(RefactoringStatus status, IProgressMonitor pm) throws JavaModelException {
    //$NON-NLS-1$
    pm.beginTask("", 9);
    pm.setTaskName(RefactoringCoreMessages.InlineMethodRefactoring_checking_overridden);
    MethodDeclaration decl = fSourceProvider.getDeclaration();
    IMethod method = (IMethod) decl.resolveBinding().getJavaElement();
    if (method == null || Flags.isPrivate(method.getFlags())) {
        pm.worked(8);
        return;
    }
    IType type = method.getDeclaringType();
    ITypeHierarchy hierarchy = type.newTypeHierarchy(new SubProgressMonitor(pm, 6));
    checkSubTypes(status, method, hierarchy.getAllSubtypes(type), new SubProgressMonitor(pm, 1));
    checkSuperClasses(status, method, hierarchy.getAllSuperclasses(type), new SubProgressMonitor(pm, 1));
    checkSuperInterfaces(status, method, hierarchy.getAllSuperInterfaces(type), new SubProgressMonitor(pm, 1));
    //$NON-NLS-1$
    pm.setTaskName("");
}
Also used : ITypeHierarchy(org.eclipse.jdt.core.ITypeHierarchy) MethodDeclaration(org.eclipse.jdt.core.dom.MethodDeclaration) IMethod(org.eclipse.jdt.core.IMethod) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) IType(org.eclipse.jdt.core.IType)

Example 18 with ITypeHierarchy

use of org.eclipse.jdt.core.ITypeHierarchy in project che by eclipse.

the class SuperTypeHierarchyCache method findTypeHierarchyInCache.

private static ITypeHierarchy findTypeHierarchyInCache(IType type) {
    synchronized (fgHierarchyCache) {
        for (int i = fgHierarchyCache.size() - 1; i >= 0; i--) {
            HierarchyCacheEntry curr = fgHierarchyCache.get(i);
            ITypeHierarchy hierarchy = curr.getTypeHierarchy();
            if (!hierarchy.exists()) {
                removeHierarchyEntryFromCache(curr);
            } else {
                if (hierarchy.contains(type)) {
                    curr.markAsAccessed();
                    return hierarchy;
                }
            }
        }
    }
    return null;
}
Also used : ITypeHierarchy(org.eclipse.jdt.core.ITypeHierarchy)

Example 19 with ITypeHierarchy

use of org.eclipse.jdt.core.ITypeHierarchy in project flux by eclipse.

the class SuperTypeHierarchyCache method getTypeHierarchy.

/**
	 * Returns a super type hierarchy that contains the given type.
	 * The returned hierarchy may actually be based on a subtype of the
	 * requested type. Therefore, queries such as {@link ITypeHierarchy#getAllClasses()}
	 * or {@link ITypeHierarchy#getRootInterfaces()} may return more types than the same
	 * queries on a type hierarchy for just the given type.
	 *
	 * @param type the focus type
	 * @param progressMonitor progress monitor
	 * @return a supertype hierarchy that contains <code>type</code>
	 * @throws JavaModelException if a problem occurs
	 */
public static ITypeHierarchy getTypeHierarchy(IType type, IProgressMonitor progressMonitor) throws JavaModelException {
    ITypeHierarchy hierarchy = findTypeHierarchyInCache(type);
    if (hierarchy == null) {
        fgCacheMisses++;
        hierarchy = type.newSupertypeHierarchy(progressMonitor);
        addTypeHierarchyToCache(hierarchy);
    } else {
        fgCacheHits++;
    }
    return hierarchy;
}
Also used : ITypeHierarchy(org.eclipse.jdt.core.ITypeHierarchy)

Example 20 with ITypeHierarchy

use of org.eclipse.jdt.core.ITypeHierarchy in project flux by eclipse.

the class SuperTypeHierarchyCache method findTypeHierarchyInCache.

private static ITypeHierarchy findTypeHierarchyInCache(IType type) {
    synchronized (fgHierarchyCache) {
        for (int i = fgHierarchyCache.size() - 1; i >= 0; i--) {
            HierarchyCacheEntry curr = fgHierarchyCache.get(i);
            ITypeHierarchy hierarchy = curr.getTypeHierarchy();
            if (!hierarchy.exists()) {
                removeHierarchyEntryFromCache(curr);
            } else {
                if (hierarchy.contains(type)) {
                    curr.markAsAccessed();
                    return hierarchy;
                }
            }
        }
    }
    return null;
}
Also used : ITypeHierarchy(org.eclipse.jdt.core.ITypeHierarchy)

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