提交 9216b3e8 编写于 作者: C Chris Beams

Removed Validator interface and inlined its implementations

上级 c278e1e9
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="var" path="CLOVER_RUNTIME"/>
<classpathentry including="**/*.java" kind="src" path="src/main/java"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
......@@ -12,5 +13,6 @@
<classpathentry combineaccessrules="false" kind="src" path="/org.springframework.beans"/>
<classpathentry combineaccessrules="false" kind="src" path="/org.springframework.core"/>
<classpathentry combineaccessrules="false" kind="src" path="/org.springframework.context"/>
<classpathentry combineaccessrules="false" kind="src" path="/org.springframework.aop"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
......@@ -10,11 +10,21 @@
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.cenqua.clover.core.prejavabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.cenqua.clover.core.postjavabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name>
<arguments>
......@@ -32,5 +42,6 @@
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
<nature>com.cenqua.clover.core.clovernature</nature>
</natures>
</projectDescription>
......@@ -28,6 +28,7 @@
<dependency org="org.objectweb.asm" name="com.springsource.org.objectweb.asm.commons" rev="2.2.3" conf="compile->compile"/>
<dependency org="org.springframework" name="org.springframework.beans" rev="latest.integration" conf="compile->compile"/>
<dependency org="org.springframework" name="org.springframework.context" rev="latest.integration" conf="compile->compile"/>
<dependency org="org.springframework" name="org.springframework.aop" rev="latest.integration" conf="compile->compile"/>
<!-- build time only dependencies -->
......
......@@ -33,7 +33,6 @@ public final class BeanMethod implements Validatable {
private final List<Annotation> annotations = new ArrayList<Annotation>();
private transient ConfigurationClass declaringClass;
private transient int lineNumber;
private transient final List<Validator> validators = new ArrayList<Validator>();
public BeanMethod(String name, int modifiers, ModelClass returnType, Annotation... annotations) {
Assert.hasText(name);
......@@ -117,10 +116,6 @@ public final class BeanMethod implements Validatable {
return lineNumber;
}
public void registerValidator(Validator validator) {
validators.add(validator);
}
public void validate(List<UsageError> errors) {
if (Modifier.isPrivate(getModifiers()))
......@@ -129,33 +124,16 @@ public final class BeanMethod implements Validatable {
if (Modifier.isFinal(getModifiers()))
errors.add(new FinalMethodError());
new BeanValidator().validate(this, errors);
if (this.getAnnotation(ScopedProxy.class) == null)
return;
Bean bean =this.getRequiredAnnotation(Bean.class);
if (bean.scope().equals(StandardScopes.SINGLETON)
|| bean.scope().equals(StandardScopes.PROTOTYPE))
errors.add(new InvalidScopedProxyDeclarationError(this));
}
// public BeanDefinitionRegistrar getRegistrar() {
// return getInstance(factoryAnno.registrar());
// }
// public Set<Validator> getValidators() {
// HashSet<Validator> validators = new HashSet<Validator>();
//
//// for (Class<? extends Validator> validatorType : factoryAnno.validators())
//// validator.add(getInstance(validatorType));
//
// validators.add(IllegalB)
//
// return validators;
// }
// public Callback getCallback() {
// Class<? extends Callback> callbackType = factoryAnno.interceptor();
//
// if (callbackType.equals(NoOpInterceptor.class))
// return NoOpInterceptor.INSTANCE;
//
// return getInstance(callbackType);
// }
//
@Override
public String toString() {
String returnTypeName = returnType == null ? "<unknown>" : returnType.getSimpleName();
......@@ -227,31 +205,4 @@ public final class BeanMethod implements Validatable {
}
}
}
/**
* Detects any user errors when declaring {@link Bean}-annotated methods.
*
* @author Chris Beams
*/
class BeanValidator implements Validator {
public boolean supports(Object object) {
return object instanceof BeanMethod;
}
public void validate(Object object, List<UsageError> errors) {
BeanMethod method = (BeanMethod) object;
if (method.getAnnotation(ScopedProxy.class) == null)
return;
Bean bean = method.getRequiredAnnotation(Bean.class);
if (bean.scope().equals(StandardScopes.SINGLETON)
|| bean.scope().equals(StandardScopes.PROTOTYPE))
errors.add(new InvalidScopedProxyDeclarationError(method));
}
}
}
\ No newline at end of file
......@@ -43,7 +43,6 @@ public final class ConfigurationModel implements Validatable {
/* list is used because order and collection equality matters. */
private final ArrayList<ConfigurationClass> configurationClasses = new ArrayList<ConfigurationClass>();
private final ArrayList<Validator> validators = new ArrayList<Validator>();
/**
* Add a {@link Configuration @Configuration} class to the model. Classes may be added
......@@ -57,10 +56,6 @@ public final class ConfigurationModel implements Validatable {
return this;
}
public void registerValidator(Validator validator) {
validators.add(validator);
}
/**
* Return configuration classes that have been directly added to this model.
*
......@@ -96,7 +91,6 @@ public final class ConfigurationModel implements Validatable {
*
* @see ConfigurationClass#validate(java.util.List)
* @see BeanMethod#validate(java.util.List)
* @see Validator
* @see UsageError
*/
public void validate(List<UsageError> errors) {
......@@ -104,27 +98,20 @@ public final class ConfigurationModel implements Validatable {
if (configurationClasses.isEmpty())
errors.add(new EmptyModelError());
// cascade through model and allow handlers to register validators
// depending on where they are registered (with the model, the class, or the method)
// they will be called directly or indirectly below
// for (ConfigurationClass configClass : getAllConfigurationClasses()) {
// for (BeanMethod method : configClass.getMethods()) {
// for (Validator validator : method.getValidators()) {
// if (validator.supports(method))
// method.registerValidator(validator);
// // TODO: support class-level validation
// // if(validator.supports(configClass))
// // configClass.registerValidator(validator);
// if (validator.supports(this))
// this.registerValidator(validator);
// }
// }
// }
// process any validators registered directly with this model object
// for (Validator validator : validators)
// validator.validate(this, errors);
new IllegalBeanOverrideValidator().validate(this, errors);
// check for any illegal @Bean overriding
ConfigurationClass[] allClasses = getAllConfigurationClasses();
for (int i = 0; i < allClasses.length; i++) {
for (BeanMethod method : allClasses[i].getMethods()) {
Bean bean = method.getAnnotation(Bean.class);
if (bean == null || bean.allowOverriding())
continue;
for (int j = i + 1; j < allClasses.length; j++)
if (allClasses[j].hasMethod(method.getName()))
errors.add(allClasses[i].new IllegalBeanOverrideError(allClasses[j], method));
}
}
// each individual configuration class must be well-formed
// note that each configClass detects usage errors on its imports recursively
......@@ -176,39 +163,4 @@ public final class ConfigurationModel implements Validatable {
}
}
}
/**
* Detects any illegally-overridden {@link Bean} definitions within a particular
* {@link ConfigurationModel}
*
* @see Bean#allowOverriding()
*
* @author Chris Beams
*/
class IllegalBeanOverrideValidator implements Validator {
public boolean supports(Object object) {
return object instanceof ConfigurationModel;
}
public void validate(Object object, List<UsageError> errors) {
ConfigurationModel model = (ConfigurationModel) object;
ConfigurationClass[] allClasses = model.getAllConfigurationClasses();
for (int i = 0; i < allClasses.length; i++) {
for (BeanMethod method : allClasses[i].getMethods()) {
Bean bean = method.getAnnotation(Bean.class);
if (bean == null || bean.allowOverriding())
continue;
for (int j = i + 1; j < allClasses.length; j++)
if (allClasses[j].hasMethod(method.getName()))
errors.add(allClasses[i].new IllegalBeanOverrideError(allClasses[j], method));
}
}
}
}
}
\ No newline at end of file
......@@ -6,8 +6,6 @@ import java.util.List;
/**
* Indicates a type is able to be validated for errors.
*
* @see Validator
*
* @author Chris Beams
*/
interface Validatable {
......
package org.springframework.config.java;
import java.util.List;
interface Validator {
boolean supports(Object object);
void validate(Object object, List<UsageError> errors);
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册