mirror of
https://github.com/collinsmith/riiablo.git
synced 2025-07-04 15:27:30 +07:00
Added PrimaryKey AnnotationMirror for PrimaryKeyElement
Added PrimaryKey AnnotationMirror for PrimaryKeyElement Created Context#getAnnotationMirror Created Constants#PRIMARY_KEY
This commit is contained in:
@ -7,6 +7,7 @@ final class Constants {
|
||||
private Constants() {}
|
||||
|
||||
static final ClassName STRING = ClassName.get(String.class);
|
||||
static final ClassName PRIMARY_KEY = ClassName.get(PrimaryKey.class);
|
||||
|
||||
static final TypeName[] PRIMARY_KEY_TYPES = { TypeName.INT, STRING };
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.riiablo.table.annotation;
|
||||
|
||||
import com.squareup.javapoet.ClassName;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.util.Objects;
|
||||
import javax.annotation.processing.Messager;
|
||||
@ -26,6 +27,16 @@ class Context {
|
||||
elementUtils = processingEnvironment.getElementUtils();
|
||||
}
|
||||
|
||||
AnnotationMirror getAnnotationMirror(Element element, Class<? extends Annotation> annotationClass) {
|
||||
for (AnnotationMirror annotationMirror : element.getAnnotationMirrors()) {
|
||||
if (Constants.PRIMARY_KEY.equals(ClassName.get(annotationMirror.getAnnotationType()))) {
|
||||
return annotationMirror;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
void log(
|
||||
Diagnostic.Kind kind,
|
||||
Element element,
|
||||
|
@ -2,6 +2,7 @@ package com.riiablo.table.annotation;
|
||||
|
||||
import com.squareup.javapoet.ClassName;
|
||||
import java.util.Collection;
|
||||
import javax.lang.model.element.AnnotationMirror;
|
||||
import javax.lang.model.element.TypeElement;
|
||||
import javax.lang.model.element.VariableElement;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
@ -25,7 +26,9 @@ class PrimaryKeyElement {
|
||||
if (primaryKeyElement == null) {
|
||||
primaryKeyElement = e;
|
||||
} else {
|
||||
context.error(e, "{} already declared as {}", primaryKeyElement, PrimaryKey.class);
|
||||
context.error(
|
||||
e, context.getAnnotationMirror(e, PrimaryKey.class),
|
||||
"{} already declared as {}", primaryKeyElement, PrimaryKey.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -41,19 +44,23 @@ class PrimaryKeyElement {
|
||||
primaryKeyElement = firstAcceptableElement;
|
||||
}
|
||||
|
||||
return new PrimaryKeyElement(primaryKeyElement);
|
||||
AnnotationMirror primaryKeyMirror = context.getAnnotationMirror(primaryKeyElement, PrimaryKey.class);
|
||||
return new PrimaryKeyElement(primaryKeyElement, primaryKeyMirror);
|
||||
}
|
||||
|
||||
final VariableElement element;
|
||||
final AnnotationMirror mirror;
|
||||
|
||||
PrimaryKeyElement(VariableElement element) {
|
||||
PrimaryKeyElement(VariableElement element, AnnotationMirror mirror) {
|
||||
this.element = element;
|
||||
this.mirror = mirror;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this)
|
||||
.append("element", element)
|
||||
.append("mirror", mirror)
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user