use of org.eclipse.wst.sse.core.internal.text.BasicStructuredDocument in project webtools.sourceediting by eclipse.
the class CSSModelUpdater method insertText.
/**
*/
private StructuredDocumentEvent insertText(int start, int oldLength, String text) {
StructuredDocumentEvent result = null;
BasicStructuredDocument structuredDocument = (BasicStructuredDocument) fModel.getStructuredDocument();
if (structuredDocument != null) {
if (text != null && 0 < oldLength && start + oldLength <= structuredDocument.getLength()) {
// minimize text change
String delText = structuredDocument.get(start, oldLength);
int newLength = text.length();
int shorterLen = Math.min(oldLength, newLength);
int stMatchLen;
for (stMatchLen = 0; stMatchLen < shorterLen && text.charAt(stMatchLen) == delText.charAt(stMatchLen); stMatchLen++) {
//
}
if (0 < stMatchLen && stMatchLen < shorterLen && text.charAt(stMatchLen - 1) == 0x000d && (text.charAt(stMatchLen) == 0x000a || delText.charAt(stMatchLen) == 0x000a)) {
// must not divide 0d->0a sequence
stMatchLen--;
}
if (stMatchLen == shorterLen) {
if (oldLength < newLength) {
// just insert
oldLength = 0;
start += stMatchLen;
text = text.substring(stMatchLen);
} else if (newLength < oldLength) {
// just remove
oldLength -= stMatchLen;
start += stMatchLen;
text = null;
} else {
// nothing to do
oldLength = 0;
text = null;
}
} else {
int edMatchLen;
for (edMatchLen = 0; stMatchLen + edMatchLen < shorterLen && text.charAt(newLength - edMatchLen - 1) == delText.charAt(oldLength - edMatchLen - 1); edMatchLen++) {
//
}
if (0 < edMatchLen && text.charAt(newLength - edMatchLen) == 0x000a && ((edMatchLen < newLength && text.charAt(newLength - edMatchLen - 1) == 0x000d) || (edMatchLen < oldLength && delText.charAt(oldLength - edMatchLen - 1) == 0x000d))) {
// must not divide 0d->0a sequence
edMatchLen--;
}
oldLength -= stMatchLen + edMatchLen;
start += stMatchLen;
if (stMatchLen + edMatchLen < newLength) {
text = text.substring(stMatchLen, newLength - edMatchLen);
} else {
text = null;
}
}
}
if (0 < oldLength || text != null) {
// String delText = structuredDocument.get(start, oldLength);
result = structuredDocument.replaceText(fModel, start, oldLength, text);
}
}
return result;
}
use of org.eclipse.wst.sse.core.internal.text.BasicStructuredDocument in project webtools.sourceediting by eclipse.
the class HTMLDocumentLoader method newEncodedDocument.
/*
* @see AbstractLoader#createNewStructuredDocument()
*/
protected IEncodedDocument newEncodedDocument() {
IStructuredDocument structuredDocument = StructuredDocumentFactory.getNewStructuredDocumentInstance(getParser());
((BasicStructuredDocument) structuredDocument).setReParser(new XMLStructuredDocumentReParser());
return structuredDocument;
}
use of org.eclipse.wst.sse.core.internal.text.BasicStructuredDocument in project webtools.sourceediting by eclipse.
the class TestObjects method testDeletedFlag.
public void testDeletedFlag() {
BasicStructuredDocumentRegion region = new BasicStructuredDocumentRegion();
region.setParentDocument(new BasicStructuredDocument());
boolean deleted = region.isDeleted();
boolean ended = region.isEnded();
region.setDeleted(!deleted);
assertEquals(!deleted, region.isDeleted());
assertEquals(ended, region.isEnded());
}
use of org.eclipse.wst.sse.core.internal.text.BasicStructuredDocument 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.text.BasicStructuredDocument in project webtools.sourceediting by eclipse.
the class TaglibController method setup.
/*
* (non-Javadoc)
*
* @see org.eclipse.core.filebuffers.IDocumentSetupParticipantExtension#setup(org.eclipse.jface.text.IDocument,
* org.eclipse.core.runtime.IPath,
* org.eclipse.core.filebuffers.LocationKind)
*/
public void setup(IDocument document, IPath location, LocationKind locationKind) {
// if we've already shutdown, just ignore
if (isShutdown())
return;
// reference the shared instance's documents directly
synchronized (_instance.fJSPdocuments) {
_instance.fJSPdocuments.add(document);
}
DocumentInfo info = new DocumentInfo();
info.document = (IStructuredDocument) document;
// will be supplied later
info.textFileBuffer = null;
info.location = location;
info.locationKind = locationKind;
info.tldDocumentManager = new TLDCMDocumentManager();
synchronized (_instance.fDocumentMap) {
_instance.fDocumentMap.put(document, info);
}
info.tldDocumentManager.setSourceParser((XMLSourceParser) info.document.getParser());
if (document instanceof BasicStructuredDocument && document.getLength() > 0) {
((BasicStructuredDocument) document).reparse(this);
}
TaglibIndex.addTaglibIndexListener(info);
}
Aggregations