mirror of
https://github.com/collinsmith/riiablo.git
synced 2025-07-06 08:18:41 +07:00
Refined primary key field error handling
This commit is contained in:
@ -7,6 +7,9 @@ import javax.lang.model.element.VariableElement;
|
||||
|
||||
final class FieldElement {
|
||||
static FieldElement get(Context context, VariableElement element) {
|
||||
FormatElement formatElement = FormatElement.get(context, element);
|
||||
PrimaryKeyElement primaryKeyElement = PrimaryKeyElement.get(context, element);
|
||||
|
||||
Set<Modifier> modifiers = element.getModifiers();
|
||||
if (!modifiers.contains(Modifier.PUBLIC)) {
|
||||
context.warn(element, "record fields should be declared {}", Modifier.PUBLIC);
|
||||
@ -20,9 +23,6 @@ final class FieldElement {
|
||||
context.error(element, "'{}' is an illegal record field name", Constants.RESERVED_NAME);
|
||||
return null;
|
||||
}
|
||||
|
||||
FormatElement formatElement = FormatElement.get(context, element);
|
||||
PrimaryKeyElement primaryKeyElement = PrimaryKeyElement.get(context, element);
|
||||
return new FieldElement(element, formatElement, primaryKeyElement);
|
||||
}
|
||||
|
||||
|
@ -1,12 +1,18 @@
|
||||
package com.riiablo.table.annotation;
|
||||
|
||||
import javax.lang.model.element.AnnotationMirror;
|
||||
import javax.lang.model.element.Modifier;
|
||||
import javax.lang.model.element.VariableElement;
|
||||
|
||||
final class PrimaryKeyElement extends AnnotationElement<PrimaryKey> {
|
||||
static PrimaryKeyElement get(Context context, VariableElement element) {
|
||||
PrimaryKey annotation = element.getAnnotation(PrimaryKey.class);
|
||||
if (annotation == null) return null;
|
||||
if (!element.getModifiers().contains(Modifier.PUBLIC)) {
|
||||
context.warn(element, "{} fields must be declared {}", PrimaryKey.class, Modifier.PUBLIC);
|
||||
return null;
|
||||
}
|
||||
|
||||
AnnotationMirror mirror = context.getAnnotationMirror(element, Constants.PRIMARY_KEY);
|
||||
return new PrimaryKeyElement(context, annotation, mirror);
|
||||
}
|
||||
|
@ -36,12 +36,12 @@ final class SchemaElement {
|
||||
} else {
|
||||
primaryKeyFieldElement = FieldElement.firstPrimaryKey(fields);
|
||||
if (primaryKeyFieldElement == null) {
|
||||
context.error(element, "{element} did not declare any {}", PrimaryKey.class);
|
||||
context.error(element, "{element} did not declare any valid {}", PrimaryKey.class);
|
||||
return null;
|
||||
}
|
||||
|
||||
context.warn(element,
|
||||
"{element} did not declare any {}, using {}",
|
||||
"{element} did not declare any valid {}, using {}",
|
||||
PrimaryKey.class, primaryKeyFieldElement);
|
||||
}
|
||||
|
||||
@ -58,7 +58,8 @@ final class SchemaElement {
|
||||
for (Element e : superclassElement.getEnclosedElements()) {
|
||||
switch (e.getKind()) {
|
||||
case FIELD:
|
||||
columns.add(FieldElement.get(context, (VariableElement) e));
|
||||
FieldElement field = FieldElement.get(context, (VariableElement) e);
|
||||
if (field != null) columns.add(field);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user