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);
}
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());
}
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);
}
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;
}
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;
}
Aggregations