use of org.eclipse.jface.text.IDocument in project AutoRefactor by JnRouvignac.
the class TestHelper method normalizeJavaSourceCode.
public static String normalizeJavaSourceCode(String source) {
final CodeFormatter codeFormatter = createCodeFormatter(getJava7Options());
final TextEdit edit = codeFormatter.format(K_COMPILATION_UNIT, // source to format
source, // source to format
0, // source to format
source.length(), // initial indentation and line separator
0, // initial indentation and line separator
System.getProperty("line.separator"));
try {
final IDocument document = new Document(source);
edit.apply(document);
return document.get();
} catch (MalformedTreeException e) {
throw new RuntimeException(e);
} catch (BadLocationException e) {
throw new RuntimeException(e);
}
}
use of org.eclipse.jface.text.IDocument in project AutoRefactor by JnRouvignac.
the class ApplyRefactoringsJob method applyRefactoring.
private void applyRefactoring(ICompilationUnit compilationUnit, AggregateASTVisitor refactoringToApply, JavaProjectOptions options, IProgressMonitor monitor) throws Exception {
final ITextFileBufferManager bufferManager = FileBuffers.getTextFileBufferManager();
final IPath path = compilationUnit.getPath();
final LocationKind locationKind = LocationKind.NORMALIZE;
try {
bufferManager.connect(path, locationKind, null);
final ITextFileBuffer textFileBuffer = bufferManager.getTextFileBuffer(path, locationKind);
if (!textFileBuffer.isSynchronized()) {
/*
* Cannot read the source when a file is not synchronized,
* Let's ignore this file to avoid problems when:
* - doing string manipulation with the source text
* - applying automated refactorings to such files
*/
environment.getLogger().error("File \"" + compilationUnit.getPath() + "\" is not synchronized with the file system." + " Automated refactorings will not be applied to it.");
return;
}
final IDocument document = textFileBuffer.getDocument();
applyRefactoring(document, compilationUnit, refactoringToApply, options, monitor);
} finally {
bufferManager.disconnect(path, locationKind, null);
}
}
use of org.eclipse.jface.text.IDocument in project ow by vtst.
the class AbstractCompletionProposal method apply.
@Override
public void apply(ITextViewer viewer, char trigger, int stateMask, int offset) {
String replacementString = getReplacementString(trigger);
try {
IDocument document = viewer.getDocument();
int replacementOffset = context.getInvocationOffset() - context.getPrefixLength();
document.replace(replacementOffset, context.getPrefixLength() + offset - context.getInvocationOffset(), replacementString);
regionToSelect = new Point(context.getInvocationOffset() + replacementString.length() - context.getPrefixLength(), 0);
setUpLinkedMode(document, replacementOffset, getFragments());
} catch (BadLocationException e) {
assert false;
}
}
use of org.eclipse.jface.text.IDocument in project ow by vtst.
the class AbstractEditorRegistry method addEditor.
private synchronized void addEditor(ITextEditor textEditor) {
IEditorInput editorInput = textEditor.getEditorInput();
if (!(editorInput instanceof IFileEditorInput))
return;
IFile file = ((IFileEditorInput) editorInput).getFile();
IDocument document = textEditor.getDocumentProvider().getDocument(editorInput);
if (file == null || document == null)
return;
editorToFile.put(textEditor, file);
editorToDocument.put(textEditor, document);
boolean newlyOpenedFile = fileToEditors.put(file, textEditor);
if (documentToEditors.put(document, textEditor)) {
DocumentListener listener = makeDocumentListener(document);
documentToListener.put(document, listener);
document.addDocumentListener(listener);
documentToFile.put(document, file);
}
if (newlyOpenedFile) {
triggerFileOpenListener(file);
}
}
use of org.eclipse.jface.text.IDocument in project ow by vtst.
the class CompilationUnitProviderFromEclipseIFile method lastModified.
@Override
public long lastModified() {
JavaScriptEditorRegistry editorRegistry = OwJsClosurePlugin.getDefault().getEditorRegistry();
IDocument document = editorRegistry.getDocument(file);
if (document == null)
return file.getModificationStamp();
else {
// Be also careful to the listener.
return editorRegistry.getLastModificationTime(document);
}
}
Aggregations