Search in sources :

Example 21 with JavaModelException

use of org.eclipse.jdt.core.JavaModelException in project che by eclipse.

the class JavaModelManager method initializeContainer.

private IClasspathContainer initializeContainer(IJavaProject project, IPath containerPath) throws JavaModelException {
    ClasspathContainerInitializer initializer = containerInitializersCache.get(containerPath.segment(0));
    IClasspathContainer container = null;
    if (initializer != null) {
        // avoid initialization cycles
        containerPut(project, containerPath, CONTAINER_INITIALIZATION_IN_PROGRESS);
        try {
            initializer.initialize(containerPath, project);
            //            if (monitor != null)
            //                monitor.subTask(""); //$NON-NLS-1$
            // retrieve value (if initialization was successful)
            container = containerBeingInitializedGet(project, containerPath);
            if (container == null && containerGet(project, containerPath) == null) {
                // initializer failed to do its job: redirect to the failure container
                container = initializer.getFailureContainer(containerPath, project);
                //                if (container == null) {
                //                    if (CP_RESOLVE_VERBOSE || CP_RESOLVE_VERBOSE_FAILURE)
                //                        verbose_container_null_failure_container(project, containerPath, initializer);
                //                    return null; // break cycle
                //                }
                //                if (CP_RESOLVE_VERBOSE || CP_RESOLVE_VERBOSE_FAILURE)
                //                    verbose_container_using_failure_container(project, containerPath, initializer);
                containerPut(project, containerPath, container);
            }
        } catch (CoreException e) {
            if (e instanceof JavaModelException) {
                throw (JavaModelException) e;
            } else {
                throw new JavaModelException(e);
            }
        }
    } else {
        // create a dummy initializer and get the default failure container
        container = (new ClasspathContainerInitializer() {

            public void initialize(IPath path, IJavaProject javaProject) throws CoreException {
            // not used
            }
        }).getFailureContainer(containerPath, project);
    }
    return container;
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) IJavaProject(org.eclipse.jdt.core.IJavaProject) CoreException(org.eclipse.core.runtime.CoreException) IPath(org.eclipse.core.runtime.IPath) IClasspathContainer(org.eclipse.jdt.core.IClasspathContainer) ClasspathContainerInitializer(org.eclipse.jdt.core.ClasspathContainerInitializer)

Example 22 with JavaModelException

use of org.eclipse.jdt.core.JavaModelException in project che by eclipse.

the class JavaModelOperation method deleteEmptyPackageFragment.

/**
	 * Convenience method to delete an empty package fragment
	 */
protected void deleteEmptyPackageFragment(IPackageFragment fragment, boolean forceFlag, IResource rootResource) throws JavaModelException {
    IContainer resource = (IContainer) ((JavaElement) fragment).resource();
    try {
        resource.delete(forceFlag ? IResource.FORCE | IResource.KEEP_HISTORY : IResource.KEEP_HISTORY, getSubProgressMonitor(1));
        setAttribute(HAS_MODIFIED_RESOURCE_ATTR, TRUE);
        while (resource instanceof IFolder) {
            // deleting a package: delete the parent if it is empty (e.g. deleting x.y where folder x doesn't have resources but y)
            // without deleting the package fragment root
            resource = resource.getParent();
            if (!resource.equals(rootResource) && resource.members().length == 0) {
                resource.delete(forceFlag ? IResource.FORCE | IResource.KEEP_HISTORY : IResource.KEEP_HISTORY, getSubProgressMonitor(1));
                setAttribute(HAS_MODIFIED_RESOURCE_ATTR, TRUE);
            }
        }
    } catch (CoreException e) {
        throw new JavaModelException(e);
    }
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) CoreException(org.eclipse.core.runtime.CoreException) IContainer(org.eclipse.core.resources.IContainer) IFolder(org.eclipse.core.resources.IFolder)

Example 23 with JavaModelException

use of org.eclipse.jdt.core.JavaModelException in project che by eclipse.

the class DeltaProcessor method createExternalArchiveDelta.

/*
     * Check if external archives have changed for the given elements and create the corresponding deltas.
     * Returns whether at least one delta was created.
     */
private boolean createExternalArchiveDelta(HashSet refreshedElements, IProgressMonitor monitor) {
    HashMap externalArchivesStatus = new HashMap();
    boolean hasDelta = false;
    // find JARs to refresh
    HashSet archivePathsToRefresh = new HashSet();
    Iterator iterator = refreshedElements.iterator();
    while (iterator.hasNext()) {
        IJavaElement element = (IJavaElement) iterator.next();
        switch(element.getElementType()) {
            case IJavaElement.PACKAGE_FRAGMENT_ROOT:
                archivePathsToRefresh.add(element.getPath());
                break;
            case IJavaElement.JAVA_PROJECT:
                JavaProject javaProject = (JavaProject) element;
                if (!JavaProject.hasJavaNature(javaProject.getProject())) {
                    // project is not accessible or has lost its Java nature
                    break;
                }
                IClasspathEntry[] classpath;
                try {
                    classpath = javaProject.getResolvedClasspath();
                    for (int j = 0, cpLength = classpath.length; j < cpLength; j++) {
                        if (classpath[j].getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                            archivePathsToRefresh.add(classpath[j].getPath());
                        }
                    }
                } catch (JavaModelException e) {
                // project doesn't exist -> ignore
                }
                break;
            case IJavaElement.JAVA_MODEL:
                //					}
                throw new UnsupportedOperationException();
        }
    }
    //		}
    return hasDelta;
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) IJavaProject(org.eclipse.jdt.core.IJavaProject) JavaModelException(org.eclipse.jdt.core.JavaModelException) HashMap(java.util.HashMap) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) Iterator(java.util.Iterator) HashSet(java.util.HashSet)

Example 24 with JavaModelException

use of org.eclipse.jdt.core.JavaModelException in project che by eclipse.

the class JavaProject method writeFileEntries.

/**
     * Writes the classpath in a sharable format (VCM-wise) only when necessary, that is, if  it is semantically different
     * from the existing one in file. Will never write an identical one.
     *
     * @param newClasspath IClasspathEntry[]
     * @param newOutputLocation IPath
     * @return boolean Return whether the .classpath file was modified.
     * @throws JavaModelException
     */
public boolean writeFileEntries(IClasspathEntry[] newClasspath, IClasspathEntry[] referencedEntries, IPath newOutputLocation) throws JavaModelException {
    if (!this.project.isAccessible())
        return false;
    Map unknownElements = new HashMap();
    IClasspathEntry[][] fileEntries = readFileEntries(unknownElements);
    if (fileEntries[0] != JavaProject.INVALID_CLASSPATH && areClasspathsEqual(newClasspath, newOutputLocation, fileEntries[0]) && (referencedEntries == null || areClasspathsEqual(referencedEntries, fileEntries[1]))) {
        // no need to save it, it is the same
        return false;
    }
    // actual file saving
    try {
        setSharedProperty(JavaProject.CLASSPATH_FILENAME, encodeClasspath(newClasspath, referencedEntries, newOutputLocation, true, unknownElements));
        return true;
    } catch (CoreException e) {
        throw new JavaModelException(e);
    }
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) CoreException(org.eclipse.core.runtime.CoreException) HashMap(java.util.HashMap) Map(java.util.Map) HashMap(java.util.HashMap)

Example 25 with JavaModelException

use of org.eclipse.jdt.core.JavaModelException in project che by eclipse.

the class JavaProject method setOptions.

@Override
public void setOptions(Map newOptions) {
    IEclipsePreferences projectPreferences = getEclipsePreferences();
    if (projectPreferences == null)
        return;
    try {
        if (newOptions == null) {
            projectPreferences.clear();
        } else {
            Iterator entries = newOptions.entrySet().iterator();
            JavaModelManager javaModelManager = getJavaModelManager();
            while (entries.hasNext()) {
                Map.Entry entry = (Map.Entry) entries.next();
                String key = (String) entry.getKey();
                String value = (String) entry.getValue();
                javaModelManager.storePreference(key, value, projectPreferences, newOptions);
            }
            // reset to default all options not in new map
            // @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=26255
            // @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=49691
            String[] pNames = projectPreferences.keys();
            int ln = pNames.length;
            for (int i = 0; i < ln; i++) {
                String key = pNames[i];
                if (!newOptions.containsKey(key)) {
                    // old preferences => remove from preferences table
                    projectPreferences.remove(key);
                }
            }
        }
        // persist options
        projectPreferences.flush();
        // flush cache immediately
        try {
            getPerProjectInfo().options = null;
        } catch (JavaModelException e) {
        // do nothing
        }
    } catch (BackingStoreException e) {
    // problem with pref store - quietly ignore
    }
}
Also used : JavaModelManager.getJavaModelManager(org.eclipse.jdt.internal.core.JavaModelManager.getJavaModelManager) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) JavaModelException(org.eclipse.jdt.core.JavaModelException) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) Iterator(java.util.Iterator) BackingStoreException(org.osgi.service.prefs.BackingStoreException) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

JavaModelException (org.eclipse.jdt.core.JavaModelException)162 IJavaProject (org.eclipse.jdt.core.IJavaProject)41 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)40 IType (org.eclipse.jdt.core.IType)39 IJavaElement (org.eclipse.jdt.core.IJavaElement)34 CoreException (org.eclipse.core.runtime.CoreException)28 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)23 ArrayList (java.util.ArrayList)21 IPath (org.eclipse.core.runtime.IPath)20 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)15 HashMap (java.util.HashMap)14 IResource (org.eclipse.core.resources.IResource)13 IMethod (org.eclipse.jdt.core.IMethod)12 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)12 IFile (org.eclipse.core.resources.IFile)11 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)11 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)11 SimpleName (org.eclipse.jdt.core.dom.SimpleName)9 Iterator (java.util.Iterator)8 ISourceRange (org.eclipse.jdt.core.ISourceRange)8