Search in sources :

Example 1 with Message

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);
        }
    }
}
Also used : ValidationMessage(org.eclipse.wst.sse.core.internal.validate.ValidationMessage) IMessage(org.eclipse.wst.validation.internal.provisional.core.IMessage) Message(org.eclipse.wst.validation.internal.core.Message) JSPELParser(org.eclipse.jst.jsp.core.internal.java.jspel.JSPELParser) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) Token(org.eclipse.jst.jsp.core.internal.java.jspel.Token) TokenMgrError(org.eclipse.jst.jsp.core.internal.java.jspel.TokenMgrError) ParseException(org.eclipse.jst.jsp.core.internal.java.jspel.ParseException)

Example 2 with 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) {
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IMessage(org.eclipse.wst.validation.internal.provisional.core.IMessage) Message(org.eclipse.wst.validation.internal.core.Message) CoreException(org.eclipse.core.runtime.CoreException) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource)

Example 3 with Message

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);
        }
    }
}
Also used : Locale(java.util.Locale) JavaScriptUnit(org.eclipse.wst.jsdt.core.dom.JavaScriptUnit) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IMessage(org.eclipse.wst.validation.internal.provisional.core.IMessage) Message(org.eclipse.wst.validation.internal.core.Message) Position(org.eclipse.jface.text.Position) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) IProblem(org.eclipse.wst.jsdt.core.compiler.IProblem) DefaultProblem(org.eclipse.wst.jsdt.internal.compiler.problem.DefaultProblem)

Example 4 with Message

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();
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IMessage(org.eclipse.wst.validation.internal.provisional.core.IMessage) Message(org.eclipse.wst.validation.internal.core.Message) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) Text(org.w3c.dom.Text) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion) INodeAdapterFactory(org.eclipse.wst.sse.core.internal.provisional.INodeAdapterFactory) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) ValidationAdapter(org.eclipse.wst.sse.core.internal.validate.ValidationAdapter) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) INodeNotifier(org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)

Example 5 with Message

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();
        }
    }
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) IMessage(org.eclipse.wst.validation.internal.provisional.core.IMessage) LocalizedMessage(org.eclipse.wst.validation.internal.operations.LocalizedMessage) Message(org.eclipse.wst.validation.internal.core.Message) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) ValidationException(org.eclipse.wst.validation.internal.core.ValidationException) CoreException(org.eclipse.core.runtime.CoreException) BadLocationException(org.eclipse.jface.text.BadLocationException) LocalizedMessage(org.eclipse.wst.validation.internal.operations.LocalizedMessage)

Aggregations

Message (org.eclipse.wst.validation.internal.core.Message)19 IMessage (org.eclipse.wst.validation.internal.provisional.core.IMessage)17 CoreException (org.eclipse.core.runtime.CoreException)10 IFile (org.eclipse.core.resources.IFile)8 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)5 IResource (org.eclipse.core.resources.IResource)4 LocalizedMessage (org.eclipse.wst.validation.internal.operations.LocalizedMessage)4 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)3 Path (org.eclipse.core.runtime.Path)3 BufferedReader (java.io.BufferedReader)2 IOException (java.io.IOException)2 InputStreamReader (java.io.InputStreamReader)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 ITextFileBuffer (org.eclipse.core.filebuffers.ITextFileBuffer)2 IContainer (org.eclipse.core.resources.IContainer)2 IProject (org.eclipse.core.resources.IProject)2 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)2 IPath (org.eclipse.core.runtime.IPath)2 BadLocationException (org.eclipse.jface.text.BadLocationException)2 JSPELParser (org.eclipse.jst.jsp.core.internal.java.jspel.JSPELParser)2