use of com.pushtorefresh.storio.common.annotations.processor.SkipNotAnnotatedClassWithAnnotatedParentException in project storio by pushtorefresh.
the class StorIOContentResolverProcessor method processAnnotatedFieldsOrMethods.
/**
* Processes fields annotated with {@link StorIOContentResolverColumn}
*
* @param roundEnvironment current processing environment
* @param annotatedClasses map of classes annotated with {@link StorIOContentResolverType}
*/
@Override
protected void processAnnotatedFieldsOrMethods(@NotNull final RoundEnvironment roundEnvironment, @NotNull final Map<TypeElement, StorIOContentResolverTypeMeta> annotatedClasses) {
final Set<? extends Element> elementsAnnotatedWithStorIOContentResolverColumn = roundEnvironment.getElementsAnnotatedWith(StorIOContentResolverColumn.class);
for (final Element annotatedFieldElement : elementsAnnotatedWithStorIOContentResolverColumn) {
try {
validateAnnotatedFieldOrMethod(annotatedFieldElement);
final StorIOContentResolverColumnMeta storIOContentResolverColumnMeta = processAnnotatedFieldOrMethod(annotatedFieldElement);
final StorIOContentResolverTypeMeta storIOContentResolverTypeMeta = annotatedClasses.get(storIOContentResolverColumnMeta.enclosingElement);
// If class already contains column with same name -> throw an exception.
if (storIOContentResolverTypeMeta.columns.containsKey(storIOContentResolverColumnMeta.storIOColumn.name())) {
throw new ProcessingException(annotatedFieldElement, "Column name already used in this class: " + storIOContentResolverColumnMeta.storIOColumn.name());
}
// If field annotation applied to both fields and methods in a same class.
if ((storIOContentResolverTypeMeta.needCreator && !storIOContentResolverColumnMeta.isMethod()) || (!storIOContentResolverTypeMeta.needCreator && storIOContentResolverColumnMeta.isMethod() && !storIOContentResolverTypeMeta.columns.isEmpty())) {
throw new ProcessingException(annotatedFieldElement, "Can't apply " + StorIOContentResolverColumn.class.getSimpleName() + " annotation to both fields and methods in a same class: " + storIOContentResolverTypeMeta.simpleName);
}
// If column needs creator then enclosing class needs it as well.
if (!storIOContentResolverTypeMeta.needCreator && storIOContentResolverColumnMeta.isMethod()) {
storIOContentResolverTypeMeta.needCreator = true;
}
// Put meta column info.
storIOContentResolverTypeMeta.columns.put(storIOContentResolverColumnMeta.storIOColumn.name(), storIOContentResolverColumnMeta);
} catch (SkipNotAnnotatedClassWithAnnotatedParentException e) {
messager.printMessage(WARNING, e.getMessage());
}
}
}
use of com.pushtorefresh.storio.common.annotations.processor.SkipNotAnnotatedClassWithAnnotatedParentException in project storio by pushtorefresh.
the class StorIOSQLiteProcessor method processAnnotatedFieldsOrMethods.
/**
* Processes fields annotated with {@link StorIOSQLiteColumn}.
*
* @param roundEnvironment current processing environment
* @param annotatedClasses map of classes annotated with {@link StorIOSQLiteType}
*/
@Override
protected void processAnnotatedFieldsOrMethods(@NotNull final RoundEnvironment roundEnvironment, @NotNull Map<TypeElement, StorIOSQLiteTypeMeta> annotatedClasses) {
final Set<? extends Element> elementsAnnotatedWithStorIOSQLiteColumn = roundEnvironment.getElementsAnnotatedWith(StorIOSQLiteColumn.class);
for (final Element annotatedFieldElement : elementsAnnotatedWithStorIOSQLiteColumn) {
try {
validateAnnotatedFieldOrMethod(annotatedFieldElement);
final StorIOSQLiteColumnMeta storIOSQLiteColumnMeta = processAnnotatedFieldOrMethod(annotatedFieldElement);
final StorIOSQLiteTypeMeta storIOSQLiteTypeMeta = annotatedClasses.get(storIOSQLiteColumnMeta.enclosingElement);
// If class already contains column with same name -> throw an exception.
if (storIOSQLiteTypeMeta.columns.containsKey(storIOSQLiteColumnMeta.storIOColumn.name())) {
throw new ProcessingException(annotatedFieldElement, "Column name already used in this class: " + storIOSQLiteColumnMeta.storIOColumn.name());
}
// If field annotation applied to both fields and methods in a same class.
if ((storIOSQLiteTypeMeta.needCreator && !storIOSQLiteColumnMeta.isMethod()) || (!storIOSQLiteTypeMeta.needCreator && storIOSQLiteColumnMeta.isMethod() && !storIOSQLiteTypeMeta.columns.isEmpty())) {
throw new ProcessingException(annotatedFieldElement, "Can't apply " + StorIOSQLiteColumn.class.getSimpleName() + " annotation to both fields and methods in a same class: " + storIOSQLiteTypeMeta.simpleName);
}
// If column needs creator then enclosing class needs it as well.
if (!storIOSQLiteTypeMeta.needCreator && storIOSQLiteColumnMeta.isMethod()) {
storIOSQLiteTypeMeta.needCreator = true;
}
// Put meta column info.
storIOSQLiteTypeMeta.columns.put(storIOSQLiteColumnMeta.storIOColumn.name(), storIOSQLiteColumnMeta);
} catch (SkipNotAnnotatedClassWithAnnotatedParentException e) {
messager.printMessage(WARNING, e.getMessage());
}
}
}
Aggregations