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