use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument in project webtools.sourceediting by eclipse.
the class JSPDocumentLoader method createNewStructuredDocument.
public IEncodedDocument createNewStructuredDocument(String filename, InputStream inputStream) throws UnsupportedEncodingException, IOException {
if (filename == null && inputStream == null) {
// $NON-NLS-1$
throw new IllegalArgumentException("can not have both null filename and inputstream");
}
IEncodedDocument structuredDocument = createNewStructuredDocument();
CodedReaderCreator codedReaderCreator = new CodedReaderCreator();
try {
codedReaderCreator.set(filename, inputStream);
fFullPreparedReader = codedReaderCreator.getCodedReader();
fEncodingMemento = codedReaderCreator.getEncodingMemento();
structuredDocument.setEncodingMemento(fEncodingMemento);
// the fact that file is null means this method/code path is no
// good for JSP fragments
EmbeddedTypeHandler embeddedType = getEmbeddedType((IFile) null);
fFullPreparedReader.reset();
if (embeddedType != null)
embeddedType.initializeParser(((IStructuredDocument) structuredDocument).getParser());
setDocumentContentsFromReader(structuredDocument, fFullPreparedReader);
} catch (CoreException e) {
// impossible in this context
throw new Error(e);
} finally {
if (fFullPreparedReader != null) {
fFullPreparedReader.close();
}
}
return structuredDocument;
}
use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument in project webtools.sourceediting by eclipse.
the class JSPDocumentLoader method createCodedDocument.
private IStructuredDocument createCodedDocument(IFile iFile) throws CoreException, UnsupportedEncodingException, IOException {
IStructuredDocument structuredDocument = (IStructuredDocument) createNewStructuredDocument();
getCodedReaderCreator().set(iFile);
fFullPreparedReader = getCodedReaderCreator().getCodedReader();
fEncodingMemento = getCodedReaderCreator().getEncodingMemento();
structuredDocument.setEncodingMemento(getCodedReaderCreator().getEncodingMemento());
return structuredDocument;
}
use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument in project webtools.sourceediting by eclipse.
the class JSPDocumentLoader method newEncodedDocument.
/**
* This method must return a new instance of IStructuredDocument, that has
* been initialized with appropriate parser. For many loaders, the
* (default) parser used is known for any input. For others, the correct
* parser (and its initialization) is normall dependent on the content of
* the file. This no-argument method should assume "empty input" and would
* therefore return the default parser for the default contentType. If the
* parser is to handle tag libraries, it must have a TaglibSupport object
* with a valid URIResolver and this IStructuredDocument attached to it
* before the contents are set on the IStructuredDocument.
*/
protected IEncodedDocument newEncodedDocument() {
IStructuredDocument structuredDocument = StructuredDocumentFactory.getNewStructuredDocumentInstance(getParser());
((BasicStructuredDocument) structuredDocument).setReParser(new JSPReParser());
// structuredDocument.setDocumentPartitioner(new
// JSPJavaDocumentPartioner());
// even though this is an "empty model" ... we want it to have at
// least
// the
// default embeddeded content type handler
EmbeddedTypeHandler embeddedType = getJSPDefaultEmbeddedType();
embeddedType.initializeParser(structuredDocument.getParser());
return structuredDocument;
}
use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument in project webtools.sourceediting by eclipse.
the class JSONObjectDocumentChangesTest method insertCloseObject.
@Test
public void insertCloseObject() {
IJSONModel model = TestUtil.loadModel("{");
IJSONDocument document = model.getDocument();
// Document contains an Object which is not closed
Assert.assertNotNull(document.getFirstChild());
Assert.assertTrue(document.getFirstChild() instanceof IJSONObject);
IJSONObject object = (IJSONObject) document.getFirstChild();
Assert.assertFalse(object.isClosed());
IStructuredDocument structuredDocument = model.getStructuredDocument();
// insert at end '}'
structuredDocument.replaceText(structuredDocument, 1, 0, "}");
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 JSONObjectDocumentChangesTest method removeObject.
@Test
public void removeObject() {
IJSONModel model = TestUtil.loadModel("{}");
IJSONDocument document = model.getDocument();
// Document contains an Object which is not closed
Assert.assertNotNull(document.getFirstChild());
Assert.assertTrue(document.getFirstChild() instanceof IJSONObject);
IJSONObject object = (IJSONObject) document.getFirstChild();
Assert.assertTrue(object.isClosed());
IStructuredDocument structuredDocument = model.getStructuredDocument();
// remove {}
structuredDocument.replaceText(structuredDocument, 0, 2, "");
Assert.assertNull(document.getFirstChild());
}
Aggregations