Example usage for org.eclipse.jdt.core.compiler IProblem ForbiddenReference

List of usage examples for org.eclipse.jdt.core.compiler IProblem ForbiddenReference

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.compiler IProblem ForbiddenReference.

Prototype

int ForbiddenReference

To view the source code for org.eclipse.jdt.core.compiler IProblem ForbiddenReference.

Click Source Link

Usage

From source file:com.codenvy.ide.ext.java.emul.AccessRuleSet.java

License:Open Source License

/**
 * Select the first access rule which is violated when accessing a given type,
 * or null if no 'non accessible' access rule applies.
 *
 * @param targetTypeFilePath//from   ww w . ja va  2s . c o  m
 *         the target type file path, formed as:
 *         "org/eclipse/jdt/core/JavaCore"
 * @return the first access restriction that applies if any, null else
 */
public AccessRestriction getViolatedRestriction(char[] targetTypeFilePath) {
    for (int i = 0, length = this.accessRules.length; i < length; i++) {
        AccessRule accessRule = this.accessRules[i];
        if (CharOperation.pathMatch(accessRule.pattern, targetTypeFilePath, true/*case sensitive*/, '/')) {
            switch (accessRule.getProblemId()) {
            case IProblem.ForbiddenReference:
            case IProblem.DiscouragedReference:
                return new AccessRestriction(accessRule, this.classpathEntryType, this.classpathEntryName);
            default:
                return null;
            }
        }
    }
    return null;
}

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  .  ja v a  2 s  . c  o  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:com.siteview.mde.internal.ui.correction.java.QuickFixProcessor.java

License:Open Source License

public IJavaCompletionProposal[] getCorrections(IInvocationContext context, IProblemLocation[] locations)
        throws CoreException {
    ArrayList results = new ArrayList();
    for (int i = 0; i < locations.length; i++) {
        int id = locations[i].getProblemId();
        switch (id) {
        case IProblem.ForbiddenReference:
            handleAccessRestrictionProblem(context, locations[i], results);
        case IProblem.ImportNotFound:
            handleImportNotFound(context, locations[i], results);

        }/*w ww  . j a  v a 2 s .  c  om*/
    }
    return (IJavaCompletionProposal[]) results.toArray(new IJavaCompletionProposal[results.size()]);
}

From source file:com.siteview.mde.internal.ui.correction.java.QuickFixProcessor.java

License:Open Source License

public boolean hasCorrections(ICompilationUnit unit, int problemId) {
    switch (problemId) {
    case IProblem.ForbiddenReference:
    case IProblem.ImportNotFound:
        IJavaElement parent = unit.getParent();
        if (parent != null) {
            IJavaProject project = parent.getJavaProject();
            if (project != null)
                return WorkspaceModelManager.isPluginProject(project.getProject());
        }// www  . j ava 2s.  c  o m
    }
    return false;
}

From source file:org.ant4eclipse.lib.jdt.ecj.internal.tools.loader.FilteringClassFileLoader.java

License:Open Source License

/**
 * <p>//  w w  w .  java 2 s  . com
 * </p>
 * 
 * @param referableType
 * @return
 */
private ReferableType setAccessRestrictions(ReferableType referableType, ClassName className) {

    //
    if (referableType == null) {
        return referableType;
    }

    // try 'shortcut'
    if (this._containedPackages != null && this._containedPackages.contains(className.getPackageName())) {
        return referableType;
    }

    //
    String classFileName = className.asClassFileName();

    //
    for (String includePattern : this._includes) {
        if (classFileName.matches(includePattern)) {
            return referableType;
        }
    }

    //
    for (String exludePattern : this._excludes) {
        if (classFileName.matches(exludePattern)) {

            if (referableType instanceof DefaultReferableType) {

                AccessRestriction accessRestriction = new AccessRestriction(
                        new AccessRule("**".toCharArray(), IProblem.ForbiddenReference),
                        referableType.getLibraryType(), referableType.getLibraryLocation());

                ((DefaultReferableType) referableType).setAccessRestriction(accessRestriction);
            }
            return referableType;
        }
    }

    return referableType;
}

From source file:org.apache.felix.sigil.eclipse.ui.internal.quickfix.ImportQuickFixProcessor.java

License:Apache License

public boolean hasCorrections(ICompilationUnit unit, int problemId) {
    switch (problemId) {
    case IProblem.ForbiddenReference:
    case IProblem.ImportNotFound:
    case IProblem.IsClassPathCorrect:
    case IProblem.UndefinedType:
    case IProblem.UndefinedName:
        return true;
    default://  w ww. j  av a  2  s .  com
        return false;
    }
}

From source file:org.apache.felix.sigil.eclipse.ui.internal.quickfix.ImportQuickFixProcessor.java

License:Apache License

public IJavaCompletionProposal[] getCorrections(IInvocationContext context, IProblemLocation[] locations)
        throws CoreException {
    try {/*w w  w. j av a2s  .co m*/
        HashMap<Object, IJavaCompletionProposal> results = new HashMap<Object, IJavaCompletionProposal>();

        ISigilProjectModel project = findProject(context);

        if (project != null) {
            for (int i = 0; i < locations.length; i++) {
                switch (locations[i].getProblemId()) {
                case IProblem.ForbiddenReference:
                    handleImportNotFound(project, context, locations[i], results);
                    break;
                case IProblem.ImportNotFound:
                    handleImportNotFound(project, context, locations[i], results);
                    break;
                case IProblem.IsClassPathCorrect:
                    handleIsClassPathCorrect(project, context, locations[i], results);
                    break;
                case IProblem.UndefinedType:
                    handleUndefinedType(project, context, locations[i], results);
                    break;
                case IProblem.UndefinedName:
                    handleUndefinedName(project, context, locations[i], results);
                    break;
                }
            }
        }

        return (IJavaCompletionProposal[]) results.values()
                .toArray(new IJavaCompletionProposal[results.size()]);
    } catch (RuntimeException e) {
        e.printStackTrace();
        throw e;
    }
}

From source file:org.apache.felix.sigil.ui.eclipse.ui.quickfix.ImportQuickFixProcessor.java

License:Apache License

public boolean hasCorrections(ICompilationUnit unit, int problemId) {
    switch (problemId) {
    case IProblem.ImportNotFound:
    case IProblem.ForbiddenReference:
    case IProblem.NotVisibleType:
    case IProblem.UndefinedType:
        return true;
    default:/*  ww w . j  ava2 s. c  om*/
        return false;
    }
}

From source file:org.codehaus.groovy.eclipse.codeassist.processors.GroovyProposalTypeSearchRequestor.java

License:Apache License

public void acceptConstructor(int modifiers, char[] simpleTypeName, int parameterCount, char[] signature,
        char[][] parameterTypes, char[][] parameterNames, int typeModifiers, char[] packageName, int extraFlags,
        String path, AccessRestriction accessRestriction) {

    if (shouldAcceptConstructors) {

        // does not check cancellation for every types to avoid performance
        // loss/*from  ww w.  java  2  s  . c  om*/
        if ((this.foundConstructorsCount % (CHECK_CANCEL_FREQUENCY)) == 0)
            checkCancel();
        this.foundConstructorsCount++;

        if ((typeModifiers & ClassFileConstants.AccEnum) != 0)
            return;

        int accessibility = IAccessRule.K_ACCESSIBLE;
        if (accessRestriction != null) {
            switch (accessRestriction.getProblemId()) {
            case IProblem.ForbiddenReference:
                // forbidden references are removed
                return;
            case IProblem.DiscouragedReference:
                // discouraged references have lower priority
                accessibility = IAccessRule.K_DISCOURAGED;
                break;
            }
        }

        if (signature == null) {
            // signature = Signature.createArraySignature(typeSignature,
            // arrayCount)
        }

        if (this.acceptedConstructors == null) {
            this.acceptedConstructors = new ObjectVector();
        }
        this.acceptedConstructors
                .add(new AcceptedConstructor(modifiers, simpleTypeName, parameterCount, signature,
                        parameterTypes, parameterNames, typeModifiers, packageName, extraFlags, accessibility));
    }

}

From source file:org.codehaus.groovy.eclipse.codeassist.processors.GroovyProposalTypeSearchRequestor.java

License:Apache License

public void acceptType(char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames, int modifiers,
        AccessRestriction accessRestriction) {
    // does not check cancellation for every types to avoid performance
    // loss//from   w  w w  . jav  a  2 s.com
    if ((this.foundTypesCount % CHECK_CANCEL_FREQUENCY) == 0)
        checkCancel();
    this.foundTypesCount++;

    // ignore synthetic
    if (CharOperation.contains('$', simpleTypeName)) {
        return;
    }

    int accessibility = IAccessRule.K_ACCESSIBLE;
    if (accessRestriction != null) {
        switch (accessRestriction.getProblemId()) {
        case IProblem.ForbiddenReference:
            // forbidden references are removed
            return;
        case IProblem.DiscouragedReference:
            // discouraged references have a lower priority
            accessibility = IAccessRule.K_DISCOURAGED;
            break;
        }
    }

    if (this.acceptedTypes == null) {
        this.acceptedTypes = new ObjectVector();
    }
    this.acceptedTypes
            .add(new AcceptedType(packageName, simpleTypeName, enclosingTypeNames, modifiers, accessibility));
}