use of org.eclipse.core.runtime.NullProgressMonitor in project che by eclipse.
the class CUCorrectionProposal method createTextChange.
/**
* Creates the text change for this proposal.
* This method is only called once and only when no text change has been passed in
* {@link #CUCorrectionProposal(String, ICompilationUnit, TextChange, int, Image)}.
*
* @return the created text change
* @throws CoreException if the creation of the text change failed
*/
protected TextChange createTextChange() throws CoreException {
ICompilationUnit cu = getCompilationUnit();
String name = getName();
TextChange change;
if (!cu.getResource().exists()) {
String source;
try {
source = cu.getSource();
} catch (JavaModelException e) {
JavaPlugin.log(e);
// empty
source = new String();
}
Document document = new Document(source);
document.setInitialLineDelimiter(StubUtility.getLineDelimiterUsed(cu));
change = new DocumentChange(name, document);
} else {
CompilationUnitChange cuChange = new CompilationUnitChange(name, cu);
cuChange.setSaveMode(TextFileChange.LEAVE_DIRTY);
change = cuChange;
}
TextEdit rootEdit = new MultiTextEdit();
change.setEdit(rootEdit);
// initialize text change
IDocument document = change.getCurrentDocument(new NullProgressMonitor());
addEdits(document, rootEdit);
return change;
}
use of org.eclipse.core.runtime.NullProgressMonitor 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.NullProgressMonitor in project che by eclipse.
the class TextChange method getCurrentDocument.
//---- Method to access the current content of the text change ---------
/**
* Returns the document this text change is associated to. The
* document returned is computed at the point in time when this
* method is called. So calling this method multiple times may
* return different document instances.
* <p>
* The returned document must not be modified by the client. Doing
* so will result in an unexpected behavior when the change is
* performed.
* </p>
*
* @param pm a progress monitor to report progress or <code>null</code>
* if no progress reporting is desired
* @return the document this change is working on
*
* @throws CoreException if the document can't be acquired
*/
public IDocument getCurrentDocument(IProgressMonitor pm) throws CoreException {
if (pm == null)
pm = new NullProgressMonitor();
IDocument result = null;
//$NON-NLS-1$
pm.beginTask("", 2);
try {
result = acquireDocument(new SubProgressMonitor(pm, 1));
} finally {
if (result != null)
releaseDocument(result, new SubProgressMonitor(pm, 1));
}
pm.done();
return result;
}
use of org.eclipse.core.runtime.NullProgressMonitor in project che by eclipse.
the class TextEditChangePreviewViewer method setInput.
// public void createControl(Composite parent) {
// fViewer = new ComparePreviewer(parent);
// }
//
// public Control getControl() {
// return fViewer;
// }
public ChangePreview setInput(ChangePreviewViewerInput input) {
try {
Change change = input.getChange();
if (input instanceof TextEditBasedChangeInput) {
TextEditBasedChangeInput extended = (TextEditBasedChangeInput) input;
if (extended.group != null && extended.surroundingLines >= 0) {
TextEditBasedChangeGroup group = extended.group;
TextEditBasedChange editChange = group.getTextEditChange();
// setInput(editChange, editChange.getCurrentContent(group.getRegion(), true, 2, new NullProgressMonitor()),
// editChange.getPreviewContent(new TextEditBasedChangeGroup[]{group}, group.getRegion(), true, 2,
// new NullProgressMonitor()),
// editChange.getTextType());
ChangePreview preview = DtoFactory.newDto(ChangePreview.class);
preview.setFileName(getFileName(editChange));
preview.setOldContent(editChange.getCurrentContent(group.getRegion(), true, 2, new NullProgressMonitor()));
preview.setNewContent(editChange.getPreviewContent(new TextEditBasedChangeGroup[] { group }, group.getRegion(), true, 2, new NullProgressMonitor()));
return preview;
} else if (extended.groups != null && extended.groups.length > 0 && extended.range != null) {
TextEditBasedChange editChange = extended.groups[0].getTextEditChange();
TextEditBasedChangeGroup[] groups = extended.groups;
// if (extended.groupCategory != null) {
//
// }
// setInput(editChange, editChange.getCurrentContent(extended.range, true, 0, new NullProgressMonitor()),
// editChange.getPreviewContent(groups, extended.range, true, 0, new NullProgressMonitor()),
// editChange.getTextType());
ChangePreview preview = DtoFactory.newDto(ChangePreview.class);
preview.setFileName(getFileName(editChange));
preview.setOldContent(editChange.getCurrentContent(extended.range, true, 0, new NullProgressMonitor()));
preview.setNewContent(editChange.getPreviewContent(groups, extended.range, true, 0, new NullProgressMonitor()));
return preview;
}
} else if (change instanceof TextEditBasedChange) {
TextEditBasedChange editChange = (TextEditBasedChange) change;
// setInput(editChange, editChange.getCurrentContent(new NullProgressMonitor()),
// editChange.getPreviewContent(new NullProgressMonitor()), editChange.getTextType());
ChangePreview preview = DtoFactory.newDto(ChangePreview.class);
preview.setFileName(getFileName(editChange));
preview.setOldContent(editChange.getCurrentContent(new NullProgressMonitor()));
preview.setNewContent(editChange.getPreviewContent(new NullProgressMonitor()));
return preview;
} else {
// fViewer.setInput(null);
return null;
}
} catch (CoreException | AssertionFailedException e) {
JavaPlugin.log(e);
// fViewer.setInput(null);
return null;
}
// }
return null;
}
use of org.eclipse.core.runtime.NullProgressMonitor in project che by eclipse.
the class CompositeResourceMapping method getTraversals.
/* (non-Javadoc)
* @see org.eclipse.core.resources.mapping.ResourceMapping#getTraversals(org.eclipse.core.internal.resources.mapping.ResourceMappingContext, org.eclipse.core.runtime.IProgressMonitor)
*/
@Override
public ResourceTraversal[] getTraversals(ResourceMappingContext context, IProgressMonitor monitor) throws CoreException {
if (monitor == null)
monitor = new NullProgressMonitor();
try {
//$NON-NLS-1$
monitor.beginTask("", 100 * mappings.length);
List<ResourceTraversal> result = new ArrayList<ResourceTraversal>();
for (int i = 0; i < mappings.length; i++) {
ResourceMapping mapping = mappings[i];
result.addAll(Arrays.asList(mapping.getTraversals(context, new SubProgressMonitor(monitor, 100))));
}
return result.toArray(new ResourceTraversal[result.size()]);
} finally {
monitor.done();
}
}
Aggregations