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());
}
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);
}
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);
}
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;
}
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;
}
Aggregations