Search in sources :

Example 26 with IStructuredDocument

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

the class StyleSheetFormatter method formatPre.

/**
 */
protected void formatPre(ICSSNode node, IRegion region, java.lang.StringBuffer source) {
    CSSCleanupStrategy stgy = getCleanupStrategy(node);
    IStructuredDocument structuredDocument = node.getOwnerDocument().getModel().getStructuredDocument();
    CompoundRegion[] regions = getRegionsWithoutWhiteSpaces(structuredDocument, region, stgy);
    CompoundRegion[] outside = getOutsideRegions(structuredDocument, region);
    for (int i = 0; i < regions.length; i++) {
        if (i != 0 || needS(outside[0]) || regions[i].getType() == CSSRegionContexts.CSS_CDO || node.getOwnerDocument().getModel().getStyleSheetType() == ICSSModel.EMBEDDED)
            appendDelimBefore(node, regions[i], source);
        source.append(decoratedRegion(regions[i], 0, stgy));
    }
    if (needS(outside[1])) {
        if (isIncludesPreEnd(node, region)) {
            if (source.length() > 0 || node.getOwnerDocument().getModel().getStyleSheetType() == ICSSModel.EMBEDDED) {
                String delim = getLineDelimiter(node);
                source.append(delim);
            }
        }
    }
}
Also used : IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) CSSCleanupStrategy(org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy)

Example 27 with IStructuredDocument

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

the class StyleSheetFormatter method formatPre.

/**
 */
protected void formatPre(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode node, java.lang.StringBuffer source) {
    int start = ((IndexedRegion) node).getStartOffset();
    int end = (node.getFirstChild() != null && ((IndexedRegion) node.getFirstChild()).getEndOffset() > 0) ? ((IndexedRegion) node.getFirstChild()).getStartOffset() : getChildInsertPos(node);
    if (end > 0) {
        CSSCleanupStrategy stgy = getCleanupStrategy(node);
        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 || regions[i].getType() == CSSRegionContexts.CSS_CDO || node.getOwnerDocument().getModel().getStyleSheetType() == ICSSModel.EMBEDDED)
                appendDelimBefore(node, regions[i], source);
            source.append(decoratedRegion(regions[i], 0, stgy));
        }
        if (node.getLastChild() != null && (source.length() > 0 || node.getOwnerDocument().getModel().getStyleSheetType() == ICSSModel.EMBEDDED)) {
            appendDelimBefore(node, null, source);
        }
    } else if (node.getOwnerDocument().getModel() != null && node.getOwnerDocument().getModel().getStyleSheetType() == ICSSModel.EMBEDDED) {
        appendDelimBefore(node, null, source);
    // source.append("<!--");
    // appendDelimBefore(node,null, source);
    } else
        // nothing
        return;
}
Also used : IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion) CSSCleanupStrategy(org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy)

Example 28 with IStructuredDocument

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

the class StyleSheetFormatter method formatPost.

/**
 */
protected void formatPost(ICSSNode node, IRegion region, StringBuffer source) {
    CSSCleanupStrategy stgy = getCleanupStrategy(node);
    IStructuredDocument structuredDocument = node.getOwnerDocument().getModel().getStructuredDocument();
    CompoundRegion[] regions = getRegionsWithoutWhiteSpaces(structuredDocument, region, stgy);
    CompoundRegion[] outside = getOutsideRegions(structuredDocument, region);
    for (int i = 0; i < regions.length; i++) {
        if (i != 0 || needS(outside[0]))
            appendDelimBefore(node, regions[i], source);
        source.append(decoratedRegion(regions[i], 0, stgy));
    }
}
Also used : IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) CSSCleanupStrategy(org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy)

Example 29 with IStructuredDocument

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

the class HTMLValidationReporter method translateMessage.

/**
 * Translate ValidationMessage to IMessage and generate result log
 */
private IMessage translateMessage(ValidationMessage message) {
    int severity = IMessage.LOW_SEVERITY;
    HTMLValidationResult result = getResult();
    switch(message.getSeverity()) {
        case ValidationMessage.ERROR:
            severity = IMessage.HIGH_SEVERITY;
            result.addError();
            break;
        case ValidationMessage.WARNING:
            severity = IMessage.NORMAL_SEVERITY;
            result.addWarning();
            break;
        case ValidationMessage.INFORMATION:
            result.addInformation();
            break;
        default:
            // result.addInformation();
            break;
    }
    IMessage mes = new LocalizedMessage(severity, message.getMessage(), this.file);
    mes.setOffset(message.getOffset());
    mes.setLength(message.getLength());
    if (this.model != null) {
        IStructuredDocument flatModel = this.model.getStructuredDocument();
        if (flatModel != null) {
            int line = flatModel.getLineOfOffset(message.getOffset());
            mes.setLineNo(line + 1);
        }
    }
    return mes;
}
Also used : IMessage(org.eclipse.wst.validation.internal.provisional.core.IMessage) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)

Example 30 with IStructuredDocument

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

the class HTMLContentAssistProcessor method computeCompletionProposals.

/**
 * Return a list of proposed code completions based on the specified
 * location within the document that corresponds to the current cursor
 * position within the text-editor control.
 *
 * @param documentPosition
 *            a location within the document
 * @return an array of code-assist items
 */
public ICompletionProposal[] computeCompletionProposals(ITextViewer textViewer, int documentPosition) {
    fTemplateContexts.clear();
    IndexedRegion treeNode = ContentAssistUtils.getNodeAt(textViewer, documentPosition);
    IDOMNode node = (IDOMNode) treeNode;
    setErrorMessage(null);
    // check if it's in a comment node
    IStructuredDocument structuredDocument = (IStructuredDocument) textViewer.getDocument();
    IStructuredDocumentRegion fn = structuredDocument.getRegionAtCharacterOffset(documentPosition);
    if (fn != null && fn.getType() == DOMRegionContext.XML_COMMENT_TEXT && documentPosition != fn.getStartOffset()) {
        return new ICompletionProposal[0];
    }
    // if it's a </script> tag, bounce back to JS ca processor...
    if (fn != null && fn.getType() == DOMRegionContext.XML_TAG_NAME && documentPosition == fn.getStartOffset()) {
        ITextRegionList v = fn.getRegions();
        if (v.size() > 1) {
            // determine that it's a close tag
            if ((v.get(0)).getType() == DOMRegionContext.XML_END_TAG_OPEN) {
                Iterator it = v.iterator();
                ITextRegion region = null;
                // search for script tag name
                while (it.hasNext()) {
                    region = (ITextRegion) it.next();
                    if (fn.getText(region).equalsIgnoreCase("script")) {
                        // $NON-NLS-1$
                        IContentAssistProcessor jsProcessor = getJSContentAssistProcessor();
                        if (jsProcessor != null) {
                            return jsProcessor.computeCompletionProposals(textViewer, documentPosition);
                        }
                        return new ICompletionProposal[0];
                    }
                }
            }
        }
    }
    isXHTML = getXHTML(node);
    // force reload of content generator
    fGenerator = null;
    // handle blank HTML document case
    if (treeNode == null || isViewerEmpty(textViewer)) {
        // cursor is at the EOF
        ICompletionProposal htmlTagProposal = getHTMLTagProposal(textViewer, documentPosition);
        ICompletionProposal[] superResults = super.computeCompletionProposals(textViewer, documentPosition);
        if (superResults != null && superResults.length > 0 && htmlTagProposal != null) {
            ICompletionProposal[] blankHTMLDocResults = new ICompletionProposal[superResults.length + 1];
            blankHTMLDocResults[0] = htmlTagProposal;
            System.arraycopy(superResults, 0, blankHTMLDocResults, 1, superResults.length);
            return blankHTMLDocResults;
        }
    }
    if (node != null && node.getNodeType() == Node.ELEMENT_NODE) {
        // check embedded CSS proposals at the beginning of the STYLE end
        // tag
        Element element = (Element) node;
        String tagName = element.getTagName();
        if (tagName != null && tagName.equalsIgnoreCase(HTML40Namespace.ATTR_NAME_STYLE)) {
            // $NON-NLS-1$
            IStructuredDocumentRegion endStructuredDocumentRegion = node.getEndStructuredDocumentRegion();
            if (endStructuredDocumentRegion != null && endStructuredDocumentRegion.getStartOffset() == documentPosition) {
                IStructuredDocumentRegion startStructuredDocumentRegion = node.getStartStructuredDocumentRegion();
                if (startStructuredDocumentRegion != null) {
                    int offset = startStructuredDocumentRegion.getEndOffset();
                    int pos = documentPosition - offset;
                    ICompletionProposal[] proposals = getCSSProposals(textViewer, pos, node, offset, (char) 0);
                    if (proposals != null)
                        return proposals;
                }
            }
        }
        // check inline CSS proposals
        // need to find attr region from sd region
        IStructuredDocumentRegion sdRegion = ContentAssistUtils.getStructuredDocumentRegion(textViewer, documentPosition);
        Iterator regions = sdRegion.getRegions().iterator();
        ITextRegion styleNameRegion = null;
        ITextRegion styleValueRegion = null;
        while (regions.hasNext()) {
            styleNameRegion = (ITextRegion) regions.next();
            if (styleNameRegion.getType().equals(DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) && sdRegion.getText(styleNameRegion).equalsIgnoreCase(HTML40Namespace.ATTR_NAME_STYLE)) {
                // the next region should be "="
                if (regions.hasNext()) {
                    // skip the "="
                    regions.next();
                    // next region should be attr value region
                    if (regions.hasNext()) {
                        styleValueRegion = (ITextRegion) regions.next();
                        break;
                    }
                }
            }
        }
        if (styleValueRegion != null) {
            int offset = sdRegion.getStartOffset(styleValueRegion);
            int end = sdRegion.getTextEndOffset(styleValueRegion);
            if (documentPosition >= offset && documentPosition <= end) {
                boolean askCSS = true;
                char quote = (char) 0;
                String text = sdRegion.getText(styleValueRegion);
                int length = (text != null ? text.length() : 0);
                if (length > 0) {
                    char firstChar = text.charAt(0);
                    if (firstChar == '"' || firstChar == '\'') {
                        if (documentPosition == offset) {
                            // before quote
                            askCSS = false;
                        } else {
                            offset++;
                            quote = firstChar;
                        }
                    }
                    if (documentPosition == end) {
                        if (length > 1 && text.charAt(length - 1) == quote) {
                            // after quote
                            askCSS = false;
                        }
                    }
                }
                if (askCSS) {
                    int pos = documentPosition - offset;
                    ICompletionProposal[] proposals = getCSSProposals(textViewer, pos, node, offset, quote);
                    if (proposals != null)
                        return proposals;
                }
            }
        }
    }
    return super.computeCompletionProposals(textViewer, documentPosition);
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) IContentAssistProcessor(org.eclipse.jface.text.contentassist.IContentAssistProcessor) Element(org.w3c.dom.Element) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion) 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) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) Iterator(java.util.Iterator) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)

Aggregations

IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)432 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)96 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)79 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)68 CSSCleanupStrategy (org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy)44 Node (org.w3c.dom.Node)42 ICSSModel (org.eclipse.wst.css.core.internal.provisional.document.ICSSModel)41 Document (org.w3c.dom.Document)36 BadLocationException (org.eclipse.jface.text.BadLocationException)35 IndexedRegion (org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)34 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)34 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)33 Element (org.w3c.dom.Element)30 IDocument (org.eclipse.jface.text.IDocument)29 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)28 IModelManager (org.eclipse.wst.sse.core.internal.provisional.IModelManager)26 StructuredDocumentEvent (org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent)23 Test (org.junit.Test)22 INodeAdapter (org.eclipse.wst.sse.core.internal.provisional.INodeAdapter)20 RegionChangedEvent (org.eclipse.wst.sse.core.internal.provisional.events.RegionChangedEvent)20