use of org.eclipse.wst.validation.internal.core.Message in project webtools.sourceediting by eclipse.
the class JSPELValidator method validateELContent.
protected void validateELContent(ITextRegionCollection container, ITextRegion elOpenRegion, Iterator elRegions, IReporter reporter, IFile file) {
int contentStart = elOpenRegion.getEnd();
int contentDocStart = container.getEndOffset(elOpenRegion);
int contentLength = container.getLength();
int regionCount = 0;
ITextRegion elRegion = null;
/* Find the EL closing region, otherwise the last region will be used to calculate the EL content text */
while (elRegions != null && elRegions.hasNext() && (regionCount++ < MAX_REGIONS)) {
elRegion = (ITextRegion) elRegions.next();
if (elRegion.getType() == DOMJSPRegionContexts.JSP_EL_CLOSE)
break;
}
String elText = container.getFullText().substring(contentStart, (elRegion != null) ? elRegion.getStart() : (contentLength - 1));
JSPELParser elParser = JSPELParser.createParser(elText);
try {
elParser.Expression();
} catch (ParseException e) {
int sev = getMessageSeverity(JSPCorePreferenceNames.VALIDATION_EL_SYNTAX);
if (sev != ValidationMessage.IGNORE) {
Token curTok = e.currentToken;
int problemStartOffset = contentDocStart + curTok.beginColumn;
Message message = new LocalizedMessage(sev, JSPCoreMessages.JSPEL_Syntax);
message.setOffset(problemStartOffset);
message.setLength(curTok.endColumn - curTok.beginColumn + 1);
message.setTargetObject(file);
reporter.addMessage(fMessageOriginator, message);
}
} catch (TokenMgrError te) {
int sev = getMessageSeverity(JSPCorePreferenceNames.VALIDATION_EL_LEXER);
if (sev != ValidationMessage.IGNORE) {
Message message = new LocalizedMessage(IMessage.NORMAL_SEVERITY, JSPCoreMessages.JSPEL_Token);
message.setOffset(contentDocStart);
message.setLength(contentLength);
message.setTargetObject(file);
reporter.addMessage(fMessageOriginator, message);
}
}
}
use of org.eclipse.wst.validation.internal.core.Message in project webtools.sourceediting by eclipse.
the class JSDTSourceValidator method validateContainer.
/**
*/
private void validateContainer(IValidationContext helper, IReporter reporter, IContainer container) {
try {
IResource[] resourceArray = container.members(false);
for (int i = 0; i < resourceArray.length; i++) {
IResource resource = resourceArray[i];
if (resource == null || reporter.isCancelled())
continue;
if (resource instanceof IFile) {
Message message = new LocalizedMessage(IMessage.LOW_SEVERITY, resource.getFullPath().toString().substring(1));
reporter.displaySubtask(this, message);
validateFile(helper, reporter, (IFile) resource, null);
} else if (resource instanceof IContainer) {
validateContainer(helper, reporter, (IContainer) resource);
}
}
} catch (CoreException ex) {
}
}
use of org.eclipse.wst.validation.internal.core.Message in project webtools.sourceediting by eclipse.
the class JSDTSourceValidator method validateFile.
/**
* @param result
*/
private void validateFile(IValidationContext helper, IReporter reporter, IFile file, ValidationResult result) {
if ((reporter != null) && (reporter.isCancelled() == true)) {
throw new OperationCanceledException();
}
if (!shouldValidate(file)) {
return;
}
char[] source = fDocument.get().toCharArray();
if (source == null) {
return;
}
parser.setSource(source);
parser.setProject(JavaScriptCore.create(file.getProject()));
JavaScriptUnit unit = (JavaScriptUnit) parser.createAST(new NullProgressMonitor());
if (unit == null) {
Message valMessage = new // $NON-NLS-1$
Message(// $NON-NLS-1$
JavaScriptUI.ID_PLUGIN, // $NON-NLS-1$
IMessage.HIGH_SEVERITY, // $NON-NLS-1$
JavaScriptUI.ID_PLUGIN + ".problem") {
/**
* @see IMessage#getText(Locale, ClassLoader)
*/
public java.lang.String getText(Locale locale, ClassLoader classLoader) {
// $NON-NLS-1$
return "AST couldn't be created due to the fatal error";
}
};
valMessage.setOffset(0);
valMessage.setLength(0);
valMessage.setLineNo(0);
reporter.addMessage(this, valMessage);
} else if (unit.getProblems().length > 0) {
for (IProblem problem : unit.getProblems()) {
final String msg = problem.getMessage();
String[] arguments = problem.getArguments();
int severity = problem.isError() ? IMessage.HIGH_SEVERITY : IMessage.ERROR_AND_WARNING;
int lineNumber = problem.getSourceLineNumber();
int sourceStart = problem.getSourceStart();
int sourceEnd = problem.getSourceEnd();
int columnNumber = (problem instanceof DefaultProblem) ? ((DefaultProblem) problem).getSourceColumnNumber() : -1;
Message valMessage = new Message(JavaScriptUI.ID_PLUGIN, severity, JavaScriptUI.ID_PLUGIN + ".problem") {
/**
* @see IMessage#getText(Locale, ClassLoader)
*/
public java.lang.String getText(Locale locale, ClassLoader classLoader) {
return msg;
}
};
Position position = sourceEnd == -1 ? calcPosition(source, sourceStart) : new Position(sourceStart, sourceEnd - sourceStart);
valMessage.setOffset(position.getOffset());
valMessage.setLength(position.getLength());
valMessage.setLineNo(lineNumber);
// System.out.println(getClass().getName() + ": " + valMessage.getLineNumber() +
// "[" + valMessage.getOffset() + ":" + valMessage.getLength() + "] : " +
// valMessage.getText() +
// "==>>>" + String.copyValueOf(source, position.getOffset(), position.getLength()) + "<<<==");
reporter.addMessage(this, valMessage);
}
}
}
use of org.eclipse.wst.validation.internal.core.Message in project webtools.sourceediting by eclipse.
the class JSPContentSourceValidator method validate.
/**
* This validate call is for the ISourceValidator partial document
* validation approach
*
* @param dirtyRegion
* @param helper
* @param reporter
* @see org.eclipse.wst.sse.ui.internal.reconcile.validator.ISourceValidator
*/
public void validate(IRegion dirtyRegion, IValidationContext helper, IReporter reporter) {
if (helper == null || fDocument == null || !fEnableSourceValidation)
return;
if ((reporter != null) && (reporter.isCancelled() == true)) {
throw new OperationCanceledException();
}
IStructuredModel model = StructuredModelManager.getModelManager().getExistingModelForRead(fDocument);
if (model == null)
// error
return;
try {
IDOMDocument document = null;
if (model instanceof IDOMModel) {
document = ((IDOMModel) model).getDocument();
}
if (document == null || !hasHTMLFeature(document))
// ignore
return;
ITextFileBuffer fb = FileBufferModelManager.getInstance().getBuffer(fDocument);
if (fb == null)
return;
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(fb.getLocation());
if (file == null || !file.exists())
return;
// this will be the wrong region if it's Text (instead of Element)
// we don't know how to validate Text
// model.getIndexedRegion(dirtyRegion.getOffset());
IndexedRegion ir = getCoveringNode(dirtyRegion);
if (ir instanceof Text) {
while (ir != null && ir instanceof Text) {
// it's assumed that this gets the IndexedRegion to
// the right of the end offset
ir = model.getIndexedRegion(ir.getEndOffset());
}
}
if (ir instanceof INodeNotifier) {
INodeAdapterFactory factory = HTMLValidationAdapterFactory.getInstance();
ValidationAdapter adapter = (ValidationAdapter) factory.adapt((INodeNotifier) ir);
if (adapter == null)
// error
return;
if (reporter != null) {
HTMLValidationReporter rep = null;
rep = getReporter(reporter, file, (IDOMModel) model);
rep.clear();
adapter.setReporter(rep);
Message mess = new LocalizedMessage(IMessage.LOW_SEVERITY, file.getFullPath().toString().substring(1));
reporter.displaySubtask(this, mess);
}
adapter.validate(ir);
}
} finally {
if (model != null)
model.releaseFromRead();
}
}
use of org.eclipse.wst.validation.internal.core.Message 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();
}
}
}
Aggregations