Search in sources :

Example 96 with JavaModelException

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

the class DeltaProcessingState method getRootInfos.

private HashMap[] getRootInfos(boolean usePreviousSession) {
    HashMap newRoots = new HashMap();
    HashMap newOtherRoots = new HashMap();
    HashMap newSourceAttachments = new HashMap();
    HashMap newProjectDependencies = new HashMap();
    IJavaModel model = manager.getJavaModel();
    IJavaProject[] projects;
    try {
        projects = model.getJavaProjects();
    } catch (JavaModelException e) {
        // nothing can be done
        return null;
    }
    for (int i = 0, length = projects.length; i < length; i++) {
        JavaProject project = (JavaProject) projects[i];
        IClasspathEntry[] classpath;
        try {
            //				if (usePreviousSession) {
            //					PerProjectInfo perProjectInfo = project.getPerProjectInfo();
            //					project.resolveClasspath(perProjectInfo, true/*use previous session values*/, false/*don't add classpath change*/);
            //					classpath = perProjectInfo.resolvedClasspath;
            //				} else {
            classpath = project.getResolvedClasspath();
        //				}
        } catch (JavaModelException e) {
            // continue with next project
            continue;
        }
        for (int j = 0, classpathLength = classpath.length; j < classpathLength; j++) {
            IClasspathEntry entry = classpath[j];
            if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
                // TODO (jerome) reuse handle
                IJavaProject key = model.getJavaProject(entry.getPath().segment(0));
                IJavaProject[] dependents = (IJavaProject[]) newProjectDependencies.get(key);
                if (dependents == null) {
                    dependents = new IJavaProject[] { project };
                } else {
                    int dependentsLength = dependents.length;
                    System.arraycopy(dependents, 0, dependents = new IJavaProject[dependentsLength + 1], 0, dependentsLength);
                    dependents[dependentsLength] = project;
                }
                newProjectDependencies.put(key, dependents);
                continue;
            }
            // root path
            IPath path = entry.getPath();
            if (newRoots.get(path) == null) {
                newRoots.put(path, new DeltaProcessor.RootInfo(project, path, ((ClasspathEntry) entry).fullInclusionPatternChars(), ((ClasspathEntry) entry).fullExclusionPatternChars(), entry.getEntryKind()));
            } else {
                ArrayList rootList = (ArrayList) newOtherRoots.get(path);
                if (rootList == null) {
                    rootList = new ArrayList();
                    newOtherRoots.put(path, rootList);
                }
                rootList.add(new DeltaProcessor.RootInfo(project, path, ((ClasspathEntry) entry).fullInclusionPatternChars(), ((ClasspathEntry) entry).fullExclusionPatternChars(), entry.getEntryKind()));
            }
            // source attachment path
            if (entry.getEntryKind() != IClasspathEntry.CPE_LIBRARY)
                continue;
            String propertyString = null;
            //				try {
            //					propertyString = Util.getSourceAttachmentProperty(path);
            //				} catch (JavaModelException e) {
            //					e.printStackTrace();
            //				}
            IPath sourceAttachmentPath;
            if (propertyString != null) {
                int index = propertyString.lastIndexOf(PackageFragmentRoot.ATTACHMENT_PROPERTY_DELIMITER);
                sourceAttachmentPath = (index < 0) ? new Path(propertyString) : new Path(propertyString.substring(0, index));
            } else {
                sourceAttachmentPath = entry.getSourceAttachmentPath();
            }
            if (sourceAttachmentPath != null) {
                newSourceAttachments.put(sourceAttachmentPath, path);
            }
        }
    }
    return new HashMap[] { newRoots, newOtherRoots, newSourceAttachments, newProjectDependencies };
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) JavaModelException(org.eclipse.jdt.core.JavaModelException) IJavaProject(org.eclipse.jdt.core.IJavaProject) IPath(org.eclipse.core.runtime.IPath) HashMap(java.util.HashMap) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) ArrayList(java.util.ArrayList) IJavaProject(org.eclipse.jdt.core.IJavaProject) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) IJavaModel(org.eclipse.jdt.core.IJavaModel)

Example 97 with JavaModelException

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

the class JavaModelOperation method deleteResources.

/**
	 * Convenience method to delete resources
	 */
protected void deleteResources(IResource[] resources, boolean forceFlag) throws JavaModelException {
    if (resources == null || resources.length == 0)
        return;
    IProgressMonitor subProgressMonitor = getSubProgressMonitor(resources.length);
    IWorkspace workspace = resources[0].getWorkspace();
    try {
        workspace.delete(resources, forceFlag ? IResource.FORCE | IResource.KEEP_HISTORY : IResource.KEEP_HISTORY, subProgressMonitor);
        setAttribute(HAS_MODIFIED_RESOURCE_ATTR, TRUE);
    } catch (CoreException e) {
        throw new JavaModelException(e);
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) JavaModelException(org.eclipse.jdt.core.JavaModelException) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace)

Example 98 with JavaModelException

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

the class JavaModelOperation method moveResources.

/**
	 * Convenience method to move resources
	 */
protected void moveResources(IResource[] resources, IPath container) throws JavaModelException {
    IProgressMonitor subProgressMonitor = null;
    if (this.progressMonitor != null) {
        subProgressMonitor = new SubProgressMonitor(this.progressMonitor, resources.length, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
    }
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    try {
        for (int i = 0, length = resources.length; i < length; i++) {
            IResource resource = resources[i];
            IPath destination = container.append(resource.getName());
            if (root.findMember(destination) == null) {
                resource.move(destination, false, subProgressMonitor);
            }
        }
        setAttribute(HAS_MODIFIED_RESOURCE_ATTR, TRUE);
    } catch (CoreException e) {
        throw new JavaModelException(e);
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) JavaModelException(org.eclipse.jdt.core.JavaModelException) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IPath(org.eclipse.core.runtime.IPath) CoreException(org.eclipse.core.runtime.CoreException) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) IResource(org.eclipse.core.resources.IResource)

Example 99 with JavaModelException

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

the class JavaModelOperation method executeNestedOperation.

/**
     * Convenience method to run an operation within this operation
     */
public void executeNestedOperation(JavaModelOperation operation, int subWorkAmount) throws JavaModelException {
    IJavaModelStatus status = operation.verify();
    if (!status.isOK()) {
        throw new JavaModelException(status);
    }
    IProgressMonitor subProgressMonitor = getSubProgressMonitor(subWorkAmount);
    // fix for 1FW7IKC, part (1)
    try {
        operation.setNested(true);
        operation.run(subProgressMonitor);
    } catch (CoreException ce) {
        if (ce instanceof JavaModelException) {
            throw (JavaModelException) ce;
        } else {
            // translate the core exception to a java model exception
            if (ce.getStatus().getCode() == IResourceStatus.OPERATION_FAILED) {
                Throwable e = ce.getStatus().getException();
                if (e instanceof JavaModelException) {
                    throw (JavaModelException) e;
                }
            }
            throw new JavaModelException(ce);
        }
    }
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IJavaModelStatus(org.eclipse.jdt.core.IJavaModelStatus)

Example 100 with JavaModelException

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

the class JavaModelOperation method createFolder.

/**
	 * Convenience method to create a folder
	 */
protected void createFolder(IContainer parentFolder, String name, boolean forceFlag) throws JavaModelException {
    IFolder folder = parentFolder.getFolder(new Path(name));
    try {
        // we should use true to create the file locally. Only VCM should use tru/false
        folder.create(forceFlag ? IResource.FORCE | IResource.KEEP_HISTORY : IResource.KEEP_HISTORY, // local
        true, getSubProgressMonitor(1));
        setAttribute(HAS_MODIFIED_RESOURCE_ATTR, TRUE);
    } catch (CoreException e) {
        throw new JavaModelException(e);
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) JavaModelException(org.eclipse.jdt.core.JavaModelException) CoreException(org.eclipse.core.runtime.CoreException) IFolder(org.eclipse.core.resources.IFolder)

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