Example usage for org.eclipse.jdt.core IJavaModelStatusConstants ELEMENT_NOT_ON_CLASSPATH

List of usage examples for org.eclipse.jdt.core IJavaModelStatusConstants ELEMENT_NOT_ON_CLASSPATH

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IJavaModelStatusConstants ELEMENT_NOT_ON_CLASSPATH.

Prototype

int ELEMENT_NOT_ON_CLASSPATH

To view the source code for org.eclipse.jdt.core IJavaModelStatusConstants ELEMENT_NOT_ON_CLASSPATH.

Click Source Link

Document

Status constant indicating that an element is not on its project's claspath.

Usage

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

License:Open Source License

public IBuffer getBuffer() throws JavaModelException {
    IStatus status = validateClassFile();
    if (status.isOK()) {
        return super.getBuffer();
    } else {/*from  w  ww. j a v  a  2  s .c  om*/
        switch (status.getCode()) {
        case IJavaModelStatusConstants.ELEMENT_NOT_ON_CLASSPATH: // don't throw a JavaModelException to be able to open .class file outside the classpath (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=138507 )
        case IJavaModelStatusConstants.INVALID_ELEMENT_TYPES: // don't throw a JavaModelException to be able to open .class file in proj==src case without source (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=221904 )
            return null;
        default:
            throw new JavaModelException((IJavaModelStatus) status);
        }
    }
}

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

License:Open Source License

protected IStatus validateCompilationUnit(File resource) {
    IPackageFragmentRoot root = getPackageFragmentRoot();
    // root never null as validation is not done for working copies
    try {/*from  w  w w  .j  a  v a  2  s  .  co  m*/
        if (root.getKind() != IPackageFragmentRoot.K_SOURCE)
            return new JavaModelStatus(IJavaModelStatusConstants.INVALID_ELEMENT_TYPES, root);
    } catch (JavaModelException e) {
        return e.getJavaModelStatus();
    }
    if (resource != null) {
        char[][] inclusionPatterns = ((PackageFragmentRoot) root).fullInclusionPatternChars();
        char[][] exclusionPatterns = ((PackageFragmentRoot) root).fullExclusionPatternChars();
        if (Util.isExcluded(new Path(resource.getPath()), inclusionPatterns, exclusionPatterns, false))
            return new JavaModelStatus(IJavaModelStatusConstants.ELEMENT_NOT_ON_CLASSPATH, this);
        if (!resource.exists())
            return new JavaModelStatus(IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST, this);
    }
    IJavaProject project = getJavaProject();
    return JavaConventions.validateCompilationUnitName(getElementName(),
            project.getOption(JavaCore.COMPILER_SOURCE, true),
            project.getOption(JavaCore.COMPILER_COMPLIANCE, true));
}

From source file:org.codehaus.groovy.eclipse.ui.GroovyResourcePropertyTester.java

License:Apache License

public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
    boolean returnValue = false;

    if (hasMain.equals(property) || isScript.equals(property)) {
        if (receiver instanceof IAdaptable) {
            try {
                ICompilationUnit unit = (ICompilationUnit) ((IAdaptable) receiver)
                        .getAdapter(ICompilationUnit.class);
                if (unit == null) {
                    IFile file = (IFile) ((IAdaptable) receiver).getAdapter(IFile.class);
                    if (file != null && Util.isJavaLikeFileName(file.getName())) {
                        unit = JavaCore.createCompilationUnitFrom(file);
                    }//from   w w  w .ja  va2  s  .com
                }
                if (unit != null) {
                    if (hasMain.equals(property) || isScript.equals(property)) {
                        List<IType> results = GroovyProjectFacade.findAllRunnableTypes(unit);
                        returnValue = results.size() > 0;
                    }
                }
            } catch (IllegalArgumentException e) {
                // can ignore
                // passed in non-JavaLike file name
            } catch (JavaModelException e) {
                // can ignore situations when trying to find types that are not on the classpath
                if (e.getStatus() != null
                        && e.getStatus().getCode() != IJavaModelStatusConstants.ELEMENT_NOT_ON_CLASSPATH) {
                    GroovyCore.logException("Exception when testing for main methods " + receiver, e);
                }
            }

        }
    }
    return returnValue;
}

From source file:org.codehaus.jdt.groovy.model.GroovyCompilationUnit.java

License:Open Source License

/**
 * There is no such thing as a primary type in Groovy. First look for a type of the same name as the CU, Else get the first type
 * in getAllTypes()//from w  ww .java 2  s.  c  o  m
 */
@SuppressWarnings("nls")
@Override
public IType findPrimaryType() {
    IType type = super.findPrimaryType();
    if (type != null) {
        return type;
    }
    try {
        IType[] types = getTypes();
        if (types != null && types.length > 0) {
            return types[0];
        }
    } catch (JavaModelException e) {
        // can ignore situations when trying to find types that are not on the classpath
        if (e.getStatus().getCode() != IJavaModelStatusConstants.ELEMENT_NOT_ON_CLASSPATH) {
            Util.log(e, "Error finding all types of " + this.getElementName());
        }
    }
    return null;
}

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

License:Open Source License

@Override
public IClasspathEntry getRawClasspathEntry() throws JavaModelException {
    IClasspathEntry rawEntry = null;//from  ww  w.  ja v a  2 s.  co  m
    JavaProject project = (JavaProject) getJavaProject();
    project.getResolvedClasspath(); // force the reverse rawEntry cache to be populated
    Map rootPathToRawEntries = project.resolvedClasspath().rawReverseMap;
    if (rootPathToRawEntries != null) {
        rawEntry = (IClasspathEntry) rootPathToRawEntries.get(getPath());
    }
    if (rawEntry == null) {
        throw new JavaModelException(
                new JavaModelStatus(IJavaModelStatusConstants.ELEMENT_NOT_ON_CLASSPATH, this));
    }
    return rawEntry;
}

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

License:Open Source License

@Override
public IClasspathEntry getResolvedClasspathEntry() throws JavaModelException {
    IClasspathEntry rawEntry = null;//from  ww w .j a  v a2  s  .  c o m
    JavaProject project = (JavaProject) getJavaProject();
    project.getResolvedClasspath(); // force the reverse rawEntry cache to be populated
    Map rootPathToRawEntries = project.resolvedClasspath().rootPathToResolvedEntries;
    if (rootPathToRawEntries != null) {
        rawEntry = (IClasspathEntry) rootPathToRawEntries.get(getPath());
    }
    if (rawEntry == null) {
        throw new JavaModelException(
                new JavaModelStatus(IJavaModelStatusConstants.ELEMENT_NOT_ON_CLASSPATH, this));
    }
    return rawEntry;
}

From source file:org.eclipse.jdt.internal.core.CompilationUnit.java

License:Open Source License

protected IStatus validateCompilationUnit(IResource resource) {
    IPackageFragmentRoot root = getPackageFragmentRoot();
    // root never null as validation is not done for working copies
    try {/* www . j a  v a 2s  . c  o  m*/
        if (root.getKind() != IPackageFragmentRoot.K_SOURCE)
            return new JavaModelStatus(IJavaModelStatusConstants.INVALID_ELEMENT_TYPES, root);
    } catch (JavaModelException e) {
        return e.getJavaModelStatus();
    }
    if (resource != null) {
        char[][] inclusionPatterns = ((PackageFragmentRoot) root).fullInclusionPatternChars();
        char[][] exclusionPatterns = ((PackageFragmentRoot) root).fullExclusionPatternChars();
        if (Util.isExcluded(resource, inclusionPatterns, exclusionPatterns))
            return new JavaModelStatus(IJavaModelStatusConstants.ELEMENT_NOT_ON_CLASSPATH, this);
        if (!resource.isAccessible())
            return new JavaModelStatus(IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST, this);
    }
    IJavaProject project = getJavaProject();
    return JavaConventions.validateCompilationUnitName(getElementName(),
            project.getOption(JavaCore.COMPILER_SOURCE, true),
            project.getOption(JavaCore.COMPILER_COMPLIANCE, true));
}