Search in sources :

Example 1 with BasicStructuredDocument

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;
}
Also used : StructuredDocumentEvent(org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent) BasicStructuredDocument(org.eclipse.wst.sse.core.internal.text.BasicStructuredDocument)

Example 2 with BasicStructuredDocument

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;
}
Also used : BasicStructuredDocument(org.eclipse.wst.sse.core.internal.text.BasicStructuredDocument) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) XMLStructuredDocumentReParser(org.eclipse.wst.xml.core.internal.parser.XMLStructuredDocumentReParser)

Example 3 with BasicStructuredDocument

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());
}
Also used : BasicStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.text.BasicStructuredDocumentRegion) BasicStructuredDocument(org.eclipse.wst.sse.core.internal.text.BasicStructuredDocument)

Example 4 with BasicStructuredDocument

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;
}
Also used : EmbeddedTypeHandler(org.eclipse.wst.sse.core.internal.ltk.modelhandler.EmbeddedTypeHandler) BasicStructuredDocument(org.eclipse.wst.sse.core.internal.text.BasicStructuredDocument) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) JSPReParser(org.eclipse.jst.jsp.core.internal.parser.JSPReParser)

Example 5 with BasicStructuredDocument

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);
}
Also used : TLDCMDocumentManager(org.eclipse.jst.jsp.core.internal.contentmodel.tld.TLDCMDocumentManager) BasicStructuredDocument(org.eclipse.wst.sse.core.internal.text.BasicStructuredDocument)

Aggregations

BasicStructuredDocument (org.eclipse.wst.sse.core.internal.text.BasicStructuredDocument)14 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)5 IModelHandler (org.eclipse.wst.sse.core.internal.ltk.modelhandler.IModelHandler)3 BadLocationException (org.eclipse.jface.text.BadLocationException)2 IDocumentExtension3 (org.eclipse.jface.text.IDocumentExtension3)2 JSPReParser (org.eclipse.jst.jsp.core.internal.parser.JSPReParser)2 EmbeddedTypeHandler (org.eclipse.wst.sse.core.internal.ltk.modelhandler.EmbeddedTypeHandler)2 BasicStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.text.BasicStructuredDocumentRegion)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ITextFileBuffer (org.eclipse.core.filebuffers.ITextFileBuffer)1 ITextFileBufferManager (org.eclipse.core.filebuffers.ITextFileBufferManager)1 IFile (org.eclipse.core.resources.IFile)1 IPath (org.eclipse.core.runtime.IPath)1 IDocument (org.eclipse.jface.text.IDocument)1 TLDCMDocumentManager (org.eclipse.jst.jsp.core.internal.contentmodel.tld.TLDCMDocumentManager)1 CSSStructuredDocumentReParser (org.eclipse.wst.css.core.internal.text.CSSStructuredDocumentReParser)1 DTDStructuredDocumentReParser (org.eclipse.wst.dtd.core.internal.text.DTDStructuredDocumentReParser)1 BlockMarker (org.eclipse.wst.sse.core.internal.ltk.parser.BlockMarker)1 BlockTagParser (org.eclipse.wst.sse.core.internal.ltk.parser.BlockTagParser)1