All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.ebean.querybean.generator.ReadModuleInfo Maven / Gradle / Ivy

There is a newer version: 15.8.0
Show newest version
package io.ebean.querybean.generator;

import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.AnnotationValue;
import javax.lang.model.element.Element;
import javax.lang.model.element.ExecutableElement;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * Helper to read the current/existing prefixed entity classes.
 * 

* These are added back on partial compile. */ class ReadModuleInfo { private final ProcessingContext ctx; public ReadModuleInfo(ProcessingContext ctx) { this.ctx = ctx; } ModuleMeta read(Element element) { final List mirrors = element.getAnnotationMirrors(); for (AnnotationMirror mirror : mirrors) { final String name = mirror.getAnnotationType().asElement().toString(); if (Constants.MODULEINFO.equals(name)) { List entities = readEntities("entities", mirror); List other = readEntities("other", mirror); return new ModuleMeta(entities, other); } } return null; } private List readEntities(String key, AnnotationMirror mirror) { final Map elementValues = mirror.getElementValues(); final Set> entries = elementValues.entrySet(); for (Map.Entry entry : entries) { if (key.equals(entry.getKey().getSimpleName().toString())) { return readAttributes(entry.getValue()); } } return Collections.emptyList(); } @SuppressWarnings("unchecked") private List readAttributes(AnnotationValue value) { final Object entitiesValue = value.getValue(); if (entitiesValue != null) { try { List vals = new ArrayList<>(); List coll = (List) entitiesValue; for (AnnotationValue annotationValue : coll) { vals.add((String) annotationValue.getValue()); } return vals; } catch (Exception e) { ctx.logError(null, "Error reading ModuleInfo annotation, err " + e); } } return Collections.emptyList(); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy