Search in sources :

Example 31 with IReporter

use of org.eclipse.wst.validation.internal.provisional.core.IReporter in project webtools.sourceediting by eclipse.

the class JSONSyntaxValidatorHelperTest method objectsInArray.

@Test
public void objectsInArray() throws Exception {
    IReporter reporter = validate("[{},{}]");
    List messages = reporter.getMessages();
    Assert.assertEquals(0, messages.size());
}
Also used : IReporter(org.eclipse.wst.validation.internal.provisional.core.IReporter) List(java.util.List) Test(org.junit.Test)

Example 32 with IReporter

use of org.eclipse.wst.validation.internal.provisional.core.IReporter in project webtools.sourceediting by eclipse.

the class JSONSyntaxValidatorHelperTest method missingEndArray.

@Test
public void missingEndArray() throws Exception {
    IReporter reporter = validate("[");
    List messages = reporter.getMessages();
    Assert.assertEquals(1, messages.size());
    LocalizedMessage msg = (LocalizedMessage) messages.get(0);
    assertMessage(msg, "Missing end array", 1, 1);
}
Also used : IReporter(org.eclipse.wst.validation.internal.provisional.core.IReporter) List(java.util.List) LocalizedMessage(org.eclipse.wst.validation.internal.operations.LocalizedMessage) Test(org.junit.Test)

Example 33 with IReporter

use of org.eclipse.wst.validation.internal.provisional.core.IReporter in project webtools.sourceediting by eclipse.

the class JSONSyntaxValidatorHelperTest method missingEndObject.

@Test
public void missingEndObject() throws Exception {
    IReporter reporter = validate("{");
    List messages = reporter.getMessages();
    Assert.assertEquals(1, messages.size());
    LocalizedMessage msg = (LocalizedMessage) messages.get(0);
    assertMessage(msg, "Missing end object", 1, 1);
}
Also used : IReporter(org.eclipse.wst.validation.internal.provisional.core.IReporter) List(java.util.List) LocalizedMessage(org.eclipse.wst.validation.internal.operations.LocalizedMessage) Test(org.junit.Test)

Example 34 with IReporter

use of org.eclipse.wst.validation.internal.provisional.core.IReporter in project webtools.sourceediting by eclipse.

the class JSONValidator method executeMarkupValidator.

private IReporter executeMarkupValidator(String uri) {
    Path path = new Path(uri);
    // $NON-NLS-1$
    String fileProtocol = "file://";
    int index = uri.indexOf(fileProtocol);
    IFile resource = null;
    if (index == 0) {
        String transformedUri = uri.substring(fileProtocol.length());
        Path transformedPath = new Path(transformedUri);
        resource = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(transformedPath);
    } else {
        resource = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
    }
    IReporter reporter = null;
    if (resource != null) {
        reporter = val.validate(resource, 0, new ValOperation().getState());
    }
    return reporter;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) IReporter(org.eclipse.wst.validation.internal.provisional.core.IReporter) ValOperation(org.eclipse.wst.validation.internal.ValOperation)

Example 35 with IReporter

use of org.eclipse.wst.validation.internal.provisional.core.IReporter in project webtools.sourceediting by eclipse.

the class AbstractNestedValidator method validate.

/**
 * Perform the validation using version 2 of the validation framework.
 */
@Override
public ValidationResult validate(IResource resource, int kind, ValidationState state, IProgressMonitor monitor) {
    ValidationResult result = new ValidationResult();
    IFile file = null;
    if (resource instanceof IFile)
        file = (IFile) resource;
    if (file != null && shouldValidate(file)) {
        IReporter reporter = result.getReporter(monitor);
        NestedValidatorContext nestedcontext = getNestedContext(state, false);
        boolean teardownRequired = false;
        if (nestedcontext == null) {
            // validationstart was not called, so manually setup and tear
            // down
            nestedcontext = getNestedContext(state, true);
            nestedcontext.setProject(file.getProject());
            setupValidation(nestedcontext);
            teardownRequired = true;
        } else {
            nestedcontext.setProject(file.getProject());
        }
        InputStream inputStream = null;
        try {
            inputStream = file.getContents();
            validate(file, inputStream, result, reporter, nestedcontext);
            List messages = reporter.getMessages();
            for (Object object : messages) {
                if (object instanceof IMessage) {
                    IMessage message = (IMessage) object;
                    message.setLineNo(message.getLineNumber() + 1);
                }
            }
        } catch (CoreException e) {
            Logger.logException(e);
        } finally {
            if (inputStream != null) {
                try {
                    inputStream.close();
                } catch (IOException e) {
                }
            }
        }
        if (teardownRequired)
            teardownValidation(nestedcontext);
    }
    return result;
}
Also used : IFile(org.eclipse.core.resources.IFile) IReporter(org.eclipse.wst.validation.internal.provisional.core.IReporter) CoreException(org.eclipse.core.runtime.CoreException) InputStream(java.io.InputStream) IMessage(org.eclipse.wst.validation.internal.provisional.core.IMessage) List(java.util.List) IOException(java.io.IOException) ValidationResult(org.eclipse.wst.validation.ValidationResult)

Aggregations

IReporter (org.eclipse.wst.validation.internal.provisional.core.IReporter)43 IFile (org.eclipse.core.resources.IFile)17 Path (org.eclipse.core.runtime.Path)15 List (java.util.List)11 JSPJavaValidator (org.eclipse.jst.jsp.core.internal.validation.JSPJavaValidator)10 ValidationResult (org.eclipse.wst.validation.ValidationResult)9 Test (org.junit.Test)8 IProject (org.eclipse.core.resources.IProject)7 IPath (org.eclipse.core.runtime.IPath)7 JSPValidator (org.eclipse.jst.jsp.core.internal.validation.JSPValidator)7 LocalizedMessage (org.eclipse.wst.validation.internal.operations.LocalizedMessage)6 CoreException (org.eclipse.core.runtime.CoreException)5 ReporterForTest (org.eclipse.jst.jsp.core.tests.validation.ReporterForTest)5 ValidationContextForTest (org.eclipse.jst.jsp.core.tests.validation.ValidationContextForTest)5 IOException (java.io.IOException)4 JSPActionValidator (org.eclipse.jst.jsp.core.internal.validation.JSPActionValidator)4 JSPDirectiveValidator (org.eclipse.jst.jsp.core.internal.validation.JSPDirectiveValidator)4 IMessage (org.eclipse.wst.validation.internal.provisional.core.IMessage)4 Iterator (java.util.Iterator)3 JSPContentValidator (org.eclipse.jst.jsp.core.internal.validation.JSPContentValidator)3