Search in sources :

Example 6 with LocalizedMessage

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

the class MarkupValidator method validateV1File.

/**
 * @param currentFile
 * @param reporter
 */
private void validateV1File(IFile currentFile, IReporter reporter) {
    Message message = new LocalizedMessage(IMessage.LOW_SEVERITY, currentFile.getFullPath().toString().substring(1));
    reporter.displaySubtask(MarkupValidator.this, message);
    IStructuredModel model = null;
    try {
        model = StructuredModelManager.getModelManager().getModelForRead(currentFile);
        IStructuredDocument document = null;
        if (model != null) {
            document = model.getStructuredDocument();
            connect(document);
            IStructuredDocumentRegion validationRegion = document.getFirstStructuredDocumentRegion();
            while (validationRegion != null) {
                validate(validationRegion, reporter);
                validationRegion = validationRegion.getNext();
            }
            disconnect(document);
        }
    } catch (Exception e) {
        Logger.logException(e);
    } finally {
        if (model != null) {
            model.releaseFromRead();
        }
    }
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) 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) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) ValidationException(org.eclipse.wst.validation.internal.core.ValidationException) CoreException(org.eclipse.core.runtime.CoreException) BadLocationException(org.eclipse.jface.text.BadLocationException) LocalizedMessage(org.eclipse.wst.validation.internal.operations.LocalizedMessage)

Example 7 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 < 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 8 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);
    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 9 with LocalizedMessage

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

Example 10 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 < AbstractStructuredTextReconcilingStrategy.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 = XMLUIMessages.End_tag_has_attributes;
        LocalizedMessage message = new LocalizedMessage(SEVERITY_END_TAG_WITH_ATTRIBUTES, messageText);
        message.setOffset(start);
        message.setLength(end - start);
        message.setLineNo(getLineNumber(start));
        if (reporter instanceof IncrementalReporter) {
            MarkupQuickAssistProcessor processor = new MarkupQuickAssistProcessor();
            processor.setProblemId(ProblemIDsXML.AttrsInEndTag);
            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)

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