本文整理汇总了Java中org.eclipse.xtext.validation.IResourceValidator.validate方法的典型用法代码示例。如果您正苦于以下问题:Java IResourceValidator.validate方法的具体用法?Java IResourceValidator.validate怎么用?Java IResourceValidator.validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.xtext.validation.IResourceValidator
的用法示例。
在下文中一共展示了IResourceValidator.validate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testRuleCalledSuper
import org.eclipse.xtext.validation.IResourceValidator; //导入方法依赖的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());
}
示例2: validate
import org.eclipse.xtext.validation.IResourceValidator; //导入方法依赖的package包/类
/**
* Validate the given resource and create the corresponding markers. The CheckMode is a constant calculated from the constructor
* parameters.
*
* @param resourceValidator
* the resource validator (not null)
* @param file
* the EFS file (not null)
* @param resource
* the EMF resource (not null)
* @param monitor
* the monitor (not null)
*/
protected void validate(final IResourceValidator resourceValidator, final IFile file, final Resource resource, final IProgressMonitor monitor) {
try {
monitor.subTask("validating " + file.getName()); //$NON-NLS-1$
final List<Issue> list = resourceValidator.validate(resource, checkMode, getCancelIndicator(monitor));
if (list != null) {
// resourceValidator.validate returns null if canceled (and not an empty list)
file.deleteMarkers(MarkerTypes.FAST_VALIDATION, true, IResource.DEPTH_ZERO);
file.deleteMarkers(MarkerTypes.NORMAL_VALIDATION, true, IResource.DEPTH_ZERO);
if (performExpensiveValidation) {
file.deleteMarkers(MarkerTypes.EXPENSIVE_VALIDATION, true, IResource.DEPTH_ZERO);
}
for (final Issue issue : list) {
markerCreator.createMarker(issue, file, MarkerTypes.forCheckType(issue.getType()));
}
}
} catch (final CoreException e) {
LOGGER.error(e.getMessage(), e);
} finally {
monitor.worked(1);
}
}
示例3: validateProject
import org.eclipse.xtext.validation.IResourceValidator; //导入方法依赖的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());
}
}
示例4: validate
import org.eclipse.xtext.validation.IResourceValidator; //导入方法依赖的package包/类
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);
}
示例5: validate
import org.eclipse.xtext.validation.IResourceValidator; //导入方法依赖的package包/类
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);
}
示例6: testExplicitOverride01
import org.eclipse.xtext.validation.IResourceValidator; //导入方法依赖的package包/类
@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());
}
示例7: testExplicitOverride04
import org.eclipse.xtext.validation.IResourceValidator; //导入方法依赖的package包/类
@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());
}
示例8: testMissingArgument
import org.eclipse.xtext.validation.IResourceValidator; //导入方法依赖的package包/类
@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());
}
示例9: testMissingArgument2
import org.eclipse.xtext.validation.IResourceValidator; //导入方法依赖的package包/类
@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());
}
示例10: testMissingArgument3
import org.eclipse.xtext.validation.IResourceValidator; //导入方法依赖的package包/类
@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());
}
示例11: testOutOfSequenceArgument_01
import org.eclipse.xtext.validation.IResourceValidator; //导入方法依赖的package包/类
@Test public void testOutOfSequenceArgument_01() throws Exception {
XtextResource resource = getResourceFromString(
"grammar com.acme.Bar with org.eclipse.xtext.common.Terminals\n" +
"generate metamodel 'myURI'\n" +
"Model: rule=Rule<true, C=false, B=true>;\n" +
"Rule<A, B, C>: name=ID;");
IResourceValidator validator = get(IResourceValidator.class);
List<Issue> issues = validator.validate(resource, CheckMode.FAST_ONLY, CancelIndicator.NullImpl);
assertEquals(issues.toString(), 2, issues.size());
assertEquals("Out of sequence named argument. Expected value for B", issues.get(0).getMessage());
assertEquals("Out of sequence named argument. Expected value for C", issues.get(1).getMessage());
}
示例12: testOutOfSequenceArgument_02
import org.eclipse.xtext.validation.IResourceValidator; //导入方法依赖的package包/类
@Test public void testOutOfSequenceArgument_02() throws Exception {
XtextResource resource = getResourceFromString(
"grammar com.acme.Bar with org.eclipse.xtext.common.Terminals\n" +
"generate metamodel 'myURI'\n" +
"Model: rule=Rule<true, B=false, C=true>;\n" +
"Rule<A, B, C>: name=ID;");
IResourceValidator validator = get(IResourceValidator.class);
List<Issue> issues = validator.validate(resource, CheckMode.FAST_ONLY, CancelIndicator.NullImpl);
assertEquals(issues.toString(), 0, issues.size());
}
示例13: testOutOfSequenceArgument_03
import org.eclipse.xtext.validation.IResourceValidator; //导入方法依赖的package包/类
@Test public void testOutOfSequenceArgument_03() throws Exception {
XtextResource resource = getResourceFromString(
"grammar com.acme.Bar with org.eclipse.xtext.common.Terminals\n" +
"generate metamodel 'myURI'\n" +
"Model: rule=Rule<A=true, C=false, B=true>;\n" +
"Rule<A, B, C>: name=ID;");
IResourceValidator validator = get(IResourceValidator.class);
List<Issue> issues = validator.validate(resource, CheckMode.FAST_ONLY, CancelIndicator.NullImpl);
assertEquals(issues.toString(), 0, issues.size());
}
示例14: testDuplicateArgument
import org.eclipse.xtext.validation.IResourceValidator; //导入方法依赖的package包/类
@Test public void testDuplicateArgument() throws Exception {
XtextResource resource = getResourceFromString(
"grammar com.acme.Bar with org.eclipse.xtext.common.Terminals\n" +
"generate metamodel 'myURI'\n" +
"Model: rule=Rule<Single=true, Single=false>;\n" +
"Rule<Single>: 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("Duplicate value for parameter Single", issues.get(0).getMessage());
}
示例15: testSupressedWarning_01
import org.eclipse.xtext.validation.IResourceValidator; //导入方法依赖的package包/类
@Test public void testSupressedWarning_01() throws Exception {
XtextResource resource = getResourceFromString(
"grammar org.acme.Bar with org.eclipse.xtext.common.Terminals\n" +
"generate metamodel 'myURI'\n" +
"Model: child=Child;\n" +
"/* SuppressWarnings[noInstantiation] */\n" +
"Child: name=ID?;");
assertTrue(resource.getErrors().toString(), resource.getErrors().isEmpty());
assertTrue(resource.getWarnings().toString(), resource.getWarnings().isEmpty());
IResourceValidator validator = get(IResourceValidator.class);
List<Issue> issues = validator.validate(resource, CheckMode.FAST_ONLY, CancelIndicator.NullImpl);
assertTrue(issues.toString(), issues.isEmpty());
}