Search in sources :

Example 41 with IndexedRegion

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

the class StructuredSelectPreviousCSSActionDelegate method getNewSelectionRegion.

protected Region getNewSelectionRegion(IndexedRegion indexedRegion, ITextSelection textSelection) {
    Region newRegion = null;
    if (indexedRegion instanceof ICSSNode) {
        ICSSNode cursorNode = (ICSSNode) indexedRegion;
        Region cursorNodeRegion = new Region(indexedRegion.getStartOffset(), indexedRegion.getEndOffset() - indexedRegion.getStartOffset());
        int currentOffset = textSelection.getOffset();
        int currentEndOffset = currentOffset + textSelection.getLength();
        if (cursorNodeRegion.getOffset() >= currentOffset && cursorNodeRegion.getOffset() <= currentEndOffset && cursorNodeRegion.getOffset() + cursorNodeRegion.getLength() >= currentOffset && cursorNodeRegion.getOffset() + cursorNodeRegion.getLength() <= currentEndOffset) {
            ICSSNode newNode = cursorNode.getPreviousSibling();
            if (newNode == null) {
                newNode = cursorNode.getParentNode();
                if (newNode instanceof IndexedRegion) {
                    IndexedRegion newIndexedRegion = (IndexedRegion) newNode;
                    newRegion = new Region(newIndexedRegion.getStartOffset(), newIndexedRegion.getEndOffset() - newIndexedRegion.getStartOffset());
                }
            } else {
                if (newNode instanceof IndexedRegion) {
                    IndexedRegion newIndexedRegion = (IndexedRegion) newNode;
                    newRegion = new Region(newIndexedRegion.getStartOffset(), currentEndOffset - newIndexedRegion.getStartOffset());
                }
            }
        } else
            newRegion = cursorNodeRegion;
    }
    return newRegion;
}
Also used : Region(org.eclipse.jface.text.Region) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)

Example 42 with IndexedRegion

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

the class UnknownRuleFormatter method formatPre.

@Override
protected void formatPre(IJSONNode node, StringBuilder source) {
    IJSONCleanupStrategy stgy = getCleanupStrategy(node);
    int start = ((IndexedRegion) node).getStartOffset();
    int end = ((IndexedRegion) node).getEndOffset();
    if (end > 0) {
        // format source
        IStructuredDocument structuredDocument = node.getOwnerDocument().getModel().getStructuredDocument();
        CompoundRegion[] regions = getRegionsWithoutWhiteSpaces(structuredDocument, new FormatRegion(start, end - start), stgy);
        for (int i = 0; i < regions.length; i++) {
            if (i != 0)
                appendSpaceBefore(node, regions[i], source);
            source.append(decoratedPropValueRegion(regions[i], stgy));
        }
    }
// else { // generate source
// JSONUnknownRule rule = (JSONUnknownRule) node;
// source.append(rule.getCssText());
// }
}
Also used : IJSONCleanupStrategy(org.eclipse.wst.json.core.cleanup.IJSONCleanupStrategy) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)

Example 43 with IndexedRegion

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

the class JSPActionValidator method processDirective.

private void processDirective(IReporter reporter, IFile file, IStructuredModel model, IStructuredDocumentRegion documentRegion) {
    IndexedRegion ir = model.getIndexedRegion(documentRegion.getStartOffset());
    if (ir instanceof IDOMElement) {
        IDOMElement element = (IDOMElement) ir;
        ModelQuery query = ModelQueryUtil.getModelQuery(model);
        if (query != null) {
            CMElementDeclaration cmElement = query.getCMElementDeclaration(element);
            if (cmElement != null) {
                CMNamedNodeMap cmAttributes = null;
                CMNamedNodeMapImpl allAttributes = new CMNamedNodeMapImpl();
                List nodes = query.getAvailableContent(element, cmElement, ModelQuery.INCLUDE_ATTRIBUTES);
                for (int k = 0; k < nodes.size(); k++) {
                    CMNode cmnode = (CMNode) nodes.get(k);
                    if (cmnode.getNodeType() == CMNode.ATTRIBUTE_DECLARATION) {
                        allAttributes.put(cmnode);
                    }
                }
                cmAttributes = allAttributes;
                boolean foundjspattribute = checkUnknownAttributes(element, cmElement, cmAttributes, reporter, file, model.getStructuredDocument(), documentRegion);
                // missing required attributes
                if (!foundjspattribute && fSeverityMissingRequiredAttribute != ValidationMessage.IGNORE)
                    checkRequiredAttributes(element, cmAttributes, reporter, file, model.getStructuredDocument(), documentRegion);
                if (fSeverityNonEmptyInlineTag != ValidationMessage.IGNORE)
                    checkNonEmptyInlineTag(element, cmElement, reporter, file, model.getStructuredDocument());
            }
        }
    }
}
Also used : CMNamedNodeMapImpl(org.eclipse.wst.xml.core.internal.contentmodel.basic.CMNamedNodeMapImpl) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) ModelQuery(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery) List(java.util.List) ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) NodeList(org.w3c.dom.NodeList) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion) IDOMElement(org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement)

Example 44 with IndexedRegion

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

the class XMLHyperlinkDetector method getCurrentNode.

/**
 * Returns the node the cursor is currently on in the document. null if no
 * node is selected
 *
 * @param offset
 * @return Node either element, doctype, text, or null
 */
private Node getCurrentNode(IDocument document, int offset) {
    // get the current node at the offset (returns either: element,
    // doctype, text)
    IndexedRegion inode = null;
    IStructuredModel sModel = null;
    try {
        sModel = StructuredModelManager.getModelManager().getExistingModelForRead(document);
        inode = sModel.getIndexedRegion(offset);
        if (inode == null) {
            inode = sModel.getIndexedRegion(offset - 1);
        }
    } finally {
        if (sModel != null) {
            sModel.releaseFromRead();
        }
    }
    if (inode instanceof Node) {
        return (Node) inode;
    }
    return null;
}
Also used : IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) Node(org.w3c.dom.Node) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)

Example 45 with IndexedRegion

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

the class QuickOutlinePopupDialog method gotoSelectedElement.

private void gotoSelectedElement() {
    Object element = getSelectedElement();
    dispose();
    if (element != null) {
        ITextEditor editor = getActiveTextEditor();
        if (editor != null) {
            editor.selectAndReveal(((IndexedRegion) element).getStartOffset(), ((IndexedRegion) element).getEndOffset() - ((IndexedRegion) element).getStartOffset());
        }
    }
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)

Aggregations

IndexedRegion (org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)148 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)33 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)32 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)31 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)27 Node (org.w3c.dom.Node)27 Region (org.eclipse.jface.text.Region)21 ICSSNode (org.eclipse.wst.css.core.internal.provisional.document.ICSSNode)21 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)21 CSSCleanupStrategy (org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy)20 RegionIterator (org.eclipse.wst.css.core.internal.util.RegionIterator)17 ArrayList (java.util.ArrayList)11 List (java.util.List)11 ITextSelection (org.eclipse.jface.text.ITextSelection)11 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)10 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)8 ITextEditor (org.eclipse.ui.texteditor.ITextEditor)8 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)8 Preferences (org.eclipse.core.runtime.Preferences)7 IDocument (org.eclipse.jface.text.IDocument)7