use of javax.lang.model.element.PackageElement in project buck by facebook.
the class TreeBackedPackageElementTest method testUnnamedPackageCanContainStuff.
@Test
public void testUnnamedPackageCanContainStuff() throws IOException {
compile("class Foo { }");
PackageElement unnamedPackage = elements.getPackageElement("");
TypeElement fooElement = elements.getTypeElement("Foo");
assertPackageContains(unnamedPackage, fooElement);
}
use of javax.lang.model.element.PackageElement in project buck by facebook.
the class TreeBackedPackageElementTest method testUnnamedPackageHasEmptyNames.
@Test
public void testUnnamedPackageHasEmptyNames() throws IOException {
initCompiler();
PackageElement unnamedPackage = elements.getPackageElement("");
Name emptyName = elements.getName("");
assertTrue(unnamedPackage.isUnnamed());
assertSame(emptyName, unnamedPackage.getSimpleName());
assertSame(emptyName, unnamedPackage.getQualifiedName());
}
use of javax.lang.model.element.PackageElement in project camel by apache.
the class AnnotationProcessorHelper method findTypeElementChildren.
public static void findTypeElementChildren(ProcessingEnvironment processingEnv, RoundEnvironment roundEnv, Set<TypeElement> found, String superClassName) {
Elements elementUtils = processingEnv.getElementUtils();
int idx = superClassName.lastIndexOf('.');
if (idx > 0) {
String packageName = superClassName.substring(0, idx);
PackageElement pe = elementUtils.getPackageElement(packageName);
if (pe != null) {
List<? extends Element> enclosedElements = pe.getEnclosedElements();
for (Element rootElement : enclosedElements) {
if (rootElement instanceof TypeElement) {
TypeElement typeElement = (TypeElement) rootElement;
String aSuperClassName = canonicalClassName(typeElement.getSuperclass().toString());
if (superClassName.equals(aSuperClassName)) {
found.add(typeElement);
}
}
}
}
}
}
use of javax.lang.model.element.PackageElement in project realm-java by realm.
the class ClassMetaData method generate.
/**
* Builds the meta data structures for this class. Any errors or messages will be
* posted on the provided Messager.
*
* @return True if meta data was correctly created and processing can continue, false otherwise.
*/
public boolean generate() {
// Get the package of the class
Element enclosingElement = classType.getEnclosingElement();
if (!enclosingElement.getKind().equals(ElementKind.PACKAGE)) {
Utils.error("The RealmClass annotation does not support nested classes.", classType);
return false;
}
TypeElement parentElement = (TypeElement) Utils.getSuperClass(classType);
if (!parentElement.toString().equals("java.lang.Object") && !parentElement.toString().equals("io.realm.RealmObject")) {
Utils.error("Valid model classes must either extend RealmObject or implement RealmModel.", classType);
return false;
}
PackageElement packageElement = (PackageElement) enclosingElement;
packageName = packageElement.getQualifiedName().toString();
if (!categorizeClassElements()) {
return false;
}
if (!checkListTypes()) {
return false;
}
if (!checkReferenceTypes()) {
return false;
}
if (!checkDefaultConstructor()) {
return false;
}
if (!checkForFinalFields()) {
return false;
}
if (!checkForTransientFields()) {
return false;
}
if (!checkForVolatileFields()) {
return false;
}
// Meta data was successfully generated
return true;
}
use of javax.lang.model.element.PackageElement in project robolectric by robolectric.
the class RobolectricModel method prepare.
/**
* Prepares the various derived parts of the model based on the class mappings
* that have been registered to date.
*/
public void prepare() {
for (Map.Entry<TypeElement, TypeElement> entry : getVisibleShadowTypes().entrySet()) {
final TypeElement shadowType = entry.getKey();
registerType(shadowType);
final TypeElement solidType = entry.getValue();
registerType(solidType);
}
for (Map.Entry<TypeElement, TypeElement> entry : getResetterShadowTypes().entrySet()) {
final TypeElement shadowType = entry.getKey();
registerType(shadowType);
}
while (!typeMap.isEmpty()) {
final HashMultimap<String, TypeElement> nextRound = HashMultimap.create();
for (Map.Entry<String, Set<TypeElement>> referents : Multimaps.asMap(typeMap).entrySet()) {
final Set<TypeElement> c = referents.getValue();
// name, then
if (c.size() == 1) {
final TypeElement type = c.iterator().next();
referentMap.put(type, referents.getKey());
} else {
for (TypeElement type : c) {
SimpleElementVisitor6<Void, TypeElement> visitor = new SimpleElementVisitor6<Void, TypeElement>() {
@Override
public Void visitType(TypeElement parent, TypeElement type) {
nextRound.put(parent.getSimpleName() + "." + type.getSimpleName(), type);
importMap.put(type, parent);
return null;
}
@Override
public Void visitPackage(PackageElement parent, TypeElement type) {
referentMap.put(type, type.getQualifiedName().toString());
importMap.remove(type);
return null;
}
};
visitor.visit(importMap.get(type).getEnclosingElement(), type);
}
}
}
typeMap = nextRound;
}
for (TypeElement imp : importMap.values()) {
if (imp.getModifiers().contains(Modifier.PUBLIC) && !JAVA_LANG.equals(imp.getEnclosingElement())) {
imports.add(imp.getQualifiedName().toString());
}
}
// Other imports that the generated class needs
imports.add("java.util.Map");
imports.add("java.util.HashMap");
imports.add("javax.annotation.Generated");
imports.add("org.robolectric.internal.ShadowExtractor");
imports.add("org.robolectric.internal.ShadowProvider");
}
Aggregations