use of org.eclipse.wst.validation.internal.operations.LocalizedMessage in project webtools.sourceediting by eclipse.
the class StreamingMarkupValidator method createMissingTagError.
/**
* Creates a missing tag error for the token
* @param token the token that's missing its pair tag
* @param isStartTag is the token a start tag
* @param reporter the reporter
*/
private void createMissingTagError(Token token, boolean isStartTag, IReporter reporter) {
Object[] args = { token.text };
String messageText = NLS.bind(isStartTag ? XMLCoreMessages.Missing_end_tag_ : XMLCoreMessages.Missing_start_tag_, args);
LocalizedMessage message = new LocalizedMessage(getPluginPreference().getInt(XMLCorePreferenceNames.MISSING_END_TAG), messageText);
message.setOffset(token.offset);
message.setLength(token.length);
message.setLineNo(getLine(token));
Object fixInfo = isStartTag ? (Object) getStartEndFixInfo(token.text, token) : token.text;
getAnnotationMsg(reporter, isStartTag ? ProblemIDsXML.MissingEndTag : ProblemIDsXML.MissingStartTag, message, fixInfo, token.length);
if (++tagErrorCount > ERROR_THRESHOLD) {
tagStack.clear();
tagStack = null;
}
}
use of org.eclipse.wst.validation.internal.operations.LocalizedMessage in project webtools.sourceediting by eclipse.
the class StreamingMarkupValidator method checkAttributes.
/**
* Checks that all the attribute in the start-tag have values and that those values are properly quoted
* @param region the start-tag region
* @param reporter the reporter
*/
private void checkAttributes(List region, IReporter reporter) {
int attrState = 0;
int errorCount = 0;
final int regionLength = region.size();
// Start at one, since we know the first token is an tag-open
for (int i = 1; i < regionLength && errorCount < ERROR_THRESHOLD; i++) {
Token t = (Token) region.get(i);
if (t.type == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME || t.type == DOMRegionContext.XML_TAG_CLOSE || t.type == DOMRegionContext.XML_EMPTY_TAG_CLOSE) {
// dangling name and '='
if ((attrState == 2) && (i >= 2)) {
// create annotation
Token nameRegion = (Token) region.get(i - 2);
Object[] args = { nameRegion.text };
String messageText = NLS.bind(XMLCoreMessages.Attribute__is_missing_a_value, args);
int start = nameRegion.offset;
int end = start + nameRegion.length;
LocalizedMessage message = new LocalizedMessage(getPluginPreference().getInt(XMLCorePreferenceNames.ATTRIBUTE_HAS_NO_VALUE), messageText);
message.setOffset(start);
message.setLength(nameRegion.length);
message.setLineNo(nameRegion.line + 1);
// quick fix info
Token equalsRegion = (Token) region.get(i - 2 + 1);
int insertOffset = (equalsRegion.offset + equalsRegion.length) - end;
Object[] additionalFixInfo = { nameRegion.text, new Integer(insertOffset) };
getAnnotationMsg(reporter, ProblemIDsXML.MissingAttrValue, message, additionalFixInfo, nameRegion.text.length());
errorCount++;
} else // name but no '=' (XML only)
if ((attrState == 1) && (i >= 1)) {
// create annotation
Token nameToken = (Token) region.get(i - 1);
Object[] args = { nameToken.text };
String messageText = NLS.bind(XMLCoreMessages.Attribute__has_no_value, args);
int start = nameToken.offset;
int textLength = nameToken.text.trim().length();
int lineNo = nameToken.line;
LocalizedMessage message = new LocalizedMessage(getPluginPreference().getInt(XMLCorePreferenceNames.ATTRIBUTE_HAS_NO_VALUE), messageText);
message.setOffset(start);
message.setLength(textLength);
message.setLineNo(lineNo + 1);
getAnnotationMsg(reporter, ProblemIDsXML.NoAttrValue, message, nameToken.text, textLength);
errorCount++;
}
attrState = 1;
} else if (t.type == DOMRegionContext.XML_TAG_ATTRIBUTE_EQUALS) {
attrState = 2;
} else if (t.type == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) {
attrState = 0;
// Check that there are quotes around the attribute value and that they match
final String trimmed = t.text.trim();
if (trimmed.length() > 0) {
final char q1 = trimmed.charAt(0), q2 = trimmed.charAt(trimmed.length() - 1);
if ((q1 == '\'' || q1 == '"') && (q1 != q2 || trimmed.length() == 1)) {
// missing closing quote
String message = XMLCoreMessages.ReconcileStepForMarkup_0;
addAttributeError(message, t.text, t.offset, t.length, t.line, ProblemIDsXML.Unclassified, reporter, getPluginPreference().getInt(XMLCorePreferenceNames.MISSING_CLOSING_QUOTE));
errorCount++;
} else if (q1 != '\'' && q1 != '"') {
// missing both
String message = XMLCoreMessages.ReconcileStepForMarkup_1;
addAttributeError(message, t.text, t.offset, t.length, t.line, ProblemIDsXML.AttrValueNotQuoted, reporter, getPluginPreference().getInt(XMLCorePreferenceNames.MISSING_CLOSING_QUOTE));
errorCount++;
}
}
}
}
}
use of org.eclipse.wst.validation.internal.operations.LocalizedMessage in project webtools.sourceediting by eclipse.
the class StreamingMarkupValidator 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(StreamingMarkupValidator.this, message);
XMLLineTokenizer tokenizer = null;
try {
tagStack = new Stack();
model = StructuredModelManager.getModelManager().getExistingModelForRead(file);
try {
if (model == null) {
tokenizer = new XMLLineTokenizer(new BufferedReader(new InputStreamReader(file.getContents(true), getCharset(file))));
} else {
tokenizer = new XMLLineTokenizer(new BufferedReader(new DocumentReader(model.getStructuredDocument())));
}
checkTokens(tokenizer, reporter);
} 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 StreamingMarkupValidator method checkNamespacesInProcessingInstruction.
/**
* Checks that the processing instruction name doesn't contain a namespace
* @param region the processing instruction region
* @param reporter the reporter
*/
private void checkNamespacesInProcessingInstruction(List region, IReporter reporter) {
final int regionLength = region.size();
for (int i = 0; i < regionLength; i++) {
Token t = (Token) region.get(i);
if (t.type == DOMRegionContext.XML_TAG_NAME) {
// $NON-NLS-1$
int index = t.text.indexOf(":");
if (index != -1) {
String messageText = XMLCoreMessages.ReconcileStepForMarkup_4;
int start = t.offset + index;
int length = t.text.trim().length() - index;
LocalizedMessage message = new LocalizedMessage(getPluginPreference().getInt(XMLCorePreferenceNames.NAMESPACE_IN_PI_TARGET), messageText);
message.setOffset(start);
message.setLength(length);
message.setLineNo(t.line + 1);
getAnnotationMsg(reporter, ProblemIDsXML.NamespaceInPI, message, null, length);
break;
}
}
}
}
use of org.eclipse.wst.validation.internal.operations.LocalizedMessage in project webtools.sourceediting by eclipse.
the class JSONSyntaxValidatorHelperTest method missingEndArray.
@Test
public void missingEndArray() throws Exception {
IReporter reporter = validate("[");
List messages = reporter.getMessages();
Assert.assertEquals(1, messages.size());
LocalizedMessage msg = (LocalizedMessage) messages.get(0);
assertMessage(msg, "Missing end array", 1, 1);
}
Aggregations