use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument in project webtools.sourceediting by eclipse.
the class TestStructuredPartitionerHTML method doComputePartitioningTest.
/**
* Compute the partitions for the given filename using the default partitioner
* for that file type.
*
* @param filename
* @return int
* @throws IOException
* @throws BadLocationException
*/
protected int doComputePartitioningTest(String filename) throws IOException, BadLocationException {
IModelManager modelManager = StructuredModelManager.getModelManager();
InputStream inStream = getClass().getResourceAsStream(filename);
if (inStream == null)
inStream = new StringBufferInputStream("");
IStructuredModel model = modelManager.getModelForEdit(filename, inStream, null);
IStructuredDocument structuredDocument = model.getStructuredDocument();
if (DEBUG_PRINT_RESULT && useFormatter) {
double baseTen = Math.log(10);
formatter.setMinimumIntegerDigits((int) (Math.log(structuredDocument.getLength()) / baseTen) + 1);
formatter.setGroupingUsed(false);
}
partitions = structuredDocument.computePartitioning(0, structuredDocument.getLength());
if (DEBUG_PRINT_RESULT) {
String contents = null;
System.out.println("\nfilename: " + filename);
for (int i = 0; i < partitions.length; i++) {
try {
contents = structuredDocument.get(partitions[i].getOffset(), partitions[i].getLength());
} catch (BadLocationException e) {
contents = "*error*";
}
if (useFormatter)
System.out.println(formatter.format(partitions[i].getOffset()) + ":" + formatter.format(partitions[i].getLength()) + " - " + partitions[i].getType() + " [" + StringUtils.escape(contents) + "]");
else
System.out.println(partitions[i] + " [" + StringUtils.escape(contents) + "]");
}
}
checkSeams();
model.releaseFromEdit();
inStream.close();
if (partitions == null)
return -1;
return partitions.length;
}
use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument in project webtools.sourceediting by eclipse.
the class TestStructuredPartitionerHTML method testGetPartitionType.
public void testGetPartitionType() {
IStructuredModel model = null;
try {
model = getModelForEdit("testfiles/html/example01.xml");
if (model != null) {
IStructuredDocument sDoc = model.getStructuredDocument();
assertTrue("sDoc implementation not instance of IDocumentExtension3", sDoc instanceof IDocumentExtension3);
IDocumentPartitioner partitioner = ((IDocumentExtension3) sDoc).getDocumentPartitioner(IStructuredPartitioning.DEFAULT_STRUCTURED_PARTITIONING);
assertTrue("paritioner doesn't implement IStructuredTextPartitioner", partitioner instanceof IStructuredTextPartitioner);
IStructuredTextPartitioner stp = (IStructuredTextPartitioner) partitioner;
String defaultPartitionType = stp.getDefaultPartitionType();
assertTrue("wrong default partition type was: [" + defaultPartitionType + "] should be: [" + IXMLPartitions.XML_DEFAULT + "]", defaultPartitionType.equals(IXMLPartitions.XML_DEFAULT));
} else {
assertTrue("could not retrieve structured model", false);
}
} finally {
if (model != null)
model.releaseFromEdit();
}
}
use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument in project webtools.sourceediting by eclipse.
the class TestStructuredPartitionerHTML method testDisconnectConnect.
public void testDisconnectConnect() {
IStructuredModel model = null;
try {
model = getModelForEdit("testfiles/html/example01.xml");
if (model != null) {
IStructuredDocument sDoc = model.getStructuredDocument();
assertTrue("sDoc implementation not instance of IDocumentExtension3", sDoc instanceof IDocumentExtension3);
IDocumentPartitioner partitioner = ((IDocumentExtension3) sDoc).getDocumentPartitioner(IStructuredPartitioning.DEFAULT_STRUCTURED_PARTITIONING);
assertTrue("partitioner doesn't implement IStructuredTextPartitioner", partitioner instanceof IStructuredTextPartitioner);
IStructuredTextPartitioner stp = (IStructuredTextPartitioner) partitioner;
assertNotNull("partitioner was null for sDoc:" + sDoc, partitioner);
try {
stp.disconnect();
} catch (Exception e) {
assertTrue("problem disconnecting w/:" + sDoc + "/n" + e, false);
}
try {
stp.connect(sDoc);
} catch (Exception e) {
assertTrue("problem connecting w/:" + sDoc + "/n" + e, false);
}
} else {
assertTrue("could not retrieve structured model", false);
}
} finally {
if (model != null)
model.releaseFromEdit();
}
}
use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument in project webtools.sourceediting by eclipse.
the class StructuredDocumentToTextAdapter method getLineDelimiter.
/*
* @see org.eclipse.swt.custom.StyledTextContent#getLineDelimiter
*/
public String getLineDelimiter() {
String result = null;
if (getParentDocument() instanceof IStructuredDocument) {
result = ((IStructuredDocument) getParentDocument()).getLineDelimiter();
} else {
IDocument doc = getSafeDocument();
result = TextUtilities.getDefaultLineDelimiter(doc);
}
return result;
}
use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument in project webtools.sourceediting by eclipse.
the class StructuredTextViewer method setDocument.
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.text.source.ISourceViewer#setDocument(org.eclipse.jface.text.IDocument,
* org.eclipse.jface.text.source.IAnnotationModel, int, int)
*/
public void setDocument(IDocument document, IAnnotationModel annotationModel, int modelRangeOffset, int modelRangeLength) {
// that blocks display thread
if (document == null) {
if (fReconciler != null) {
fReconciler.uninstall();
}
}
super.setDocument(document, annotationModel, modelRangeOffset, modelRangeLength);
if (document instanceof IStructuredDocument) {
IStructuredDocument structuredDocument = (IStructuredDocument) document;
// notify highlighter
updateHighlighter(structuredDocument);
// set the formatter again now that document has been set
if (!fFormatterSet && fConfiguration != null) {
fContentFormatter = fConfiguration.getContentFormatter(this);
fFormatterSet = true;
}
// set document in the viewer-based undo manager
if (fUndoManager != null) {
fUndoManager.disconnect();
fUndoManager.connect(this);
}
// CaretEvent is not sent to ViewerSelectionManager after Save As.
// Need to notify ViewerSelectionManager here.
// notifyViewerSelectionManager(getSelectedRange().x,
// getSelectedRange().y);
}
}
Aggregations