Search in sources :

Example 6 with IncrementalReporter

use of org.eclipse.wst.sse.ui.internal.reconcile.validator.IncrementalReporter in project webtools.sourceediting by eclipse.

the class MarkupValidator method checkAttributesInEndTag.

private void checkAttributesInEndTag(IStructuredDocumentRegion structuredDocumentRegion, IReporter reporter) {
    if (structuredDocumentRegion.isDeleted()) {
        return;
    }
    ITextRegionList textRegions = structuredDocumentRegion.getRegions();
    int errorCount = 0;
    int start = structuredDocumentRegion.getEndOffset();
    int end = structuredDocumentRegion.getEndOffset();
    for (int i = 0; (i < textRegions.size()) && (errorCount < AbstractStructuredTextReconcilingStrategy.ELEMENT_ERROR_LIMIT) && !structuredDocumentRegion.isDeleted(); i++) {
        ITextRegion textRegion = textRegions.get(i);
        if ((textRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) || (textRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_EQUALS) || (textRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE)) {
            if (start > structuredDocumentRegion.getStartOffset(textRegion)) {
                start = structuredDocumentRegion.getStartOffset(textRegion);
            }
            end = structuredDocumentRegion.getEndOffset(textRegion);
            errorCount++;
        }
    }
    // create one error for all attributes in the end tag
    if (errorCount > 0) {
        // Position p = new Position(start, end - start);
        String messageText = XMLUIMessages.End_tag_has_attributes;
        LocalizedMessage message = new LocalizedMessage(SEVERITY_END_TAG_WITH_ATTRIBUTES, messageText);
        message.setOffset(start);
        message.setLength(end - start);
        message.setLineNo(getLineNumber(start));
        if (reporter instanceof IncrementalReporter) {
            MarkupQuickAssistProcessor processor = new MarkupQuickAssistProcessor();
            processor.setProblemId(ProblemIDsXML.AttrsInEndTag);
            message.setAttribute(QUICKASSISTPROCESSOR, processor);
            AnnotationInfo info = new AnnotationInfo(message);
            ((IncrementalReporter) reporter).addAnnotationInfo(this, info);
        } else {
            reporter.addMessage(this, message);
        }
    }
}
Also used : IncrementalReporter(org.eclipse.wst.sse.ui.internal.reconcile.validator.IncrementalReporter) ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) LocalizedMessage(org.eclipse.wst.validation.internal.operations.LocalizedMessage) AnnotationInfo(org.eclipse.wst.sse.ui.internal.reconcile.validator.AnnotationInfo)

Example 7 with IncrementalReporter

use of org.eclipse.wst.sse.ui.internal.reconcile.validator.IncrementalReporter in project webtools.sourceediting by eclipse.

the class DelegatingSourceValidator method updateValidationMessages.

/**
 * iterates through the messages and calculates a "better" offset and
 * length
 *
 * @param messages -
 *            a List of IMessages
 * @param document -
 *            the document
 * @param reporter -
 *            the reporter the messages are to be added to
 */
protected void updateValidationMessages(List messages, IDOMDocument document, IReporter reporter) {
    for (int i = 0; i < messages.size(); i++) {
        IMessage message = (IMessage) messages.get(i);
        try {
            if (message.getAttribute(COLUMN_NUMBER_ATTRIBUTE) != null) {
                int column = ((Integer) message.getAttribute(COLUMN_NUMBER_ATTRIBUTE)).intValue();
                if (message.getAttribute(AnnotationMsg.PROBMLEM_ID) != null && reporter instanceof IncrementalReporter) {
                    Integer problemId = (Integer) message.getAttribute(AnnotationMsg.PROBMLEM_ID);
                    MarkupQuickAssistProcessor processor = new MarkupQuickAssistProcessor();
                    processor.setProblemId(problemId.intValue());
                    message.setOffset(column);
                    Integer length = (Integer) message.getAttribute(AnnotationMsg.LENGTH);
                    message.setLength(length.intValue());
                    Object attrValue = message.getAttribute(AnnotationMsg.ATTRVALUETEXT);
                    if (attrValue != null)
                        processor.setAdditionalFixInfo(attrValue);
                    else {
                        Object attrValueNo = message.getAttribute(AnnotationMsg.ATTRVALUENO);
                        if (attrValueNo != null) {
                            int len = ((Integer) attrValueNo).intValue();
                            Object[] objArray = new Object[len];
                            for (int j = 0; j < len; j++) {
                                objArray[j] = message.getAttribute(AnnotationMsg.ATTRNO + j);
                            }
                            processor.setAdditionalFixInfo(objArray);
                        }
                    }
                    message.setAttribute(QUICKASSISTPROCESSOR, processor);
                    AnnotationInfo info = new AnnotationInfo(message);
                    ((IncrementalReporter) reporter).addAnnotationInfo(this, info);
                } else {
                    String selectionStrategy = (String) message.getAttribute(SQUIGGLE_SELECTION_STRATEGY_ATTRIBUTE);
                    String nameOrValue = (String) message.getAttribute(SQUIGGLE_NAME_OR_VALUE_ATTRIBUTE);
                    // convert the line and Column numbers to an offset:
                    int start = document.getStructuredDocument().getLineOffset(message.getLineNumber() - 1) + column - 1;
                    int[] result = computeStartAndEndLocation(start, selectionStrategy, getErrorSide(message), nameOrValue, document);
                    if (result != null) {
                        message.setOffset(result[0]);
                        message.setLength(result[1] - result[0]);
                        reporter.addMessage(this, message);
                    }
                }
            }
        } catch (BadLocationException e) {
        // this exception should not
        // occur - it is thrown if
        // trying to convert an
        // invalid line number to and
        // offset
        }
    }
}
Also used : IncrementalReporter(org.eclipse.wst.sse.ui.internal.reconcile.validator.IncrementalReporter) IMessage(org.eclipse.wst.validation.internal.provisional.core.IMessage) BadLocationException(org.eclipse.jface.text.BadLocationException) AnnotationInfo(org.eclipse.wst.sse.ui.internal.reconcile.validator.AnnotationInfo)

Example 8 with IncrementalReporter

use of org.eclipse.wst.sse.ui.internal.reconcile.validator.IncrementalReporter in project webtools.sourceediting by eclipse.

the class MarkupValidator method checkStartingSpaceForPI.

private void checkStartingSpaceForPI(IStructuredDocumentRegion structuredDocumentRegion, IReporter reporter) {
    if (structuredDocumentRegion.isDeleted()) {
        return;
    }
    IStructuredDocumentRegion prev = structuredDocumentRegion.getPrevious();
    if ((prev != null) && prev.getStartOffset() == 0) {
        if (prev.getType() == DOMRegionContext.XML_CONTENT) {
            String messageText = XMLUIMessages.ReconcileStepForMarkup_5;
            int start = prev.getStartOffset();
            int length = prev.getLength();
            LocalizedMessage message = new LocalizedMessage(SEVERITY_WHITESPACE_AT_START, messageText);
            message.setOffset(start);
            message.setLength(length);
            message.setLineNo(getLineNumber(start));
            if (reporter instanceof IncrementalReporter) {
                MarkupQuickAssistProcessor processor = new MarkupQuickAssistProcessor();
                processor.setProblemId(ProblemIDsXML.SpacesBeforePI);
                message.setAttribute(QUICKASSISTPROCESSOR, processor);
                AnnotationInfo info = new AnnotationInfo(message);
                ((IncrementalReporter) reporter).addAnnotationInfo(this, info);
            } else {
                reporter.addMessage(this, message);
            }
        // Position p = new Position(start, length);
        // 
        // ReconcileAnnotationKey key =
        // createKey(structuredDocumentRegion, getScope());
        // TemporaryAnnotation annotation = new TemporaryAnnotation(p,
        // SEVERITY_SYNTAX_ERROR, message, key,
        // ProblemIDsXML.SpacesBeforePI);
        // results.add(annotation);
        }
    }
}
Also used : IncrementalReporter(org.eclipse.wst.sse.ui.internal.reconcile.validator.IncrementalReporter) IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) LocalizedMessage(org.eclipse.wst.validation.internal.operations.LocalizedMessage) AnnotationInfo(org.eclipse.wst.sse.ui.internal.reconcile.validator.AnnotationInfo)

Example 9 with IncrementalReporter

use of org.eclipse.wst.sse.ui.internal.reconcile.validator.IncrementalReporter in project webtools.sourceediting by eclipse.

the class MarkupValidator method checkClosingBracket.

private void checkClosingBracket(IStructuredDocumentRegion structuredDocumentRegion, IReporter reporter) {
    if (structuredDocumentRegion.isDeleted()) {
        return;
    }
    ITextRegionList regions = structuredDocumentRegion.getRegions();
    ITextRegion r = null;
    boolean closed = false;
    for (int i = 0; (i < regions.size()) && !structuredDocumentRegion.isDeleted(); i++) {
        r = regions.get(i);
        if ((r.getType() == DOMRegionContext.XML_TAG_CLOSE) || (r.getType() == DOMRegionContext.XML_EMPTY_TAG_CLOSE)) {
            closed = true;
        }
    }
    if (!closed) {
        String messageText = XMLUIMessages.ReconcileStepForMarkup_6;
        int start = structuredDocumentRegion.getStartOffset();
        int length = structuredDocumentRegion.getText().trim().length();
        int lineNo = getLineNumber(start);
        LocalizedMessage message = new LocalizedMessage(SEVERITY_MISSING_CLOSING_BRACKET, messageText);
        message.setOffset(start);
        message.setLength(length);
        message.setLineNo(lineNo);
        if (reporter instanceof IncrementalReporter) {
            MarkupQuickAssistProcessor processor = new MarkupQuickAssistProcessor();
            processor.setProblemId(ProblemIDsXML.MissingClosingBracket);
            message.setAttribute(QUICKASSISTPROCESSOR, processor);
            AnnotationInfo info = new AnnotationInfo(message);
            ((IncrementalReporter) reporter).addAnnotationInfo(this, info);
        } else {
            reporter.addMessage(this, message);
        }
    }
}
Also used : IncrementalReporter(org.eclipse.wst.sse.ui.internal.reconcile.validator.IncrementalReporter) ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) LocalizedMessage(org.eclipse.wst.validation.internal.operations.LocalizedMessage) AnnotationInfo(org.eclipse.wst.sse.ui.internal.reconcile.validator.AnnotationInfo)

Example 10 with IncrementalReporter

use of org.eclipse.wst.sse.ui.internal.reconcile.validator.IncrementalReporter in project webtools.sourceediting by eclipse.

the class MarkupValidator method checkStartEndTagPairs.

private void checkStartEndTagPairs(IStructuredDocumentRegion sdRegion, IReporter reporter) {
    if (sdRegion.isDeleted()) {
        return;
    }
    // check start/end tag pairs
    IDOMNode xmlNode = getXMLNode(sdRegion);
    if (xmlNode == null) {
        return;
    }
    boolean selfClosed = false;
    String tagName = null;
    /**
     * For tags that aren't meant to be EMPTY, make sure it's empty or has an end tag
     */
    if (xmlNode.isContainer()) {
        IStructuredDocumentRegion endRegion = xmlNode.getEndStructuredDocumentRegion();
        if (endRegion == null) {
            IStructuredDocumentRegion startRegion = xmlNode.getStartStructuredDocumentRegion();
            if (startRegion != null && !startRegion.isDeleted() && DOMRegionContext.XML_TAG_OPEN.equals(startRegion.getFirstRegion().getType())) {
                // analyze the tag (check self closing)
                ITextRegionList regions = startRegion.getRegions();
                ITextRegion r = null;
                int start = sdRegion.getStart();
                int length = sdRegion.getTextLength();
                for (int i = 0; i < regions.size(); i++) {
                    r = regions.get(i);
                    if (r.getType() == DOMRegionContext.XML_TAG_NAME) {
                        tagName = sdRegion.getText(r);
                        start = sdRegion.getStartOffset(r);
                        length = r.getTextLength();
                    } else if (r.getType() == DOMRegionContext.XML_EMPTY_TAG_CLOSE) {
                        selfClosed = true;
                    }
                }
                if (!selfClosed && (tagName != null)) {
                    Object[] args = { tagName };
                    String messageText = NLS.bind(XMLUIMessages.Missing_end_tag_, args);
                    int lineNumber = getLineNumber(start);
                    IMessage message = new LocalizedMessage(SEVERITY_MISSING_END_TAG, messageText);
                    message.setOffset(start);
                    message.setLength(length);
                    message.setLineNo(lineNumber);
                    if (reporter instanceof IncrementalReporter) {
                        Object[] additionalFixInfo = getStartEndFixInfo(xmlNode, tagName, r);
                        MarkupQuickAssistProcessor processor = new MarkupQuickAssistProcessor();
                        processor.setProblemId(ProblemIDsXML.MissingEndTag);
                        processor.setAdditionalFixInfo(additionalFixInfo);
                        message.setAttribute(QUICKASSISTPROCESSOR, processor);
                        AnnotationInfo info = new AnnotationInfo(message);
                        ((IncrementalReporter) reporter).addAnnotationInfo(this, info);
                    } else {
                        reporter.addMessage(this, message);
                    }
                }
            }
        } else {
            IStructuredDocumentRegion startRegion = xmlNode.getStartStructuredDocumentRegion();
            if (startRegion == null || startRegion.isDeleted()) {
                // analyze the tag (check self closing)
                ITextRegionList regions = endRegion.getRegions();
                ITextRegion r = null;
                int start = sdRegion.getStart();
                int length = sdRegion.getTextLength();
                for (int i = 0; i < regions.size(); i++) {
                    r = regions.get(i);
                    if (r.getType() == DOMRegionContext.XML_TAG_NAME) {
                        tagName = sdRegion.getText(r);
                        start = sdRegion.getStartOffset(r);
                        length = r.getTextLength();
                    }
                }
                if (tagName != null) {
                    Object[] args = { tagName };
                    String messageText = NLS.bind(XMLUIMessages.Missing_start_tag_, args);
                    int lineNumber = getLineNumber(start);
                    IMessage message = new LocalizedMessage(SEVERITY_MISSING_START_TAG, messageText);
                    message.setOffset(start);
                    message.setLength(length);
                    message.setLineNo(lineNumber);
                    if (reporter instanceof IncrementalReporter) {
                        Object[] additionalFixInfo = getStartEndFixInfo(xmlNode, tagName, r);
                        MarkupQuickAssistProcessor processor = new MarkupQuickAssistProcessor();
                        processor.setProblemId(ProblemIDsXML.MissingStartTag);
                        processor.setAdditionalFixInfo(additionalFixInfo);
                        message.setAttribute(QUICKASSISTPROCESSOR, processor);
                        AnnotationInfo info = new AnnotationInfo(message);
                        ((IncrementalReporter) reporter).addAnnotationInfo(this, info);
                    } else {
                        reporter.addMessage(this, message);
                    }
                }
            }
        }
    } else /*
		 * Check for an end tag that has no start tag
		 */
    {
        IStructuredDocumentRegion startRegion = xmlNode.getStartStructuredDocumentRegion();
        if (startRegion == null) {
            IStructuredDocumentRegion endRegion = xmlNode.getEndStructuredDocumentRegion();
            if (!endRegion.isDeleted()) {
                // get name
                ITextRegionList regions = endRegion.getRegions();
                ITextRegion r = null;
                for (int i = 0; i < regions.size(); i++) {
                    r = regions.get(i);
                    if (r.getType() == DOMRegionContext.XML_TAG_NAME) {
                        tagName = sdRegion.getText(r);
                    }
                }
                if (!selfClosed && (tagName != null)) {
                    String messageText = XMLUIMessages.Indicate_no_grammar_specified_severities_error;
                    int start = sdRegion.getStart();
                    int lineNumber = getLineNumber(start);
                    // SEVERITY_STRUCTURE == IMessage.HIGH_SEVERITY
                    IMessage message = new LocalizedMessage(IMessage.HIGH_SEVERITY, messageText);
                    message.setOffset(start);
                    message.setLength(sdRegion.getTextLength());
                    message.setLineNo(lineNumber);
                    reporter.addMessage(this, message);
                }
            }
        }
    }
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) IMessage(org.eclipse.wst.validation.internal.provisional.core.IMessage) IncrementalReporter(org.eclipse.wst.sse.ui.internal.reconcile.validator.IncrementalReporter) 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) LocalizedMessage(org.eclipse.wst.validation.internal.operations.LocalizedMessage) AnnotationInfo(org.eclipse.wst.sse.ui.internal.reconcile.validator.AnnotationInfo)

Aggregations

AnnotationInfo (org.eclipse.wst.sse.ui.internal.reconcile.validator.AnnotationInfo)11 IncrementalReporter (org.eclipse.wst.sse.ui.internal.reconcile.validator.IncrementalReporter)11 LocalizedMessage (org.eclipse.wst.validation.internal.operations.LocalizedMessage)9 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)6 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)5 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)3 IMessage (org.eclipse.wst.validation.internal.provisional.core.IMessage)3 BadLocationException (org.eclipse.jface.text.BadLocationException)2 ITextRegionContainer (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer)1 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)1