use of org.eclipse.wst.validation.internal.provisional.core.IMessage in project webtools.sourceediting by eclipse.
the class JsValidator method validate.
public void validate(IValidationContext helper, IReporter reporter) throws ValidationException {
/* Added by BC ---- */
// if(true) return;
/* end Added by BC ---- */
String[] uris = helper.getURIs();
if (uris.length > 0) {
IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot();
IFile currentFile = null;
for (int i = 0; i < uris.length && !reporter.isCancelled(); i++) {
currentFile = wsRoot.getFile(new Path(uris[i]));
reporter.removeAllMessages(this, currentFile);
if (currentFile != null && currentFile.exists()) {
if (shouldValidate(currentFile)) {
// && fragmentCheck(currentFile)) {
int percent = (i * 100) / uris.length + 1;
// $NON-NLS-1$
IMessage message = new LocalizedMessage(IMessage.LOW_SEVERITY, percent + "% " + uris[i]);
reporter.displaySubtask(this, message);
validateFile(currentFile, reporter);
}
if (DEBUG) {
// $NON-NLS-1$ //$NON-NLS-2$
System.out.println("validating: [" + uris[i] + "]");
}
}
}
} else {
// if uris[] length 0 -> validate() gets called for each project
if (helper instanceof IWorkbenchContext) {
IProject project = ((IWorkbenchContext) helper).getProject();
JSFileVisitor visitor = new JSFileVisitor(reporter);
try {
// collect all jsp files for the project
project.accept(visitor, IResource.DEPTH_INFINITE);
} catch (CoreException e) {
if (DEBUG) {
e.printStackTrace();
}
}
IFile[] files = visitor.getFiles();
for (int i = 0; i < files.length && !reporter.isCancelled(); i++) {
int percent = (i * 100) / files.length + 1;
// $NON-NLS-1$
IMessage message = new LocalizedMessage(IMessage.LOW_SEVERITY, percent + "% " + files[i].getFullPath().toString());
reporter.displaySubtask(this, message);
validateFile(files[i], reporter);
if (DEBUG) {
// $NON-NLS-1$ //$NON-NLS-2$
System.out.println("validating: [" + files[i] + "]");
}
}
}
}
}
use of org.eclipse.wst.validation.internal.provisional.core.IMessage in project webtools.sourceediting by eclipse.
the class HTMLValidationReporter method translateMessage.
/**
* Translate ValidationMessage to IMessage and generate result log
*/
private IMessage translateMessage(ValidationMessage message) {
int severity = IMessage.LOW_SEVERITY;
switch(message.getSeverity()) {
case ValidationMessage.ERROR:
severity = IMessage.HIGH_SEVERITY;
break;
case ValidationMessage.WARNING:
severity = IMessage.NORMAL_SEVERITY;
break;
case ValidationMessage.INFORMATION:
break;
default:
break;
}
IMessage mes = new LocalizedMessage(severity, message.getMessage(), this.file);
mes.setOffset(message.getOffset());
mes.setLength(message.getLength());
if (this.model != null) {
IStructuredDocument flatModel = this.model.getStructuredDocument();
if (flatModel != null) {
int line = flatModel.getLineOfOffset(message.getOffset());
mes.setLineNo(line + 1);
}
}
return mes;
}
use of org.eclipse.wst.validation.internal.provisional.core.IMessage in project webtools.sourceediting by eclipse.
the class JSPJavaValidator method performValidation.
void performValidation(IFile f, IReporter reporter, IStructuredModel model) {
for (int i = 0; i < DEPEND_ONs.length; i++) {
addDependsOn(f.getProject().getFile(DEPEND_ONs[i]));
}
if (model instanceof IDOMModel) {
IDOMModel domModel = (IDOMModel) model;
ModelHandlerForJSP.ensureTranslationAdapterFactory(domModel);
IDOMDocument xmlDoc = domModel.getDocument();
JSPTranslationAdapter translationAdapter = (JSPTranslationAdapter) xmlDoc.getAdapterFor(IJSPTranslation.class);
IJSPTranslation translation = translationAdapter.getJSPTranslation();
if (!reporter.isCancelled()) {
loadPreferences(f);
// only update task markers if the model is the same as what's on disk
boolean updateJavaTasks = UPDATE_JAVA_TASKS && !domModel.isDirty() && f != null && f.isAccessible();
if (updateJavaTasks) {
// remove old Java task markers
try {
IMarker[] foundMarkers = f.findMarkers(JAVA_TASK_MARKER_TYPE, true, IResource.DEPTH_ONE);
for (int i = 0; i < foundMarkers.length; i++) {
foundMarkers[i].delete();
}
} catch (CoreException e) {
Logger.logException(e);
}
}
translation.setProblemCollectingActive(true);
translation.reconcileCompilationUnit();
List problems = translation.getProblems();
// add new messages
for (int i = 0; i < problems.size() && !reporter.isCancelled(); i++) {
IProblem problem = (IProblem) problems.get(i);
/*
* Possible error in problem collection; EL translation is
* extensible, so we must be paranoid about this.
*/
if (problem == null)
continue;
IMessage m = createMessageFromProblem(problem, f, translation, domModel.getStructuredDocument());
if (m != null) {
if (problem.getID() == IProblem.Task) {
if (updateJavaTasks) {
// add new Java task marker
try {
IMarker task = f.createMarker(JAVA_TASK_MARKER_TYPE);
task.setAttribute(IMarker.LINE_NUMBER, new Integer(m.getLineNumber()));
task.setAttribute(IMarker.CHAR_START, new Integer(m.getOffset()));
task.setAttribute(IMarker.CHAR_END, new Integer(m.getOffset() + m.getLength()));
task.setAttribute(IMarker.MESSAGE, m.getText());
task.setAttribute(IMarker.USER_EDITABLE, Boolean.FALSE);
switch(m.getSeverity()) {
case IMessage.HIGH_SEVERITY:
{
task.setAttribute(IMarker.PRIORITY, new Integer(IMarker.PRIORITY_HIGH));
task.setAttribute(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR));
}
break;
case IMessage.LOW_SEVERITY:
{
task.setAttribute(IMarker.PRIORITY, new Integer(IMarker.PRIORITY_LOW));
task.setAttribute(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO));
}
break;
default:
{
task.setAttribute(IMarker.PRIORITY, new Integer(IMarker.PRIORITY_NORMAL));
task.setAttribute(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_WARNING));
}
}
} catch (CoreException e) {
Logger.logException(e);
}
}
} else {
reporter.addMessage(fMessageOriginator, m);
}
}
}
}
}
unloadPreferences();
}
use of org.eclipse.wst.validation.internal.provisional.core.IMessage in project webtools.sourceediting by eclipse.
the class DelegatingSourceValidator method updateValidationMessages.
/**
* iterates through the messages and calculates a "better" offset and
* length
*
* @param messages -
* a List of IMessages
* @param document -
* the document
* @param reporter -
* the reporter the messages are to be added to
*/
protected void updateValidationMessages(List messages, IJSONDocument document, IReporter reporter) {
for (int i = 0; i < messages.size(); i++) {
IMessage message = (IMessage) messages.get(i);
try {
if (message.getAttribute(COLUMN_NUMBER_ATTRIBUTE) != null) {
int column = ((Integer) message.getAttribute(COLUMN_NUMBER_ATTRIBUTE)).intValue();
if (message.getAttribute(AnnotationMsg.PROBMLEM_ID) != null && reporter instanceof IncrementalReporter) {
Integer problemId = (Integer) message.getAttribute(AnnotationMsg.PROBMLEM_ID);
SyntaxQuickAssistProcessor processor = new SyntaxQuickAssistProcessor();
processor.setProblemId(problemId.intValue());
message.setOffset(column);
Integer length = (Integer) message.getAttribute(AnnotationMsg.LENGTH);
message.setLength(length.intValue());
Object attrValue = message.getAttribute(AnnotationMsg.ATTRVALUETEXT);
if (attrValue != null)
processor.setAdditionalFixInfo(attrValue);
else {
Object attrValueNo = message.getAttribute(AnnotationMsg.ATTRVALUENO);
if (attrValueNo != null) {
int len = ((Integer) attrValueNo).intValue();
Object[] objArray = new Object[len];
for (int j = 0; j < len; j++) {
objArray[j] = message.getAttribute(AnnotationMsg.ATTRNO + j);
}
processor.setAdditionalFixInfo(objArray);
}
}
message.setAttribute(QUICKASSISTPROCESSOR, processor);
AnnotationInfo info = new AnnotationInfo(message);
((IncrementalReporter) reporter).addAnnotationInfo(this, info);
} else {
String selectionStrategy = (String) message.getAttribute(SQUIGGLE_SELECTION_STRATEGY_ATTRIBUTE);
String nameOrValue = (String) message.getAttribute(SQUIGGLE_NAME_OR_VALUE_ATTRIBUTE);
// convert the line and Column numbers to an offset:
int start = document.getStructuredDocument().getLineOffset(message.getLineNumber() - 1) + column - 1;
int[] result = computeStartAndEndLocation(start, selectionStrategy, getErrorSide(message), nameOrValue, document);
if (result != null) {
message.setOffset(result[0]);
message.setLength(result[1] - result[0]);
reporter.addMessage(this, message);
}
}
}
} catch (BadLocationException e) {
// this exception should not
// occur - it is thrown if
// trying to convert an
// invalid line number to and
// offset
}
}
}
use of org.eclipse.wst.validation.internal.provisional.core.IMessage 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