use of org.eclipse.wst.jsdt.internal.compiler.problem.DefaultProblem 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);
}
}
}
Aggregations