use of org.eclipse.wst.validation.internal.provisional.core.IMessage in project jbosstools-hibernate by jbosstools.
the class HibernateJpaValidationMessage method buildMessage.
public static IMessage buildMessage(int defaultSeverity, String messageId, String[] parms, IResource targetObject, TextRange textRange) {
// determine whether default severity should be overridden
int severity = defaultSeverity;
int severityPreference = getProblemSeverityPreference(targetObject, messageId);
if (severityPreference != -1) {
severity = severityPreference;
}
IMessage message = new LocalMessage(severity, messageId, parms, targetObject);
message.setMarkerId(JpaProject.MARKER_TYPE);
if (textRange == null) {
// log an exception and then continue without setting location information
// At least the user will still get the validation message and will
// be able to see other validation messages with valid textRanges
// $NON-NLS-1$
HibernateJptPlugin.logException(new NullPointerException("Null text range for message ID: " + messageId));
} else {
message.setLineNo(textRange.getLineNumber());
message.setOffset(textRange.getOffset());
message.setLength(textRange.getLength());
}
return message;
}
use of org.eclipse.wst.validation.internal.provisional.core.IMessage in project webtools.sourceediting by eclipse.
the class ReconcileStepForValidator method createAnnotations.
protected IReconcileResult[] createAnnotations(AnnotationInfo[] infos) {
List annotations = new ArrayList();
for (int i = 0; i < infos.length; i++) {
AnnotationInfo info = infos[i];
IMessage validationMessage = info.getMessage();
int offset = validationMessage.getOffset();
if (offset < 0)
continue;
String messageText = null;
try {
messageText = validationMessage.getText(validationMessage.getClass().getClassLoader());
} catch (Exception t) {
// $NON-NLS-1$
Logger.logException("exception reporting message from validator", t);
continue;
}
String type = getSeverity(validationMessage);
// this position seems like it would be possibly be the wrong
// length
int length = validationMessage.getLength();
if (length >= 0) {
Position p = new Position(offset, length);
ReconcileAnnotationKey key = createKey(getPartitionType(getDocument(), offset), getScope());
// create an annotation w/ problem ID and fix info
TemporaryAnnotation annotation = new TemporaryAnnotation(p, type, messageText, key);
Object extraInfo = info.getAdditionalFixInfo();
// add quick fix information
if (extraInfo == null) {
extraInfo = validationMessage.getAttribute(QUICKASSISTPROCESSOR);
}
annotation.setAdditionalFixInfo(extraInfo);
annotation.setAttributes(validationMessage.getAttributes());
annotations.add(annotation);
}
}
return (IReconcileResult[]) annotations.toArray(new IReconcileResult[annotations.size()]);
}
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;
HTMLValidationResult result = getResult();
switch(message.getSeverity()) {
case ValidationMessage.ERROR:
severity = IMessage.HIGH_SEVERITY;
result.addError();
break;
case ValidationMessage.WARNING:
severity = IMessage.NORMAL_SEVERITY;
result.addWarning();
break;
case ValidationMessage.INFORMATION:
result.addInformation();
break;
default:
// result.addInformation();
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 HTMLValidationReporter method report.
/**
*/
public void report(ValidationMessage message) {
if (message == null || message.getSeverity() == ValidationMessage.IGNORE)
return;
IMessage mes = translateMessage(message);
if (this.reporter != null) {
this.reporter.addMessage(this.owner, mes);
} else {
if (this.file == null)
return;
// add by myself?
String id = HTMLValidator.class.getName();
String location = Integer.toString(mes.getLineNumber());
// $NON-NLS-1$
String name = "";
IPath filePath = this.file.getFullPath();
if (filePath != null) {
name = filePath.toString();
}
try {
TaskListHelper.getTaskList().addTask(id, this.file, location, mes.getId(), mes.getText(), mes.getSeverity(), name, mes.getGroupName(), mes.getOffset(), mes.getLength());
} catch (CoreException ex) {
}
}
}
use of org.eclipse.wst.validation.internal.provisional.core.IMessage in project webtools.sourceediting by eclipse.
the class JsValidator method performValidation.
void performValidation(IFile f, IReporter reporter, IStructuredModel model, boolean inBatch) {
if (model instanceof IDOMModel) {
IDOMModel domModel = (IDOMModel) model;
JsTranslationAdapterFactory.setupAdapterFactory(domModel);
IDOMDocument xmlDoc = domModel.getDocument();
JsTranslationAdapter translationAdapter = (JsTranslationAdapter) xmlDoc.getAdapterFor(IJsTranslation.class);
// translationAdapter.resourceChanged();
IJsTranslation translation = translationAdapter.getJsTranslation(false);
if (!reporter.isCancelled()) {
translation.setProblemCollectingActive(true);
translation.reconcileCompilationUnit();
List problems = translation.getProblems();
// only update task markers if the model is the same as what's on disk
boolean updateTasks = !domModel.isDirty() && f != null && f.isAccessible();
if (updateTasks) {
// remove old JavaScript task markers
try {
IMarker[] foundMarkers = f.findMarkers(JAVASCRIPT_TASK_MARKER_TYPE, true, IResource.DEPTH_ONE);
for (int i = 0; i < foundMarkers.length; i++) {
foundMarkers[i].delete();
}
} catch (CoreException e) {
Logger.logException(e);
}
}
// add new messages
for (int i = 0; i < problems.size() && !reporter.isCancelled(); i++) {
IProblem problem = (IProblem) problems.get(i);
IMessage m = createMessageFromProblem(problem, f, translation, domModel.getStructuredDocument());
if (m != null) {
if (problem.getID() == IProblem.Task) {
if (updateTasks) {
// add new JavaScript task marker
try {
IMarker task = f.createMarker(JAVASCRIPT_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);
}
}
}
}
}
}
Aggregations