Search in sources :

Example 1 with Diagnostician

use of org.eclipse.emf.ecore.util.Diagnostician in project rest-modeling-framework by commercetools.

the class RamlValidationSetup method setupCustom.

/**
 * Registers validators.
 */
static Diagnostician setupCustom(List<RamlValidator> customValidators) {
    final EValidator.Registry registry = new EValidatorRegistryImpl();
    final List<EValidator> eValidators = customValidators.stream().map(ramlValidator -> (EValidator) ramlValidator).collect(Collectors.toList());
    registry.put(TypesPackage.eINSTANCE, new TypesValidator());
    registry.put(ModulesPackage.eINSTANCE, new ModulesValidator());
    registry.put(ResourcesPackage.eINSTANCE, new ResourcesValidator());
    registry.put(ResponsesPackage.eINSTANCE, new ResponsesValidator());
    final RamlObjectValidator ramlObjectValidator = new RamlObjectValidator();
    for (final EPackage ePackage : PACKAGES) {
        final CompositeValidator compositeValidator = new CompositeValidator();
        compositeValidator.add(ramlObjectValidator);
        final EValidator validator = registry.getEValidator(ePackage);
        if (validator != null) {
            compositeValidator.add(validator);
        }
        if (eValidators.size() > 0) {
            compositeValidator.addAll(eValidators);
        }
        registry.put(ePackage, compositeValidator);
    }
    return new Diagnostician(registry);
}
Also used : java.util(java.util) EValidatorRegistryImpl(org.eclipse.emf.ecore.impl.EValidatorRegistryImpl) ResponsesPackage(io.vrap.rmf.raml.model.responses.ResponsesPackage) ValuesPackage(io.vrap.rmf.raml.model.values.ValuesPackage) ModulesPackage(io.vrap.rmf.raml.model.modules.ModulesPackage) Collectors(java.util.stream.Collectors) EPackage(org.eclipse.emf.ecore.EPackage) EValidator(org.eclipse.emf.ecore.EValidator) Diagnostician(org.eclipse.emf.ecore.util.Diagnostician) Lists(com.google.common.collect.Lists) SecurityPackage(io.vrap.rmf.raml.model.security.SecurityPackage) ElementsPackage(io.vrap.rmf.raml.model.elements.ElementsPackage) ResourcesPackage(io.vrap.rmf.raml.model.resources.ResourcesPackage) TypesPackage(io.vrap.rmf.raml.model.types.TypesPackage) EPackage(org.eclipse.emf.ecore.EPackage) Diagnostician(org.eclipse.emf.ecore.util.Diagnostician) EValidator(org.eclipse.emf.ecore.EValidator) EValidatorRegistryImpl(org.eclipse.emf.ecore.impl.EValidatorRegistryImpl)

Example 2 with Diagnostician

use of org.eclipse.emf.ecore.util.Diagnostician in project rest-modeling-framework by commercetools.

the class RamlValidationSetup method setupCustomOnly.

static Diagnostician setupCustomOnly(List<RamlValidator> customValidators) {
    final EValidator.Registry registry = new EValidatorRegistryImpl();
    final List<EValidator> eValidators = customValidators.stream().map(ramlValidator -> (EValidator) ramlValidator).collect(Collectors.toList());
    for (final EPackage ePackage : PACKAGES) {
        final CompositeValidator compositeValidator = new CompositeValidator();
        final EValidator validator = registry.getEValidator(ePackage);
        if (validator != null) {
            compositeValidator.add(validator);
        }
        if (eValidators.size() > 0) {
            compositeValidator.addAll(eValidators);
        }
        registry.put(ePackage, compositeValidator);
    }
    return new Diagnostician(registry);
}
Also used : java.util(java.util) EValidatorRegistryImpl(org.eclipse.emf.ecore.impl.EValidatorRegistryImpl) ResponsesPackage(io.vrap.rmf.raml.model.responses.ResponsesPackage) ValuesPackage(io.vrap.rmf.raml.model.values.ValuesPackage) ModulesPackage(io.vrap.rmf.raml.model.modules.ModulesPackage) Collectors(java.util.stream.Collectors) EPackage(org.eclipse.emf.ecore.EPackage) EValidator(org.eclipse.emf.ecore.EValidator) Diagnostician(org.eclipse.emf.ecore.util.Diagnostician) Lists(com.google.common.collect.Lists) SecurityPackage(io.vrap.rmf.raml.model.security.SecurityPackage) ElementsPackage(io.vrap.rmf.raml.model.elements.ElementsPackage) ResourcesPackage(io.vrap.rmf.raml.model.resources.ResourcesPackage) TypesPackage(io.vrap.rmf.raml.model.types.TypesPackage) Diagnostician(org.eclipse.emf.ecore.util.Diagnostician) EValidator(org.eclipse.emf.ecore.EValidator) EValidatorRegistryImpl(org.eclipse.emf.ecore.impl.EValidatorRegistryImpl) EPackage(org.eclipse.emf.ecore.EPackage)

Example 3 with Diagnostician

use of org.eclipse.emf.ecore.util.Diagnostician in project sirius-components by eclipse-sirius.

the class EMFValidationService method validate.

private List<Object> validate(EditingContext editingContext) {
    AdapterFactoryEditingDomain domain = editingContext.getDomain();
    Map<Object, Object> options = new HashMap<>();
    options.put(Diagnostician.VALIDATE_RECURSIVELY, true);
    Diagnostician diagnostician = this.getNewDiagnostician();
    // @formatter:off
    return domain.getResourceSet().getResources().stream().map(Resource::getContents).flatMap(Collection::stream).map(eObject -> diagnostician.validate(eObject, options)).map(Diagnostic::getChildren).flatMap(Collection::stream).collect(Collectors.toList());
// @formatter:on
}
Also used : AdapterFactoryEditingDomain(org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain) Registry(org.eclipse.emf.ecore.EValidator.Registry) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) Collection(java.util.Collection) Diagnostic(org.eclipse.emf.common.util.Diagnostic) HashMap(java.util.HashMap) EObject(org.eclipse.emf.ecore.EObject) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) EValidator(org.eclipse.emf.ecore.EValidator) List(java.util.List) Diagnostician(org.eclipse.emf.ecore.util.Diagnostician) IItemLabelProvider(org.eclipse.emf.edit.provider.IItemLabelProvider) Service(org.springframework.stereotype.Service) Map(java.util.Map) Resource(org.eclipse.emf.ecore.resource.Resource) Optional(java.util.Optional) IValidationService(org.eclipse.sirius.components.collaborative.validation.api.IValidationService) AdapterFactoryEditingDomain(org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain) ComposedAdapterFactory(org.eclipse.emf.edit.provider.ComposedAdapterFactory) Diagnostician(org.eclipse.emf.ecore.util.Diagnostician) HashMap(java.util.HashMap) Collection(java.util.Collection) Diagnostic(org.eclipse.emf.common.util.Diagnostic) EObject(org.eclipse.emf.ecore.EObject)

Example 4 with Diagnostician

use of org.eclipse.emf.ecore.util.Diagnostician in project xtext-extras by eclipse.

the class AbstractTypeProviderTest method setUp.

@Before
public void setUp() throws Exception {
    EValidator.Registry registry = new EValidatorRegistryImpl(EValidator.Registry.INSTANCE);
    registry.put(TypesPackage.eINSTANCE, new EObjectValidator());
    diagnostician = new Diagnostician(registry);
}
Also used : Diagnostician(org.eclipse.emf.ecore.util.Diagnostician) EObjectValidator(org.eclipse.emf.ecore.util.EObjectValidator) EValidator(org.eclipse.emf.ecore.EValidator) EValidatorRegistryImpl(org.eclipse.emf.ecore.impl.EValidatorRegistryImpl) Before(org.junit.Before)

Example 5 with Diagnostician

use of org.eclipse.emf.ecore.util.Diagnostician in project xtext-eclipse by eclipse.

the class AbstractTypeProviderTest method setUp.

@Before
public void setUp() throws Exception {
    EValidator.Registry registry = new EValidatorRegistryImpl(EValidator.Registry.INSTANCE);
    registry.put(TypesPackage.eINSTANCE, new EObjectValidator());
    diagnostician = new Diagnostician(registry);
}
Also used : Diagnostician(org.eclipse.emf.ecore.util.Diagnostician) EObjectValidator(org.eclipse.emf.ecore.util.EObjectValidator) EValidator(org.eclipse.emf.ecore.EValidator) EValidatorRegistryImpl(org.eclipse.emf.ecore.impl.EValidatorRegistryImpl) Before(org.junit.Before)

Aggregations

EValidator (org.eclipse.emf.ecore.EValidator)6 Diagnostician (org.eclipse.emf.ecore.util.Diagnostician)6 Collectors (java.util.stream.Collectors)4 EValidatorRegistryImpl (org.eclipse.emf.ecore.impl.EValidatorRegistryImpl)4 Lists (com.google.common.collect.Lists)2 ElementsPackage (io.vrap.rmf.raml.model.elements.ElementsPackage)2 ModulesPackage (io.vrap.rmf.raml.model.modules.ModulesPackage)2 ResourcesPackage (io.vrap.rmf.raml.model.resources.ResourcesPackage)2 ResponsesPackage (io.vrap.rmf.raml.model.responses.ResponsesPackage)2 SecurityPackage (io.vrap.rmf.raml.model.security.SecurityPackage)2 TypesPackage (io.vrap.rmf.raml.model.types.TypesPackage)2 ValuesPackage (io.vrap.rmf.raml.model.values.ValuesPackage)2 java.util (java.util)2 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Objects (java.util.Objects)2 Optional (java.util.Optional)2 Diagnostic (org.eclipse.emf.common.util.Diagnostic)2