Search in sources :

Example 1 with IDocumentExtension4

use of org.eclipse.jface.text.IDocumentExtension4 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 2 with IDocumentExtension4

use of org.eclipse.jface.text.IDocumentExtension4 in project che by eclipse.

the class TextChange method performEdits.

/**
	 * Executes the text edits on the given document.
	 * Subclasses that override this method should call <code>super.performEdits(document)</code>.
	 * 
	 * @param document the document
	 * @return an object representing the undo of the executed edits
	 * @exception MalformedTreeException is thrown if the edit tree isn't
	 *  in a valid state. This exception is thrown before any edit is executed.
	 *  So the document is still in its original state.
	 * @exception BadLocationException is thrown if one of the edits in the
	 *  tree can't be executed. The state of the document is undefined if this
	 *  exception is thrown.
	 * @since 3.5
	 */
protected UndoEdit performEdits(IDocument document) throws BadLocationException, MalformedTreeException {
    DocumentRewriteSession session = null;
    try {
        if (document instanceof IDocumentExtension4) {
            session = ((IDocumentExtension4) document).startRewriteSession(DocumentRewriteSessionType.UNRESTRICTED);
        }
        LinkedModeModel.closeAllModels(document);
        TextEditProcessor processor = createTextEditProcessor(document, TextEdit.CREATE_UNDO, false);
        return processor.performEdits();
    } finally {
        if (session != null) {
            ((IDocumentExtension4) document).stopRewriteSession(session);
        }
    }
}
Also used : DocumentRewriteSession(org.eclipse.jface.text.DocumentRewriteSession) IDocumentExtension4(org.eclipse.jface.text.IDocumentExtension4) TextEditProcessor(org.eclipse.text.edits.TextEditProcessor)

Example 3 with IDocumentExtension4

use of org.eclipse.jface.text.IDocumentExtension4 in project che by eclipse.

the class TextFileBufferManager method createEmptyDocument.

/*
	 * @see org.eclipse.core.filebuffers.ITextFileBufferManager#createEmptyDocument(org.eclipse.core.runtime.IPath, org.eclipse.core.filebuffers.LocationKind)
	 * @since 3.3
	 */
public IDocument createEmptyDocument(final IPath location, final LocationKind locationKind) {
    //		IDocument documentFromFactory= createDocumentFromFactory(location, locationKind);
    final IDocument document;
    //		if (documentFromFactory != null)
    //			document= documentFromFactory;
    //		else
    document = new SynchronizableDocument();
    if (location == null)
        return document;
    // Set the initial line delimiter
    if (document instanceof IDocumentExtension4) {
        String initalLineDelimiter = getLineDelimiterPreference(location, locationKind);
        if (initalLineDelimiter != null)
            ((IDocumentExtension4) document).setInitialLineDelimiter(initalLineDelimiter);
    }
    return document;
}
Also used : IDocumentExtension4(org.eclipse.jface.text.IDocumentExtension4) IDocument(org.eclipse.jface.text.IDocument)

Example 4 with IDocumentExtension4

use of org.eclipse.jface.text.IDocumentExtension4 in project dbeaver by serge-rider.

the class FileRefDocumentProvider method createElementInfo.

@Override
protected ElementInfo createElementInfo(Object element) throws CoreException {
    if (element instanceof IEditorInput) {
        IEditorInput input = (IEditorInput) element;
        IStorage storage = EditorUtils.getStorageFromInput(input);
        if (storage instanceof IFile) {
            IFile file = (IFile) storage;
            try {
                refreshFile(file);
            } catch (CoreException x) {
                log.warn("Can't refresh file", x);
            }
            IDocument d;
            IStatus s = null;
            try {
                d = createDocument(element);
            } catch (CoreException x) {
                log.warn("Can't create document", x);
                s = x.getStatus();
                d = createEmptyDocument();
            }
            // Set the initial line delimiter
            String initialLineDelimiter = GeneralUtils.getDefaultLineSeparator();
            if (initialLineDelimiter != null) {
                ((IDocumentExtension4) d).setInitialLineDelimiter(initialLineDelimiter);
            }
            IAnnotationModel m = createAnnotationModel(element);
            FileSynchronizer f = new FileSynchronizer(input);
            f.install();
            FileInfo info = new FileInfo(d, m, f);
            info.modificationStamp = computeModificationStamp(file);
            info.fStatus = s;
            return info;
        }
    }
    return super.createElementInfo(element);
}
Also used : IDocumentExtension4(org.eclipse.jface.text.IDocumentExtension4) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) IEditorInput(org.eclipse.ui.IEditorInput) IDocument(org.eclipse.jface.text.IDocument)

Example 5 with IDocumentExtension4

use of org.eclipse.jface.text.IDocumentExtension4 in project tdi-studio-se by Talend.

the class JavaProcessor method formatCode.

/**
     * DOC nrousseau Comment method "formatCode".
     *
     * from SourceViewer.doOperation for FORMAT.
     *
     * @param processCode
     * @return
     */
@SuppressWarnings({ "unchecked" })
private String formatCode(String processCode) {
    // we cannot make calls to Ui in headless mode
    if (ProcessorUtilities.isExportConfig() || CommonsPlugin.isHeadless()) {
        // nothing to do
        return processCode;
    }
    final IDocument document = new Document(processCode);
    JavaTextTools tools = JavaPlugin.getDefault().getJavaTextTools();
    tools.setupJavaDocumentPartitioner(document, IJavaPartitions.JAVA_PARTITIONING);
    IFormattingContext context = null;
    DocumentRewriteSession rewriteSession = null;
    if (document instanceof IDocumentExtension4) {
        rewriteSession = ((IDocumentExtension4) document).startRewriteSession(DocumentRewriteSessionType.SEQUENTIAL);
    }
    try {
        final String rememberedContents = document.get();
        try {
            final MultiPassContentFormatter formatter = new MultiPassContentFormatter(IJavaPartitions.JAVA_PARTITIONING, IDocument.DEFAULT_CONTENT_TYPE);
            formatter.setMasterStrategy(new JavaFormattingStrategy());
            // formatter.setSlaveStrategy(new CommentFormattingStrategy(),
            // IJavaPartitions.JAVA_DOC);
            // formatter.setSlaveStrategy(new CommentFormattingStrategy(),
            // IJavaPartitions.JAVA_SINGLE_LINE_COMMENT);
            // formatter.setSlaveStrategy(new CommentFormattingStrategy(),
            // IJavaPartitions.JAVA_MULTI_LINE_COMMENT);
            context = new FormattingContext();
            context.setProperty(FormattingContextProperties.CONTEXT_DOCUMENT, Boolean.TRUE);
            Map<String, String> preferences;
            if (this.getTalendJavaProject() == null) {
                preferences = new HashMap<String, String>(JavaCore.getOptions());
            } else {
                // use project options
                preferences = new HashMap<String, String>(this.getTalendJavaProject().getJavaProject().getOptions(true));
            }
            context.setProperty(FormattingContextProperties.CONTEXT_PREFERENCES, preferences);
            formatter.format(document, context);
        } catch (RuntimeException x) {
            // fire wall for
            // https://bugs.eclipse.org/bugs/show_bug.cgi?id=47472
            // if something went wrong we undo the changes we just did
            // TODO to be removed after 3.0 M8
            document.set(rememberedContents);
            throw x;
        }
    } finally {
        if (rewriteSession != null && document instanceof IDocumentExtension4) {
            ((IDocumentExtension4) document).stopRewriteSession(rewriteSession);
        }
        if (context != null) {
            context.dispose();
        }
    }
    return document.get();
}
Also used : IFormattingContext(org.eclipse.jface.text.formatter.IFormattingContext) FormattingContext(org.eclipse.jface.text.formatter.FormattingContext) IFormattingContext(org.eclipse.jface.text.formatter.IFormattingContext) IDocumentExtension4(org.eclipse.jface.text.IDocumentExtension4) JavaTextTools(org.eclipse.jdt.ui.text.JavaTextTools) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) DocumentRewriteSession(org.eclipse.jface.text.DocumentRewriteSession) MultiPassContentFormatter(org.eclipse.jface.text.formatter.MultiPassContentFormatter) JavaFormattingStrategy(org.eclipse.jdt.internal.ui.text.java.JavaFormattingStrategy) IDocument(org.eclipse.jface.text.IDocument)

Aggregations

IDocumentExtension4 (org.eclipse.jface.text.IDocumentExtension4)6 IDocument (org.eclipse.jface.text.IDocument)4 DocumentRewriteSession (org.eclipse.jface.text.DocumentRewriteSession)3 Iterator (java.util.Iterator)1 ITextFileBuffer (org.eclipse.core.filebuffers.ITextFileBuffer)1 IFile (org.eclipse.core.resources.IFile)1 JavaFormattingStrategy (org.eclipse.jdt.internal.ui.text.java.JavaFormattingStrategy)1 JavaTextTools (org.eclipse.jdt.ui.text.JavaTextTools)1 Document (org.eclipse.jface.text.Document)1 FormattingContext (org.eclipse.jface.text.formatter.FormattingContext)1 IFormattingContext (org.eclipse.jface.text.formatter.IFormattingContext)1 MultiPassContentFormatter (org.eclipse.jface.text.formatter.MultiPassContentFormatter)1 IAnnotationModel (org.eclipse.jface.text.source.IAnnotationModel)1 TextEditProcessor (org.eclipse.text.edits.TextEditProcessor)1 UndoEdit (org.eclipse.text.edits.UndoEdit)1 IEditorInput (org.eclipse.ui.IEditorInput)1