Search in sources :

Example 41 with IStructuredDocument

use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument in project webtools.sourceediting by eclipse.

the class TestStructuredPartitionerHTML method doComputePartitioningTest.

/**
 * Compute the partitions for the given filename using the default partitioner
 * for that file type.
 *
 * @param filename
 * @return int
 * @throws IOException
 * @throws BadLocationException
 */
protected int doComputePartitioningTest(String filename) throws IOException, BadLocationException {
    IModelManager modelManager = StructuredModelManager.getModelManager();
    InputStream inStream = getClass().getResourceAsStream(filename);
    if (inStream == null)
        inStream = new StringBufferInputStream("");
    IStructuredModel model = modelManager.getModelForEdit(filename, inStream, null);
    IStructuredDocument structuredDocument = model.getStructuredDocument();
    if (DEBUG_PRINT_RESULT && useFormatter) {
        double baseTen = Math.log(10);
        formatter.setMinimumIntegerDigits((int) (Math.log(structuredDocument.getLength()) / baseTen) + 1);
        formatter.setGroupingUsed(false);
    }
    partitions = structuredDocument.computePartitioning(0, structuredDocument.getLength());
    if (DEBUG_PRINT_RESULT) {
        String contents = null;
        System.out.println("\nfilename: " + filename);
        for (int i = 0; i < partitions.length; i++) {
            try {
                contents = structuredDocument.get(partitions[i].getOffset(), partitions[i].getLength());
            } catch (BadLocationException e) {
                contents = "*error*";
            }
            if (useFormatter)
                System.out.println(formatter.format(partitions[i].getOffset()) + ":" + formatter.format(partitions[i].getLength()) + " - " + partitions[i].getType() + " [" + StringUtils.escape(contents) + "]");
            else
                System.out.println(partitions[i] + " [" + StringUtils.escape(contents) + "]");
        }
    }
    checkSeams();
    model.releaseFromEdit();
    inStream.close();
    if (partitions == null)
        return -1;
    return partitions.length;
}
Also used : StringBufferInputStream(java.io.StringBufferInputStream) StringBufferInputStream(java.io.StringBufferInputStream) InputStream(java.io.InputStream) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 42 with IStructuredDocument

use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument in project webtools.sourceediting by eclipse.

the class TestStructuredPartitionerHTML method testGetPartitionType.

public void testGetPartitionType() {
    IStructuredModel model = null;
    try {
        model = getModelForEdit("testfiles/html/example01.xml");
        if (model != null) {
            IStructuredDocument sDoc = model.getStructuredDocument();
            assertTrue("sDoc implementation not instance of IDocumentExtension3", sDoc instanceof IDocumentExtension3);
            IDocumentPartitioner partitioner = ((IDocumentExtension3) sDoc).getDocumentPartitioner(IStructuredPartitioning.DEFAULT_STRUCTURED_PARTITIONING);
            assertTrue("paritioner doesn't implement IStructuredTextPartitioner", partitioner instanceof IStructuredTextPartitioner);
            IStructuredTextPartitioner stp = (IStructuredTextPartitioner) partitioner;
            String defaultPartitionType = stp.getDefaultPartitionType();
            assertTrue("wrong default partition type was: [" + defaultPartitionType + "] should be: [" + IXMLPartitions.XML_DEFAULT + "]", defaultPartitionType.equals(IXMLPartitions.XML_DEFAULT));
        } else {
            assertTrue("could not retrieve structured model", false);
        }
    } finally {
        if (model != null)
            model.releaseFromEdit();
    }
}
Also used : IDocumentExtension3(org.eclipse.jface.text.IDocumentExtension3) IDocumentPartitioner(org.eclipse.jface.text.IDocumentPartitioner) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IStructuredTextPartitioner(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredTextPartitioner)

Example 43 with IStructuredDocument

use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument in project webtools.sourceediting by eclipse.

the class TestStructuredPartitionerHTML method testDisconnectConnect.

public void testDisconnectConnect() {
    IStructuredModel model = null;
    try {
        model = getModelForEdit("testfiles/html/example01.xml");
        if (model != null) {
            IStructuredDocument sDoc = model.getStructuredDocument();
            assertTrue("sDoc implementation not instance of IDocumentExtension3", sDoc instanceof IDocumentExtension3);
            IDocumentPartitioner partitioner = ((IDocumentExtension3) sDoc).getDocumentPartitioner(IStructuredPartitioning.DEFAULT_STRUCTURED_PARTITIONING);
            assertTrue("partitioner doesn't implement IStructuredTextPartitioner", partitioner instanceof IStructuredTextPartitioner);
            IStructuredTextPartitioner stp = (IStructuredTextPartitioner) partitioner;
            assertNotNull("partitioner was null for sDoc:" + sDoc, partitioner);
            try {
                stp.disconnect();
            } catch (Exception e) {
                assertTrue("problem disconnecting w/:" + sDoc + "/n" + e, false);
            }
            try {
                stp.connect(sDoc);
            } catch (Exception e) {
                assertTrue("problem connecting w/:" + sDoc + "/n" + e, false);
            }
        } else {
            assertTrue("could not retrieve structured model", false);
        }
    } finally {
        if (model != null)
            model.releaseFromEdit();
    }
}
Also used : IDocumentExtension3(org.eclipse.jface.text.IDocumentExtension3) IDocumentPartitioner(org.eclipse.jface.text.IDocumentPartitioner) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IStructuredTextPartitioner(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredTextPartitioner) IOException(java.io.IOException) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 44 with IStructuredDocument

use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument in project webtools.sourceediting by eclipse.

the class StructuredDocumentToTextAdapter method getLineDelimiter.

/*
	 * @see org.eclipse.swt.custom.StyledTextContent#getLineDelimiter
	 */
public String getLineDelimiter() {
    String result = null;
    if (getParentDocument() instanceof IStructuredDocument) {
        result = ((IStructuredDocument) getParentDocument()).getLineDelimiter();
    } else {
        IDocument doc = getSafeDocument();
        result = TextUtilities.getDefaultLineDelimiter(doc);
    }
    return result;
}
Also used : IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IDocument(org.eclipse.jface.text.IDocument)

Example 45 with IStructuredDocument

use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument in project webtools.sourceediting by eclipse.

the class StructuredTextViewer method setDocument.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.jface.text.source.ISourceViewer#setDocument(org.eclipse.jface.text.IDocument,
	 *      org.eclipse.jface.text.source.IAnnotationModel, int, int)
	 */
public void setDocument(IDocument document, IAnnotationModel annotationModel, int modelRangeOffset, int modelRangeLength) {
    // that blocks display thread
    if (document == null) {
        if (fReconciler != null) {
            fReconciler.uninstall();
        }
    }
    super.setDocument(document, annotationModel, modelRangeOffset, modelRangeLength);
    if (document instanceof IStructuredDocument) {
        IStructuredDocument structuredDocument = (IStructuredDocument) document;
        // notify highlighter
        updateHighlighter(structuredDocument);
        // set the formatter again now that document has been set
        if (!fFormatterSet && fConfiguration != null) {
            fContentFormatter = fConfiguration.getContentFormatter(this);
            fFormatterSet = true;
        }
        // set document in the viewer-based undo manager
        if (fUndoManager != null) {
            fUndoManager.disconnect();
            fUndoManager.connect(this);
        }
    // CaretEvent is not sent to ViewerSelectionManager after Save As.
    // Need to notify ViewerSelectionManager here.
    // notifyViewerSelectionManager(getSelectedRange().x,
    // getSelectedRange().y);
    }
}
Also used : IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)

Aggregations

IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)432 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)96 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)79 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)68 CSSCleanupStrategy (org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy)44 Node (org.w3c.dom.Node)42 ICSSModel (org.eclipse.wst.css.core.internal.provisional.document.ICSSModel)41 Document (org.w3c.dom.Document)36 BadLocationException (org.eclipse.jface.text.BadLocationException)35 IndexedRegion (org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)34 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)34 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)33 Element (org.w3c.dom.Element)30 IDocument (org.eclipse.jface.text.IDocument)29 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)28 IModelManager (org.eclipse.wst.sse.core.internal.provisional.IModelManager)26 StructuredDocumentEvent (org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent)23 Test (org.junit.Test)22 INodeAdapter (org.eclipse.wst.sse.core.internal.provisional.INodeAdapter)20 RegionChangedEvent (org.eclipse.wst.sse.core.internal.provisional.events.RegionChangedEvent)20