Search in sources :

Example 16 with StructuredDocumentEvent

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

the class JSPReParser method checkForJSP.

/**
 * A change to a JSP tag can result in all being reparsed.
 */
private StructuredDocumentEvent checkForJSP() {
    StructuredDocumentEvent result = null;
    // $NON-NLS-1$
    result = checkForCriticalKey("<%");
    if (result == null)
        // $NON-NLS-1$
        result = checkForCriticalKey("<%=");
    if (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 17 with StructuredDocumentEvent

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

the class AbstractNodeCleanupHandler method replaceSource.

protected static StructuredDocumentEvent replaceSource(IDOMModel model, Object requester, int offset, int length, String source) {
    StructuredDocumentEvent result = null;
    if (model == null)
        return result;
    IStructuredDocument structuredDocument = model.getStructuredDocument();
    if (structuredDocument == null)
        return result;
    if (source == null)
        source = new String();
    if (structuredDocument.containsReadOnly(offset, length))
        return result;
    if (requester == null) {
        requester = structuredDocument;
    }
    return structuredDocument.replaceText(requester, offset, length, source);
}
Also used : StructuredDocumentEvent(org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)

Example 18 with StructuredDocumentEvent

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

the class JSONStructuredDocumentReParser 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 (JSONRegionUtil.isDeclarationType(type) || type ==
    // JSONRegionContexts.JSON_LBRACE || type ==
    // JSONRegionContexts.JSON_RBRACE) {
    // bDeclaration = true;
    // }
    // if (!bDeclaration) {
    // IStructuredDocumentRegion prevRegion =
    // JSONUtil.findPreviousSignificantNode(region);
    // if (prevRegion != null) {
    // type = prevRegion.getType();
    // if (JSONRegionUtil.isDeclarationType(type) || type ==
    // JSONRegionContexts.JSON_LBRACE) {
    // bDeclaration = true;
    // }
    // }
    // }
    // if (!bDeclaration) {
    // IStructuredDocumentRegion nextRegion =
    // JSONUtil.findNextSignificantNode(region);
    // if (nextRegion != null) {
    // type = nextRegion.getType();
    // if (JSONRegionUtil.isDeclarationType(type) || type ==
    // JSONRegionContexts.JSON_RBRACE) {
    // bDeclaration = true;
    // }
    // }
    // }
    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 19 with StructuredDocumentEvent

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

the class JSONStructuredDocumentReParser method checkForCrossStructuredDocumentRegionSyntax.

/**
 */
// public StructuredDocumentEvent
// checkForCrossStructuredDocumentRegionBoundryCases2() {
// StructuredDocumentEvent result = specialPositionUpdate(fStart, fStart +
// fLengthToReplace - 1);
// if (result == null) {
// result = checkInsideBrace();
// }
// return result;
// }
@Override
protected StructuredDocumentEvent checkForCrossStructuredDocumentRegionSyntax() {
    int checkStart = fStart;
    int checkEnd = fStart + fLengthToReplace - 1;
    IStructuredDocumentRegion endRegion = fStructuredDocument.getRegionAtCharacterOffset(checkEnd);
    if (endRegion != null) {
        checkEnd = endRegion.getEndOffset();
    }
    ReparseRange range = new ReparseRange(checkStart, checkEnd);
    range.expand(getUpdateRangeForDelimiter(range.getStart(), range.getEnd()));
    range.expand(getUpdateRangeForUnknownRegion(range.getStart(), range.getEnd()));
    // range.expand(getUpdateRangeForQuotes(range.getStart(),
    // range.getEnd()));
    // range.expand(getUpdateRangeForComments(range.getStart(),
    // range.getEnd()));
    range.expand(getUpdateRangeForBraces(range.getStart(), range.getEnd()));
    StructuredDocumentEvent result;
    result = checkInsideBrace(range.getStart(), range.getEnd());
    if (result == null) {
        result = reparse(range.getStart(), range.getEnd());
    }
    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 20 with StructuredDocumentEvent

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

the class RegionChangedAdapterNotificationTests method testReplaceTrailingSpaceofEqualSignWithTwoSpaces.

public void testReplaceTrailingSpaceofEqualSignWithTwoSpaces() 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, 5, 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)

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