Search in sources :

Example 1 with IMessage

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;
}
Also used : IMessage(org.eclipse.wst.validation.internal.provisional.core.IMessage)

Example 2 with IMessage

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()]);
}
Also used : Position(org.eclipse.jface.text.Position) IReconcileResult(org.eclipse.jface.text.reconciler.IReconcileResult) IReconcileAnnotationKey(org.eclipse.wst.sse.ui.internal.reconcile.IReconcileAnnotationKey) ReconcileAnnotationKey(org.eclipse.wst.sse.ui.internal.reconcile.ReconcileAnnotationKey) IMessage(org.eclipse.wst.validation.internal.provisional.core.IMessage) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) TemporaryAnnotation(org.eclipse.wst.sse.ui.internal.reconcile.TemporaryAnnotation)

Example 3 with IMessage

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;
}
Also used : IMessage(org.eclipse.wst.validation.internal.provisional.core.IMessage) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)

Example 4 with IMessage

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) {
        }
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) CoreException(org.eclipse.core.runtime.CoreException) IMessage(org.eclipse.wst.validation.internal.provisional.core.IMessage)

Example 5 with IMessage

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);
                    }
                }
            }
        }
    }
}
Also used : IJsTranslation(org.eclipse.wst.jsdt.web.core.javascript.IJsTranslation) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IMessage(org.eclipse.wst.validation.internal.provisional.core.IMessage) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) JsTranslationAdapter(org.eclipse.wst.jsdt.web.core.javascript.JsTranslationAdapter) IProblem(org.eclipse.wst.jsdt.core.compiler.IProblem) CoreException(org.eclipse.core.runtime.CoreException) ArrayList(java.util.ArrayList) List(java.util.List) IMarker(org.eclipse.core.resources.IMarker)

Aggregations

IMessage (org.eclipse.wst.validation.internal.provisional.core.IMessage)25 CoreException (org.eclipse.core.runtime.CoreException)7 List (java.util.List)6 Iterator (java.util.Iterator)5 IPath (org.eclipse.core.runtime.IPath)5 Path (org.eclipse.core.runtime.Path)5 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)4 ArrayList (java.util.ArrayList)3 IFile (org.eclipse.core.resources.IFile)3 BadLocationException (org.eclipse.jface.text.BadLocationException)3 Position (org.eclipse.jface.text.Position)3 JSPDirectiveValidator (org.eclipse.jst.jsp.core.internal.validation.JSPDirectiveValidator)3 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)3 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)3 AnnotationInfo (org.eclipse.wst.sse.ui.internal.reconcile.validator.AnnotationInfo)3 IncrementalReporter (org.eclipse.wst.sse.ui.internal.reconcile.validator.IncrementalReporter)3 IReporter (org.eclipse.wst.validation.internal.provisional.core.IReporter)3 IOException (java.io.IOException)2 IMarker (org.eclipse.core.resources.IMarker)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2