mirror of
https://github.com/collinsmith/riiablo.git
synced 2025-07-05 07:48:05 +07:00
Added DeclaredType resolution to TableElement
This commit is contained in:
@ -1,6 +1,8 @@
|
|||||||
package com.riiablo.table.annotation;
|
package com.riiablo.table.annotation;
|
||||||
|
|
||||||
import javax.lang.model.element.Element;
|
import javax.lang.model.element.Element;
|
||||||
|
import javax.lang.model.element.ElementKind;
|
||||||
|
import javax.lang.model.element.ExecutableElement;
|
||||||
import javax.lang.model.element.TypeElement;
|
import javax.lang.model.element.TypeElement;
|
||||||
import javax.lang.model.type.DeclaredType;
|
import javax.lang.model.type.DeclaredType;
|
||||||
import javax.lang.model.type.MirroredTypeException;
|
import javax.lang.model.type.MirroredTypeException;
|
||||||
@ -10,17 +12,20 @@ final class TableElement {
|
|||||||
static TableElement get(Context context, Element element) {
|
static TableElement get(Context context, Element element) {
|
||||||
Table annotation = element.getAnnotation(Table.class);
|
Table annotation = element.getAnnotation(Table.class);
|
||||||
final TypeElement tableElement, tableImplElement;
|
final TypeElement tableElement, tableImplElement;
|
||||||
|
final DeclaredType declaredType;
|
||||||
if (annotation == null) {
|
if (annotation == null) {
|
||||||
// Only need tableElement if generating Table impl
|
// Only need tableElement if generating Table impl
|
||||||
tableElement = context.elementUtils.getTypeElement(com.riiablo.table.Table.class.getCanonicalName());
|
tableElement = context.elementUtils.getTypeElement(com.riiablo.table.Table.class.getCanonicalName());
|
||||||
|
declaredType = context.typeUtils.getDeclaredType(tableElement, element.asType());
|
||||||
tableImplElement = null;
|
tableImplElement = null;
|
||||||
} else {
|
} else {
|
||||||
// Only need tableImplElement if @Table present
|
// Only need tableImplElement if @Table present
|
||||||
tableImplElement = getTableImpl(context, annotation);
|
tableImplElement = getTableImpl(context, annotation);
|
||||||
tableElement = null;
|
tableElement = null;
|
||||||
|
declaredType = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new TableElement(annotation, tableElement, tableImplElement);
|
return new TableElement(annotation, declaredType, tableElement, tableImplElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
static TypeElement getTableImpl(Context context, Table annotation) {
|
static TypeElement getTableImpl(Context context, Table annotation) {
|
||||||
@ -35,22 +40,39 @@ final class TableElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final Table annotation;
|
final Table annotation;
|
||||||
|
final DeclaredType declaredType;
|
||||||
final TypeElement tableElement; // Class<Table>
|
final TypeElement tableElement; // Class<Table>
|
||||||
final TypeElement tableImplElement; // Class<? extends Table<?>>
|
final TypeElement tableImplElement; // Class<? extends Table<?>>
|
||||||
|
|
||||||
TableElement(
|
TableElement(
|
||||||
Table annotation,
|
Table annotation,
|
||||||
|
DeclaredType declaredType,
|
||||||
TypeElement tableElement,
|
TypeElement tableElement,
|
||||||
TypeElement tableImplElement) {
|
TypeElement tableImplElement) {
|
||||||
this.annotation = annotation;
|
this.annotation = annotation;
|
||||||
|
this.declaredType = declaredType;
|
||||||
this.tableElement = tableElement;
|
this.tableElement = tableElement;
|
||||||
this.tableImplElement = tableImplElement;
|
this.tableImplElement = tableImplElement;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ExecutableElement getMethod(CharSequence methodName) {
|
||||||
|
for (Element e : tableElement.getEnclosedElements()) {
|
||||||
|
if (e.getKind() == ElementKind.METHOD) {
|
||||||
|
ExecutableElement methodElement = (ExecutableElement) e;
|
||||||
|
if (methodElement.getSimpleName().contentEquals(methodName)) {
|
||||||
|
return methodElement;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new AssertionError(tableElement + " does not contain " + methodName);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return new ToStringBuilder(this)
|
return new ToStringBuilder(this)
|
||||||
.append("annotation", annotation)
|
.append("annotation", annotation)
|
||||||
|
.append("declaredType", declaredType)
|
||||||
.append("tableElement", tableElement)
|
.append("tableElement", tableElement)
|
||||||
.append("tableImplElement", tableImplElement)
|
.append("tableImplElement", tableImplElement)
|
||||||
.toString();
|
.toString();
|
||||||
|
Reference in New Issue
Block a user