Search in sources :

Example 11 with LocalizedMessage

use of org.eclipse.wst.validation.internal.operations.LocalizedMessage in project webtools.sourceediting by eclipse.

the class StreamingMarkupValidator method checkEmptyTag.

/**
 * Check that a tag has a name (<> is invalid)
 * @param token The xml tag close token
 * @param region the tag region
 * @param reporter the reporter
 */
private void checkEmptyTag(List region, IReporter reporter) {
    if (region.size() == 2) {
        // Check that the tag is not empty
        Token first = (Token) region.get(0);
        if (first.type == DOMRegionContext.XML_TAG_OPEN) {
            String messageText = XMLCoreMessages.ReconcileStepForMarkup_3;
            final int length = first.length + ((Token) region.get(1)).length;
            LocalizedMessage message = new LocalizedMessage(getPluginPreference().getInt(XMLCorePreferenceNames.MISSING_TAG_NAME), messageText);
            message.setOffset(first.offset);
            message.setLength(length);
            message.setLineNo(first.line + 1);
            getAnnotationMsg(reporter, ProblemIDsXML.EmptyTag, message, null, length);
        }
    }
}
Also used : LocalizedMessage(org.eclipse.wst.validation.internal.operations.LocalizedMessage)

Example 12 with LocalizedMessage

use of org.eclipse.wst.validation.internal.operations.LocalizedMessage in project webtools.sourceediting by eclipse.

the class StreamingMarkupValidator method checkContentBeforeProcessingInstruction.

/**
 * Checks that there is no content before the XML declaration
 * @param previousRegion the region prior to the processing instruction
 * @param reporter the reporter
 */
private void checkContentBeforeProcessingInstruction(List previousRegion, IReporter reporter) {
    if (previousRegion != null && previousRegion.size() > 0) {
        Token first = (Token) previousRegion.get(0);
        if (first.type == DOMRegionContext.XML_CONTENT && first.offset == 0) {
            // XML declaration only allowed at the start of the document
            String messageText = XMLCoreMessages.ReconcileStepForMarkup_5;
            LocalizedMessage message = new LocalizedMessage(getPluginPreference().getInt(XMLCorePreferenceNames.WHITESPACE_AT_START), messageText);
            message.setOffset(first.offset);
            message.setLength(first.length);
            message.setLineNo(first.line + 1);
            getAnnotationMsg(reporter, ProblemIDsXML.SpacesBeforePI, message, null, first.length);
        }
    }
}
Also used : LocalizedMessage(org.eclipse.wst.validation.internal.operations.LocalizedMessage)

Example 13 with LocalizedMessage

use of org.eclipse.wst.validation.internal.operations.LocalizedMessage in project webtools.sourceediting by eclipse.

the class StreamingMarkupValidator method checkAttributsInEndTag.

/**
 * Checks the end-tag region for attributes. There should be no attributes in the end tag
 * @param first the first token in the region
 * @param region the end-tag region
 * @param reporter the reporter
 */
private void checkAttributsInEndTag(Token first, List region, IReporter reporter) {
    int errors = 0;
    int start = first.offset, end = first.offset;
    final int regionLength = region.size();
    // Start at one, since we know the first token is an tag-open
    for (int i = 1; (i < regionLength) && (errors < ERROR_THRESHOLD); i++) {
        Token t = (Token) region.get(i);
        if ((t.type == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) || (t.type == DOMRegionContext.XML_TAG_ATTRIBUTE_EQUALS) || (t.type == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE)) {
            if (start == first.offset) {
                start = t.offset;
            }
            end = t.offset + t.length;
            errors++;
        }
    }
    // create one error for all attributes in the end tag
    if (errors > 0) {
        // Position p = new Position(start, end - start);
        String messageText = XMLCoreMessages.End_tag_has_attributes;
        LocalizedMessage message = new LocalizedMessage(getPluginPreference().getInt(XMLCorePreferenceNames.END_TAG_WITH_ATTRIBUTES), messageText);
        message.setOffset(start);
        message.setLength(end - start);
        message.setLineNo(first.line + 1);
        getAnnotationMsg(reporter, ProblemIDsXML.AttrsInEndTag, message, null, end - start);
    }
}
Also used : LocalizedMessage(org.eclipse.wst.validation.internal.operations.LocalizedMessage)

Example 14 with LocalizedMessage

use of org.eclipse.wst.validation.internal.operations.LocalizedMessage in project webtools.sourceediting by eclipse.

the class StreamingMarkupValidator method checkForSpaceBeforeName.

/**
 * Checks that a start tag is immediately followed by a tag name
 * @param token the token to check
 * @param previousRegion the previous region
 * @param reporter the reporter
 */
private void checkForSpaceBeforeName(Token token, List previousRegion, IReporter reporter) {
    if (previousRegion != null && previousRegion.size() == 1) {
        // Check that the start tag's name comes right after the <
        Token first = (Token) previousRegion.get(0);
        if (DOMRegionContext.XML_TAG_OPEN.equals(first.type) && token.text.trim().length() == 0) {
            final String messageText = XMLCoreMessages.ReconcileStepForMarkup_2;
            final int length = token.length;
            LocalizedMessage message = new LocalizedMessage(getPluginPreference().getInt(XMLCorePreferenceNames.WHITESPACE_BEFORE_TAGNAME), messageText);
            message.setOffset(token.offset);
            message.setLength(length);
            message.setLineNo(getLine(token));
            getAnnotationMsg(reporter, ProblemIDsXML.SpacesBeforeTagName, message, null, length);
        }
    }
}
Also used : LocalizedMessage(org.eclipse.wst.validation.internal.operations.LocalizedMessage)

Example 15 with LocalizedMessage

use of org.eclipse.wst.validation.internal.operations.LocalizedMessage in project webtools.sourceediting by eclipse.

the class StreamingMarkupValidator method checkForTagClose.

/**
 * Check that when a start- or end-tag has been opened it is properly closed
 * @param previousRegion the previous region
 * @param reporter the reporter
 */
private void checkForTagClose(List previousRegion, IReporter reporter) {
    if (previousRegion != null && previousRegion.size() > 0) {
        final Token first = (Token) previousRegion.get(0);
        // If the previous region was a start- or end-tag, look for the tag close
        if (first.type == DOMRegionContext.XML_TAG_OPEN || first.type == DOMRegionContext.XML_END_TAG_OPEN) {
            final int length = previousRegion.size();
            boolean isClosed = false;
            int textLength = first.length;
            for (int i = 1; i < length; i++) {
                Token t = (Token) previousRegion.get(i);
                // Valid tag closings, EMPTY_TAG_CLOSE only works for a start tag, though
                if ((t.type == DOMRegionContext.XML_EMPTY_TAG_CLOSE && first.type == DOMRegionContext.XML_TAG_OPEN) || t.type == DOMRegionContext.XML_TAG_CLOSE) {
                    isClosed = true;
                    break;
                } else if (t.type == DOMRegionContext.XML_TAG_NAME) {
                    textLength += t.length;
                }
            }
            if (!isClosed) {
                String messageText = XMLCoreMessages.ReconcileStepForMarkup_6;
                LocalizedMessage message = new LocalizedMessage(getPluginPreference().getInt(XMLCorePreferenceNames.MISSING_CLOSING_BRACKET), messageText);
                message.setOffset(first.offset);
                message.setLength(textLength);
                message.setLineNo(getLine(first));
                getAnnotationMsg(reporter, ProblemIDsXML.MissingClosingBracket, message, null, textLength);
            }
        }
    }
}
Also used : LocalizedMessage(org.eclipse.wst.validation.internal.operations.LocalizedMessage)

Aggregations

LocalizedMessage (org.eclipse.wst.validation.internal.operations.LocalizedMessage)41 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)12 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)10 AnnotationInfo (org.eclipse.wst.sse.ui.internal.reconcile.validator.AnnotationInfo)9 IncrementalReporter (org.eclipse.wst.sse.ui.internal.reconcile.validator.IncrementalReporter)9 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)8 List (java.util.List)7 IMessage (org.eclipse.wst.validation.internal.provisional.core.IMessage)6 IReporter (org.eclipse.wst.validation.internal.provisional.core.IReporter)6 Test (org.junit.Test)5 CoreException (org.eclipse.core.runtime.CoreException)4 Message (org.eclipse.wst.validation.internal.core.Message)4 BufferedReader (java.io.BufferedReader)3 IOException (java.io.IOException)3 InputStreamReader (java.io.InputStreamReader)3 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 Stack (java.util.Stack)2 BadLocationException (org.eclipse.jface.text.BadLocationException)2 DocumentReader (org.eclipse.wst.sse.core.internal.document.DocumentReader)2