Search in sources :

Example 26 with LocalizedMessage

use of org.eclipse.wst.validation.internal.operations.LocalizedMessage 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 = XMLCoreMessages.ReconcileStepForMarkup_5;
            int start = prev.getStartOffset();
            int length = prev.getLength();
            LocalizedMessage message = new LocalizedMessage(getPluginPreference().getInt(XMLCorePreferenceNames.WHITESPACE_AT_START), messageText);
            message.setOffset(start);
            message.setLength(length);
            message.setLineNo(getLineNumber(start));
            getAnnotationMsg(reporter, ProblemIDsXML.SpacesBeforePI, message, null, length);
        // 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 : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) LocalizedMessage(org.eclipse.wst.validation.internal.operations.LocalizedMessage)

Example 27 with LocalizedMessage

use of org.eclipse.wst.validation.internal.operations.LocalizedMessage 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 < 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 = 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(getLineNumber(start));
        getAnnotationMsg(reporter, ProblemIDsXML.AttrsInEndTag, message, null, end - start);
    }
}
Also used : 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)

Example 28 with LocalizedMessage

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

the class MarkupValidator method checkEmptyTag.

private void checkEmptyTag(IStructuredDocumentRegion structuredDocumentRegion, IReporter reporter) {
    if (structuredDocumentRegion.isDeleted()) {
        return;
    }
    // navigate to name
    ITextRegionList regions = structuredDocumentRegion.getRegions();
    if (regions.size() == 2) {
        // missing name region
        if ((regions.get(0).getType() == DOMRegionContext.XML_TAG_OPEN) && (regions.get(1).getType() == DOMRegionContext.XML_TAG_CLOSE)) {
            String messageText = XMLCoreMessages.ReconcileStepForMarkup_3;
            int start = structuredDocumentRegion.getStartOffset();
            int length = structuredDocumentRegion.getLength();
            int lineNo = getLineNumber(start);
            LocalizedMessage message = new LocalizedMessage(getPluginPreference().getInt(XMLCorePreferenceNames.MISSING_TAG_NAME), messageText);
            message.setOffset(start);
            message.setLength(length);
            message.setLineNo(lineNo);
            getAnnotationMsg(reporter, ProblemIDsXML.EmptyTag, message, null, length);
        }
    }
}
Also used : ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) LocalizedMessage(org.eclipse.wst.validation.internal.operations.LocalizedMessage)

Example 29 with LocalizedMessage

use of org.eclipse.wst.validation.internal.operations.LocalizedMessage 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);
    getAnnotationMsg(reporter, problemId, message, attributeValueText, length);
}
Also used : LocalizedMessage(org.eclipse.wst.validation.internal.operations.LocalizedMessage)

Example 30 with LocalizedMessage

use of org.eclipse.wst.validation.internal.operations.LocalizedMessage 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 < 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 = XMLCoreMessages.ReconcileStepForMarkup_4;
                int start = structuredDocumentRegion.getStartOffset(r) + index;
                int length = piText.trim().length() - index;
                LocalizedMessage message = new LocalizedMessage(getPluginPreference().getInt(XMLCorePreferenceNames.NAMESPACE_IN_PI_TARGET), messageText);
                message.setOffset(start);
                message.setLength(length);
                message.setLineNo(getLineNumber(start));
                getAnnotationMsg(reporter, ProblemIDsXML.NamespaceInPI, message, null, length);
                errorCount++;
            }
        }
    }
}
Also used : 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)

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