Search in sources :

Example 31 with ITypeHierarchy

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

the class ParametersHints method findHintsRecursive.

private void findHintsRecursive(IJavaElement method, IJavaElement parent, List<MethodParameters> result) throws JavaModelException {
    findHints(method, parent, result);
    IType type = (IType) parent;
    ITypeHierarchy typeHierarchy = type.newTypeHierarchy(new NullProgressMonitor());
    IType[] superTypes = typeHierarchy.getAllSupertypes(type);
    for (IType iType : superTypes) {
        findHintsRecursive(method, iType, result);
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ITypeHierarchy(org.eclipse.jdt.core.ITypeHierarchy) IType(org.eclipse.jdt.core.IType)

Example 32 with ITypeHierarchy

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

the class ReplaceInvocationsRefactoring 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 33 with ITypeHierarchy

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

the class MemberVisibilityAdjustor method getTypeHierarchy.

/**
	 * Returns a cached type hierarchy for the specified type.
	 *
	 * @param type the type to get the hierarchy for
	 * @param monitor the progress monitor to use
	 * @return the type hierarchy
	 * @throws JavaModelException if the type hierarchy could not be created
	 */
private ITypeHierarchy getTypeHierarchy(final IType type, final IProgressMonitor monitor) throws JavaModelException {
    ITypeHierarchy hierarchy = null;
    try {
        //$NON-NLS-1$
        monitor.beginTask("", 1);
        monitor.setTaskName(RefactoringCoreMessages.MemberVisibilityAdjustor_checking);
        try {
            hierarchy = fTypeHierarchies.get(type);
            if (hierarchy == null) {
                if (fOwner == null) {
                    hierarchy = type.newSupertypeHierarchy(new SubProgressMonitor(monitor, 1, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
                } else {
                    hierarchy = type.newSupertypeHierarchy(fOwner, new SubProgressMonitor(monitor, 1, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
                }
                fTypeHierarchies.put(type, hierarchy);
            }
        } finally {
            monitor.done();
        }
    } finally {
        monitor.done();
    }
    return hierarchy;
}
Also used : ITypeHierarchy(org.eclipse.jdt.core.ITypeHierarchy) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 34 with ITypeHierarchy

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

the class MemberVisibilityAdjustor method thresholdTypeToMethod.

/**
	 * Returns the visibility threshold from a type to a method.
	 *
	 * @param referencing the referencing type
	 * @param referenced the referenced method
	 * @param monitor the progress monitor to use
	 * @return the visibility keyword corresponding to the threshold, or <code>null</code> for default visibility
	 * @throws JavaModelException if the java elements could not be accessed
	 */
private ModifierKeyword thresholdTypeToMethod(final IType referencing, final IMethod referenced, final IProgressMonitor monitor) throws JavaModelException {
    final ICompilationUnit referencedUnit = referenced.getCompilationUnit();
    ModifierKeyword keyword = ModifierKeyword.PUBLIC_KEYWORD;
    if (referenced.getDeclaringType().equals(referencing))
        keyword = ModifierKeyword.PRIVATE_KEYWORD;
    else {
        final ITypeHierarchy hierarchy = getTypeHierarchy(referencing, new SubProgressMonitor(monitor, 1));
        final IType[] types = hierarchy.getSupertypes(referencing);
        IType superType = null;
        for (int index = 0; index < types.length; index++) {
            superType = types[index];
            if (superType.equals(referenced.getDeclaringType())) {
                keyword = ModifierKeyword.PROTECTED_KEYWORD;
                return keyword;
            }
        }
    }
    final ICompilationUnit typeUnit = referencing.getCompilationUnit();
    if (referencedUnit != null && referencedUnit.equals(typeUnit)) {
        if (referenced.getDeclaringType().getDeclaringType() != null)
            keyword = null;
        else
            keyword = ModifierKeyword.PRIVATE_KEYWORD;
    } else if (referencedUnit != null && referencedUnit.getParent().equals(typeUnit.getParent()))
        keyword = null;
    return keyword;
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) ITypeHierarchy(org.eclipse.jdt.core.ITypeHierarchy) ModifierKeyword(org.eclipse.jdt.core.dom.Modifier.ModifierKeyword) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) IType(org.eclipse.jdt.core.IType)

Example 35 with ITypeHierarchy

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

the class MemberVisibilityAdjustor method thresholdTypeToField.

/**
	 * Returns the visibility threshold from a type to a field.
	 *
	 * @param referencing the referencing type
	 * @param referenced the referenced field
	 * @param monitor the progress monitor to use
	 * @return the visibility keyword corresponding to the threshold, or <code>null</code> for default visibility
	 * @throws JavaModelException if the java elements could not be accessed
	 */
private ModifierKeyword thresholdTypeToField(final IType referencing, final IField referenced, final IProgressMonitor monitor) throws JavaModelException {
    ModifierKeyword keyword = ModifierKeyword.PUBLIC_KEYWORD;
    final ICompilationUnit referencedUnit = referenced.getCompilationUnit();
    if (referenced.getDeclaringType().equals(referencing))
        keyword = ModifierKeyword.PRIVATE_KEYWORD;
    else {
        final ITypeHierarchy hierarchy = getTypeHierarchy(referencing, new SubProgressMonitor(monitor, 1));
        final IType[] types = hierarchy.getSupertypes(referencing);
        IType superType = null;
        for (int index = 0; index < types.length; index++) {
            superType = types[index];
            if (superType.equals(referenced.getDeclaringType())) {
                keyword = ModifierKeyword.PROTECTED_KEYWORD;
                return keyword;
            }
        }
    }
    final ICompilationUnit typeUnit = referencing.getCompilationUnit();
    if (referencedUnit != null && referencedUnit.equals(typeUnit))
        keyword = ModifierKeyword.PRIVATE_KEYWORD;
    else if (referencedUnit != null && typeUnit != null && referencedUnit.getParent().equals(typeUnit.getParent()))
        keyword = null;
    return keyword;
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) ITypeHierarchy(org.eclipse.jdt.core.ITypeHierarchy) ModifierKeyword(org.eclipse.jdt.core.dom.Modifier.ModifierKeyword) 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