Example usage for org.eclipse.jdt.internal.core.search JavaSearchTypeNameMatch setAccessibility

List of usage examples for org.eclipse.jdt.internal.core.search JavaSearchTypeNameMatch setAccessibility

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.core.search JavaSearchTypeNameMatch setAccessibility.

Prototype

public void setAccessibility(int accessibility) 

Source Link

Document

Sets the accessibility of the accepted match.

Usage

From source file:com.codenvy.ide.ext.java.server.internal.core.search.TypeNameMatchRequestorWrapper.java

License:Open Source License

public void acceptType(int modifiers, char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames,
        String path, AccessRestriction access) {

    // Get type/*from  ww w . j  a  v  a2  s  .co  m*/
    try {
        IType type = null;
        if (this.handleFactory != null) {
            //todo openable
            Openable openable = null;//this.handleFactory.createOpenable(path, this.scope);
            if (openable == null)
                return;
            switch (openable.getElementType()) {
            case IJavaElement.COMPILATION_UNIT:
                ICompilationUnit cu = (ICompilationUnit) openable;
                if (enclosingTypeNames != null && enclosingTypeNames.length > 0) {
                    type = cu.getType(new String(enclosingTypeNames[0]));
                    for (int j = 1, l = enclosingTypeNames.length; j < l; j++) {
                        type = type.getType(new String(enclosingTypeNames[j]));
                    }
                    type = type.getType(new String(simpleTypeName));
                } else {
                    type = cu.getType(new String(simpleTypeName));
                }
                break;
            case IJavaElement.CLASS_FILE:
                type = ((IClassFile) openable).getType();
                break;
            }
        } else {
            int separatorIndex = path.indexOf(IJavaSearchScope.JAR_FILE_ENTRY_SEPARATOR);
            type = separatorIndex == -1
                    ? createTypeFromPath(path, new String(simpleTypeName), enclosingTypeNames)
                    : createTypeFromJar(path, separatorIndex);
        }

        // Accept match if the type has been found
        if (type != null) {
            // hierarchy scopes require one more check:
            if (!(this.scope instanceof org.eclipse.jdt.internal.core.search.HierarchyScope)
                    || ((HierarchyScope) this.scope).enclosesFineGrained(type)) {

                // Create the match
                final JavaSearchTypeNameMatch match = new JavaSearchTypeNameMatch(type, modifiers);

                // Update match accessibility
                if (access != null) {
                    switch (access.getProblemId()) {
                    case IProblem.ForbiddenReference:
                        match.setAccessibility(IAccessRule.K_NON_ACCESSIBLE);
                        break;
                    case IProblem.DiscouragedReference:
                        match.setAccessibility(IAccessRule.K_DISCOURAGED);
                        break;
                    }
                }

                // Accept match
                this.requestor.acceptTypeNameMatch(match);
            }
        }
    } catch (JavaModelException e) {
        // skip
    }
}

From source file:org.eclipse.che.jdt.internal.core.search.TypeNameMatchRequestorWrapper.java

License:Open Source License

public void acceptType(int modifiers, char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames,
        String path, AccessRestriction access) {

    // Get type/*from w  ww .j  av a 2 s  . c  o  m*/
    try {
        IType type = null;
        if (this.handleFactory != null) {
            Openable openable = this.handleFactory.createOpenable(path, this.scope);
            if (openable == null)
                return;
            switch (openable.getElementType()) {
            case IJavaElement.COMPILATION_UNIT:
                ICompilationUnit cu = (ICompilationUnit) openable;
                if (enclosingTypeNames != null && enclosingTypeNames.length > 0) {
                    type = cu.getType(new String(enclosingTypeNames[0]));
                    for (int j = 1, l = enclosingTypeNames.length; j < l; j++) {
                        type = type.getType(new String(enclosingTypeNames[j]));
                    }
                    type = type.getType(new String(simpleTypeName));
                } else {
                    type = cu.getType(new String(simpleTypeName));
                }
                break;
            case IJavaElement.CLASS_FILE:
                type = ((IClassFile) openable).getType();
                break;
            }
        } else {
            int separatorIndex = path.indexOf(IJavaSearchScope.JAR_FILE_ENTRY_SEPARATOR);
            type = separatorIndex == -1
                    ? createTypeFromPath(path, new String(simpleTypeName), enclosingTypeNames)
                    : createTypeFromJar(path, separatorIndex);
        }

        // Accept match if the type has been found
        if (type != null) {
            // hierarchy scopes require one more check:
            if (!(this.scope instanceof HierarchyScope)
                    || ((HierarchyScope) this.scope).enclosesFineGrained(type)) {

                // Create the match
                final JavaSearchTypeNameMatch match = new JavaSearchTypeNameMatch(type, modifiers);

                // Update match accessibility
                if (access != null) {
                    switch (access.getProblemId()) {
                    case IProblem.ForbiddenReference:
                        match.setAccessibility(IAccessRule.K_NON_ACCESSIBLE);
                        break;
                    case IProblem.DiscouragedReference:
                        match.setAccessibility(IAccessRule.K_DISCOURAGED);
                        break;
                    }
                }

                // Accept match
                this.requestor.acceptTypeNameMatch(match);
            }
        }
    } catch (JavaModelException e) {
        // skip
    }
}