Search in sources :

Example 1 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, IJSONDocument 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);
                    SyntaxQuickAssistProcessor processor = new SyntaxQuickAssistProcessor();
                    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 2 with IncrementalReporter

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

the class MarkupValidator method checkForAttributeValue.

private void checkForAttributeValue(IStructuredDocumentRegion structuredDocumentRegion, IReporter reporter) {
    if (structuredDocumentRegion.isDeleted()) {
        return;
    }
    // check for attributes without a value
    // track the attribute/equals/value sequence using a state of 0, 1 ,2
    // representing the name, =, and value, respectively
    int attrState = 0;
    ITextRegionList textRegions = structuredDocumentRegion.getRegions();
    // ReconcileAnnotationKey key = createKey(structuredDocumentRegion,
    // getScope());
    int errorCount = 0;
    for (int i = 0; (i < textRegions.size()) && (errorCount < AbstractStructuredTextReconcilingStrategy.ELEMENT_ERROR_LIMIT); i++) {
        ITextRegion textRegion = textRegions.get(i);
        if ((textRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) || isTagCloseTextRegion(textRegion)) {
            // dangling name and '='
            if ((attrState == 2) && (i >= 2)) {
                // create annotation
                ITextRegion nameRegion = textRegions.get(i - 2);
                if (!(nameRegion instanceof ITextRegionContainer)) {
                    Object[] args = { structuredDocumentRegion.getText(nameRegion) };
                    String messageText = NLS.bind(XMLUIMessages.Attribute__is_missing_a_value, args);
                    int start = structuredDocumentRegion.getStartOffset(nameRegion);
                    int end = structuredDocumentRegion.getEndOffset();
                    int lineNo = getLineNumber(start);
                    int textLength = structuredDocumentRegion.getText(nameRegion).trim().length();
                    LocalizedMessage message = new LocalizedMessage(SEVERITY_ATTRIBUTE_HAS_NO_VALUE, messageText);
                    message.setOffset(start);
                    message.setLength(textLength);
                    message.setLineNo(lineNo);
                    // quick fix info
                    ITextRegion equalsRegion = textRegions.get(i - 2 + 1);
                    int insertOffset = structuredDocumentRegion.getTextEndOffset(equalsRegion) - end;
                    Object[] additionalFixInfo = { structuredDocumentRegion.getText(nameRegion), new Integer(insertOffset) };
                    if (reporter instanceof IncrementalReporter) {
                        MarkupQuickAssistProcessor processor = new MarkupQuickAssistProcessor();
                        processor.setProblemId(ProblemIDsXML.MissingAttrValue);
                        processor.setAdditionalFixInfo(additionalFixInfo);
                        message.setAttribute(QUICKASSISTPROCESSOR, processor);
                        AnnotationInfo info = new AnnotationInfo(message);
                        ((IncrementalReporter) reporter).addAnnotationInfo(this, info);
                    } else {
                        reporter.addMessage(this, message);
                    }
                    errorCount++;
                }
            } else // name but no '=' (XML only)
            if ((attrState == 1) && (i >= 1)) {
                // create annotation
                ITextRegion previousRegion = textRegions.get(i - 1);
                if (!(previousRegion instanceof ITextRegionContainer)) {
                    Object[] args = { structuredDocumentRegion.getText(previousRegion) };
                    String messageText = NLS.bind(XMLUIMessages.Attribute__has_no_value, args);
                    int start = structuredDocumentRegion.getStartOffset(previousRegion);
                    int textLength = structuredDocumentRegion.getText(previousRegion).trim().length();
                    int lineNo = getLineNumber(start);
                    LocalizedMessage message = new LocalizedMessage(SEVERITY_ATTRIBUTE_HAS_NO_VALUE, messageText);
                    message.setOffset(start);
                    message.setLength(textLength);
                    message.setLineNo(lineNo);
                    if (reporter instanceof IncrementalReporter) {
                        MarkupQuickAssistProcessor processor = new MarkupQuickAssistProcessor();
                        processor.setProblemId(ProblemIDsXML.NoAttrValue);
                        processor.setAdditionalFixInfo(structuredDocumentRegion.getText(previousRegion));
                        message.setAttribute(QUICKASSISTPROCESSOR, processor);
                        AnnotationInfo info = new AnnotationInfo(message);
                        ((IncrementalReporter) reporter).addAnnotationInfo(this, info);
                    } else {
                        reporter.addMessage(this, message);
                    }
                    errorCount++;
                }
            }
            attrState = 1;
        } else if (textRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_EQUALS) {
            attrState = 2;
        } else if (textRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) {
            attrState = 0;
        }
    }
}
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) ITextRegionContainer(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer) LocalizedMessage(org.eclipse.wst.validation.internal.operations.LocalizedMessage) AnnotationInfo(org.eclipse.wst.sse.ui.internal.reconcile.validator.AnnotationInfo)

Example 3 with IncrementalReporter

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

the class MarkupValidator method checkNoNamespaceInPI.

private void checkNoNamespaceInPI(IStructuredDocumentRegion structuredDocumentRegion, IReporter reporter) {
    if (structuredDocumentRegion.isDeleted()) {
        return;
    }
    // navigate to name
    ITextRegionList regions = structuredDocumentRegion.getRegions();
    ITextRegion r = null;
    int errorCount = 0;
    for (int i = 0; (i < regions.size()) && (errorCount < AbstractStructuredTextReconcilingStrategy.ELEMENT_ERROR_LIMIT) && !structuredDocumentRegion.isDeleted(); i++) {
        r = regions.get(i);
        if (r.getType() == DOMRegionContext.XML_TAG_NAME) {
            String piText = structuredDocumentRegion.getText(r);
            // $NON-NLS-1$
            int index = piText.indexOf(":");
            if (index != -1) {
                String messageText = XMLUIMessages.ReconcileStepForMarkup_4;
                int start = structuredDocumentRegion.getStartOffset(r) + index;
                int length = piText.trim().length() - index;
                LocalizedMessage message = new LocalizedMessage(SEVERITY_NAMESPACE_IN_PI_TARGET, messageText);
                message.setOffset(start);
                message.setLength(length);
                message.setLineNo(getLineNumber(start));
                if (reporter instanceof IncrementalReporter) {
                    MarkupQuickAssistProcessor processor = new MarkupQuickAssistProcessor();
                    processor.setProblemId(ProblemIDsXML.NamespaceInPI);
                    message.setAttribute(QUICKASSISTPROCESSOR, processor);
                    AnnotationInfo info = new AnnotationInfo(message);
                    ((IncrementalReporter) reporter).addAnnotationInfo(this, info);
                } else {
                    reporter.addMessage(this, message);
                }
                errorCount++;
            }
        }
    }
}
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 4 with IncrementalReporter

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

the class MarkupValidator method addAttributeError.

private void addAttributeError(String messageText, String attributeValueText, int start, int length, int problemId, IStructuredDocumentRegion sdRegion, IReporter reporter, int messageSeverity) {
    if (sdRegion.isDeleted()) {
        return;
    }
    int lineNo = getLineNumber(start);
    LocalizedMessage message = new LocalizedMessage(messageSeverity, messageText);
    message.setOffset(start);
    message.setLength(length);
    message.setLineNo(lineNo);
    if (reporter instanceof IncrementalReporter) {
        MarkupQuickAssistProcessor processor = new MarkupQuickAssistProcessor();
        processor.setProblemId(problemId);
        processor.setAdditionalFixInfo(attributeValueText);
        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) LocalizedMessage(org.eclipse.wst.validation.internal.operations.LocalizedMessage) AnnotationInfo(org.eclipse.wst.sse.ui.internal.reconcile.validator.AnnotationInfo)

Example 5 with IncrementalReporter

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

the class MarkupValidator method checkForSpaceBeforeName.

private void checkForSpaceBeforeName(IStructuredDocumentRegion structuredDocumentRegion, IReporter reporter) {
    if (structuredDocumentRegion.isDeleted()) {
        return;
    }
    String sdRegionText = structuredDocumentRegion.getFullText();
    if (sdRegionText.startsWith(" ")) {
        // $NON-NLS-1$
        IStructuredDocumentRegion prev = structuredDocumentRegion.getPrevious();
        if (prev != null) {
            // this is possibly the case of "< tag"
            if ((prev.getRegions().size() == 1) && isStartTag(prev)) {
                // add the error for preceding space in tag name
                String messageText = XMLUIMessages.ReconcileStepForMarkup_2;
                int start = structuredDocumentRegion.getStartOffset();
                // find length of whitespace
                // $NON-NLS-1$
                int length = sdRegionText.trim().equals("") ? sdRegionText.length() : sdRegionText.indexOf(sdRegionText.trim());
                LocalizedMessage message = new LocalizedMessage(SEVERITY_INVALID_WHITESPACE_BEFORE_TAGNAME, messageText);
                message.setOffset(start);
                message.setLength(length);
                message.setLineNo(getLineNumber(start));
                if (reporter instanceof IncrementalReporter) {
                    MarkupQuickAssistProcessor processor = new MarkupQuickAssistProcessor();
                    processor.setProblemId(ProblemIDsXML.SpacesBeforeTagName);
                    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) 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)

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