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);
}
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) {
}
}
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);
}
}
}
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);
}
}
}
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);
}
}
}
}
}
Aggregations