org.eclipse.xtext.validation.AbstractInjectableValidator Java Examples

The following examples show how to use org.eclipse.xtext.validation.AbstractInjectableValidator. 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: ValidatorTester.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Inject
public ValidatorTester(T validator, EValidatorRegistrar registrar, @Named(Constants.LANGUAGE_NAME) final String languageName) {
	this.validator = validator;
	EValidator.Registry originalRegistry = registrar.getRegistry();
	EValidatorRegistryImpl newRegistry = new EValidatorRegistryImpl();
	registrar.setRegistry(newRegistry);
	this.validator.register(registrar);
	diagnostician = new Diagnostician(newRegistry) {
		@Override
		public java.util.Map<Object,Object> createDefaultContext() {
			java.util.Map<Object,Object> map = super.createDefaultContext();
			map.put(AbstractInjectableValidator.CURRENT_LANGUAGE_NAME, languageName);
			return map;
		}
	};
	registrar.setRegistry(originalRegistry);
	validatorCalled = false;
}
 
Example #2
Source File: SemverResourceValidator.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/** Copied from parent class to change language to {@code SemverGlobals.LANGUAGE_NAME} */
@Override
protected void validate(Resource resource, EObject eObject, CheckMode mode, CancelIndicator monitor,
		IAcceptor<Issue> acceptor) {
	try {
		Map<Object, Object> options = Maps.newHashMap();
		options.put(CheckMode.KEY, mode);
		options.put(CancelableDiagnostician.CANCEL_INDICATOR, monitor);
		// disable concrete syntax validation, since a semantic model that has been parsed
		// from the concrete syntax always complies with it - otherwise there are parse errors.
		options.put(ConcreteSyntaxEValidator.DISABLE_CONCRETE_SYNTAX_EVALIDATOR, Boolean.TRUE);
		// see EObjectValidator.getRootEValidator(Map<Object, Object>)
		options.put(EValidator.class, diagnostician);
		options.put(AbstractInjectableValidator.CURRENT_LANGUAGE_NAME, SemverGlobals.LANGUAGE_NAME);

		Diagnostic diagnostic = diagnostician.validate(eObject, options);
		if (!diagnostic.getChildren().isEmpty()) {
			for (Diagnostic childDiagnostic : diagnostic.getChildren()) {
				issueFromEValidatorDiagnostic(childDiagnostic, acceptor);
			}
		} else {
			issueFromEValidatorDiagnostic(diagnostic, acceptor);
		}
	} catch (RuntimeException e) {
		operationCanceledManager.propagateAsErrorIfCancelException(e);
	}
}
 
Example #3
Source File: DotValidator.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
private void doRecordLabelValidation(Attribute attribute) {
	Injector recordLabelInjector = new DotRecordLabelStandaloneSetup()
			.createInjectorAndDoEMFRegistration();
	DotRecordLabelValidator validator = recordLabelInjector
			.getInstance(DotRecordLabelValidator.class);
	IParser parser = recordLabelInjector.getInstance(IParser.class);

	DotSubgrammarValidationMessageAcceptor messageAcceptor = new DotSubgrammarValidationMessageAcceptor(
			attribute, DotPackage.Literals.ATTRIBUTE__VALUE,
			"record-based label", getMessageAcceptor(), "\"".length());

	validator.setMessageAcceptor(messageAcceptor);

	IParseResult result = parser
			.parse(new StringReader(attribute.getValue().toValue()));

	for (INode error : result.getSyntaxErrors())
		messageAcceptor.acceptSyntaxError(error);

	Map<Object, Object> validationContext = new HashMap<Object, Object>();
	validationContext.put(AbstractInjectableValidator.CURRENT_LANGUAGE_NAME,
			ReflectionUtils.getPrivateFieldValue(validator,
					"languageName"));

	// validate both the children (loop) and root element
	Iterator<EObject> iterator = result.getRootASTElement().eAllContents();
	while (iterator.hasNext())
		validator.validate(iterator.next(), null/* diagnostic chain */,
				validationContext);

	validator.validate(result.getRootASTElement(), null, validationContext);
}