Search in sources :

Example 66 with IStructuredDocument

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

the class CSSHyperlinkDetector method getNode.

private ICSSNode getNode(IDocument document, IRegion region) {
    if (!(document instanceof IStructuredDocument))
        return null;
    IStructuredModel model = null;
    ICSSNode node = null;
    try {
        model = StructuredModelManager.getModelManager().getModelForRead((IStructuredDocument) document);
        node = (ICSSNode) model.getIndexedRegion(region.getOffset());
    } finally {
        if (model != null) {
            model.releaseFromRead();
        }
    }
    return node;
}
Also used : IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode)

Example 67 with IStructuredDocument

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

the class ScannerUnitTests method testBlockScanBufferBoundaries.

protected void testBlockScanBufferBoundaries(String contentTypeID) {
    IStructuredDocument document = null;
    // for (int i = 17000; i > 15000; i--) {
    for (int i = 16384 + 25; i > 16364 - 25; i--) {
        StringBuffer text = new StringBuffer();
        document = StructuredModelManager.getModelManager().createStructuredDocumentFor(contentTypeID);
        appendTagBlock(text, "script", i);
        String string = text.toString();
        try {
            document.setText(this, string);
            verifyLengths(document, string);
            assertTrue("too few document regions [run value " + i + "] ", new CoreNodeList(document.getFirstStructuredDocumentRegion()).getLength() == 3);
            verifyLengths(document, string);
            IStructuredDocumentRegion startTag = document.getFirstStructuredDocumentRegion();
            IStructuredDocumentRegion middleBlock = startTag.getNext();
            // IStructuredDocumentRegion endTag = middleBlock.getNext();
            assertTrue("not block text in middle", middleBlock.getFirstRegion().getType() == DOMRegionContext.BLOCK_TEXT);
        } catch (Exception e) {
            assertNull("exception caught" + e, e);
        }
    // System.gc();
    }
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) CoreNodeList(org.eclipse.wst.sse.core.internal.text.CoreNodeList) IOException(java.io.IOException)

Example 68 with IStructuredDocument

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

the class StructuredDocumentToDOMUnitTests method testNodeDeletion.

/**
 * Unit test -- tests basic parsing results of inserting a test string
 * into an initial string.
 */
void testNodeDeletion() {
    // String initialString =
    // "<par><x>\ntextx\n</x>\n<y>\ntexty\n</y></par>";
    // String initialString = "<par><x>textx</x><y>texty</y></par>";
    // test cases for two text nodes left together (remove <b/>):
    // first case works, second doesn't
    // String initialString = "<a>a<b /></a>"; // -> <a>a</a>
    // String initialString = "<a>a<b />b</a>"; // -> <a>ab</a>
    // String initialString = getTestString1();
    String initialString = getTestString2();
    // print out what we always can
    System.out.println();
    System.out.println("----------------");
    System.out.println("Test Node Deletion");
    String outString = StringUtils.escape(initialString);
    System.out.println("Initial String: " + outString);
    // always start with fresh model
    IStructuredDocument f = null;
    IModelManager mm = StructuredModelManager.getModelManager();
    try {
        f = mm.createStructuredDocumentFor("dummy.xml", (InputStream) null, null);
    } catch (IOException e) {
    // do nothing, since dummy
    }
    // 
    // we'll listen to structuredDocument events to print out diagnostics
    f.addDocumentChangedListener(this);
    // 
    IDOMModel tree = new DOMModelImpl();
    f.addDocumentChangingListener((IStructuredDocumentListener) tree);
    // set text to structuredDocument (which updates tree)
    f.setText(null, initialString);
    // dump initial structuredDocument
    Debug.dump(f);
    // dump initial dom
    DebugDocument.dump(tree.getDocument());
    // 
    // 
    // makeChange1(tree);
    makeChange2(f);
    // display resulting text
    System.out.println("resultString (from structuredDocument): ");
    System.out.println(StringUtils.escape(f.getText()));
    // 
    // 
    // dump post change structuredDocument
    Debug.dump(f);
    // dump post change DOM
    DebugDocument.dump(tree.getDocument());
// 
}
Also used : InputStream(java.io.InputStream) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) DOMModelImpl(org.eclipse.wst.xml.core.internal.document.DOMModelImpl) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IOException(java.io.IOException)

Example 69 with IStructuredDocument

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

the class TestModelsFromFiles method doTestNotEmptyDocument.

/**
 * @param string
 * @param class1
 * @param class2
 * @throws CoreException
 * @throws IOException
 * @throws ResourceInUse
 * @throws ResourceAlreadyExists
 */
private void doTestNotEmptyDocument(String filePath, Class expectedDocumentClass, Class expectedPartioner) throws ResourceAlreadyExists, ResourceInUse, IOException, CoreException {
    String contents = null;
    IModelManager modelManager = StructuredModelManager.getModelManager();
    IFile file = (IFile) fTestProject.findMember(filePath);
    if (file == null) {
        file = fTestProject.getFile(filePath);
    }
    IStructuredDocument document = modelManager.createStructuredDocumentFor(file);
    assertNotNull(document);
    assertTrue("wrong class of document", expectedDocumentClass.isInstance(document));
    IDocumentPartitioner setupPartitioner = null;
    if (Utilities.contains(expectedDocumentClass.getInterfaces(), IDocumentExtension3.class)) {
        setupPartitioner = ((IDocumentExtension3) document).getDocumentPartitioner(IStructuredPartitioning.DEFAULT_STRUCTURED_PARTITIONING);
    } else {
        setupPartitioner = document.getDocumentPartitioner();
    }
    assertTrue("wrong partitioner in document.", expectedPartioner.isInstance(setupPartitioner));
    contents = document.get();
    assertNotNull("contents were null", contents);
    assertTrue("contents were empty", contents.length() > 0);
}
Also used : IFile(org.eclipse.core.resources.IFile) IDocumentPartitioner(org.eclipse.jface.text.IDocumentPartitioner) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)

Example 70 with IStructuredDocument

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

the class TestModelsFromFiles method doTestCreate.

/**
 * @param string
 * @param class1
 * @param class2
 * @throws CoreException
 * @throws IOException
 * @throws ResourceInUse
 * @throws ResourceAlreadyExists
 */
private String doTestCreate(String filePath, Class expectedDocumentClass, Class expectedPartioner) throws ResourceAlreadyExists, ResourceInUse, IOException, CoreException {
    String contents = null;
    IModelManager modelManager = StructuredModelManager.getModelManager();
    IFile file = (IFile) fTestProject.findMember(filePath);
    // file will be null if the resource does not exist
    if (file == null) {
        file = fTestProject.getFile(filePath);
    }
    IStructuredModel model = modelManager.getNewModelForEdit(file, true);
    try {
        assertNotNull(model);
        IStructuredDocument document = model.getStructuredDocument();
        assertNotNull(document);
        contents = document.get();
        assertTrue("wrong class of document", expectedDocumentClass.isInstance(document));
        IDocumentPartitioner setupPartitioner = null;
        if (Utilities.contains(expectedDocumentClass.getInterfaces(), IDocumentExtension3.class)) {
            setupPartitioner = ((IDocumentExtension3) document).getDocumentPartitioner(IStructuredPartitioning.DEFAULT_STRUCTURED_PARTITIONING);
        } else {
            setupPartitioner = document.getDocumentPartitioner();
        }
        assertTrue("wrong partitioner in document.", expectedPartioner.isInstance(setupPartitioner));
        testClone(model);
    } finally {
        if (model != null)
            model.releaseFromEdit();
    }
    return contents;
}
Also used : IFile(org.eclipse.core.resources.IFile) IDocumentPartitioner(org.eclipse.jface.text.IDocumentPartitioner) 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)

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