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;
}
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);
}
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();
}
}
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());
}
}
}
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;
}
Aggregations