Search in sources :

Example 1 with JSONLineTokenizer

use of org.eclipse.wst.json.core.internal.parser.JSONLineTokenizer in project webtools.sourceediting by eclipse.

the class JSONSyntaxValidatorHelperTest method validate.

public IReporter validate(String json) {
    IReporter reporter = new MockReporter();
    JSONLineTokenizer tokenizer = new JSONLineTokenizer(new StringReader(json));
    JSONSyntaxValidatorHelper.validate(tokenizer, reporter, null, PROVIDER);
    return reporter;
}
Also used : JSONLineTokenizer(org.eclipse.wst.json.core.internal.parser.JSONLineTokenizer) IReporter(org.eclipse.wst.validation.internal.provisional.core.IReporter) StringReader(java.io.StringReader)

Example 2 with JSONLineTokenizer

use of org.eclipse.wst.json.core.internal.parser.JSONLineTokenizer in project webtools.sourceediting by eclipse.

the class JSONSyntaxValidator method validateFile.

/**
 * Validates the given file. It will stream the contents of the file without
 * creating a model for the file; it will only use existing
 *
 * @param file
 *            the file to validate
 * @param reporter
 *            the reporter
 */
private void validateFile(IFile file, IReporter reporter) {
    Message message = new LocalizedMessage(IMessage.LOW_SEVERITY, file.getFullPath().toString().substring(1));
    reporter.displaySubtask(JSONSyntaxValidator.this, message);
    JSONLineTokenizer tokenizer = null;
    try {
        IStructuredModel model = StructuredModelManager.getModelManager().getExistingModelForRead(file);
        try {
            if (model == null) {
                tokenizer = new JSONLineTokenizer(new BufferedReader(new InputStreamReader(file.getContents(true), getCharset(file))));
            } else {
                tokenizer = new JSONLineTokenizer(new BufferedReader(new DocumentReader(model.getStructuredDocument())));
            }
            JSONSyntaxValidatorHelper.validate(tokenizer, reporter, this, this);
        } finally {
            if (model != null) {
                model.releaseFromRead();
                model = null;
            }
        }
    } catch (UnsupportedEncodingException e) {
    } catch (CoreException e) {
    } catch (IOException e) {
    }
}
Also used : JSONLineTokenizer(org.eclipse.wst.json.core.internal.parser.JSONLineTokenizer) 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) InputStreamReader(java.io.InputStreamReader) CoreException(org.eclipse.core.runtime.CoreException) BufferedReader(java.io.BufferedReader) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) DocumentReader(org.eclipse.wst.sse.core.internal.document.DocumentReader) IOException(java.io.IOException) LocalizedMessage(org.eclipse.wst.validation.internal.operations.LocalizedMessage)

Aggregations

JSONLineTokenizer (org.eclipse.wst.json.core.internal.parser.JSONLineTokenizer)2 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 StringReader (java.io.StringReader)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 CoreException (org.eclipse.core.runtime.CoreException)1 DocumentReader (org.eclipse.wst.sse.core.internal.document.DocumentReader)1 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)1 Message (org.eclipse.wst.validation.internal.core.Message)1 LocalizedMessage (org.eclipse.wst.validation.internal.operations.LocalizedMessage)1 IMessage (org.eclipse.wst.validation.internal.provisional.core.IMessage)1 IReporter (org.eclipse.wst.validation.internal.provisional.core.IReporter)1