use of org.eclipse.core.filebuffers.ITextFileBuffer in project che by eclipse.
the class TextSearchVisitor method getOpenDocument.
private IDocument getOpenDocument(IFile file, Map documentsInEditors) {
IDocument document = (IDocument) documentsInEditors.get(file);
if (document == null) {
ITextFileBufferManager bufferManager = FileBuffers.getTextFileBufferManager();
ITextFileBuffer textFileBuffer = bufferManager.getTextFileBuffer(file.getFullPath(), LocationKind.IFILE);
if (textFileBuffer != null) {
document = textFileBuffer.getDocument();
}
}
return document;
}
use of org.eclipse.core.filebuffers.ITextFileBuffer in project che by eclipse.
the class ResourceChange method getModificationStamp.
private long getModificationStamp(IResource resource) {
if (!(resource instanceof IFile))
return resource.getModificationStamp();
IFile file = (IFile) resource;
ITextFileBuffer buffer = getBuffer(file);
if (buffer == null) {
return file.getModificationStamp();
} else {
IDocument document = buffer.getDocument();
if (document instanceof IDocumentExtension4) {
return ((IDocumentExtension4) document).getModificationStamp();
} else {
return file.getModificationStamp();
}
}
}
use of org.eclipse.core.filebuffers.ITextFileBuffer in project che by eclipse.
the class MultiStateUndoChange method isValid.
/**
* {@inheritDoc}
*/
public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException {
if (pm == null)
pm = new NullProgressMonitor();
//$NON-NLS-1$
pm.beginTask("", 1);
try {
if (fValidationState == null)
//$NON-NLS-1$
throw new CoreException(new Status(IStatus.ERROR, RefactoringCorePlugin.getPluginId(), "MultiStateUndoChange has not been initialialized"));
ITextFileBuffer buffer = FileBuffers.getTextFileBufferManager().getTextFileBuffer(fFile.getFullPath(), LocationKind.IFILE);
fDirty = buffer != null && buffer.isDirty();
return fValidationState.isValid(needsSaving(), true);
} finally {
pm.done();
}
}
use of org.eclipse.core.filebuffers.ITextFileBuffer in project che by eclipse.
the class MultiStateUndoChange method perform.
/**
* {@inheritDoc}
*/
public Change perform(IProgressMonitor pm) throws CoreException {
if (fValidationState == null || fValidationState.isValid(needsSaving(), false).hasFatalError())
return new NullChange();
if (pm == null)
pm = new NullProgressMonitor();
ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
//$NON-NLS-1$
pm.beginTask("", 2);
ITextFileBuffer buffer = null;
try {
manager.connect(fFile.getFullPath(), LocationKind.IFILE, new SubProgressMonitor(pm, 1));
buffer = manager.getTextFileBuffer(fFile.getFullPath(), LocationKind.IFILE);
IDocument document = buffer.getDocument();
ContentStamp currentStamp = ContentStamps.get(fFile, document);
// perform the changes
LinkedList list = new LinkedList();
for (int index = 0; index < fUndos.length; index++) {
UndoEdit edit = fUndos[index];
UndoEdit redo = edit.apply(document, TextEdit.CREATE_UNDO);
list.addFirst(redo);
}
// try to restore the document content stamp
boolean success = ContentStamps.set(document, fContentStampToRestore);
if (needsSaving()) {
buffer.commit(pm, false);
if (!success) {
// We weren't able to restore document stamp.
// Since we save restore the file stamp instead
ContentStamps.set(fFile, fContentStampToRestore);
}
}
return createUndoChange((UndoEdit[]) list.toArray(new UndoEdit[list.size()]), currentStamp);
} catch (BadLocationException e) {
throw Changes.asCoreException(e);
} finally {
if (buffer != null)
manager.disconnect(fFile.getFullPath(), LocationKind.IFILE, new SubProgressMonitor(pm, 1));
}
}
use of org.eclipse.core.filebuffers.ITextFileBuffer in project che by eclipse.
the class SourceProvider method replaceParameterWithExpression.
private void replaceParameterWithExpression(ASTRewrite rewriter, CallContext context, ImportRewrite importRewrite) throws CoreException {
Expression[] arguments = context.arguments;
try {
ITextFileBuffer buffer = RefactoringFileBuffers.acquire(context.compilationUnit);
for (int i = 0; i < arguments.length; i++) {
Expression expression = arguments[i];
String expressionString = null;
if (expression instanceof SimpleName) {
expressionString = ((SimpleName) expression).getIdentifier();
} else {
try {
expressionString = buffer.getDocument().get(expression.getStartPosition(), expression.getLength());
} catch (BadLocationException exception) {
JavaPlugin.log(exception);
continue;
}
}
ParameterData parameter = getParameterData(i);
List<SimpleName> references = parameter.references();
for (Iterator<SimpleName> iter = references.iterator(); iter.hasNext(); ) {
ASTNode element = iter.next();
Expression newExpression = (Expression) rewriter.createStringPlaceholder(expressionString, expression.getNodeType());
AST ast = rewriter.getAST();
ITypeBinding explicitCast = ASTNodes.getExplicitCast(expression, (Expression) element);
if (explicitCast != null) {
CastExpression cast = ast.newCastExpression();
if (NecessaryParenthesesChecker.needsParentheses(expression, cast, CastExpression.EXPRESSION_PROPERTY)) {
newExpression = createParenthesizedExpression(newExpression, ast);
}
cast.setExpression(newExpression);
ImportRewriteContext importRewriteContext = new ContextSensitiveImportRewriteContext(expression, importRewrite);
cast.setType(importRewrite.addImport(explicitCast, ast, importRewriteContext));
expression = newExpression = cast;
}
if (NecessaryParenthesesChecker.needsParentheses(expression, element.getParent(), element.getLocationInParent())) {
newExpression = createParenthesizedExpression(newExpression, ast);
}
rewriter.replace(element, newExpression, null);
}
}
} finally {
RefactoringFileBuffers.release(context.compilationUnit);
}
}
Aggregations