Removed Validator interface and inlined its implementations
This commit is contained in:
parent
c278e1e943
commit
9216b3e8e1
|
|
@ -1,5 +1,6 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<classpath>
|
<classpath>
|
||||||
|
<classpathentry kind="var" path="CLOVER_RUNTIME"/>
|
||||||
<classpathentry including="**/*.java" kind="src" path="src/main/java"/>
|
<classpathentry including="**/*.java" kind="src" path="src/main/java"/>
|
||||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
|
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
<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.beans"/>
|
||||||
<classpathentry combineaccessrules="false" kind="src" path="/org.springframework.core"/>
|
<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.context"/>
|
||||||
|
<classpathentry combineaccessrules="false" kind="src" path="/org.springframework.aop"/>
|
||||||
<classpathentry kind="output" path="target/classes"/>
|
<classpathentry kind="output" path="target/classes"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
|
|
||||||
|
|
@ -10,11 +10,21 @@
|
||||||
<arguments>
|
<arguments>
|
||||||
</arguments>
|
</arguments>
|
||||||
</buildCommand>
|
</buildCommand>
|
||||||
|
<buildCommand>
|
||||||
|
<name>com.cenqua.clover.core.prejavabuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
<buildCommand>
|
<buildCommand>
|
||||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||||
<arguments>
|
<arguments>
|
||||||
</arguments>
|
</arguments>
|
||||||
</buildCommand>
|
</buildCommand>
|
||||||
|
<buildCommand>
|
||||||
|
<name>com.cenqua.clover.core.postjavabuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
<buildCommand>
|
<buildCommand>
|
||||||
<name>org.eclipse.wst.validation.validationbuilder</name>
|
<name>org.eclipse.wst.validation.validationbuilder</name>
|
||||||
<arguments>
|
<arguments>
|
||||||
|
|
@ -32,5 +42,6 @@
|
||||||
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
|
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
|
||||||
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
|
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
|
||||||
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
|
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
|
||||||
|
<nature>com.cenqua.clover.core.clovernature</nature>
|
||||||
</natures>
|
</natures>
|
||||||
</projectDescription>
|
</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.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.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.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 -->
|
<!-- build time only dependencies -->
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,6 @@ public final class BeanMethod implements Validatable {
|
||||||
private final List<Annotation> annotations = new ArrayList<Annotation>();
|
private final List<Annotation> annotations = new ArrayList<Annotation>();
|
||||||
private transient ConfigurationClass declaringClass;
|
private transient ConfigurationClass declaringClass;
|
||||||
private transient int lineNumber;
|
private transient int lineNumber;
|
||||||
private transient final List<Validator> validators = new ArrayList<Validator>();
|
|
||||||
|
|
||||||
public BeanMethod(String name, int modifiers, ModelClass returnType, Annotation... annotations) {
|
public BeanMethod(String name, int modifiers, ModelClass returnType, Annotation... annotations) {
|
||||||
Assert.hasText(name);
|
Assert.hasText(name);
|
||||||
|
|
@ -117,10 +116,6 @@ public final class BeanMethod implements Validatable {
|
||||||
return lineNumber;
|
return lineNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerValidator(Validator validator) {
|
|
||||||
validators.add(validator);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void validate(List<UsageError> errors) {
|
public void validate(List<UsageError> errors) {
|
||||||
|
|
||||||
if (Modifier.isPrivate(getModifiers()))
|
if (Modifier.isPrivate(getModifiers()))
|
||||||
|
|
@ -129,33 +124,16 @@ public final class BeanMethod implements Validatable {
|
||||||
if (Modifier.isFinal(getModifiers()))
|
if (Modifier.isFinal(getModifiers()))
|
||||||
errors.add(new FinalMethodError());
|
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
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
String returnTypeName = returnType == null ? "<unknown>" : returnType.getSimpleName();
|
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));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
@ -43,7 +43,6 @@ public final class ConfigurationModel implements Validatable {
|
||||||
|
|
||||||
/* list is used because order and collection equality matters. */
|
/* list is used because order and collection equality matters. */
|
||||||
private final ArrayList<ConfigurationClass> configurationClasses = new ArrayList<ConfigurationClass>();
|
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
|
* 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;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerValidator(Validator validator) {
|
|
||||||
validators.add(validator);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return configuration classes that have been directly added to this model.
|
* 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 ConfigurationClass#validate(java.util.List)
|
||||||
* @see BeanMethod#validate(java.util.List)
|
* @see BeanMethod#validate(java.util.List)
|
||||||
* @see Validator
|
|
||||||
* @see UsageError
|
* @see UsageError
|
||||||
*/
|
*/
|
||||||
public void validate(List<UsageError> errors) {
|
public void validate(List<UsageError> errors) {
|
||||||
|
|
@ -104,27 +98,20 @@ public final class ConfigurationModel implements Validatable {
|
||||||
if (configurationClasses.isEmpty())
|
if (configurationClasses.isEmpty())
|
||||||
errors.add(new EmptyModelError());
|
errors.add(new EmptyModelError());
|
||||||
|
|
||||||
// cascade through model and allow handlers to register validators
|
// check for any illegal @Bean overriding
|
||||||
// depending on where they are registered (with the model, the class, or the method)
|
ConfigurationClass[] allClasses = getAllConfigurationClasses();
|
||||||
// they will be called directly or indirectly below
|
for (int i = 0; i < allClasses.length; i++) {
|
||||||
// for (ConfigurationClass configClass : getAllConfigurationClasses()) {
|
for (BeanMethod method : allClasses[i].getMethods()) {
|
||||||
// for (BeanMethod method : configClass.getMethods()) {
|
Bean bean = method.getAnnotation(Bean.class);
|
||||||
// for (Validator validator : method.getValidators()) {
|
|
||||||
// if (validator.supports(method))
|
if (bean == null || bean.allowOverriding())
|
||||||
// method.registerValidator(validator);
|
continue;
|
||||||
// // TODO: support class-level validation
|
|
||||||
// // if(validator.supports(configClass))
|
for (int j = i + 1; j < allClasses.length; j++)
|
||||||
// // configClass.registerValidator(validator);
|
if (allClasses[j].hasMethod(method.getName()))
|
||||||
// if (validator.supports(this))
|
errors.add(allClasses[i].new IllegalBeanOverrideError(allClasses[j], method));
|
||||||
// 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);
|
|
||||||
|
|
||||||
// each individual configuration class must be well-formed
|
// each individual configuration class must be well-formed
|
||||||
// note that each configClass detects usage errors on its imports recursively
|
// 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));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -6,8 +6,6 @@ import java.util.List;
|
||||||
/**
|
/**
|
||||||
* Indicates a type is able to be validated for errors.
|
* Indicates a type is able to be validated for errors.
|
||||||
*
|
*
|
||||||
* @see Validator
|
|
||||||
*
|
|
||||||
* @author Chris Beams
|
* @author Chris Beams
|
||||||
*/
|
*/
|
||||||
interface Validatable {
|
interface Validatable {
|
||||||
|
|
|
||||||
|
|
@ -1,10 +0,0 @@
|
||||||
package org.springframework.config.java;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
|
|
||||||
interface Validator {
|
|
||||||
boolean supports(Object object);
|
|
||||||
|
|
||||||
void validate(Object object, List<UsageError> errors);
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue