Search in sources :

Example 86 with IStructuredDocumentRegion

use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion in project webtools.sourceediting by eclipse.

the class StyleElementAdapter method replaceStructuredDocumentRegions.

/**
 * Preparation of applying changes from CSS sub-model to HTML model
 */
private void replaceStructuredDocumentRegions(IStructuredDocumentRegionList newStructuredDocumentRegions, IStructuredDocumentRegionList oldStructuredDocumentRegions) {
    int offset = 0;
    int length = 0;
    if (oldStructuredDocumentRegions != null) {
        int count = oldStructuredDocumentRegions.getLength();
        if (count > 0) {
            IStructuredDocumentRegion first = oldStructuredDocumentRegions.item(0);
            if (first != null)
                offset = first.getStart();
            IStructuredDocumentRegion last = oldStructuredDocumentRegions.item(count - 1);
            if (last != null)
                length = last.getEnd() - offset;
        }
    }
    String data = null;
    if (newStructuredDocumentRegions != null) {
        int count = newStructuredDocumentRegions.getLength();
        if (count > 0) {
            StringBuffer buffer = new StringBuffer();
            for (int i = 0; i < count; i++) {
                IStructuredDocumentRegion flatNode = newStructuredDocumentRegions.item(i);
                if (flatNode == null)
                    continue;
                buffer.append(flatNode.getText());
                if (i == 0)
                    offset = flatNode.getStart();
            }
            data = buffer.toString();
        }
    }
    replaceData(offset, length, data);
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)

Example 87 with IStructuredDocumentRegion

use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion in project webtools.sourceediting by eclipse.

the class StyleElementAdapter method regionsReplaced.

/**
 * Implementing IStructuredDocumentListener's method
 * Event from CSS Flat Model
 */
public void regionsReplaced(RegionsReplacedEvent event) {
    if (event == null)
        return;
    if (event.getOriginalRequester() == getRequesterH2C())
        return;
    IStructuredDocumentRegion flatNode = event.getStructuredDocumentRegion();
    if (flatNode == null)
        return;
    changeStructuredDocumentRegion(flatNode);
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)

Example 88 with IStructuredDocumentRegion

use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion in project webtools.sourceediting by eclipse.

the class HTMLElementFormatter method formatEndTag.

/**
 */
private void formatEndTag(IDOMElement element, HTMLFormatContraints contraints) {
    Node lastChild = element.getLastChild();
    if (lastChild != null && lastChild instanceof IDOMElement && lastChild.getNodeName().equals("jsp:scriptlet")) {
        // $NON-NLS-1$
        insertBreakAfter((IDOMElement) lastChild, contraints);
        return;
    }
    IStructuredDocumentRegion endStructuredDocumentRegion = element.getEndStructuredDocumentRegion();
    if (endStructuredDocumentRegion == null)
        return;
    if (element.isJSPTag() || element.isCommentTag()) {
        String endTag = endStructuredDocumentRegion.getText();
        if (endTag != null && endTag.length() > 0) {
            setWidth(contraints, endTag);
        }
        return;
    }
    ITextRegion prevRegion = null;
    ITextRegionList regions = endStructuredDocumentRegion.getRegions();
    Iterator e = regions.iterator();
    while (e.hasNext()) {
        ITextRegion region = (ITextRegion) e.next();
        if (region == null)
            continue;
        String regionType = region.getType();
        if (regionType == DOMRegionContext.XML_TAG_NAME || isNestedTag(regionType)) {
            if (prevRegion != null && prevRegion.getType() == DOMRegionContext.XML_END_TAG_OPEN) {
                removeTailingSpaces(endStructuredDocumentRegion, prevRegion);
            }
        } else if (regionType == DOMRegionContext.XML_TAG_CLOSE) {
            if (prevRegion != null && (prevRegion.getType() == DOMRegionContext.XML_TAG_NAME || isNestedRootTag(prevRegion.getType()))) {
                removeTailingSpaces(endStructuredDocumentRegion, prevRegion);
            }
        }
        prevRegion = region;
    }
    if (prevRegion != null && (prevRegion.getType() == DOMRegionContext.XML_TAG_NAME || isNestedRootTag(prevRegion.getType()))) {
        removeTailingSpaces(endStructuredDocumentRegion, prevRegion);
    }
// BUG123890 (end tag length was already prefactored into
// formatStartTag so no need to do it here)
// String newEndTag = endStructuredDocumentRegion.getText();
// if (newEndTag != null && newEndTag.length() > 0) {
// setWidth(contraints, newEndTag);
// }
}
Also used : ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode) Node(org.w3c.dom.Node) Iterator(java.util.Iterator) IDOMElement(org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement)

Example 89 with IStructuredDocumentRegion

use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion in project webtools.sourceediting by eclipse.

the class HTMLTextFormatter method canFormatText.

/**
 */
private boolean canFormatText(IDOMText text) {
    if (text == null)
        return false;
    IStructuredDocumentRegion flatNode = text.getFirstStructuredDocumentRegion();
    if (flatNode != null) {
        String type = flatNode.getType();
        if (isUnparsedRegion(type))
            return false;
    }
    Node parent = text.getParentNode();
    if (parent != null && parent.getNodeType() == Node.ELEMENT_NODE) {
        IDOMElement element = (IDOMElement) parent;
        if (!element.isGlobalTag() && !text.isElementContentWhitespace())
            return false;
    }
    return canFormatChild(parent);
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) Node(org.w3c.dom.Node) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) IDOMElement(org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement)

Example 90 with IStructuredDocumentRegion

use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion in project webtools.sourceediting by eclipse.

the class TEIValidation method testCustomTagInAttribute.

public void testCustomTagInAttribute() throws Exception {
    // $NON-NLS-1$
    final String path = "/" + PROJECT_NAME + "/WebContent/test.jsp";
    final IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(path));
    IStructuredModel model = StructuredModelManager.getModelManager().getModelForRead(file);
    try {
        assertTrue("Not an IDOMModel", model instanceof IDOMModel);
        NodeList divs = ((IDOMModel) model).getDocument().getElementsByTagName("div");
        assertTrue("Missing a div", divs.getLength() > 0);
        IDOMNode node = (IDOMNode) divs.item(0);
        IStructuredDocumentRegion region = node.getStartStructuredDocumentRegion();
        ITextRegionList regions = region.getRegions();
        assertTrue(regions.size() > 2);
        /* This test is failing as of 20180213 so until someone can debug and fix it, comment it out */
        /* JSPJavaTranslatorCoreTest.waitForBuildAndValidation(getProject()); */
        final TaglibHelper helper = new TaglibHelper(getProject());
        final List problems = new ArrayList();
        final IStructuredDocument document = model.getStructuredDocument();
        ITextRegion embedded = regions.get(2);
        assertTrue("Not a container region", embedded instanceof ITextRegionContainer);
        helper.getCustomTag("test:foo", document, (ITextRegionContainer) embedded, problems);
    /* assertEquals("No problems should be generated", 0, problems.size()); */
    } finally {
        if (model != null)
            model.releaseFromRead();
    }
}
Also used : Path(org.eclipse.core.runtime.Path) IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) IFile(org.eclipse.core.resources.IFile) TaglibHelper(org.eclipse.jst.jsp.core.internal.taglib.TaglibHelper) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) ITextRegionContainer(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer) ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) List(java.util.List) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)

Aggregations

IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)439 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)174 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)99 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)87 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)70 List (java.util.List)40 BadLocationException (org.eclipse.jface.text.BadLocationException)39 ArrayList (java.util.ArrayList)38 Iterator (java.util.Iterator)35 IndexedRegion (org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)35 Node (org.w3c.dom.Node)30 ITextRegionContainer (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer)26 RegionIterator (org.eclipse.wst.css.core.internal.util.RegionIterator)19 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)19 CustomCompletionProposal (org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal)17 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)15 CMElementDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)15 ICSSNode (org.eclipse.wst.css.core.internal.provisional.document.ICSSNode)14 CMNamedNodeMap (org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)13 NodeList (org.w3c.dom.NodeList)13