use of javax.lang.model.element.ElementKind in project LoganSquare by bluelinelabs.
the class JsonFieldProcessor method ensureTypeConverterClassValid.
private boolean ensureTypeConverterClassValid(TypeMirror typeConverterClassMirror, Elements elements, Types types) {
TypeElement typeConverterElement = elements.getTypeElement(typeConverterClassMirror.toString());
if (typeConverterElement != null) {
boolean isTypeConverterType = false;
TypeElement element = typeConverterElement;
while (!isTypeConverterType && element != null) {
for (TypeMirror iface : element.getInterfaces()) {
if (types.erasure(iface).toString().equals(TypeConverter.class.getCanonicalName())) {
isTypeConverterType = true;
}
}
TypeMirror superClassMirror = element.getSuperclass();
if (superClassMirror != null) {
superClassMirror = types.erasure(superClassMirror);
element = elements.getTypeElement(superClassMirror.toString());
} else {
element = null;
}
}
if (!isTypeConverterType) {
error(element, "TypeConverter elements must implement the TypeConverter interface or extend from one of the convenience helpers (ie StringBasedTypeConverter or DateTypeConverter).");
return false;
}
boolean constructorIsDeclared = false;
boolean hasAccessibleConstructor = false;
List<? extends Element> enclosedElements = typeConverterElement.getEnclosedElements();
for (Element enclosedElement : enclosedElements) {
ElementKind enclosedElementKind = enclosedElement.getKind();
if (enclosedElementKind == ElementKind.CONSTRUCTOR) {
constructorIsDeclared = true;
if (!enclosedElement.getModifiers().contains(Modifier.PRIVATE)) {
ExecutableElement executableElement = (ExecutableElement) enclosedElement;
if (executableElement.getParameters().size() == 0) {
hasAccessibleConstructor = true;
}
}
}
}
if (constructorIsDeclared && !hasAccessibleConstructor) {
error(element, "TypeConverter classes must have a non-private zero argument constructor.");
return false;
}
}
return true;
}
use of javax.lang.model.element.ElementKind in project LoganSquare by bluelinelabs.
the class JsonObjectProcessor method addAllNonPrivateAccessors.
private void addAllNonPrivateAccessors(Element element, Elements elements, Types types, JsonObjectHolder objectHolder) {
List<? extends Element> enclosedElements = element.getEnclosedElements();
for (Element enclosedElement : enclosedElements) {
ElementKind enclosedElementKind = enclosedElement.getKind();
if (enclosedElementKind == ElementKind.FIELD) {
Set<Modifier> modifiers = enclosedElement.getModifiers();
if (modifiers.contains(Modifier.PRIVATE) && !modifiers.contains(Modifier.TRANSIENT) && !modifiers.contains(Modifier.STATIC)) {
String getter = JsonFieldHolder.getGetter(enclosedElement, elements);
String setter = JsonFieldHolder.getSetter(enclosedElement, elements);
if (!TextUtils.isEmpty(getter) && !TextUtils.isEmpty(setter)) {
createOrUpdateFieldHolder(enclosedElement, elements, types, objectHolder);
}
}
}
}
}
use of javax.lang.model.element.ElementKind in project buck by facebook.
the class TreeBackedElements method enterElement.
public TreeBackedElement enterElement(Element underlyingElement) {
TreeBackedElement result = treeBackedElements.get(underlyingElement);
if (result != null) {
return result;
}
ElementKind kind = underlyingElement.getKind();
switch(kind) {
case PACKAGE:
result = newTreeBackedPackage((PackageElement) underlyingElement);
break;
case ANNOTATION_TYPE:
case CLASS:
case ENUM:
case INTERFACE:
result = newTreeBackedType((TypeElement) underlyingElement);
break;
case TYPE_PARAMETER:
result = newTreeBackedTypeParameter((TypeParameterElement) underlyingElement);
break;
case ENUM_CONSTANT:
case FIELD:
case PARAMETER:
result = newTreeBackedVariable((VariableElement) underlyingElement);
break;
case CONSTRUCTOR:
case METHOD:
result = newTreeBackedExecutable((ExecutableElement) underlyingElement);
break;
// $CASES-OMITTED$
default:
throw new UnsupportedOperationException(String.format("Element kind %s NYI", kind));
}
treeBackedElements.put(underlyingElement, result);
return result;
}
use of javax.lang.model.element.ElementKind in project tiger by google.
the class DependencyInformationCollectorProcessor method process.
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment env) {
if (annotations.isEmpty()) {
return false;
}
boolean foundSomething = false;
Element someElement = Iterables.getFirst(env.getElementsAnnotatedWith(Iterables.getFirst(annotations, null)), null);
ElementKind elementKind = someElement.getKind();
while (!(elementKind.equals(ElementKind.CLASS) || elementKind.equals(ElementKind.INTERFACE))) {
someElement = someElement.getEnclosingElement();
elementKind = someElement.getKind();
}
String suffix = ((TypeElement) someElement).getQualifiedName().toString().replace(".", "_");
String uniqueSuffix = suffix + BaseEncoding.base64().encode(UUID.randomUUID().toString().getBytes());
TypeSpec.Builder dependencyInfoCollectedBuilder = TypeSpec.classBuilder("DependencyInfo_" + uniqueSuffix).addModifiers(Modifier.PUBLIC, Modifier.FINAL);
for (Element element : env.getElementsAnnotatedWith(Module.class)) {
foundSomething = true;
moduleStrings.add(element.toString());
}
String jsonString = gson.toJson(moduleStrings);
dependencyInfoCollectedBuilder.addField(FieldSpec.builder(String.class, SharedNames.DEPENDENCY_INFORMATION_FIELD_NAME_MODULES, Modifier.PUBLIC, Modifier.FINAL).initializer("$S", jsonString).build());
for (Element element : env.getElementsAnnotatedWith(MembersInjector.class)) {
foundSomething = true;
membersInjectors.add(element.toString());
}
jsonString = gson.toJson(membersInjectors);
dependencyInfoCollectedBuilder.addField(FieldSpec.builder(String.class, SharedNames.DEPENDENCY_INFORMATION_FIELD_NAME_MEMBERS_INJECTORS, Modifier.PUBLIC, Modifier.FINAL).initializer("$S", jsonString).build());
for (Element element : env.getElementsAnnotatedWith(ScopeDependency.class)) {
foundSomething = true;
scopeDependencies.add(element.toString());
}
if (!scopeDependencies.isEmpty()) {
jsonString = gson.toJson(scopeDependencies);
dependencyInfoCollectedBuilder.addField(FieldSpec.builder(String.class, SharedNames.DEPENDENCY_INFORMATION_FIELD_NAME_SCOPE_DEPENDENCIES, Modifier.PUBLIC, Modifier.FINAL).initializer("$S", jsonString).build());
}
for (Element element : env.getElementsAnnotatedWith(ScopedComponentNames.class)) {
foundSomething = true;
scopedComponentNames.add(element.toString());
}
if (!scopedComponentNames.isEmpty()) {
jsonString = gson.toJson(scopedComponentNames);
dependencyInfoCollectedBuilder.addField(FieldSpec.builder(String.class, SharedNames.DEPENDENCY_INFORMATION_FIELD_NAME_SCOPED_COMPONENT_NAMES, Modifier.PUBLIC, Modifier.FINAL).initializer("$S", jsonString).build());
}
for (Element element : env.getElementsAnnotatedWith(PackageForGenerated.class)) {
foundSomething = true;
jsonString = getPackageForGenerated((TypeElement) element);
dependencyInfoCollectedBuilder.addField(FieldSpec.builder(String.class, SharedNames.DEPENDENCY_INFORMATION_FIELD_NAME_PACKAGE_FOR_GENERATED, Modifier.PUBLIC, Modifier.FINAL).initializer("$S", jsonString).build());
}
for (Element element : env.getElementsAnnotatedWith(Inject.class)) {
if (element.getKind().equals(ElementKind.CONSTRUCTOR)) {
Element classElement = element.getEnclosingElement();
if (Utils.getScopeType(classElement) != null) {
foundSomething = true;
ctorInjectedClassStrings.add(classElement.toString());
}
}
}
jsonString = gson.toJson(ctorInjectedClassStrings);
dependencyInfoCollectedBuilder.addField(FieldSpec.builder(String.class, SharedNames.DEPENDENCY_INFORMATION_FIELD_NAME_CTOR_INJECTED_CLASSES, Modifier.PUBLIC, Modifier.FINAL).initializer("$S", jsonString).build());
if (foundSomething) {
writeJavaFile(SharedNames.DEPENDENCY_INFORMATION_PACKAGE_NAME, dependencyInfoCollectedBuilder.build());
}
return false;
}
use of javax.lang.model.element.ElementKind in project hibernate-orm by hibernate.
the class XmlMetaEntity method parseManyToOne.
private void parseManyToOne(ManyToOne manyToOne) {
XmlMetaSingleAttribute attribute;
ElementKind elementKind = getElementKind(manyToOne.getAccess());
String type = getType(manyToOne.getName(), manyToOne.getTargetEntity(), elementKind);
if (type != null) {
attribute = new XmlMetaSingleAttribute(this, manyToOne.getName(), type);
members.add(attribute);
}
}
Aggregations