org.eclipse.xtext.validation.IResourceValidator Java Examples

The following examples show how to use org.eclipse.xtext.validation.IResourceValidator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LinkingTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testBug345433_02() throws Exception {
	String classAsString = 
		"import static extension org.eclipse.xtext.GrammarUtil.*\n" +
		"class Foo {" +
		"	org.eclipse.xtext.Grammar grammar\n" +
		"	def function1() {\n" + 
		"		grammar.containedRuleCalls.filter(e0 | " +
		"			!e0.isAssigned() && !e0.isEObjectRuleCall()" +
		"		).map(e1 | e1.rule)\n" + 
		"	}\n" +
		"}";
	XtendClass clazz = clazz(classAsString);
	IResourceValidator validator = ((XtextResource) clazz.eResource()).getResourceServiceProvider().getResourceValidator();
	List<Issue> issues = validator.validate(clazz.eResource(), CheckMode.ALL, CancelIndicator.NullImpl);
	assertTrue("Resource contained errors : " + issues.toString(), issues.isEmpty());
	XtendFunction function = (XtendFunction) clazz.getMembers().get(1);
	XExpression body = function.getExpression();
	LightweightTypeReference bodyType = getType(body);
	assertEquals("java.lang.Iterable<org.eclipse.xtext.AbstractRule>", bodyType.getIdentifier());
	XBlockExpression block = (XBlockExpression) body;
	XMemberFeatureCall featureCall = (XMemberFeatureCall) block.getExpressions().get(0);
	XClosure closure = (XClosure) featureCall.getMemberCallArguments().get(0);
	JvmFormalParameter e1 = closure.getFormalParameters().get(0);
	assertEquals("e1", e1.getSimpleName());
	assertEquals("org.eclipse.xtext.RuleCall", getType(e1).getIdentifier());
}
 
Example #2
Source File: ValidMarkerUpdateJob.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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);
  }
}
 
Example #3
Source File: JavaSourceLanguageRuntimeModule.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected void configure() {
	bind(Resource.Factory.class).to(JavaResource.Factory.class);
	bind(IResourceValidator.class).toInstance(IResourceValidator.NULL);
	bind(IGenerator.class).to(IGenerator.NullGenerator.class);
	bind(IEncodingProvider.class).to(IEncodingProvider.Runtime.class);
	bind(IResourceServiceProvider.class).to(JavaResourceServiceProvider.class);
	bind(IContainer.Manager.class).to(SimpleResourceDescriptionsBasedContainerManager.class);
	bind(IResourceDescription.Manager.class).to(JavaResourceDescriptionManager.class);
	bind(IQualifiedNameProvider.class).to(JvmIdentifiableQualifiedNameProvider.class);
	bind(String.class).annotatedWith(Names.named(Constants.FILE_EXTENSIONS)).toInstance("java");
	bind(String.class).annotatedWith(Names.named(Constants.LANGUAGE_NAME))
			.toInstance("org.eclipse.xtext.java.Java");
	bind(IJvmTypeProvider.Factory.class).to(ClasspathTypeProviderFactory.class);
	bind(ClassLoader.class).toInstance(JavaSourceLanguageRuntimeModule.class.getClassLoader());
	bind(IReferableElementsUnloader.class).to(IReferableElementsUnloader.GenericUnloader.class);
	bind(IResourceDescriptionsProvider.class)
			.toInstance((ResourceSet rs) -> ChunkedResourceDescriptions.findInEmfObject(rs));
}
 
Example #4
Source File: SCTXtextIntegrationModule.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void configure(Binder binder) {
	binder.bind(IResourceValidator.class).to(SCTResourceValidatorImpl.class);
	binder.bind(String.class).annotatedWith(Names.named(Constants.FILE_EXTENSIONS)).toInstance("sct");
	binder.bind(IEncodingProvider.class).to(IEncodingProvider.Runtime.class);
	binder.bind(IQualifiedNameProvider.class).to(StextNameProvider.class);
	binder.bind(org.eclipse.jface.viewers.ILabelProvider.class)
			.annotatedWith(org.eclipse.xtext.ui.resource.ResourceServiceDescriptionLabelProvider.class)
			.to(DefaultDescriptionLabelProvider.class);
	binder.bind(IDefaultResourceDescriptionStrategy.class).to(SCTResourceDescriptionStrategy.class);
	
	binder.bind(MarkerCreator.class).to(SCTMarkerCreator.class);
	binder.bind(MarkerTypeProvider.class).to(SCTMarkerTypeProvider.class);
	binder.bind(IDiagnosticConverter.class).to(SCTDiagnosticConverterImpl.class);
	binder.bind(IURIEditorOpener.class).annotatedWith(LanguageSpecific.class).to(SCTFileEditorOpener.class);
	
	binder.bind(IMarkerContributor.class).to(TaskMarkerContributor.class);
	binder.bind(ITaskFinder.class).to(DomainSpecificTaskFinder.class);
	binder.bind(TaskMarkerCreator.class).to(SCTTaskMarkerCreator.class);
	binder.bind(TaskMarkerTypeProvider.class).to(SCTTaskMarkerTypeProvider.class);
}
 
Example #5
Source File: LinkingTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testBug345433_01() throws Exception {
	String classAsString = 
		"import static extension org.eclipse.xtext.GrammarUtil.*\n" +
		"class Foo {" +
		"	org.eclipse.xtext.Grammar grammar\n" +
		"	def function1() {\n" + 
		"		grammar.containedRuleCalls.filter(e | " +
		"			!e.isAssigned() && !e.isEObjectRuleCall()" +
		"		).map(e | e.rule)\n" + 
		"	}\n" +
		"	def function2() {\n" +
		"		newArrayList(function1().head())\n" +
		"	}\n" +
		"}";
	XtendClass clazz = clazz(classAsString);
	IResourceValidator validator = ((XtextResource) clazz.eResource()).getResourceServiceProvider().getResourceValidator();
	List<Issue> issues = validator.validate(clazz.eResource(), CheckMode.ALL, CancelIndicator.NullImpl);
	assertTrue("Resource contained errors : " + issues.toString(), issues.isEmpty());
	XtendFunction function1 = (XtendFunction) clazz.getMembers().get(1);
	JvmOperation operation1 = associator.getDirectlyInferredOperation(function1);
	assertEquals("java.lang.Iterable<org.eclipse.xtext.AbstractRule>", operation1.getReturnType().getIdentifier());
	XtendFunction function2 = (XtendFunction) clazz.getMembers().get(2);
	JvmOperation operation2 = associator.getDirectlyInferredOperation(function2);
	assertEquals("java.util.ArrayList<org.eclipse.xtext.AbstractRule>", operation2.getReturnType().getIdentifier());
}
 
Example #6
Source File: ActiveAnnotationsRuntimeTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
public void assertIssues(final Pair<String, String> macroFile, final Pair<String, String> clientFile, final Procedure1<? super List<Issue>> expectations) {
  try {
    final XtextResourceSet resourceSet = this.compileMacroResourceSet(macroFile, clientFile);
    Resource _head = IterableExtensions.<Resource>head(resourceSet.getResources());
    final XtextResource singleResource = ((XtextResource) _head);
    boolean _isLoaded = singleResource.isLoaded();
    boolean _not = (!_isLoaded);
    if (_not) {
      singleResource.load(resourceSet.getLoadOptions());
    }
    final IResourceValidator validator = singleResource.getResourceServiceProvider().getResourceValidator();
    expectations.apply(validator.validate(singleResource, CheckMode.ALL, CancelIndicator.NullImpl));
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #7
Source File: XtextValidationTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@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());
}
 
Example #8
Source File: OwnResourceValidatorAwareValidatingEditorCallback.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
private ValidationJob newValidationJob(final XtextEditor editor) {

		final IXtextDocument document = editor.getDocument();
		final IAnnotationModel annotationModel = editor.getInternalSourceViewer().getAnnotationModel();

		final IssueResolutionProvider issueResolutionProvider = getService(editor, IssueResolutionProvider.class);
		final MarkerTypeProvider markerTypeProvider = getService(editor, MarkerTypeProvider.class);
		final MarkerCreator markerCreator = getService(editor, MarkerCreator.class);

		final IValidationIssueProcessor issueProcessor = new CompositeValidationIssueProcessor(
				new AnnotationIssueProcessor(document, annotationModel, issueResolutionProvider),
				new MarkerIssueProcessor(editor.getResource(), annotationModel, markerCreator, markerTypeProvider));

		return editor.getDocument().modify(resource -> {
			final IResourceServiceProvider serviceProvider = resource.getResourceServiceProvider();
			final IResourceValidator resourceValidator = serviceProvider.getResourceValidator();
			return new ValidationJob(resourceValidator, editor.getDocument(), issueProcessor, ALL);
		});
	}
 
Example #9
Source File: ComparisonExpressionValidator.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
public IStatus validateXtextResource(final Injector injector, Resource resource, ResourceSet resourceSet) throws OperationCanceledError {
      final IResourceValidator xtextResourceChecker = injector.getInstance(IResourceValidator.class);
final MultiStatus status = new MultiStatus(ExpressionEditorPlugin.PLUGIN_ID, 0, "", null);
      final ConditionModelJavaValidator validator = injector.getInstance(ConditionModelJavaValidator.class);
      validator.setCurrentResourceSet(resourceSet);
final List<Issue> issues = xtextResourceChecker.validate(resource, CheckMode.FAST_ONLY, null);
if(issues.isEmpty()){
	updateDependencies(resource);
}
for(final Issue issue : issues){
	int severity = IStatus.ERROR;
	final Severity issueSeverity = issue.getSeverity();
	if(issueSeverity == Severity.WARNING){
		severity = IStatus.WARNING;
	}
	status.add(new Status(severity, ExpressionEditorPlugin.PLUGIN_ID, issue.getMessage()));
}

return status;
  }
 
Example #10
Source File: GenericEditorModule.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
public void configure(Binder binder) {
	super.configure(binder);
	Multibinder<IEditProposalProvider> proposalProviderBinder = Multibinder.newSetBinder(binder,
			IEditProposalProvider.class);
	proposalProviderBinder.addBinding().to(SmartEditProposalProvider.class);
	proposalProviderBinder.addBinding().to(RefactoringProposalProvider.class);
	binder.bind(IResourceValidator.class).to(SCTResourceValidatorImpl.class);
	binder.bind(IValidationIssueProcessor.class).to(DefaultValidationIssueStore.class);
}
 
Example #11
Source File: DslParser.java    From bromium with MIT License 5 votes vote down vote up
@Inject
public DslParser(ResourceSet resourceSet,
                 IResourceValidator validator,
                 ASTNodeConverter<Model, ApplicationConfiguration> ASTNodeConverter) {
    this.resourceSet = resourceSet;
    this.validator = validator;
    this.ASTNodeConverter = ASTNodeConverter;
}
 
Example #12
Source File: DslParserTest.java    From bromium with MIT License 5 votes vote down vote up
private void initMocks(File file) {
    applicationConfiguration = mock(ApplicationConfiguration.class);
    model = mock(Model.class);
    resource = mock(Resource.class, RETURNS_DEEP_STUBS);
    when(resource.getAllContents().next()).thenReturn(model);
    resourceSet = mock(ResourceSet.class);
    when(resourceSet.getResource(URI.createFileURI(file.getAbsolutePath()), true)).thenReturn(resource);
    resourceValidator = mock(IResourceValidator.class);
    ASTNodeConverter = mock(ASTNodeConverter.class);
    when(ASTNodeConverter.convert(model)).thenReturn(applicationConfiguration);
}
 
Example #13
Source File: DefaultValidationJob.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
public TransactionalValidationRunner(IResourceValidator validator, Resource resource, CheckMode checkMode,
		CancelIndicator indicator) {
	this.validator = validator;
	this.resource = resource;
	this.checkMode = checkMode;
	this.indicator = indicator;

}
 
Example #14
Source File: IssuesProvider.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
@SuppressWarnings("javadoc")
public IssuesProvider(IResourceValidator resourceValidator, Resource res, CheckMode checkMode,
		OperationCanceledManager operationCanceledManager, CancelIndicator ci) {
	this.rv = resourceValidator;
	this.r = res;
	this.checkMode = checkMode;
	this.operationCanceledManager = operationCanceledManager;
	this.ci = ci;
}
 
Example #15
Source File: GamlRuntimeModule.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void configure(final Binder binder) {
	super.configure(binder);
	staticInitialize();
	// binder.bind(ExpressionDescriptionBuilder.class);
	// binder.bind(IDocManager.class).to(GamlResourceDocumenter.class);
	// binder.bind(GamlSyntacticConverter.class);
	binder.bind(IDefaultResourceDescriptionStrategy.class).to(GamlResourceDescriptionStrategy.class);
	binder.bind(IQualifiedNameConverter.class).to(GamlNameConverter.class);
	binder.bind(IResourceDescription.Manager.class).to(GamlResourceDescriptionManager.class);
	// binder.bind(IOutputConfigurationProvider.class).to(GamlOutputConfigurationProvider.class);
	binder.bind(IResourceValidator.class).to(GamlResourceValidator.class);
	binder.bind(ErrorToDiagnoticTranslator.class);

}
 
Example #16
Source File: XtextValidationTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@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());
}
 
Example #17
Source File: XtextValidationTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@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());
}
 
Example #18
Source File: XtextValidationTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@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());
}
 
Example #19
Source File: XtextValidationTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testSupressedWarning_02() throws Exception {
	XtextResource resource = getResourceFromString(
			"grammar org.acme.Bar with org.eclipse.xtext.common.Terminals\n" +
			"generate metamodel 'myURI'\n" +
					
			"/* SuppressWarnings[potentialOverride] */\n" + 
			"Parens: \n" + 
			"  ('(' Parens ')'|name=ID) em='!'?;");
	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());
}
 
Example #20
Source File: ValidationJob.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public ValidationJob(IResourceValidator xtextResourceChecker, IReadAccess<XtextResource> xtextDocument,
		IValidationIssueProcessor validationIssueProcessor,CheckMode checkMode) {
	super(Messages.ValidationJob_0);
	this.xtextDocument = xtextDocument;
	this.resourceValidator = xtextResourceChecker;
	this.validationIssueProcessor = validationIssueProcessor;
	this.checkMode = checkMode;
}
 
Example #21
Source File: XtextValidationTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@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());
}
 
Example #22
Source File: XtextValidationTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@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());
}
 
Example #23
Source File: XtextValidationTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@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());
}
 
Example #24
Source File: XtextValidationTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@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());
}
 
Example #25
Source File: XtendPreviewFactory.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
public XtendFormatterPreview createNewPreview(Composite composite, String previewContent) {
	XtendFormatterPreview formatterPreview = new XtendFormatterPreview();
	memberInjector.injectMembers(formatterPreview);
	EmbeddedEditor embeddedEditor = editorFactory.newEditor(resourceProvider)
			.withResourceValidator(IResourceValidator.NULL).readOnly().withParent(composite);
	return formatterPreview.forEmbeddedEditor(embeddedEditor).withPreviewContent(previewContent);
}
 
Example #26
Source File: AbstractBuilderParticipantTest.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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);
		}
	});
}
 
Example #27
Source File: XtendBatchCompiler.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected List<Issue> validate(ResourceSet resourceSet) {
	List<Issue> issues = Lists.newArrayList();
	List<Resource> resources = Lists.newArrayList(resourceSet.getResources());
	for (Resource resource : resources) {
		IResourceServiceProvider resourceServiceProvider = IResourceServiceProvider.Registry.INSTANCE
				.getResourceServiceProvider(resource.getURI());
		if (resourceServiceProvider != null && isSourceFile(resource)) {
			IResourceValidator resourceValidator = resourceServiceProvider.getResourceValidator();
			List<Issue> result = resourceValidator.validate(resource, CheckMode.ALL, null);
			addAll(issues, result);
		}
	}
	return issues;
}
 
Example #28
Source File: XtextValidationTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@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());
}
 
Example #29
Source File: XtextValidationTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@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());
	
}
 
Example #30
Source File: IncrementalBuilder.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Validate the resource and return true, if the build should proceed for the current state.
 */
protected boolean validate(Resource resource) {
	IResourceValidator resourceValidator = getResourceServiceProvider(resource).getResourceValidator();
	if (resourceValidator == null) {
		return true;
	}
	List<Issue> validationResult = resourceValidator.validate(resource, CheckMode.ALL,
			request.getCancelIndicator());
	return request.getAfterValidate().afterValidate(resource.getURI(), validationResult);
}