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