use of org.eclipse.jface.text.IDocument in project che by eclipse.
the class JavaDocContext method getKey.
/*
* @see org.eclipse.jdt.internal.corext.template.DocumentTemplateContext#getKey()
*/
@Override
public String getKey() {
if (getCompletionLength() == 0)
return super.getKey();
try {
IDocument document = getDocument();
int start = getStart();
int end = getCompletionOffset();
return start <= end ? document.get(start, end - start) : //$NON-NLS-1$
"";
} catch (BadLocationException e) {
return super.getKey();
}
}
use of org.eclipse.jface.text.IDocument in project che by eclipse.
the class JavaDocContext method getEnd.
/*
* @see org.eclipse.jdt.internal.corext.template.DocumentTemplateContext#getEnd()
*/
@Override
public int getEnd() {
if (fIsManaged || getCompletionLength() == 0)
return super.getEnd();
try {
IDocument document = getDocument();
int start = getCompletionOffset();
int end = getCompletionOffset() + getCompletionLength();
while (start != end && Character.isWhitespace(document.getChar(end - 1))) end--;
return end;
} catch (BadLocationException e) {
return super.getEnd();
}
}
use of org.eclipse.jface.text.IDocument in project che by eclipse.
the class JavaFormatter method format.
/**
* Formats the template buffer.
* @param buffer
* @param context
* @throws BadLocationException
*/
public void format(TemplateBuffer buffer, TemplateContext context) throws BadLocationException {
try {
VariableTracker tracker = new VariableTracker(buffer);
IDocument document = tracker.getDocument();
internalFormat(document, context);
convertLineDelimiters(document);
if (!(context instanceof JavaDocContext) && !isReplacedAreaEmpty(context))
trimStart(document);
tracker.updateBuffer();
} catch (MalformedTreeException e) {
throw new BadLocationException();
}
}
use of org.eclipse.jface.text.IDocument 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.jface.text.IDocument 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));
}
}
Aggregations