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