Search in sources :

Example 1 with LocalizedMessage

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

the class JSONSyntaxValidatorHelperTest method missingEndObjectAndBadObjectKey.

@Test
@Ignore
public void missingEndObjectAndBadObjectKey() throws Exception {
    IReporter reporter = validate("{aa");
    List messages = reporter.getMessages();
    Assert.assertEquals(2, messages.size());
    LocalizedMessage msg = (LocalizedMessage) messages.get(0);
    assertMessage(msg, "Expected object key but found undefined", 1, 1);
    msg = (LocalizedMessage) messages.get(1);
    assertMessage(msg, "Missing end object", 1, 1);
}
Also used : IReporter(org.eclipse.wst.validation.internal.provisional.core.IReporter) List(java.util.List) LocalizedMessage(org.eclipse.wst.validation.internal.operations.LocalizedMessage) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with LocalizedMessage

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

the class JSONSyntaxValidatorHelperTest method badObjectKey.

@Test
@Ignore
public void badObjectKey() throws Exception {
    IReporter reporter = validate("{aa}");
    List messages = reporter.getMessages();
    Assert.assertEquals(1, messages.size());
    LocalizedMessage msg = (LocalizedMessage) messages.get(0);
    assertMessage(msg, "Expected object key but found undefined", 1, 1);
// msg = (LocalizedMessage) messages.get(1);
// assertMessage(msg, "Unexpected token", 1, 1);
}
Also used : IReporter(org.eclipse.wst.validation.internal.provisional.core.IReporter) List(java.util.List) LocalizedMessage(org.eclipse.wst.validation.internal.operations.LocalizedMessage) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with LocalizedMessage

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

the class JSONSyntaxValidatorHelperTest method unexpectedColonInArray.

@Test
public void unexpectedColonInArray() throws Exception {
    IReporter reporter = validate("[\"a\":]");
    List messages = reporter.getMessages();
    Assert.assertEquals(1, messages.size());
    LocalizedMessage msg = (LocalizedMessage) messages.get(0);
    assertMessage(msg, "Unexpected token", 1, 1);
}
Also used : IReporter(org.eclipse.wst.validation.internal.provisional.core.IReporter) List(java.util.List) LocalizedMessage(org.eclipse.wst.validation.internal.operations.LocalizedMessage) Test(org.junit.Test)

Example 4 with LocalizedMessage

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

the class JSONSyntaxValidatorHelper method createMissingTagError.

private static void createMissingTagError(Token token, boolean isStartTag, IReporter reporter, int tagErrorCount, Stack<Token> tagStack, IValidator validator, ISeverityProvider provider) {
    boolean isArray = (token.type == JSONRegionContexts.JSON_ARRAY_OPEN || token.type == JSONRegionContexts.JSON_ARRAY_CLOSE);
    Object[] args = { token.text };
    String messageText = NLS.bind(getMessage(isStartTag, isArray), args);
    LocalizedMessage message = createMessage(token, messageText, JSONCorePreferenceNames.MISSING_BRACKET, provider);
    Object fixInfo = /*
						 * isStartTag ? (Object) getStartEndFixInfo(token.text,
						 * token) :
						 */
    token.text;
    getAnnotationMsg(reporter, isStartTag ? ProblemIDsJSON.MissingEndBracket : ProblemIDsJSON.MissingStartBracket, message, fixInfo, token.length, validator);
    if (++tagErrorCount > ERROR_THRESHOLD) {
        tagStack.clear();
    }
}
Also used : LocalizedMessage(org.eclipse.wst.validation.internal.operations.LocalizedMessage)

Example 5 with LocalizedMessage

use of org.eclipse.wst.validation.internal.operations.LocalizedMessage 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)

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