/** * @since 2.4 */ protected void error(String message, EObject source, EStructuralFeature feature) { error(message, source, feature, ValidationMessageAcceptor.INSIGNIFICANT_INDEX); }
/** * @since 2.4 */ protected void warning(String message, EObject source, EStructuralFeature feature) { warning(message, source, feature, ValidationMessageAcceptor.INSIGNIFICANT_INDEX); }
/** * @since 2.4 */ protected void addIssue(String message, EObject source, EStructuralFeature feature, String issueCode, String... issueData) { addIssue(message, source, feature, INSIGNIFICANT_INDEX, issueCode, issueData); }
public void acceptWarning(String message, EObject object, EStructuralFeature feature, int index, String code, String... issueData) { checkIsFromCurrentlyCheckedResource(object); state.get().chain.add(createDiagnostic(Severity.WARNING, message, object, feature, index, code, issueData)); }
public AssertableDiagnostics diagnose() { if (!validatorCalled) throw new IllegalStateException("You have to call validator() before you call diagnose()"); validatorCalled = false; AssertableDiagnostics ad = new AssertableDiagnostics((Diagnostic) validator.setMessageAcceptor(validator) .getState().chain); validator.setMessageAcceptor(validator).getState().chain = new BasicDiagnostic(); return ad; }
@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; }
private void collectMethods(AbstractDeclarativeValidator instance, Class<? extends AbstractDeclarativeValidator> clazz, Collection<Class<?>> visitedClasses, Collection<MethodWrapper> result) { if (visitedClasses.contains(clazz)) return; collectMethodsImpl(instance, clazz, visitedClasses, result); Class<? extends AbstractDeclarativeValidator> k = clazz; while (k != null) { ComposedChecks checks = k.getAnnotation(ComposedChecks.class); if (checks != null) { for (Class<? extends AbstractDeclarativeValidator> external : checks.validators()) collectMethods(null, external, visitedClasses, result); } k = getSuperClass(k); } }
private void collectMethodsImpl(AbstractDeclarativeValidator instance, Class<? extends AbstractDeclarativeValidator> clazz, Collection<Class<?>> visitedClasses, Collection<MethodWrapper> result) { if (!visitedClasses.add(clazz)) return; AbstractDeclarativeValidator instanceToUse; instanceToUse = instance; if (instanceToUse == null) { instanceToUse = newInstance(clazz); } Method[] methods = clazz.getDeclaredMethods(); for (Method method : methods) { if (method.getAnnotation(Check.class) != null && method.getParameterTypes().length == 1) { result.add(new MethodWrapper(instanceToUse, method)); } } Class<? extends AbstractDeclarativeValidator> superClass = getSuperClass(clazz); if (superClass != null) collectMethodsImpl(instanceToUse, superClass, visitedClasses, result); }
private List<MethodWrapper> collectMethods(Class<? extends AbstractDeclarativeValidator> clazz) { List<MethodWrapper> checkMethods = new ArrayList<MethodWrapper>(); Set<Class<?>> visitedClasses = new HashSet<Class<?>>(4); collectMethods(this, clazz, visitedClasses, checkMethods); return checkMethods; }
public AssertableDiagnostics diagnose() { if (!validatorCalled) throw new IllegalStateException("You have to call validator() before you call diagnose()"); validatorCalled = false; AssertableDiagnostics ad = new AssertableDiagnostics((Diagnostic) validator.setMessageAcceptor(validator) .getState().chain); validator.setMessageAcceptor(validator).getState().chain = new BasicDiagnostic(); return ad; }
@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; }
public void acceptInfo(String message, EObject object, EStructuralFeature feature, int index, String code, String... issueData) { checkIsFromCurrentlyCheckedResource(object); state.get().chain.add(createDiagnostic(Severity.INFO, message, object, feature, index, code, issueData)); }
@Override protected final boolean internalValidate(EClass class1, EObject object, DiagnosticChain diagnostics, Map<Object, Object> context) { if (checkMethods == null) { synchronized (this) { if (checkMethods == null) { Set<MethodWrapper> checkMethods = Sets.newLinkedHashSet(); checkMethods.addAll(collectMethods(getClass())); this.checkMethods = checkMethods; } } } CheckMode checkMode = CheckMode.getCheckMode(context); State state = new State(); state.chain = diagnostics; state.currentObject = object; state.checkMode = checkMode; state.context = context; for (MethodWrapper method : methodsForType.get(object.getClass())) { method.invoke(state); } return !state.hasErrors; }
@Override public void error(String message, EObject source, EStructuralFeature feature, String code, String... issueData) { super.error(message, source, feature, code, issueData); } }
@Override public void warning(String message, EObject source, EStructuralFeature feature, String code, String... issueData) { super.warning(message, source, feature, code, issueData); }
public AssertableDiagnostics diagnose() { if (!validatorCalled) throw new IllegalStateException("You have to call validator() before you call diagnose()"); validatorCalled = false; AssertableDiagnostics ad = new AssertableDiagnostics((Diagnostic) validator.setMessageAcceptor(validator) .getState().chain); validator.setMessageAcceptor(validator).getState().chain = new BasicDiagnostic(); return ad; }
@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; }
public void acceptInfo(String message, EObject object, int offset, int length, String code, String... issueData) { checkIsFromCurrentlyCheckedResource(object); state.get().chain.add(createDiagnostic(Severity.INFO, message, object, offset, length, code, issueData)); }
/** * @since 2.4 */ protected void addIssue(String message, EObject source, int offset, int length, String issueCode){ addIssue(message, source, offset, length, issueCode, (String[])null); }
protected void error(String message, EStructuralFeature feature) { error(message, feature, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, null); }