Search in sources :

Example 36 with LocalizedMessage

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

the class JSONSyntaxValidatorHelperTest method missingEndObject.

@Test
public void missingEndObject() throws Exception {
    IReporter reporter = validate("{");
    List messages = reporter.getMessages();
    Assert.assertEquals(1, messages.size());
    LocalizedMessage msg = (LocalizedMessage) messages.get(0);
    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) Test(org.junit.Test)

Example 37 with LocalizedMessage

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

the class JSONSyntaxValidator method validateFile.

/**
 * Validates the given file. It will stream the contents of the file without
 * creating a model for the file; it will only use existing
 *
 * @param file
 *            the file to validate
 * @param reporter
 *            the reporter
 */
private void validateFile(IFile file, IReporter reporter) {
    Message message = new LocalizedMessage(IMessage.LOW_SEVERITY, file.getFullPath().toString().substring(1));
    reporter.displaySubtask(JSONSyntaxValidator.this, message);
    JSONLineTokenizer tokenizer = null;
    try {
        IStructuredModel model = StructuredModelManager.getModelManager().getExistingModelForRead(file);
        try {
            if (model == null) {
                tokenizer = new JSONLineTokenizer(new BufferedReader(new InputStreamReader(file.getContents(true), getCharset(file))));
            } else {
                tokenizer = new JSONLineTokenizer(new BufferedReader(new DocumentReader(model.getStructuredDocument())));
            }
            JSONSyntaxValidatorHelper.validate(tokenizer, reporter, this, this);
        } finally {
            if (model != null) {
                model.releaseFromRead();
                model = null;
            }
        }
    } catch (UnsupportedEncodingException e) {
    } catch (CoreException e) {
    } catch (IOException e) {
    }
}
Also used : JSONLineTokenizer(org.eclipse.wst.json.core.internal.parser.JSONLineTokenizer) IMessage(org.eclipse.wst.validation.internal.provisional.core.IMessage) LocalizedMessage(org.eclipse.wst.validation.internal.operations.LocalizedMessage) Message(org.eclipse.wst.validation.internal.core.Message) InputStreamReader(java.io.InputStreamReader) CoreException(org.eclipse.core.runtime.CoreException) BufferedReader(java.io.BufferedReader) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) DocumentReader(org.eclipse.wst.sse.core.internal.document.DocumentReader) IOException(java.io.IOException) LocalizedMessage(org.eclipse.wst.validation.internal.operations.LocalizedMessage)

Example 38 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 = 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 39 with LocalizedMessage

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

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

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