Search in sources :

Example 31 with IDocument

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();
    }
}
Also used : IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 32 with IDocument

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();
    }
}
Also used : IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 33 with IDocument

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();
    }
}
Also used : MalformedTreeException(org.eclipse.text.edits.MalformedTreeException) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 34 with IDocument

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();
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IDocumentExtension4(org.eclipse.jface.text.IDocumentExtension4) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) IDocument(org.eclipse.jface.text.IDocument)

Example 35 with IDocument

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));
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) NullChange(org.eclipse.ltk.core.refactoring.NullChange) ITextFileBufferManager(org.eclipse.core.filebuffers.ITextFileBufferManager) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) ContentStamp(org.eclipse.ltk.core.refactoring.ContentStamp) UndoEdit(org.eclipse.text.edits.UndoEdit) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) IDocument(org.eclipse.jface.text.IDocument) LinkedList(java.util.LinkedList) BadLocationException(org.eclipse.jface.text.BadLocationException)

Aggregations

IDocument (org.eclipse.jface.text.IDocument)1055 BadLocationException (org.eclipse.jface.text.BadLocationException)379 Document (org.eclipse.jface.text.Document)189 IRegion (org.eclipse.jface.text.IRegion)150 Test (org.junit.Test)107 CoreException (org.eclipse.core.runtime.CoreException)102 Point (org.eclipse.swt.graphics.Point)94 IFile (org.eclipse.core.resources.IFile)90 ArrayList (java.util.ArrayList)85 ITextFileBuffer (org.eclipse.core.filebuffers.ITextFileBuffer)84 Position (org.eclipse.jface.text.Position)74 ITextEditor (org.eclipse.ui.texteditor.ITextEditor)74 IEditorPart (org.eclipse.ui.IEditorPart)62 ITextFileBufferManager (org.eclipse.core.filebuffers.ITextFileBufferManager)54 IPath (org.eclipse.core.runtime.IPath)54 ITextSelection (org.eclipse.jface.text.ITextSelection)53 TextEdit (org.eclipse.text.edits.TextEdit)49 Region (org.eclipse.jface.text.Region)47 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)44 IDocumentProvider (org.eclipse.ui.texteditor.IDocumentProvider)41