use of org.eclipse.core.runtime.Status in project che by eclipse.
the class InferTypeArgumentsRefactoring method checkFinalConditions.
/*
* @see org.eclipse.ltk.core.refactoring.Refactoring#checkFinalConditions(org.eclipse.core.runtime.IProgressMonitor)
*/
@Override
public RefactoringStatus checkFinalConditions(final IProgressMonitor pm) throws CoreException, OperationCanceledException {
HashMap<IJavaProject, ArrayList<IJavaElement>> projectsToElements = getJavaElementsPerProject(fElements);
//$NON-NLS-1$
pm.beginTask("", projectsToElements.size() + 2);
final RefactoringStatus result = new RefactoringStatus();
try {
fTCModel = new InferTypeArgumentsTCModel();
final InferTypeArgumentsConstraintCreator unitCollector = new InferTypeArgumentsConstraintCreator(fTCModel, fAssumeCloneReturnsSameType);
for (Iterator<Entry<IJavaProject, ArrayList<IJavaElement>>> iter = projectsToElements.entrySet().iterator(); iter.hasNext(); ) {
Entry<IJavaProject, ArrayList<IJavaElement>> entry = iter.next();
IJavaProject project = entry.getKey();
ArrayList<IJavaElement> javaElementsList = entry.getValue();
IJavaElement[] javaElements = javaElementsList.toArray(new IJavaElement[javaElementsList.size()]);
List<ICompilationUnit> cus = Arrays.asList(JavaModelUtil.getAllCompilationUnits(javaElements));
int batchSize = 150;
int batches = ((cus.size() - 1) / batchSize) + 1;
SubProgressMonitor projectMonitor = new SubProgressMonitor(pm, 1);
//$NON-NLS-1$
projectMonitor.beginTask("", batches);
projectMonitor.setTaskName(RefactoringCoreMessages.InferTypeArgumentsRefactoring_building);
for (int i = 0; i < batches; i++) {
List<ICompilationUnit> batch = cus.subList(i * batchSize, Math.min(cus.size(), (i + 1) * batchSize));
ICompilationUnit[] batchCus = batch.toArray(new ICompilationUnit[batch.size()]);
final SubProgressMonitor batchMonitor = new SubProgressMonitor(projectMonitor, 1);
batchMonitor.subTask(RefactoringCoreMessages.InferTypeArgumentsRefactoring_calculating_dependencies);
ASTParser parser = ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
parser.setProject(project);
parser.setCompilerOptions(RefactoringASTParser.getCompilerOptions(project));
parser.setResolveBindings(true);
parser.createASTs(batchCus, new String[0], new ASTRequestor() {
@Override
public void acceptAST(final ICompilationUnit source, final CompilationUnit ast) {
batchMonitor.subTask(BasicElementLabels.getFileName(source));
SafeRunner.run(new ISafeRunnable() {
public void run() throws Exception {
IProblem[] problems = ast.getProblems();
for (int p = 0; p < problems.length; p++) {
if (problems[p].isError()) {
String cuName = JavaElementLabels.getElementLabel(source, JavaElementLabels.CU_QUALIFIED);
String msg = Messages.format(RefactoringCoreMessages.InferTypeArgumentsRefactoring_error_in_cu_skipped, new Object[] { cuName });
result.addError(msg, JavaStatusContext.create(source, SourceRangeFactory.create(problems[p])));
return;
}
}
ast.accept(unitCollector);
}
public void handleException(Throwable exception) {
String cuName = JavaElementLabels.getElementLabel(source, JavaElementLabels.CU_QUALIFIED);
String msg = Messages.format(RefactoringCoreMessages.InferTypeArgumentsRefactoring_internal_error, new Object[] { cuName });
JavaPlugin.log(new Status(IStatus.ERROR, JavaPlugin.getPluginId(), IJavaStatusConstants.INTERNAL_ERROR, msg, null));
String msg2 = Messages.format(RefactoringCoreMessages.InferTypeArgumentsRefactoring_error_skipped, new Object[] { cuName });
result.addError(msg2, JavaStatusContext.create(source));
}
});
fTCModel.newCu();
}
@Override
public void acceptBinding(String bindingKey, IBinding binding) {
//do nothing
}
}, batchMonitor);
}
projectMonitor.done();
fTCModel.newCu();
}
// Display.getDefault().syncExec(new Runnable() {
// public void run() {
// MessageDialog.openInformation(Display.getCurrent().getActiveShell(), "Debugging...", "after constraint gen");
// }
// });
pm.setTaskName(RefactoringCoreMessages.InferTypeArgumentsRefactoring_solving);
InferTypeArgumentsConstraintsSolver solver = new InferTypeArgumentsConstraintsSolver(fTCModel);
InferTypeArgumentsUpdate updates = solver.solveConstraints(new SubProgressMonitor(pm, 1));
//free caches
solver = null;
fChangeManager = new TextChangeManager();
rewriteDeclarations(updates, new SubProgressMonitor(pm, 1));
IFile[] filesToModify = ResourceUtil.getFiles(fChangeManager.getAllCompilationUnits());
result.merge(Checks.validateModifiesFiles(filesToModify, getValidationContext()));
return result;
} finally {
pm.done();
clearGlobalState();
}
}
use of org.eclipse.core.runtime.Status in project che by eclipse.
the class CompilationUnitRewriteOperationsFix method createChange.
// /**
// * {@inheritDoc}
// */
// @Override
// public LinkedProposalModel getLinkedPositions() {
// if (!fLinkedProposalModel.hasLinkedPositions())
// return null;
//
// return fLinkedProposalModel;
// }
/**
* {@inheritDoc}
*/
public CompilationUnitChange createChange(IProgressMonitor progressMonitor) throws CoreException {
CompilationUnitRewrite cuRewrite = new CompilationUnitRewrite((ICompilationUnit) fCompilationUnit.getJavaElement(), fCompilationUnit);
fLinkedProposalModel.clear();
for (int i = 0; i < fOperations.length; i++) {
CompilationUnitRewriteOperation operation = fOperations[i];
operation.rewriteAST(cuRewrite, fLinkedProposalModel);
}
CompilationUnitChange result = cuRewrite.createChange(getDisplayString(), true, null);
if (result == null)
throw new CoreException(new Status(IStatus.ERROR, JavaPlugin.ID_PLUGIN, Messages.format(FixMessages.CompilationUnitRewriteOperationsFix_nullChangeError, getDisplayString())));
return result;
}
use of org.eclipse.core.runtime.Status in project che by eclipse.
the class ContributionContextTypeRegistry method createResolver.
private static TemplateVariableResolver createResolver(IConfigurationElement element) throws CoreException {
try {
String type = element.getAttribute(TYPE);
if (type != null) {
TemplateVariableResolver resolver = (TemplateVariableResolver) element.createExecutableExtension(CLASS);
resolver.setType(type);
String desc = element.getAttribute(DESCRIPTION);
//$NON-NLS-1$
resolver.setDescription(desc == null ? "" : desc);
return resolver;
}
} catch (ClassCastException e) {
//$NON-NLS-1$
throw new CoreException(new Status(IStatus.ERROR, "org.eclipse.ui.editors", IStatus.OK, "extension does not implement " + TemplateVariableResolver.class.getName(), e));
}
return null;
}
use of org.eclipse.core.runtime.Status in project che by eclipse.
the class MultiStateTextFileChange method isValid.
/*
* @see org.eclipse.ltk.core.refactoring.Change#isValid(org.eclipse.core.runtime.IProgressMonitor)
*/
public final RefactoringStatus isValid(IProgressMonitor monitor) throws CoreException, OperationCanceledException {
if (monitor == null)
monitor = new NullProgressMonitor();
//$NON-NLS-1$
monitor.beginTask("", 1);
try {
if (fValidationState == null)
//$NON-NLS-1$
throw new CoreException(new Status(IStatus.ERROR, RefactoringCorePlugin.getPluginId(), "MultiStateTextFileChange has not been initialialized"));
final ITextFileBuffer buffer = FileBuffers.getTextFileBufferManager().getTextFileBuffer(fFile.getFullPath(), LocationKind.IFILE);
fDirty = buffer != null && buffer.isDirty();
final RefactoringStatus status = fValidationState.isValid(needsSaving());
if (needsSaving()) {
status.merge(Changes.validateModifiesFiles(new IFile[] { fFile }));
} else {
// we are reading the file. So it should be at least in sync
status.merge(Changes.checkInSync(new IFile[] { fFile }));
}
return status;
} finally {
monitor.done();
}
}
use of org.eclipse.core.runtime.Status in project che by eclipse.
the class ChePreferences method save.
protected void save(String location) throws BackingStoreException {
if (location == null) {
// PrefsMessages.message("Unable to determine location of preference file for node: " + absolutePath()); //$NON-NLS-1$
return;
}
// if (DEBUG_PREFERENCE_GENERAL)
// PrefsMessages.message("Saving preferences to file: " + location); //$NON-NLS-1$
Properties table = convertToProperties(new SortedProperties(), EMPTY_STRING);
if (table.isEmpty()) {
File file = new File(location);
// nothing to save. delete existing file if one exists.
if (file.exists() && !file.delete()) {
// String message = NLS.bind(PrefsMessages.preferences_failedDelete, location);
ResourcesPlugin.log(new Status(IStatus.WARNING, PrefsMessages.OWNER_NAME, IStatus.WARNING, "preferences save failed, file was delete", null));
}
return;
}
table.put(VERSION_KEY, VERSION_VALUE);
write(table, location);
}
Aggregations