Search in sources :

Example 26 with StructuredDocumentEvent

use of org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent in project webtools.sourceediting by eclipse.

the class RegionChangedAdapterNotificationTests method testPrependSpaceToAttributeValue.

public void testPrependSpaceToAttributeValue() throws IOException {
    IDOMModel model = (IDOMModel) StructuredModelManager.getModelManager().getModelForEdit(getName() + ".xml", new NullInputStream(), null);
    try {
        Document document = model.getDocument();
        IStructuredDocument structuredDocument = model.getStructuredDocument();
        structuredDocument.setText(this, "<a b= c></a>");
        Node before = document.getFirstChild();
        final int[] changed = new int[] { -1 };
        INodeAdapter adapter = new INodeAdapter() {

            public boolean isAdapterForType(Object type) {
                return type.equals(RegionChangedAdapterNotificationTests.class);
            }

            public void notifyChanged(INodeNotifier notifier, int eventType, Object changedFeature, Object oldValue, Object newValue, int pos) {
                changed[0] = eventType;
            }
        };
        ((INodeNotifier) before).addAdapter(adapter);
        Object[] originalRegions = structuredDocument.getFirstStructuredDocumentRegion().getRegions().toArray();
        StructuredDocumentEvent fmEvent = structuredDocument.replaceText(null, 6, 0, " ");
        assertTrue("Region instances changed", Arrays.equals(originalRegions, structuredDocument.getFirstStructuredDocumentRegion().getRegions().toArray()));
        assertTrue(fmEvent instanceof RegionChangedEvent);
        Node after = document.getFirstChild();
        assertEquals("Node replaced", before, after);
        assertEquals("unexpected adapter notification event sent " + structuredDocument.get(), -1, changed[0]);
        assertEquals("unexpected document content", "<a b=  c></a>", structuredDocument.get());
    } finally {
        model.releaseFromEdit();
    }
}
Also used : StructuredDocumentEvent(org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent) INodeAdapter(org.eclipse.wst.sse.core.internal.provisional.INodeAdapter) RegionChangedEvent(org.eclipse.wst.sse.core.internal.provisional.events.RegionChangedEvent) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) Node(org.w3c.dom.Node) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) Document(org.w3c.dom.Document) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) INodeNotifier(org.eclipse.wst.sse.core.internal.provisional.INodeNotifier) NullInputStream(org.eclipse.wst.sse.core.internal.encoding.util.NullInputStream)

Example 27 with StructuredDocumentEvent

use of org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent in project webtools.sourceediting by eclipse.

the class JSPReParser method reparse.

/**
 * The core reparsing method ... after the dirty start and dirty end have
 * been calculated elsewhere. - this method overrides, does not extend
 * super's method. changes/fixes to super may have to be made here as
 * well.
 */
protected StructuredDocumentEvent reparse(IStructuredDocumentRegion dirtyStart, IStructuredDocumentRegion dirtyEnd) {
    StructuredDocumentEvent result = null;
    int rescanStart = -1;
    int rescanEnd = -1;
    boolean firstTime = false;
    boolean detectedBreakingChange = false;
    // 
    // "save" the oldNodes (that may be replaced) in a list
    CoreNodeList oldNodes = formOldNodes(dirtyStart, dirtyEnd);
    if (containsBreakingChange(oldNodes) || isBreakingWithNestedTag(dirtyStart, dirtyEnd)) {
        if (Debug.debugTaglibs)
            // $NON-NLS-1$
            System.out.println("reparse: is taglib or include");
        detectedBreakingChange = true;
        rescanStart = 0;
        rescanEnd = fStructuredDocument.getLength() + fLengthDifference;
        oldNodes = formOldNodes(fStructuredDocument.getFirstStructuredDocumentRegion(), fStructuredDocument.getLastStructuredDocumentRegion());
        clearTaglibInfo();
    } else if (dirtyStart == null || dirtyEnd == null) {
        // dirtyStart or dirty end are null, then that means we didn't
        // have a
        // cached node, which means we have an empty document, so we
        // just need to rescan the changes
        rescanStart = 0;
        rescanEnd = fChanges.length();
        firstTime = true;
    } else {
        // set the start of the text to rescan
        rescanStart = dirtyStart.getStart();
        // 
        // set the end of the text to rescan
        // notice we use the same rationale as for the rescanStart,
        // with the added caveat that length has to be added to it,
        // to compensate for the new text which has been added or deleted.
        // If changes has zero length, then "length" will be negative,
        // since
        // we are deleting text. Otherwise, use the difference between
        // what's selected to be replaced and the length of the new text.
        rescanEnd = dirtyEnd.getEnd() + fLengthDifference;
    }
    // now that we have the old stuff "saved" away, update the document
    // with the changes.
    fStructuredDocument.updateDocumentData(fStart, fLengthToReplace, fChanges);
    // ------------------ now the real work
    result = core_reparse(rescanStart, rescanEnd, oldNodes, firstTime);
    // everthing, so no need to do again.
    if ((!detectedBreakingChange) && (containsBreakingChange(oldNodes))) {
        clearTaglibInfo();
        // reparse all
        oldNodes = formOldNodes(fStructuredDocument.getFirstStructuredDocumentRegion(), fStructuredDocument.getLastStructuredDocumentRegion());
        result = core_reparse(0, fStructuredDocument.getLength(), oldNodes, firstTime);
    }
    // some optimization they can do
    return result;
}
Also used : StructuredDocumentEvent(org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent) CoreNodeList(org.eclipse.wst.sse.core.internal.text.CoreNodeList)

Example 28 with StructuredDocumentEvent

use of org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent in project webtools.sourceediting by eclipse.

the class JSPReParser method checkForJSPEL.

private StructuredDocumentEvent checkForJSPEL() {
    StructuredDocumentEvent result = null;
    // $NON-NLS-1$
    result = checkForCriticalKey("${");
    if (result == null)
        // $NON-NLS-1$
        result = checkForCriticalKey("}");
    return result;
}
Also used : StructuredDocumentEvent(org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent)

Example 29 with StructuredDocumentEvent

use of org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent in project webtools.sourceediting by eclipse.

the class CSSStructuredDocumentReParser method checkInsideBrace.

private StructuredDocumentEvent checkInsideBrace(int start, int end) {
    StructuredDocumentEvent result = null;
    IStructuredDocumentRegion region = fStructuredDocument.getRegionAtCharacterOffset(start);
    if (region == null) {
        return null;
    }
    boolean bDeclaration = false;
    String type = region.getType();
    if (CSSRegionUtil.isDeclarationType(type) || type == CSSRegionContexts.CSS_LBRACE || type == CSSRegionContexts.CSS_RBRACE) {
        bDeclaration = true;
    }
    if (!bDeclaration) {
        IStructuredDocumentRegion prevRegion = CSSUtil.findPreviousSignificantNode(region);
        if (prevRegion != null) {
            type = prevRegion.getType();
            if (CSSRegionUtil.isDeclarationType(type) || type == CSSRegionContexts.CSS_LBRACE) {
                bDeclaration = true;
            }
        }
    }
    if (!bDeclaration) {
        IStructuredDocumentRegion nextRegion = CSSUtil.findNextSignificantNode(region);
        if (nextRegion != null) {
            type = nextRegion.getType();
            if (CSSRegionUtil.isDeclarationType(type) || type == CSSRegionContexts.CSS_RBRACE) {
                bDeclaration = true;
            }
        }
    }
    if (bDeclaration) {
        IStructuredDocumentRegion startRegion = findRuleStart(region);
        if (startRegion != null) {
            IStructuredDocumentRegion endRegion = fStructuredDocument.getRegionAtCharacterOffset(end);
            if (endRegion != null) {
                result = reparse(startRegion, endRegion);
            }
        }
    }
    return result;
}
Also used : StructuredDocumentEvent(org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent) IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)

Example 30 with StructuredDocumentEvent

use of org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent in project webtools.sourceediting by eclipse.

the class UpdaterTestRegionChanged method testModel.

public void testModel() {
    IDOMModel model = createXMLModel();
    try {
        Document document = model.getDocument();
        IStructuredDocument structuredDocument = model.getStructuredDocument();
        structuredDocument.setText(this, "<a b= c></a>");
        Node before = document.getFirstChild();
        StructuredDocumentEvent fmEvent = structuredDocument.replaceText(null, 5, 1, "");
        if (fmEvent instanceof RegionChangedEvent) {
            fOutputWriter.writeln("ok: RegionChangedEvent");
        } else {
            fOutputWriter.writeln("not ok: " + fmEvent.getClass().getName());
        }
        Node after = document.getFirstChild();
        if (before != after) {
            fOutputWriter.writeln("not ok: Node replaced");
        } else {
            fOutputWriter.writeln("ok: Node not replaced");
        }
        saveAndCompareTestResults();
    } finally {
        model.releaseFromEdit();
    }
}
Also used : StructuredDocumentEvent(org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent) RegionChangedEvent(org.eclipse.wst.sse.core.internal.provisional.events.RegionChangedEvent) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) Node(org.w3c.dom.Node) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) Document(org.w3c.dom.Document) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)

Aggregations

StructuredDocumentEvent (org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent)59 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)23 RegionChangedEvent (org.eclipse.wst.sse.core.internal.provisional.events.RegionChangedEvent)22 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)20 Document (org.w3c.dom.Document)20 Node (org.w3c.dom.Node)20 NullInputStream (org.eclipse.wst.sse.core.internal.encoding.util.NullInputStream)18 INodeAdapter (org.eclipse.wst.sse.core.internal.provisional.INodeAdapter)18 INodeNotifier (org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)18 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)8 NoChangeEvent (org.eclipse.wst.sse.core.internal.provisional.events.NoChangeEvent)6 IExecutionDelegate (org.eclipse.wst.sse.core.internal.IExecutionDelegate)3 StructuredDocumentRegionsReplacedEvent (org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentRegionsReplacedEvent)3 RegionsReplacedEvent (org.eclipse.wst.sse.core.internal.provisional.events.RegionsReplacedEvent)2 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)2 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)2 List (java.util.List)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1 DocumentEvent (org.eclipse.jface.text.DocumentEvent)1 IRegion (org.eclipse.jface.text.IRegion)1