下面列出了怎么用javax.persistence.metamodel.StaticMetamodel的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
if (roundEnv.processingOver() || annotations.isEmpty()) {
return ALLOW_OTHER_PROCESSORS_TO_CLAIM_ANNOTATIONS;
}
roundEnv
.getElementsAnnotatedWith(StaticMetamodel.class)
.stream()
.map(TypeElement.class::cast)
.map(typeElement -> new MetamodelClass(elements, types, typeElement))
.forEach(metamodelClass -> metamodelClass.writeEntityGraphTo(filer));
return ALLOW_OTHER_PROCESSORS_TO_CLAIM_ANNOTATIONS;
}
private void populateEntityInfo() throws NoSuchMethodException {
Set<Class<?>> metaClasses = BeanUtils.reflections.getTypesAnnotatedWith(StaticMetamodel.class);
for (Class it : metaClasses) {
StaticMetamodel at = (StaticMetamodel) it.getAnnotation(StaticMetamodel.class);
metaModelClasses.put(at.value(), it);
}
Set<Class<?>> invClasses = BeanUtils.reflections.getTypesAnnotatedWith(Inventory.class);
for (Class invClass : invClasses) {
EntityInfo info = buildEntityInfo(invClass);
if (info.inventoryAnnotation.parent().length > 0) {
Parent pat = info.inventoryAnnotation.parent()[0];
Class pinvClass = pat.inventoryClass();
DebugUtils.Assert(pinvClass.isAnnotationPresent(Inventory.class), String.format("inventory[%s]'s parent inventory class[%s] is not annotated by @Inventory", info.inventoryClass.getName(), pinvClass.getName()));
EntityInfo pinfo = buildEntityInfo(pinvClass);
info.parent = pinfo;
pinfo.children.add(info);
}
}
for (EntityInfo e : entityInfos.values()) {
e.buildFlatTypeEntityMap();
}
}
@Override
public Set<String> getSupportedAnnotationTypes() {
return Collections.singleton(StaticMetamodel.class.getCanonicalName());
}