Example usage for org.eclipse.jdt.core JavaConventions validateClasspathEntry

List of usage examples for org.eclipse.jdt.core JavaConventions validateClasspathEntry

Introduction

In this page you can find the example usage for org.eclipse.jdt.core JavaConventions validateClasspathEntry.

Prototype

public static IJavaModelStatus validateClasspathEntry(IJavaProject project, IClasspathEntry entry,
        boolean checkSourceAttachment) 

Source Link

Document

Returns a Java model status describing the problem related to this classpath entry if any, a status object with code IStatus.OK if the entry is fine (that is, if the given classpath entry denotes a valid element to be referenced onto a classpath).

Usage

From source file:com.google.gdt.eclipse.managedapis.ui.ManageApiInfoDecorator.java

License:Open Source License

/**
 * Checks if classpath entry will cause error. If it does, it will add error
 * icon to Managed Api container and return true. Else will return false.
 *//*from  w w  w  . j  ava2s.  com*/
private boolean checkAndApplyErrorDecoration(IDecoration decoration, ManagedApiProject managedApiProject,
        IClasspathEntry entry) {
    if (!JavaConventions.validateClasspathEntry(managedApiProject.getJavaProject(), entry, false).isOK()) {
        ImageDescriptor overlay = JFaceResources.getImageRegistry()
                .getDescriptor("org.eclipse.jface.fieldassist.IMG_DEC_FIELD_ERROR");
        decoration.addOverlay(overlay, IDecoration.BOTTOM_LEFT);
        return true;
    }
    return false;
}

From source file:org.eclim.plugin.jdt.project.JavaProjectManager.java

License:Open Source License

/**
 * Sets the classpath for the supplied project.
 *
 * @param javaProject The project./* ww w. j a va2  s.  c o m*/
 * @param entries The classpath entries.
 * @param classpath The file path of the .classpath file.
 * @return Array of Error or null if no errors reported.
 */
protected List<Error> setClasspath(IJavaProject javaProject, IClasspathEntry[] entries, String classpath)
        throws Exception {
    FileOffsets offsets = FileOffsets.compile(classpath);
    String classpathValue = IOUtils.toString(new FileInputStream(classpath));
    ArrayList<Error> errors = new ArrayList<Error>();
    for (IClasspathEntry entry : entries) {
        IJavaModelStatus status = JavaConventions.validateClasspathEntry(javaProject, entry, true);
        if (!status.isOK()) {
            errors.add(createErrorForEntry(javaProject, entry, status, offsets, classpath, classpathValue));
        }
    }

    IJavaModelStatus status = JavaConventions.validateClasspath(javaProject, entries,
            javaProject.getOutputLocation());

    // always set the classpathValue anyways, so that the user can correct the
    // file.
    //if(status.isOK() && errors.isEmpty()){
    javaProject.setRawClasspath(entries, null);
    javaProject.makeConsistent(null);
    //}

    if (!status.isOK()) {
        errors.add(new Error(status.getMessage(), classpath, 1, 1, false));
    }
    return errors;
}

From source file:org.org.eclipse.dws.core.internal.bridges.ProjectInteractionHelper.java

License:Open Source License

/**
 * Gets the classpath entries.//  www  .  j a v a  2  s  . com
 * 
 * @param javaProject the java project
 * 
 * @return the classpath entries
 */
public static Set<DWSClasspathEntryDescriptor> getClasspathEntries(IJavaProject javaProject) {
    Set<DWSClasspathEntryDescriptor> classpathEntryDescriptors = new LinkedHashSet<DWSClasspathEntryDescriptor>();
    try {
        if (javaProject.exists()) {
            for (IClasspathEntry classpathEntry : javaProject.getRawClasspath()) {
                DWSClasspathEntryDescriptor classpathEntryDescriptor = new DWSClasspathEntryDescriptor();
                classpathEntryDescriptor
                        .setEncodedClasspathEntry(javaProject.encodeClasspathEntry(classpathEntry));
                classpathEntryDescriptor.setPath(classpathEntry.getPath().toPortableString());
                classpathEntryDescriptor.setProjectName(javaProject.getElementName());
                IJavaModelStatus javaModelStatus = JavaConventions.validateClasspathEntry(javaProject,
                        classpathEntry, false);
                classpathEntryDescriptor.setValid(classpathEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY
                        || classpathEntry.getEntryKind() == IClasspathEntry.CPE_VARIABLE
                                && javaModelStatus.isOK());
                classpathEntryDescriptors.add(classpathEntryDescriptor);
            }
        }
    } catch (JavaModelException e) {
        throw new JavaProjectInteractionException(
                "An error occured while scanning for classpath entries in project:" + javaProject, e);
    }
    return classpathEntryDescriptors;
}