use of javax.lang.model.element.PackageElement in project j2objc by google.
the class ElementUtil method areParametersNonnullByDefault.
public boolean areParametersNonnullByDefault(TypeElement typeElement, Options options) {
if (ElementUtil.hasAnnotation(typeElement, ParametersAreNonnullByDefault.class)) {
return true;
}
PackageElement pkg = getPackage(typeElement);
String pkgName = pkg.getQualifiedName().toString();
return options.getPackageInfoLookup().hasParametersAreNonnullByDefault(pkgName);
}
use of javax.lang.model.element.PackageElement in project glide by bumptech.
the class ModuleAnnotationProcessor method process.
/**
* Each round we do the following:
* <ol>
* <li>Find all RootGlideModules and save them to an instance variable (throw if > 1).
* <li>Find all ChildGlideModules
* <li>For each ChildGlideModule, write an Indexer with an Annotation with the class name.
* <li>If we wrote any Indexers, return and wait for the next round.
* <li>If we didn't write any Indexers and there is a RootGlideModule, write the
* GeneratedRootGlideModule. Once the GeneratedRootGlideModule is written, we expect to be
* finished. Any further generation of related classes will result in errors.
* </ol>
*/
@Override
public boolean process(Set<? extends TypeElement> set, RoundEnvironment env) {
round++;
// Order matters here, if we find an Indexer below, we return before writing the root module. If
// we fail to add to rootModules before then, we might accidentally skip a valid RootModule.
List<TypeElement> childGlideModules = new ArrayList<>();
for (TypeElement element : getElementsFor(GlideModule.class, env)) {
if (processingEnv.getTypeUtils().isAssignable(element.asType(), rootGlideModuleType.asType())) {
rootGlideModules.add(element);
} else if (processingEnv.getTypeUtils().isAssignable(element.asType(), childGlideModuleType.asType())) {
childGlideModules.add(element);
} else {
throw new IllegalStateException("@GlideModule can only be applied to ChildGlideModule" + " and RootGlideModule implementations, not: " + element);
}
}
debugLog("got child modules: " + childGlideModules);
debugLog("got root modules: " + rootGlideModules);
if (rootGlideModules.size() > 1) {
throw new IllegalStateException("You cannot have more than one RootGlideModule, found: " + rootGlideModules);
}
if (!childGlideModules.isEmpty()) {
if (isGeneratedRootGlideModuleWritten) {
throw new IllegalStateException("Cannot process ChildModules after writing RootModules: " + childGlideModules);
}
TypeSpec indexer = GlideIndexerGenerator.generate(childGlideModules);
writeIndexer(indexer);
debugLog("Wrote an Indexer this round, skipping the root module to ensure all indexers are" + " found");
// and we can safely wait to write our RootModule until then.
return true;
}
// most once.
if (isGeneratedRootGlideModuleWritten || rootGlideModules.isEmpty()) {
return false;
}
debugLog("Processing root module: " + rootGlideModules.iterator().next());
// If this package is null, it means there are no classes with this package name. One way this
// could happen is if we process an annotation and reach this point without writing something
// to the package. We do not error check here because that shouldn't happen with the
// current implementation.
PackageElement glideGenPackage = processingEnv.getElementUtils().getPackageElement(COMPILER_PACKAGE_NAME);
glideModuleClassNames.addAll(getGlideModuleClassNames(glideGenPackage));
TypeSpec generatedRootGlideModule = RootModuleGenerator.generate(processingEnv, rootGlideModules.get(0).getQualifiedName().toString(), glideModuleClassNames);
writeRootModule(generatedRootGlideModule);
isGeneratedRootGlideModuleWritten = true;
infoLog("Wrote GeneratedRootGlideModule with: " + glideModuleClassNames);
return true;
}
use of javax.lang.model.element.PackageElement in project glide by bumptech.
the class ModuleAnnotationProcessor method getGlideModuleClassNames.
@SuppressWarnings("unchecked")
private Set<String> getGlideModuleClassNames(PackageElement glideGenPackage) {
Set<String> glideModules = new HashSet<>();
List<? extends Element> glideGeneratedElements = glideGenPackage.getEnclosedElements();
for (Element indexer : glideGeneratedElements) {
ModuleIndex annotation = indexer.getAnnotation(ModuleIndex.class);
// that we can safely ignore.
if (annotation != null) {
Collections.addAll(glideModules, annotation.glideModules());
}
}
debugLog("Found GlideModules: " + glideModules);
return glideModules;
}
use of javax.lang.model.element.PackageElement 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.PackageElement in project buck by facebook.
the class TreeBackedPackageElementTest method testAccept.
@Test
public void testAccept() throws IOException {
initCompiler();
PackageElement expectedPackage = elements.getPackageElement("java.lang");
Object expectedResult = new Object();
Object actualResult = expectedPackage.accept(new SimpleElementVisitor8<Object, Object>() {
@Override
protected Object defaultAction(Element e, Object o) {
return null;
}
@Override
public Object visitPackage(PackageElement actualPackage, Object o) {
assertSame(expectedPackage, actualPackage);
return o;
}
}, expectedResult);
assertSame(expectedResult, actualResult);
}
Aggregations