Java 类org.eclipse.xtext.validation.CheckMode 实例源码

项目:n4js    文件:ExceptionAnalyser.java   
@Override
protected List<Diagnostic> getScriptErrors(Script script) {
    EcoreUtil.resolveAll(script.eResource());
    List<Diagnostic> diagnostics = super.getScriptErrors(script);
    Iterator<Expression> expressions = Iterators.filter(EcoreUtil2.eAll(script), Expression.class);
    List<Diagnostic> result = Lists.<Diagnostic> newArrayList(Iterables.filter(diagnostics,
            ExceptionDiagnostic.class));
    while (expressions.hasNext()) {
        Expression expression = expressions.next();
        RuleEnvironment ruleEnvironment = RuleEnvironmentExtensions.newRuleEnvironment(expression);
        Result<TypeRef> type = typeSystem.type(ruleEnvironment, expression);
        if (type.getRuleFailedException() != null) {
            Throwable cause = Throwables.getRootCause(type.getRuleFailedException());
            if (!(cause instanceof RuleFailedException)) {
                if (cause instanceof Exception) {
                    result.add(new ExceptionDiagnostic((Exception) cause));
                } else {
                    throw new RuntimeException(cause);
                }
            }
        }
    }
    validator.validate(script.eResource(), CheckMode.ALL, CancelIndicator.NullImpl);
    return result;
}
项目:n4js    文件:XpectN4JSES5TranspilerHelper.java   
private boolean registerErrors(Resource dep, StringBuilder errorResult) {
    boolean hasErrors = false;
    List<Issue> issues = resourceValidator.validate(dep, CheckMode.ALL, CancelIndicator.NullImpl);
    List<Issue> errorIssues = new ArrayList<>();
    for (Issue issue : issues) {
        if (Severity.ERROR == issue.getSeverity()) {
            errorIssues.add(issue);
        }
    }
    hasErrors = !errorIssues.isEmpty();
    if (hasErrors) {
        errorResult.append("Couldn't compile resource " + dep.getURI() + " because it contains errors: ");
        for (Issue errorIssue : errorIssues) {
            errorResult
                    .append(nl + errorIssue.getMessage() + " at line " + errorIssue.getLineNumber());
        }
    }
    return hasErrors;
}
项目:n4js    文件:ResourceUIValidatorExtension.java   
private void addMarkers(IFile file, Resource resource, CheckMode mode, IProgressMonitor monitor)
        throws OperationCanceledException {
    try {
        List<Issue> list = getValidator(resource).validate(resource, mode, getCancelIndicator(monitor));
        if (monitor.isCanceled()) {
            throw new OperationCanceledException();
        }
        deleteMarkers(file, mode, monitor);
        if (monitor.isCanceled()) {
            throw new OperationCanceledException();
        }
        createMarkers(file, list, getMarkerCreator(resource), getMarkerTypeProvider(resource));
    } catch (OperationCanceledError error) {
        throw error.getWrapped();
    } catch (CoreException e) {
        LOGGER.error(e.getMessage(), e);
    }
}
项目:n4js    文件:N4JSResourceValidator.java   
/**
 * Don't validate the inferred module since all validation information should be available on the AST elements.
 */
@Override
protected void validate(Resource resource, CheckMode mode, CancelIndicator cancelIndicator,
        IAcceptor<Issue> acceptor) {
    operationCanceledManager.checkCanceled(cancelIndicator);
    if (n4jsCore.isNoValidate(resource.getURI())) {
        return;
    }
    List<EObject> contents = resource.getContents();
    if (!contents.isEmpty()) {
        EObject firstElement = contents.get(0);
        // // Mark the scoping as sealed. (No other usage-flags should be set for import-declarations.)
        // if (firstElement instanceof Script) {
        // ((Script) firstElement).setFlaggedBound(true);
        // }
        validate(resource, firstElement, mode, cancelIndicator, acceptor);

        // UtilN4.takeSnapshotInGraphView("post validation", resource);
    }
}
项目:DocIT    文件:Main.java   
protected void runGenerator(String string) {
    // load the resource
    ResourceSet set = resourceSetProvider.get();
    Resource resource = set.getResource(URI.createURI(string), true);

    // validate the resource
    List<Issue> list = validator.validate(resource, CheckMode.ALL, CancelIndicator.NullImpl);
    if (!list.isEmpty()) {
        for (Issue issue : list) {
            System.err.println(issue);
        }
        return;
    }

    // configure and start the generator
    fileAccess.setOutputPath("src-gen/");
    generator.doGenerate(resource, fileAccess);

    System.out.println("Code generation finished.");
}
项目:jason-eclipse-plugin    文件:Main.java   
protected void runGenerator(String string) {
    // load the resource
    ResourceSet set = resourceSetProvider.get();
    Resource resource = set.getResource(URI.createURI(string), true);

    // validate the resource
    List<Issue> list = validator.validate(resource, CheckMode.ALL, CancelIndicator.NullImpl);
    if (!list.isEmpty()) {
        for (Issue issue : list) {
            System.err.println(issue);
        }
        return;
    }

    // configure and start the generator
    fileAccess.setOutputPath("src-gen/");
    generator.doGenerate(resource, fileAccess);

    System.out.println("Code generation finished.");
}
项目:jason-eclipse-plugin    文件:Main.java   
protected void runGenerator(String string) {
    // load the resource
    ResourceSet set = resourceSetProvider.get();
    Resource resource = set.getResource(URI.createURI(string), true);

    // validate the resource
    List<Issue> list = validator.validate(resource, CheckMode.ALL, CancelIndicator.NullImpl);
    if (!list.isEmpty()) {
        for (Issue issue : list) {
            System.err.println(issue);
        }
        return;
    }

    // configure and start the generator
    fileAccess.setOutputPath("src-gen/");
    generator.doGenerate(resource, fileAccess);

    System.out.println("Code generation finished.");
}
项目:xtext-core    文件:XtextValidationTest.java   
@Test public void testRuleCalledSuper() throws Exception {
    XtextResource resource = getResourceFromString(
            "grammar com.acme.Bar with org.eclipse.xtext.common.Terminals\n" +
            "generate metamodel 'myURI'\n" +
            "Model: super=super;\n" + 
            "super: name=ID;");

    IResourceValidator validator = get(IResourceValidator.class);
    List<Issue> issues = validator.validate(resource, CheckMode.FAST_ONLY, CancelIndicator.NullImpl);
    assertEquals(issues.toString(), 1, issues.size());
    assertEquals("Discouraged rule name 'super'", issues.get(0).getMessage());
    Grammar grammar = (Grammar) resource.getContents().get(0);
    AbstractRule model = grammar.getRules().get(0);
    Assignment assignment = (Assignment) model.getAlternatives();
    RuleCall ruleCall = (RuleCall) assignment.getTerminal();
    assertSame(grammar.getRules().get(1), ruleCall.getRule());
}
项目:chariot    文件:Main.java   
protected void runGenerator(String string) {
    // load the resource
    ResourceSet set = resourceSetProvider.get();
    Resource resource = set.getResource(URI.createURI(string), true);

    // validate the resource
    List<Issue> list = validator.validate(resource, CheckMode.ALL, CancelIndicator.NullImpl);
    if (!list.isEmpty()) {
        for (Issue issue : list) {
            System.err.println(issue);
        }
        return;
    }

    // configure and start the generator
    fileAccess.setOutputPath("src-gen/");
    generator.doGenerate(resource, fileAccess);

    System.out.println("Code generation finished.");
}
项目:statecharts    文件:AbstractGeneratorEntryExecutor.java   
protected boolean valid(GeneratorEntry entry) {
    if (skipValidation) {
        logger.log("Validation skipped...");
        return true;
    }
    List<Issue> issues = validator.validate(entry.getElementRef().eResource(), CheckMode.ALL, null);
    Iterable<Issue> errors = Iterables.filter(issues, new Predicate<Issue>() {
        @Override
        public boolean apply(Issue input) {
            return input.getSeverity() == Severity.ERROR;
        }
    });
    if (!Iterables.isEmpty(errors)) {
        logger.log("The referenced model(" + ((NamedElement) entry.getElementRef()).getName()
                + ") contains errors and could not be generated:");
        for (Issue issue : errors) {
            logger.log(issue.getMessage());
        }
        return false;
    }
    return true;
}
项目:umple    文件:Main.java   
protected void runGenerator(String string) {
    // load the resource
    ResourceSet set = resourceSetProvider.get();
    Resource resource = set.getResource(URI.createURI(string), true);

    // validate the resource
    List<Issue> list = validator.validate(resource, CheckMode.ALL, CancelIndicator.NullImpl);
    if (!list.isEmpty()) {
        for (Issue issue : list) {
            System.err.println(issue);
        }
        return;
    }

    // configure and start the generator
    fileAccess.setOutputPath("src-gen/");
    generator.doGenerate(resource, fileAccess);

    System.out.println("Code generation finished.");
}
项目:PDFReporter-Studio    文件:Main.java   
protected void runGenerator(String string) {
    // load the resource
    ResourceSet set = resourceSetProvider.get();
    Resource resource = set.getResource(URI.createURI(string), true);

    // validate the resource
    List<Issue> list = validator.validate(resource, CheckMode.ALL, CancelIndicator.NullImpl);
    if (!list.isEmpty()) {
        for (Issue issue : list) {
            System.err.println(issue);
        }
        return;
    }

    // configure and start the generator
    fileAccess.setOutputPath("src-gen/");
    generator.doGenerate(resource, fileAccess);

    System.out.println("Code generation finished.");
}
项目:gama    文件:GamlResourceValidator.java   
@Override
public List<Issue> validate(final Resource resource, final CheckMode mode, final CancelIndicator indicator) {
    final LazyAcceptor acceptor = new LazyAcceptor();
    // We resolve the cross references
    EcoreUtil2.resolveLazyCrossReferences(resource, indicator);
    // And collect the syntax / linking issues
    for (int i = 0; i < resource.getErrors().size(); i++)
        converter.convertResourceDiagnostic(resource.getErrors().get(i), Severity.ERROR, acceptor);
    // We then ask the resource to validate itself
    final GamlResource r = (GamlResource) resource;
    // Enables faster compilation (but less accurate error reporting in
    // navigator)
    if (GamlRuntimeModule.ENABLE_FAST_COMPIL.getValue()) {
        if (GamlResourceServices.isEdited(r) || !GamlResourceIndexer.isImported(r))
            r.validate();
    } else
        r.validate();
    // And collect the semantic errors from its error collector
    for (final Diagnostic d : errorTranslator.translate(r.getValidationContext(), r, mode).getChildren())
        converter.convertValidatorDiagnostic(d, acceptor);
    GamlResourceServices.discardValidationContext(r);
    return acceptor.result == null ? Collections.EMPTY_LIST : acceptor.result;
}
项目:mm-dsl    文件:Main.java   
protected void runGenerator(String string) {
    // load the resource
    ResourceSet set = resourceSetProvider.get();
    Resource resource = set.getResource(URI.createURI(string), true);

    // validate the resource
    List<Issue> list = validator.validate(resource, CheckMode.ALL, CancelIndicator.NullImpl);
    if (!list.isEmpty()) {
        for (Issue issue : list) {
            System.err.println(issue);
        }
        return;
    }

    // configure and start the generator
    fileAccess.setOutputPath("src-gen/");
    generator.doGenerate(resource, fileAccess);

    System.out.println("Code generation finished.");
}
项目:CooperateModelingEnvironment    文件:CooperateCDOXtextEditor.java   
private void performIssueValidationFixingWithoutAutomatedStateCalculation(Collection<Issue> detectedIssues,
        Resource documentResource) {
    int fixAttempts = 0;
    Collection<IAutomatedIssueResolution> issueResolutions = Collections.emptyList();
    do {
        if (fixAttempts++ > MAX_AUTOMATED_FIX_ATTEMPTS) {
            break;
        }
        issueResolutions.forEach(IAutomatedIssueResolution::resolve);
        if (documentResource instanceof DerivedStateAwareResource) {
            resourceStateHandler.cleanState(documentResource);
            resourceStateHandler.initState(documentResource);
            resourceStateHandler.calculateState(documentResource);
        }
        detectedIssues.clear();
        detectedIssues
                .addAll(resourceValidator.validate(documentResource, CheckMode.ALL, CancelIndicator.NullImpl));
        issueResolutions = automatedIssueResolutionProvider.get(documentResource, detectedIssues);
    } while (issueResolutions.stream().anyMatch(IAutomatedIssueResolution::resolvePossible));
}
项目:EASyProducer    文件:Main.java   
protected void runGenerator(String string) {
    // load the resource
    ResourceSet set = resourceSetProvider.get();
    Resource resource = set.getResource(URI.createURI(string), true);

    // validate the resource
    List<Issue> list = validator.validate(resource, CheckMode.ALL, CancelIndicator.NullImpl);
    if (!list.isEmpty()) {
        for (Issue issue : list) {
            System.err.println(issue);
        }
        return;
    }

    // configure and start the generator
    fileAccess.setOutputPath("src-gen/");
    generator.doGenerate(resource, fileAccess);

    System.out.println("Code generation finished.");
}
项目:EASyProducer    文件:Main.java   
protected void runGenerator(String string) {
    // load the resource
    ResourceSet set = resourceSetProvider.get();
    Resource resource = set.getResource(URI.createURI(string), true);

    // validate the resource
    List<Issue> list = validator.validate(resource, CheckMode.ALL, CancelIndicator.NullImpl);
    if (!list.isEmpty()) {
        for (Issue issue : list) {
            System.err.println(issue);
        }
        return;
    }

    // configure and start the generator
    fileAccess.setOutputPath("src-gen/");
    generator.doGenerate(resource, fileAccess);

    System.out.println("Code generation finished.");
}
项目:EASyProducer    文件:Main.java   
/**
 * Executes the generator on an EMF resource.
 * 
 * @param string the EMF resource
 */
protected void runGenerator(String string) {
    // load the resource
    ResourceSet set = resourceSetProvider.get();
    Resource resource = set.getResource(URI.createURI(string), true);

    // validate the resource
    List<Issue> list = validator.validate(resource, CheckMode.ALL,
            CancelIndicator.NullImpl);
    if (!list.isEmpty()) {
        for (Issue issue : list) {
            System.err.println(issue);
        }
        return;
    }

    // configure and start the generator
    fileAccess.setOutputPath("src-gen/");
    generator.doGenerate(resource, fileAccess);

    System.out.println("Code generation finished.");
}
项目:eclipse-avro    文件:Main.java   
protected void runGenerator(String string) {
    // load the resource
    ResourceSet set = resourceSetProvider.get();
    Resource resource = set.getResource(URI.createURI(string), true);

    // validate the resource
    List<Issue> list = validator.validate(resource, CheckMode.ALL, CancelIndicator.NullImpl);
    if (!list.isEmpty()) {
        for (Issue issue : list) {
            System.err.println(issue);
        }
        return;
    }

    // configure and start the generator
    fileAccess.setOutputPath("src-gen/");
    generator.doGenerate(resource, fileAccess);

    System.out.println("Code generation finished.");
}
项目:xsemantics    文件:GeneratorForTests.java   
public List<Issue> runGenerator(String string, ResourceSet set) {
    // load the resource
    Resource resource = set.getResource(URI.createURI(string), true);

    // validate the resource
    List<Issue> issues = validator.validate(resource, CheckMode.ALL,
            CancelIndicator.NullImpl);
    if (!issues.isEmpty()) {
        for (Issue issue : issues) {
            System.err.println(issue);
        }
        if (GeneratorUtils.hasErrors(issues))
            return issues;
    }

    fileAccess.setOutputPath(outputPath);
    generator.doGenerate(resource, fileAccess);

    System.out.println("Code generation finished.");

    return issues;
}
项目:packtpub-xtext-book-examples    文件:Main.java   
protected void runGenerator(String string) {
    // load the resource
    ResourceSet set = resourceSetProvider.get();
    Resource resource = set.getResource(URI.createURI(string), true);

    // validate the resource
    List<Issue> list = validator.validate(resource, CheckMode.ALL, CancelIndicator.NullImpl);
    if (!list.isEmpty()) {
        for (Issue issue : list) {
            System.err.println(issue);
        }
        return;
    }

    // configure and start the generator
    fileAccess.setOutputPath("src-gen/");
    generator.doGenerate(resource, fileAccess);

    System.out.println("Code generation finished.");
}
项目:n4js    文件:AbstractBuilderParticipantTest.java   
/**
 * Returns validation errors in given Xtext editor.
 */
protected List<Issue> getEditorValidationErrors(XtextEditor editor) {
    return editor.getDocument().readOnly(new IUnitOfWork<List<Issue>, XtextResource>() {
        @Override
        public List<Issue> exec(XtextResource state) throws Exception {
            final IResourceValidator validator = state.getResourceServiceProvider().getResourceValidator();
            return validator.validate(state, CheckMode.ALL, CancelIndicator.NullImpl);
        }
    });
}
项目:n4js    文件:N4HeadlessCompiler.java   
/**
 * Validates all non-external Xtext resources of the given project. Prints issues and adds them to the given issue
 * acceptor.
 *
 * @param markedProject
 *            the project to validate
 * @param recorder
 *            the progress recorder
 * @param issueAcceptor
 *            the issue acceptor
 * @throws N4JSCompileErrorException
 *             if an error occurs during validation
 */
private void validateProject(MarkedProject markedProject, N4ProgressStateRecorder recorder,
        IssueAcceptor issueAcceptor) throws N4JSCompileErrorException {

    if (logger.isVerbose())
        logger.info(" Validating project " + markedProject);
    IssueCollector issueCollector = new IssueCollector();
    IssueFilter issueFilter = new IssueFilter(issueCollector, issue -> issue.getSeverity() == Severity.ERROR);
    issueAcceptor = new IssueAcceptorTee(issueAcceptor, issueFilter);

    // validation TODO see IDE-1426 redesign validation calls with generators
    for (Resource resource : markedProject.resources) {
        if (resource instanceof XtextResource && // is Xtext resource
                (!n4jsCore.isNoValidate(resource.getURI())) && // is validating
                (!markedProject.externalResources.contains(resource)) // not in external folder
        ) {
            if (logger.isCreateDebugOutput())
                logger.debug("   Validating resource " + resource.getURI());
            XtextResource xtextResource = (XtextResource) resource;
            IResourceValidator validator = xtextResource.getResourceServiceProvider().getResourceValidator();
            List<Issue> issues = validator.validate(xtextResource, CheckMode.ALL, CancelIndicator.NullImpl);

            if (!issues.isEmpty()) {
                recorder.markResourceIssues(resource, issues);
                issueAcceptor.acceptAll(issues);
                issues.stream().forEach(logger::issue);
            }
        }
    }

    // Projects should not compile if there are severe errors:
    if (!isKeepOnCompiling()) {
        failOnErrors(issueCollector.getCollectedIssues(), markedProject.project.getProjectId());
    }
}
项目:n4js    文件:ManifestAwareResourceValidator.java   
@Override
public List<Issue> validate(Resource resource, CheckMode mode, CancelIndicator cancelIndicator) {
    final Measurement measurment = collector.getMeasurement(resource.getURI().toString());
    operationCanceledManager.checkCanceled(cancelIndicator);
    if (!isInSourceFolder(resource)) {
        return Collections.emptyList();
    }
    List<Issue> res = super.validate(resource, mode, cancelIndicator);
    measurment.end();
    return res;
}
项目:n4js    文件:ResourceUIValidatorExtension.java   
@Override
public void updateValidationMarkers(IFile file, Resource resource, CheckMode mode, IProgressMonitor monitor)
        throws OperationCanceledException {
    if (shouldProcess(file)) {
        addMarkers(file, resource, mode, monitor);
    }
}
项目:n4js    文件:IssuesProvider.java   
/**
 * Why does this method resort to returning via exceptional-control-flow upon detecting a cancellation request?
 * Didn't the validation method already handle it?
 * <p>
 * Upon cancellation, some validators (for example, {@code ManifestAwareResourceValidator}) may decide to stop all
 * work and return only the issues found thus far (or even an empty list of issues). That's a valid realization of
 * the cancellation contract. Thus the {@code validate()} method returned normally. If we were to return those
 * partial results, the caller of this method would proceed to pollute the cache with them. That's prevented by
 * throwing a fabricated {@link OperationCanceledError}
 */
@Override
public List<Issue> get() throws OperationCanceledError {
    operationCanceledManager.checkCanceled(ci);
    List<Issue> issues = rv.validate(r, CheckMode.ALL, ci);
    if (!issues.contains(null)) {
        operationCanceledManager.checkCanceled(ci);
        return issues;
    }
    ArrayList<Issue> result = new ArrayList<>(issues);
    result.removeAll(Collections.singleton(null));
    operationCanceledManager.checkCanceled(ci);
    return result;
}
项目:bromium    文件:DslParser.java   
@Override
public ApplicationConfiguration parseApplicationConfiguration(File file) throws IOException {
    Resource resource = resourceSet.getResource(URI.createFileURI(file.getAbsolutePath()), true);

    List<Issue> issues = validator.validate(resource, CheckMode.ALL, CancelIndicator.NullImpl);

    if (!issues.isEmpty()) {
        throw new IllegalStateException("Invalid bromium configuration. Issues: " + issues);
    }

    Model model = (Model) resource.getAllContents().next();
    return ASTNodeConverter.convert(model);
}
项目:bromium    文件:DslParserTest.java   
@Test
public void ifNoIssuesThenDelegatedToConverter() throws IOException {
    File file = new File(getClass().getResource("/name.brm").getFile());
    initMocks(file);
    when(resourceValidator.validate(resource, CheckMode.ALL, CancelIndicator.NullImpl)).thenReturn(new ArrayList<>());

    ApplicationConfigurationParser parser = new DslParser(resourceSet, resourceValidator, ASTNodeConverter);

    ApplicationConfiguration actual = parser.parseApplicationConfiguration(file);

    assertEquals(applicationConfiguration, actual);
}
项目:bromium    文件:DslParserTest.java   
@Test
public void ifNoIssuesByFilenameThenDelegatedToConverter() throws IOException {
    String filename = getClass().getResource("/name.brm").getFile();
    initMocks(new File(filename));
    when(resourceValidator.validate(resource, CheckMode.ALL, CancelIndicator.NullImpl)).thenReturn(new ArrayList<>());

    ApplicationConfigurationParser parser = new DslParser(resourceSet, resourceValidator, ASTNodeConverter);

    ApplicationConfiguration actual = parser.parseApplicationConfiguration(filename);

    assertEquals(applicationConfiguration, actual);
}
项目:bromium    文件:DslParserTest.java   
@Test
public void parsesActionsWithExposedParameters() throws IOException {
    File file = new File(getClass().getResource("/actions.brm").getFile());
    initMocks(file);
    List<Issue> issues = Arrays.asList(mock(Issue.class));
    when(resourceValidator.validate(resource, CheckMode.ALL, CancelIndicator.NullImpl)).thenReturn(issues);

    ApplicationConfigurationParser parser = new DslParser(resourceSet, resourceValidator, ASTNodeConverter);

    expectedException.expect(IllegalStateException.class);
    parser.parseApplicationConfiguration(file);
}
项目:xtext-extras    文件:DerivedStateAwareResourceValidator.java   
@Override
protected void validate(Resource resource, CheckMode mode, CancelIndicator monitor, IAcceptor<Issue> acceptor) {
    getOperationCanceledManager().checkCanceled(monitor);
    if (resource instanceof DerivedStateAwareResource) {
        List<EObject> contents = resource.getContents();
        if (!contents.isEmpty()) {
            validate(resource, contents.get(0), mode, monitor, acceptor);
        }
    } else {
        super.validate(resource, mode, monitor, acceptor);
    }
}
项目:xtext-extras    文件:StandaloneBuilder.java   
protected boolean validate(final Resource resource) {
  String _lastSegment = resource.getURI().lastSegment();
  String _plus = ("Starting validation for input: \'" + _lastSegment);
  String _plus_1 = (_plus + "\'");
  StandaloneBuilder.LOG.info(_plus_1);
  final IResourceValidator resourceValidator = this.languageAccess(resource.getURI()).getResourceValidator();
  final List<Issue> validationResult = resourceValidator.validate(resource, CheckMode.ALL, null);
  return this.issueHandler.handleIssue(validationResult);
}
项目:xtext-core    文件:Validator.java   
public void validate(ResourceSet resourceSet, IResourceServiceProvider.Registry registry, Issues issues) {
    List<Resource> resources = Lists.newArrayList(resourceSet.getResources());
    for (Resource resource : resources) {
        try {
            resource.load(null);
            IResourceServiceProvider provider = registry.getResourceServiceProvider(resource.getURI());
            if (provider != null) {
                List<Issue> result = provider.getResourceValidator().validate(resource, CheckMode.ALL, null);
                for (Issue issue : result) {
                    switch (issue.getSeverity()) {
                        case ERROR:
                            issues.addError(issue.getMessage(), issue);
                            break;
                        case WARNING:
                            issues.addWarning(issue.getMessage(), issue);
                            break;
                        case INFO:
                            issues.addInfo(issue.getMessage(), issue);
                            break;
                        case IGNORE:
                            break;
                    }
                }
            }
        } catch (IOException e) {
            throw new WorkflowInterruptedException("Couldn't load resource (" + resource.getURI() + ")", e);
        }
    }
    if (isStopOnError() && issues.hasErrors()) {
        String errorMessage = toString(issues);
        throw new WorkflowInterruptedException("Validation problems: \n" + errorMessage);
    }
}
项目:xtext-core    文件:IShouldGenerate.java   
@Override
public boolean shouldGenerate(final Resource resource, final CancelIndicator cancelIndicator) {
  boolean _isEmpty = resource.getErrors().isEmpty();
  boolean _not = (!_isEmpty);
  if (_not) {
    return false;
  }
  final List<Issue> issues = this.resourceValidator.validate(resource, CheckMode.NORMAL_AND_FAST, cancelIndicator);
  final Function1<Issue, Boolean> _function = (Issue it) -> {
    Severity _severity = it.getSeverity();
    return Boolean.valueOf(Objects.equal(_severity, Severity.ERROR));
  };
  boolean _exists = IterableExtensions.<Issue>exists(issues, _function);
  return (!_exists);
}
项目:xtext-core    文件:IncrementalBuilder.java   
protected boolean validate(final Resource resource) {
  final IResourceValidator resourceValidator = this.context.getResourceServiceProvider(resource.getURI()).getResourceValidator();
  if ((resourceValidator == null)) {
    return true;
  }
  String _lastSegment = resource.getURI().lastSegment();
  String _plus = ("Starting validation for input: \'" + _lastSegment);
  String _plus_1 = (_plus + "\'");
  IncrementalBuilder.InternalStatefulIncrementalBuilder.LOG.info(_plus_1);
  final List<Issue> validationResult = resourceValidator.validate(resource, CheckMode.ALL, null);
  return this.request.getAfterValidate().afterValidate(resource.getURI(), validationResult);
}
项目:xtext-core    文件:XtextValidationTest.java   
@Test public void testExplicitOverride01() throws Exception {
    IResourceValidator validator = get(IResourceValidator.class);

    XtextResource resource = getResourceFromString(
            "grammar org.foo.Bar with org.eclipse.xtext.common.Terminals\n" +
            "terminal ID_2: ('a'..'z'|'A'..'Z'|'_');");
    List<Issue> issues = validator.validate(resource, CheckMode.FAST_ONLY, CancelIndicator.NullImpl);
    assertEquals(issues.toString(), 0, issues.size());

}
项目:xtext-core    文件:XtextValidationTest.java   
@Test public void testExplicitOverride04() throws Exception {
    IResourceValidator validator = get(IResourceValidator.class);
    XtextResource resource = getResourceFromString(
            "grammar org.foo.Bar with org.eclipse.xtext.common.Terminals\n" +
            "@Override\n" +
            "terminal ID: ('a'..'z'|'A'..'Z'|'_');");
    List<Issue> issues = validator.validate(resource, CheckMode.FAST_ONLY, CancelIndicator.NullImpl);
    assertEquals(issues.toString(), 0, issues.size());
}
项目:xtext-core    文件:XtextValidationTest.java   
@Test public void testMissingArgument() throws Exception {
    XtextResource resource = getResourceFromString(
            "grammar com.acme.Bar with org.eclipse.xtext.common.Terminals\n" +
            "generate metamodel 'myURI'\n" +
            "Model: rule=Rule<First=true, Second=false>;\n" + 
            "Rule<First, Missing, Second>: name=ID;");

    IResourceValidator validator = get(IResourceValidator.class);
    List<Issue> issues = validator.validate(resource, CheckMode.FAST_ONLY, CancelIndicator.NullImpl);
    assertEquals(issues.toString(), 1, issues.size());
    assertEquals("Missing argument for parameter Missing", issues.get(0).getMessage());
}
项目:xtext-core    文件:XtextValidationTest.java   
@Test public void testMissingArgument2() throws Exception {
    XtextResource resource = getResourceFromString(
            "grammar com.acme.Bar with org.eclipse.xtext.common.Terminals\n" +
            "generate metamodel 'myURI'\n" +
            "Model: rule=Rule<First=true>;\n" + 
            "Rule<First, Missing, AlsoMissing>: name=ID;");

    IResourceValidator validator = get(IResourceValidator.class);
    List<Issue> issues = validator.validate(resource, CheckMode.FAST_ONLY, CancelIndicator.NullImpl);
    assertEquals(issues.toString(), 1, issues.size());
    assertEquals("2 missing arguments for the following parameters: Missing, AlsoMissing", issues.get(0).getMessage());
}
项目:xtext-core    文件:XtextValidationTest.java   
@Test public void testMissingArgument3() throws Exception {
    XtextResource resource = getResourceFromString(
            "grammar com.acme.Bar with org.eclipse.xtext.common.Terminals\n" +
            "generate metamodel 'myURI'\n" +
            "Model: rule=Rule<true>;\n" + 
            "Rule<First, Missing, AlsoMissing>: name=ID;");

    IResourceValidator validator = get(IResourceValidator.class);
    List<Issue> issues = validator.validate(resource, CheckMode.FAST_ONLY, CancelIndicator.NullImpl);
    assertEquals(issues.toString(), 1, issues.size());
    assertEquals("Expected 3 arguments but got 1", issues.get(0).getMessage());
}