本文整理汇总了Java中org.eclipse.xtext.validation.CheckMode类的典型用法代码示例。如果您正苦于以下问题:Java CheckMode类的具体用法?Java CheckMode怎么用?Java CheckMode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CheckMode类属于org.eclipse.xtext.validation包,在下文中一共展示了CheckMode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getScriptErrors
import org.eclipse.xtext.validation.CheckMode; //导入依赖的package包/类
@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;
}
示例2: registerErrors
import org.eclipse.xtext.validation.CheckMode; //导入依赖的package包/类
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;
}
示例3: addMarkers
import org.eclipse.xtext.validation.CheckMode; //导入依赖的package包/类
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);
}
}
示例4: validate
import org.eclipse.xtext.validation.CheckMode; //导入依赖的package包/类
/**
* 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);
}
}
示例5: runGenerator
import org.eclipse.xtext.validation.CheckMode; //导入依赖的package包/类
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.");
}
示例6: testRuleCalledSuper
import org.eclipse.xtext.validation.CheckMode; //导入依赖的package包/类
@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());
}
示例7: valid
import org.eclipse.xtext.validation.CheckMode; //导入依赖的package包/类
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;
}
示例8: validate
import org.eclipse.xtext.validation.CheckMode; //导入依赖的package包/类
@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;
}
示例9: performIssueValidationFixingWithoutAutomatedStateCalculation
import org.eclipse.xtext.validation.CheckMode; //导入依赖的package包/类
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));
}
示例10: runGenerator
import org.eclipse.xtext.validation.CheckMode; //导入依赖的package包/类
/**
* 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.");
}
示例11: runGenerator
import org.eclipse.xtext.validation.CheckMode; //导入依赖的package包/类
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;
}
示例12: getEditorValidationErrors
import org.eclipse.xtext.validation.CheckMode; //导入依赖的package包/类
/**
* 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);
}
});
}
示例13: validateProject
import org.eclipse.xtext.validation.CheckMode; //导入依赖的package包/类
/**
* 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());
}
}
示例14: validate
import org.eclipse.xtext.validation.CheckMode; //导入依赖的package包/类
@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;
}
示例15: updateValidationMarkers
import org.eclipse.xtext.validation.CheckMode; //导入依赖的package包/类
@Override
public void updateValidationMarkers(IFile file, Resource resource, CheckMode mode, IProgressMonitor monitor)
throws OperationCanceledException {
if (shouldProcess(file)) {
addMarkers(file, resource, mode, monitor);
}
}