Search in sources :

Example 6 with CoreException

use of org.eclipse.core.runtime.CoreException in project che by eclipse.

the class RenameMethodProcessor method batchFindNewOccurrences.

//Lower memory footprint than batchFindNewOccurrences. Not used because it is too slow.
//Final solution is maybe to do searches in chunks of ~ 50 CUs.
//	private SearchResultGroup[] findNewOccurrences(IMethod[] newMethods, ICompilationUnit[] newDeclarationWCs, IProgressMonitor pm) throws CoreException {
//		pm.beginTask("", fOccurrences.length * 2); //$NON-NLS-1$
//
//		SearchPattern refsPattern= RefactoringSearchEngine.createOrPattern(newMethods, IJavaSearchConstants.REFERENCES);
//		SearchParticipant[] searchParticipants= SearchUtils.getDefaultSearchParticipants();
//		IJavaSearchScope scope= RefactoringScopeFactory.create(newMethods);
//		MethodOccurenceCollector requestor= new MethodOccurenceCollector(getNewElementName());
//		SearchEngine searchEngine= new SearchEngine(fWorkingCopyOwner);
//
//		//TODO: should process only references
//		for (int j= 0; j < fOccurrences.length; j++) { //should be getReferences()
//			//cut memory peak by holding only one reference CU at a time in memory
//			ICompilationUnit originalCu= fOccurrences[j].getCompilationUnit();
//			ICompilationUnit newWc= null;
//			try {
//				ICompilationUnit wc= RenameAnalyzeUtil.findWorkingCopyForCu(newDeclarationWCs, originalCu);
//				if (wc == null) {
//					newWc= RenameAnalyzeUtil.createNewWorkingCopy(originalCu, fChangeManager, fWorkingCopyOwner,
//							new SubProgressMonitor(pm, 1));
//				}
//				searchEngine.search(refsPattern, searchParticipants, scope,	requestor, new SubProgressMonitor(pm, 1));
//			} finally {
//				if (newWc != null)
//					newWc.discardWorkingCopy();
//			}
//		}
//		SearchResultGroup[] newResults= RefactoringSearchEngine.groupByResource(requestor.getResults());
//		pm.done();
//		return newResults;
//	}
private SearchResultGroup[] batchFindNewOccurrences(IMethod[] wcNewMethods, final IMethod[] wcOldMethods, ICompilationUnit[] newDeclarationWCs, IProgressMonitor pm, RefactoringStatus status) throws CoreException {
    //$NON-NLS-1$
    pm.beginTask("", 2);
    SearchPattern refsPattern = RefactoringSearchEngine.createOrPattern(wcNewMethods, IJavaSearchConstants.REFERENCES);
    SearchParticipant[] searchParticipants = SearchUtils.getDefaultSearchParticipants();
    IJavaSearchScope scope = RefactoringScopeFactory.create(wcNewMethods);
    MethodOccurenceCollector requestor;
    if (getDelegateUpdating()) {
        // There will be two new matches inside the delegate(s) (the invocation
        // and the javadoc) which are OK and must not be reported.
        // Note that except these ocurrences, the delegate bodies are empty
        // (as they were created this way).
        requestor = new MethodOccurenceCollector(getNewElementName()) {

            @Override
            public void acceptSearchMatch(ICompilationUnit unit, SearchMatch match) throws CoreException {
                for (int i = 0; i < wcOldMethods.length; i++) if (wcOldMethods[i].equals(match.getElement()))
                    return;
                super.acceptSearchMatch(unit, match);
            }
        };
    } else
        requestor = new MethodOccurenceCollector(getNewElementName());
    SearchEngine searchEngine = new SearchEngine(fWorkingCopyOwner);
    ArrayList<ICompilationUnit> needWCs = new ArrayList<ICompilationUnit>();
    HashSet<ICompilationUnit> declaringCUs = new HashSet<ICompilationUnit>(newDeclarationWCs.length);
    for (int i = 0; i < newDeclarationWCs.length; i++) declaringCUs.add(newDeclarationWCs[i].getPrimary());
    for (int i = 0; i < fOccurrences.length; i++) {
        ICompilationUnit cu = fOccurrences[i].getCompilationUnit();
        if (!declaringCUs.contains(cu))
            needWCs.add(cu);
    }
    ICompilationUnit[] otherWCs = null;
    try {
        otherWCs = RenameAnalyzeUtil.createNewWorkingCopies(needWCs.toArray(new ICompilationUnit[needWCs.size()]), fChangeManager, fWorkingCopyOwner, new SubProgressMonitor(pm, 1));
        searchEngine.search(refsPattern, searchParticipants, scope, requestor, new SubProgressMonitor(pm, 1));
    } finally {
        pm.done();
        if (otherWCs != null) {
            for (int i = 0; i < otherWCs.length; i++) {
                otherWCs[i].discardWorkingCopy();
            }
        }
    }
    SearchResultGroup[] newResults = RefactoringSearchEngine.groupByCu(requestor.getResults(), status);
    return newResults;
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) SearchMatch(org.eclipse.jdt.core.search.SearchMatch) ArrayList(java.util.ArrayList) SearchResultGroup(org.eclipse.jdt.internal.corext.refactoring.SearchResultGroup) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) SearchParticipant(org.eclipse.jdt.core.search.SearchParticipant) SearchEngine(org.eclipse.jdt.core.search.SearchEngine) RefactoringSearchEngine(org.eclipse.jdt.internal.corext.refactoring.RefactoringSearchEngine) CoreException(org.eclipse.core.runtime.CoreException) IJavaSearchScope(org.eclipse.jdt.core.search.IJavaSearchScope) SearchPattern(org.eclipse.jdt.core.search.SearchPattern) HashSet(java.util.HashSet)

Example 7 with CoreException

use of org.eclipse.core.runtime.CoreException in project che by eclipse.

the class RenameFieldProcessor method getNewReferences.

private SearchResultGroup[] getNewReferences(IProgressMonitor pm, RefactoringStatus status, WorkingCopyOwner owner, ICompilationUnit[] newWorkingCopies) throws CoreException {
    //$NON-NLS-1$
    pm.beginTask("", 2);
    ICompilationUnit declaringCuWorkingCopy = RenameAnalyzeUtil.findWorkingCopyForCu(newWorkingCopies, fField.getCompilationUnit());
    if (declaringCuWorkingCopy == null)
        return new SearchResultGroup[0];
    IField field = getFieldInWorkingCopy(declaringCuWorkingCopy, getNewElementName());
    if (field == null || !field.exists())
        return new SearchResultGroup[0];
    CollectingSearchRequestor requestor = null;
    if (fDelegateUpdating && RefactoringAvailabilityTester.isDelegateCreationAvailable(getField())) {
        // There will be two new matches inside the delegate (the invocation
        // and the javadoc) which are OK and must not be reported.
        final IField oldField = getFieldInWorkingCopy(declaringCuWorkingCopy, getCurrentElementName());
        requestor = new CollectingSearchRequestor() {

            @Override
            public void acceptSearchMatch(SearchMatch match) throws CoreException {
                if (!oldField.equals(match.getElement()))
                    super.acceptSearchMatch(match);
            }
        };
    } else
        requestor = new CollectingSearchRequestor();
    SearchPattern newPattern = SearchPattern.createPattern(field, IJavaSearchConstants.REFERENCES);
    IJavaSearchScope scope = RefactoringScopeFactory.create(fField, true, true);
    return RefactoringSearchEngine.search(newPattern, owner, scope, requestor, new SubProgressMonitor(pm, 1), status);
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) SearchMatch(org.eclipse.jdt.core.search.SearchMatch) CoreException(org.eclipse.core.runtime.CoreException) IJavaSearchScope(org.eclipse.jdt.core.search.IJavaSearchScope) SearchPattern(org.eclipse.jdt.core.search.SearchPattern) CuCollectingSearchRequestor(org.eclipse.jdt.internal.corext.refactoring.CuCollectingSearchRequestor) CollectingSearchRequestor(org.eclipse.jdt.internal.corext.refactoring.CollectingSearchRequestor) IField(org.eclipse.jdt.core.IField) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 8 with CoreException

use of org.eclipse.core.runtime.CoreException in project che by eclipse.

the class ImportOperation method execute.

/* (non-Javadoc)
     * Method declared on WorkbenchModifyOperation.
     * Imports the specified file system objects from the file system.
     */
protected void execute(IProgressMonitor progressMonitor) {
    monitor = progressMonitor;
    try {
        if (selectedFiles == null) {
            //Set the amount to 1000 as we have no idea of how long this will take
            monitor.beginTask("Importing:", 1000);
            ContainerGenerator generator = new ContainerGenerator(destinationPath);
            monitor.worked(30);
            validateFiles(Arrays.asList(new Object[] { source }));
            monitor.worked(50);
            destinationContainer = generator.generateContainer(new SubProgressMonitor(monitor, 50));
            importRecursivelyFrom(source, POLICY_DEFAULT);
            //Be sure it finishes
            monitor.worked(90);
        } else {
            // Choose twice the selected files size to take folders into account
            int creationCount = selectedFiles.size();
            monitor.beginTask("Importing:", creationCount + 100);
            ContainerGenerator generator = new ContainerGenerator(destinationPath);
            monitor.worked(30);
            validateFiles(selectedFiles);
            monitor.worked(50);
            destinationContainer = generator.generateContainer(new SubProgressMonitor(monitor, 50));
            importFileSystemObjects(selectedFiles);
            monitor.done();
        }
    } catch (CoreException e) {
        errorTable.add(e.getStatus());
    } finally {
        monitor.done();
    }
}
Also used : ContainerGenerator(org.eclipse.ui.dialogs.ContainerGenerator) CoreException(org.eclipse.core.runtime.CoreException) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 9 with CoreException

use of org.eclipse.core.runtime.CoreException in project che by eclipse.

the class ClasspathBuilder method addJars.

private void addJars(IJavaProject project, List<String> library, final List<IClasspathEntry> classpathEntries) {
    if (library == null || library.isEmpty()) {
        return;
    }
    for (String libFolder : library) {
        if (libFolder.isEmpty()) {
            continue;
        }
        IFolder libraryFolder = project.getProject().getFolder(libFolder);
        if (!libraryFolder.exists()) {
            return;
        }
        try {
            libraryFolder.accept(proxy -> {
                if (IResource.FILE != proxy.getType()) {
                    return true;
                }
                IPath path = proxy.requestFullPath();
                if (!path.toString().endsWith(".jar")) {
                    return false;
                }
                IClasspathEntry libEntry = JavaCore.newLibraryEntry(proxy.requestResource().getLocation(), null, null);
                classpathEntries.add(libEntry);
                return false;
            }, IContainer.INCLUDE_PHANTOMS);
        } catch (CoreException e) {
            LOG.warn("Can't read folder structure: " + libraryFolder.getFullPath().toString());
        }
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) CoreException(org.eclipse.core.runtime.CoreException) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) IFolder(org.eclipse.core.resources.IFolder)

Example 10 with CoreException

use of org.eclipse.core.runtime.CoreException 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)

Aggregations

CoreException (org.eclipse.core.runtime.CoreException)569 IStatus (org.eclipse.core.runtime.IStatus)127 Status (org.eclipse.core.runtime.Status)124 IFile (org.eclipse.core.resources.IFile)119 IOException (java.io.IOException)96 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)93 IProject (org.eclipse.core.resources.IProject)90 IResource (org.eclipse.core.resources.IResource)84 ArrayList (java.util.ArrayList)71 InvocationTargetException (java.lang.reflect.InvocationTargetException)63 IPath (org.eclipse.core.runtime.IPath)63 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)60 File (java.io.File)56 IFolder (org.eclipse.core.resources.IFolder)45 InputStream (java.io.InputStream)42 IWorkspace (org.eclipse.core.resources.IWorkspace)40 PersistenceException (org.talend.commons.exception.PersistenceException)39 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)37 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)36 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)34