Search in sources :

Example 56 with IStructuredDocument

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

the class JSONObjectCreationTest method createComplexObject.

@Test
public void createComplexObject() throws Exception {
    IJSONModel model = (IJSONModel) TestUtil.createModel();
    IStructuredDocument structuredDocument = model.getStructuredDocument();
    IJSONDocument document = model.getDocument();
    assertNull(document.getFirstChild());
    structuredDocument.set("{\n\t\"aaaaa\": {},\n\t\"array\": [\n\t\t1,\n\t\t2,\n\t\t3],\n\t\"boolean\": true,\n\t\"null\": null,\n\t\"number\": 123,\n\t\"object\": {\n\t\t\"a\": \"b\",\n\t\t\"c\": \"d\"\n\t},\n\t\"string\": \"Hello World\"\n}");
    assertNotNull(document.getFirstChild());
    Assert.assertTrue(document.getFirstChild() instanceof IJSONObject);
}
Also used : IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) Test(org.junit.Test)

Example 57 with IStructuredDocument

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

the class JSONObjectCreationTest method createEmptyObject.

@Test
public void createEmptyObject() throws Exception {
    IJSONModel model = (IJSONModel) TestUtil.createModel();
    IStructuredDocument structuredDocument = model.getStructuredDocument();
    IJSONDocument document = model.getDocument();
    assertNull(document.getFirstChild());
    // Load JSON Object
    structuredDocument.set("{}");
    assertNotNull(document.getFirstChild());
    Assert.assertTrue(document.getFirstChild() instanceof IJSONObject);
    // The JSON object is closed.
    IJSONObject object = (IJSONObject) document.getFirstChild();
    Assert.assertTrue(object.isClosed());
}
Also used : IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) Test(org.junit.Test)

Example 58 with IStructuredDocument

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

the class JSONSampleDocumentTest method loadSample.

@Test
public void loadSample() throws Exception {
    IJSONModel model = (IJSONModel) TestUtil.createModel();
    IStructuredDocument structuredDocument = model.getStructuredDocument();
    IJSONDocument document = model.getDocument();
    assertNull(document.getFirstChild());
    String actual = TestUtil.toString(JSONSampleDocumentTest.class.getResourceAsStream("sample.json"));
    structuredDocument.set(actual);
    assertNotNull(document.getFirstChild());
    Assert.assertTrue(document.getFirstChild() instanceof IJSONObject);
    String s = TestUtil.toString(document);
    System.err.println(actual);
    System.err.println(s);
}
Also used : IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) Test(org.junit.Test)

Example 59 with IStructuredDocument

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

the class JSONHoverProcessor method getHoverRegion.

@Override
public IRegion getHoverRegion(ITextViewer textViewer, int offset) {
    if ((textViewer == null) || (textViewer.getDocument() == null)) {
        return null;
    }
    IStructuredDocumentRegion flatNode = ((IStructuredDocument) textViewer.getDocument()).getRegionAtCharacterOffset(offset);
    ITextRegion region = null;
    if (flatNode != null) {
        region = flatNode.getRegionAtCharacterOffset(offset);
    }
    if (region != null) {
        // only supply hoverhelp for object key, or simple JSON value
        String regionType = region.getType();
        if ((regionType == JSONRegionContexts.JSON_OBJECT_KEY) || JSONUtil.isJSONSimpleValue(regionType)) {
            try {
                // check if we are at whitespace before or after line
                IRegion line = textViewer.getDocument().getLineInformationOfOffset(offset);
                if ((offset > (line.getOffset())) && (offset < (line.getOffset() + line.getLength()))) {
                    // (whitespace after relevant info)
                    if (offset < flatNode.getTextEndOffset(region)) {
                        return new Region(flatNode.getStartOffset(region), region.getTextLength());
                    }
                }
            } catch (BadLocationException e) {
                Logger.logException(e);
            }
        }
    }
    return null;
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) Region(org.eclipse.jface.text.Region) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) IRegion(org.eclipse.jface.text.IRegion) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IRegion(org.eclipse.jface.text.IRegion) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 60 with IStructuredDocument

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

the class JSPDocumentLoader method createNewStructuredDocument.

public synchronized IEncodedDocument createNewStructuredDocument(IFile iFile) throws IOException, CoreException {
    IStructuredDocument structuredDocument = null;
    try {
        structuredDocument = createCodedDocument(iFile);
        EmbeddedTypeHandler embeddedType = getEmbeddedType(iFile);
        if (embeddedType != null)
            embeddedType.initializeParser(structuredDocument.getParser());
        fFullPreparedReader.reset();
        setDocumentContentsFromReader(structuredDocument, fFullPreparedReader);
    } finally {
        if (fFullPreparedReader != null) {
            fFullPreparedReader.close();
        }
    }
    return structuredDocument;
}
Also used : EmbeddedTypeHandler(org.eclipse.wst.sse.core.internal.ltk.modelhandler.EmbeddedTypeHandler) 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