Java 类javax.lang.model.util.SimpleTypeVisitor7 实例源码
项目:alchemy
文件:RelationRule.java
@Override
public void process(Element element) throws Exception {
final Element enclosingElement = element.getEnclosingElement();
if (enclosingElement.getAnnotation(Entry.class) == null) {
throw new ElementException("Class containing @Relation must be annotated with @Entry", enclosingElement);
}
element.asType().accept(new SimpleTypeVisitor7<Void, Void>() {
@Override
public Void visitDeclared(DeclaredType t, Void unused) {
final List<? extends TypeMirror> args = t.getTypeArguments();
if (args.isEmpty()) {
processOneToOne(element, t.asElement());
} else {
processOneToMany(element, (TypeElement) t.asElement(), args.get(0));
}
return super.visitDeclared(t, unused);
}
}, null);
}
项目:alchemy
文件:RelationRule.java
private void processOneToMany(Element field, Element collectionType, TypeMirror relation) {
if (!mTypeUtils.isAssignable(collectionType.asType(), List.class)) {
throw new ElementException("Relation type must be subclass of List<E>", field);
}
relation.accept(new SimpleTypeVisitor7<Void, Void>() {
@Override
public Void visitDeclared(DeclaredType t, Void unused) {
final Element element = t.asElement();
if (element.getAnnotation(Entry.class) == null) {
throw new ElementException("Related type must be annotated with @Entry", element);
}
final Element enclosingElement = field.getEnclosingElement();
final TableSpec lTable = mCompileGraph.findTableSpec(enclosingElement);
final TableSpec rTable = mCompileGraph.findTableSpec(element);
final ClassName className = makeClassName(field);
final RelationSpec relationSpec = new RelationSpec(
field, className, lTable, rTable, true);
mCompileGraph.putRelationSpec(enclosingElement, relationSpec);
return super.visitDeclared(t, unused);
}
}, null);
}
项目:Smirk
文件:TypeNames.java
public TypeName forTypeMirror(TypeMirror mirror) {
return mirror.accept(new SimpleTypeVisitor7<TypeName, Void>(){
}, null);
}