use of javax.lang.model.element.TypeElement in project j2objc by google.
the class ElementReferenceMapper method endVisit.
//TODO(malvania): Add the field type class to reference classes.
//Currently, jdt only supports well known types. Soon, we can get type mirror from field
//and resolve the type by its name using a resolve method in the parser environment.
@Override
public void endVisit(VariableDeclarationFragment fragment) {
//TODO(malvania): Add field to elementReferenceMap when field detection is enabled and the
// ElementUtil.getBinaryName() method doesn't break when called on a static block's
// ExecutableElement.
//String fieldID = stitchFieldIdentifier(fragment);
//elementReferenceMap.putIfAbsent(fieldID, new FieldReferenceNode(fragment));
Element element = fragment.getVariableElement().getEnclosingElement();
if (element instanceof TypeElement) {
TypeElement type = (TypeElement) element;
if (ElementUtil.isPublic(fragment.getVariableElement())) {
ClassReferenceNode node = (ClassReferenceNode) elementReferenceMap.get(stitchClassIdentifier(type));
if (node == null) {
node = new ClassReferenceNode(type);
}
node.containsPublicField = true;
elementReferenceMap.putIfAbsent(stitchClassIdentifier(type), node);
}
}
}
use of javax.lang.model.element.TypeElement in project realm-java by realm.
the class RealmProcessor method processAnnotations.
// Create all proxy classes
private boolean processAnnotations(RoundEnvironment roundEnv) {
for (Element classElement : roundEnv.getElementsAnnotatedWith(RealmClass.class)) {
// The class must either extend RealmObject or implement RealmModel
if (!Utils.isImplementingMarkerInterface(classElement)) {
Utils.error("A RealmClass annotated object must implement RealmModel or derive from RealmObject.", classElement);
return false;
}
// Check the annotation was applied to a Class
if (!classElement.getKind().equals(ElementKind.CLASS)) {
Utils.error("The RealmClass annotation can only be applied to classes.", classElement);
return false;
}
ClassMetaData metadata = new ClassMetaData(processingEnv, (TypeElement) classElement);
if (!metadata.isModelClass()) {
continue;
}
Utils.note("Processing class " + metadata.getSimpleClassName());
if (!metadata.generate()) {
return false;
}
classesToValidate.add(metadata);
backlinksToValidate.addAll(metadata.getBacklinkFields());
RealmProxyInterfaceGenerator interfaceGenerator = new RealmProxyInterfaceGenerator(processingEnv, metadata);
try {
interfaceGenerator.generate();
} catch (IOException e) {
Utils.error(e.getMessage(), classElement);
}
RealmProxyClassGenerator sourceCodeGenerator = new RealmProxyClassGenerator(processingEnv, metadata);
try {
sourceCodeGenerator.generate();
} catch (IOException e) {
Utils.error(e.getMessage(), classElement);
} catch (UnsupportedOperationException e) {
Utils.error(e.getMessage(), classElement);
}
}
return true;
}
use of javax.lang.model.element.TypeElement in project realm-java by realm.
the class ClassMetaData method checkListTypes.
private boolean checkListTypes() {
for (VariableElement field : fields) {
if (Utils.isRealmList(field) || Utils.isRealmResults(field)) {
// Check for missing generic (default back to Object)
if (Utils.getGenericTypeQualifiedName(field) == null) {
Utils.error("No generic type supplied for field", field);
return false;
}
// Check that the referenced type is a concrete class and not an interface
TypeMirror fieldType = field.asType();
List<? extends TypeMirror> typeArguments = ((DeclaredType) fieldType).getTypeArguments();
String genericCanonicalType = typeArguments.get(0).toString();
TypeElement typeElement = elements.getTypeElement(genericCanonicalType);
if (typeElement.getSuperclass().getKind() == TypeKind.NONE) {
Utils.error("Only concrete Realm classes are allowed in RealmLists. " + "Neither interfaces nor abstract classes are allowed.", field);
return false;
}
}
}
return true;
}
use of javax.lang.model.element.TypeElement in project camel by apache.
the class AnnotationProcessorHelper method findTypeElement.
public static TypeElement findTypeElement(ProcessingEnvironment processingEnv, RoundEnvironment roundEnv, String className) {
if (isNullOrEmpty(className) || "java.lang.Object".equals(className)) {
return null;
}
Set<? extends Element> rootElements = roundEnv.getRootElements();
for (Element rootElement : rootElements) {
if (rootElement instanceof TypeElement) {
TypeElement typeElement = (TypeElement) rootElement;
String aRootName = canonicalClassName(typeElement.getQualifiedName().toString());
if (className.equals(aRootName)) {
return typeElement;
}
}
}
// fallback using package name
Elements elementUtils = processingEnv.getElementUtils();
int idx = className.lastIndexOf('.');
if (idx > 0) {
String packageName = className.substring(0, idx);
PackageElement pe = elementUtils.getPackageElement(packageName);
if (pe != null) {
List<? extends Element> enclosedElements = getEnclosedElements(pe);
for (Element rootElement : enclosedElements) {
if (rootElement instanceof TypeElement) {
TypeElement typeElement = (TypeElement) rootElement;
String aRootName = canonicalClassName(typeElement.getQualifiedName().toString());
if (className.equals(aRootName)) {
return typeElement;
}
}
}
}
}
return null;
}
use of javax.lang.model.element.TypeElement in project camel by apache.
the class AnnotationProcessorHelper method hasSuperClass.
public static boolean hasSuperClass(ProcessingEnvironment processingEnv, RoundEnvironment roundEnv, TypeElement classElement, String superClassName) {
String aRootName = canonicalClassName(classElement.getQualifiedName().toString());
// do not check the classes from JDK itself
if (isNullOrEmpty(aRootName) || aRootName.startsWith("java.") || aRootName.startsWith("javax.")) {
return false;
}
String aSuperClassName = canonicalClassName(classElement.getSuperclass().toString());
if (superClassName.equals(aSuperClassName)) {
return true;
}
TypeElement aSuperClass = findTypeElement(processingEnv, roundEnv, aSuperClassName);
if (aSuperClass != null) {
return hasSuperClass(processingEnv, roundEnv, aSuperClass, superClassName);
} else {
return false;
}
}
Aggregations