/**
* Verifies that all class that are annotated with {@link Entity} observe the rules for JPA entities.
*
* <ul>
* <li>The class must have a public or protected, no-argument constructor. The class may have other
* constructors.</li>
* <li>The class must not be declared final.</li>
* <li>No methods or persistent instance variables must be declared final.</li>
* <li>Persistent instance variables must be declared private, protected, or package-private.</li>
* </ul>
*
* @return Self.
*/
public JandexAssert hasOnlyValidJpaEntities() {
// Precondition
isNotNull();
final List<AnnotationInstance> annotations = new ArrayList<>();
annotations.addAll(actual.getAnnotations(DotName.createSimple(Entity.class.getName())));
annotations.addAll(actual.getAnnotations(DotName.createSimple(MappedSuperclass.class.getName())));
for (final AnnotationInstance ai : annotations) {
final AnnotationTarget target = ai.target();
final ClassInfo info = target.asClass();
final AssertionRules<ClassInfo> rules = new AssertionRules<ClassInfo>(
new RulePublicOrProtectedNoArgConstructor(), new RuleClassNotFinal(),
new RuleClassHasNoFinalMethods(), new RulePersistentInstanceFieldVisibility());
final AssertionResult result = rules.verify(info);
if (!result.isValid()) {
failWithMessage(result.getErrorMessage());
}
}
return this;
}
JandexAssert.java 文件源码
java
阅读 25
收藏 0
点赞 0
评论 0
项目:units4j
作者:
评论列表
文章目录