Search in sources :

Example 11 with ModifierKeyword

use of org.eclipse.jdt.core.dom.Modifier.ModifierKeyword 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

ModifierKeyword (org.eclipse.jdt.core.dom.Modifier.ModifierKeyword)11 IType (org.eclipse.jdt.core.IType)7 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)5 ITypeHierarchy (org.eclipse.jdt.core.ITypeHierarchy)4 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)3 IField (org.eclipse.jdt.core.IField)3 IMethod (org.eclipse.jdt.core.IMethod)3 IExtendedModifier (org.eclipse.jdt.core.dom.IExtendedModifier)3 Modifier (org.eclipse.jdt.core.dom.Modifier)3 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)1 IInitializer (org.eclipse.jdt.core.IInitializer)1 IMember (org.eclipse.jdt.core.IMember)1 MarkerAnnotation (org.eclipse.jdt.core.dom.MarkerAnnotation)1 Name (org.eclipse.jdt.core.dom.Name)1 QualifiedName (org.eclipse.jdt.core.dom.QualifiedName)1 SimpleName (org.eclipse.jdt.core.dom.SimpleName)1 Annotation (org.eclipse.jdt.internal.compiler.ast.Annotation)1 MethodOverrideTester (org.eclipse.jdt.internal.corext.util.MethodOverrideTester)1