Search in sources :

Example 66 with ITypedRegion

use of org.eclipse.jface.text.ITypedRegion in project webtools.sourceediting by eclipse.

the class JavascriptValidationStrategy method reconcile.

/* (non-Javadoc)
	 * @see org.eclipse.jface.text.reconciler.IReconcilingStrategy#reconcile(org.eclipse.jface.text.IRegion)
	 */
public void reconcile(IRegion partition) {
    ITypedRegion[] partitions = computePartitioning(partition);
    // call the validator strategy once for each effected partition
    DirtyRegion dirty = null;
    for (int i = 0; i < partitions.length; i++) {
        dirty = createDirtyRegion(partitions[i], DirtyRegion.INSERT);
        // [source]validator (extension) for this partition
        if (getValidatorStrategy() != null) {
            getValidatorStrategy().reconcile(partitions[i], dirty);
        }
    }
}
Also used : ITypedRegion(org.eclipse.jface.text.ITypedRegion) DirtyRegion(org.eclipse.jface.text.reconciler.DirtyRegion)

Example 67 with ITypedRegion

use of org.eclipse.jface.text.ITypedRegion in project webtools.sourceediting by eclipse.

the class AddBlockCommentHandler method processAction.

/**
 * @see org.eclipse.wst.sse.ui.internal.handlers.AbstractCommentHandler#processAction(
 * 	org.eclipse.ui.texteditor.ITextEditor, org.eclipse.jface.text.IDocument, org.eclipse.jface.text.ITextSelection)
 */
protected void processAction(ITextEditor textEditor, IStructuredDocument document, ITextSelection textSelection) {
    IStructuredModel model = null;
    boolean changed = false;
    DocumentRewriteSession session = null;
    try {
        model = StructuredModelManager.getModelManager().getModelForEdit(document);
        if (model != null) {
            // makes it so one undo will undo all the edits to the document
            model.beginRecording(this, SSEUIMessages.AddBlockComment_label, SSEUIMessages.AddBlockComment_description);
            // keeps listeners from doing anything until updates are all done
            model.aboutToChangeModel();
            if (document instanceof IDocumentExtension4) {
                session = ((IDocumentExtension4) document).startRewriteSession(DocumentRewriteSessionType.UNRESTRICTED);
            }
            changed = true;
            ITypedRegion[] typedRegions = document.computePartitioning(textSelection.getOffset(), textSelection.getLength());
            CommentingStrategy commentType = CommentingStrategyRegistry.getDefault().getBlockCommentingStrategy(model.getContentTypeIdentifier(), typedRegions);
            if (commentType != null) {
                commentType.apply(document, textSelection.getOffset(), textSelection.getLength());
            }
        }
    } catch (BadLocationException e) {
        // $NON-NLS-1$ //$NON-NLS-2$
        Logger.logException("The given selection " + textSelection + " must be invalid", e);
    } finally {
        // clean everything up
        if (session != null && document instanceof IDocumentExtension4) {
            ((IDocumentExtension4) document).stopRewriteSession(session);
        }
        if (model != null) {
            model.endRecording(this);
            if (changed) {
                model.changedModel();
            }
            model.releaseFromEdit();
        }
    }
}
Also used : DocumentRewriteSession(org.eclipse.jface.text.DocumentRewriteSession) IDocumentExtension4(org.eclipse.jface.text.IDocumentExtension4) ITypedRegion(org.eclipse.jface.text.ITypedRegion) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) CommentingStrategy(org.eclipse.wst.sse.ui.internal.comment.CommentingStrategy) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 68 with ITypedRegion

use of org.eclipse.jface.text.ITypedRegion in project webtools.sourceediting by eclipse.

the class TestXSLLineStyleProvider method testPrepareRegion.

@Test
public void testPrepareRegion() throws Exception {
    setUpTest("utils.xsl");
    LineStyleProvider provider = initializeProvider();
    ITypedRegion[] partitions = setupPartitions();
    assertTrue("No Partitions found.", partitions.length > 0);
    ArrayList holdStyleResults = new ArrayList();
    applyStyles(provider, partitions, holdStyleResults);
    assertFalse("No styles applied.", holdStyleResults.isEmpty());
    assertEquals("Unexpected StyleRange size", 241, holdStyleResults.size());
}
Also used : LineStyleProvider(org.eclipse.wst.sse.ui.internal.provisional.style.LineStyleProvider) ArrayList(java.util.ArrayList) ITypedRegion(org.eclipse.jface.text.ITypedRegion) Test(org.junit.Test) AbstractXSLUITest(org.eclipse.wst.xsl.ui.tests.AbstractXSLUITest)

Example 69 with ITypedRegion

use of org.eclipse.jface.text.ITypedRegion in project webtools.sourceediting by eclipse.

the class TestXSLLineStyleProvider method setupPartitions.

private ITypedRegion[] setupPartitions() throws BadLocationException {
    int startOffset = document.getFirstStructuredDocumentRegion().getStartOffset();
    int endLineLength = document.getLength();
    IRegion styleRegion = getDocumentRangeFromWidgetRange(startOffset, endLineLength);
    ITypedRegion[] partitions = TextUtilities.computePartitioning(document, Partitioning, styleRegion.getOffset(), styleRegion.getLength(), false);
    return partitions;
}
Also used : ITypedRegion(org.eclipse.jface.text.ITypedRegion) IRegion(org.eclipse.jface.text.IRegion)

Example 70 with ITypedRegion

use of org.eclipse.jface.text.ITypedRegion in project webtools.sourceediting by eclipse.

the class XSLBreakpointProvider method getValidPosition.

private int getValidPosition(IDocument idoc, int editorLineNumber) {
    int result = -1;
    if (idoc != null) {
        int startOffset = 0;
        int endOffset = 0;
        try {
            IRegion line = idoc.getLineInformation(editorLineNumber - 1);
            startOffset = line.getOffset();
            endOffset = Math.max(line.getOffset(), line.getOffset() + line.getLength());
            String lineText = idoc.get(startOffset, endOffset - startOffset).trim();
            // blank lines or PI's cannot have breakpoints
            if (// $NON-NLS-1$ //$NON-NLS-2$
            lineText.trim().equals("") || lineText.startsWith("<?")) {
                result = -1;
            } else {
                // get all partitions for current line
                ITypedRegion[] partitions = null;
                partitions = idoc.computePartitioning(startOffset, endOffset - startOffset);
                for (int i = 0; i < partitions.length; ++i) {
                    // String type = partitions[i].getType();
                    result = partitions[i].getOffset();
                }
            }
        } catch (BadLocationException e) {
            result = -1;
        }
    }
    return result;
}
Also used : ITypedRegion(org.eclipse.jface.text.ITypedRegion) IBreakpoint(org.eclipse.debug.core.model.IBreakpoint) XSLLineBreakpoint(org.eclipse.wst.xsl.launching.model.XSLLineBreakpoint) IRegion(org.eclipse.jface.text.IRegion) BadLocationException(org.eclipse.jface.text.BadLocationException)

Aggregations

ITypedRegion (org.eclipse.jface.text.ITypedRegion)129 BadLocationException (org.eclipse.jface.text.BadLocationException)59 IRegion (org.eclipse.jface.text.IRegion)42 IDocument (org.eclipse.jface.text.IDocument)21 Region (org.eclipse.jface.text.Region)19 ArrayList (java.util.ArrayList)17 TypedRegion (org.eclipse.jface.text.TypedRegion)16 BadPositionCategoryException (org.eclipse.jface.text.BadPositionCategoryException)14 Position (org.eclipse.jface.text.Position)14 TypedPosition (org.eclipse.jface.text.TypedPosition)13 List (java.util.List)11 StyleRange (org.eclipse.swt.custom.StyleRange)7 Test (org.junit.Test)7 Iterator (java.util.Iterator)6 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)6 ITextSelection (org.eclipse.jface.text.ITextSelection)5 BadPartitioningException (org.eclipse.jface.text.BadPartitioningException)4 Document (org.eclipse.jface.text.Document)4 IDocumentExtension3 (org.eclipse.jface.text.IDocumentExtension3)4 IDocumentPartitioner (org.eclipse.jface.text.IDocumentPartitioner)4