use of javax.lang.model.element.PackageElement in project auto by google.
the class MoreElements method getLocalAndInheritedMethods.
private static ImmutableSet<ExecutableElement> getLocalAndInheritedMethods(TypeElement type, Overrides overrides) {
PackageElement pkg = getPackage(type);
ImmutableSet.Builder<ExecutableElement> methods = ImmutableSet.builder();
for (ExecutableElement method : getAllMethods(type, overrides)) {
// Filter out all static and non-visible methods.
if (!method.getModifiers().contains(STATIC) && methodVisibleFromPackage(method, pkg)) {
methods.add(method);
}
}
return methods.build();
}
use of javax.lang.model.element.PackageElement in project auto by google.
the class AutoServiceProcessor method getBinaryNameImpl.
private String getBinaryNameImpl(TypeElement element, String className) {
Element enclosingElement = element.getEnclosingElement();
if (enclosingElement instanceof PackageElement) {
PackageElement pkg = MoreElements.asPackage(enclosingElement);
if (pkg.isUnnamed()) {
return className;
}
return pkg.getQualifiedName() + "." + className;
}
TypeElement typeElement = MoreElements.asType(enclosingElement);
return getBinaryNameImpl(typeElement, typeElement.getSimpleName() + "$" + className);
}
use of javax.lang.model.element.PackageElement in project tiger by google.
the class NewInjectorGenerator method generateProvisionMethodForSet.
private void generateProvisionMethodForSet(NewBindingKey key, TypeElement referencingClass, String suffix) {
TypeSpec.Builder componentSpecBuilder = getInjectorTypeSpecBuilder(getInjectorFor(key, referencingClass));
// messager.printMessage(Kind.NOTE, "generateProvisionMethodForSet: " + key +
// " PackagedInjector: "
// + getInjectorFor(key, referencingClass) + " SpecBuilder: " + componentSpecBuilder);
ParameterizedTypeName type = (ParameterizedTypeName) key.getTypeName();
Preconditions.checkArgument(type.rawType.equals(ClassName.get(Set.class)));
TypeName elementType = Iterables.getOnlyElement(type.typeArguments);
MethodSpec.Builder methodSpecBuilder = MethodSpec.methodBuilder(getProvisionMethodName(key) + suffix).addModifiers(suffix.isEmpty() ? Modifier.PUBLIC : Modifier.PRIVATE).returns(type);
methodSpecBuilder.addStatement("$T result = new $T<>()", type, HashSet.class);
methodSpecBuilder.addStatement("$T setVar", type);
methodSpecBuilder.addStatement("$T elementVar", elementType);
SetMultimap<PackageElement, NewDependencyInfo> packageToDependencyInfoMap = HashMultimap.create();
for (NewDependencyInfo dependencyInfo : dependencies.get(key)) {
packageToDependencyInfoMap.put(Utils.getPackage(dependencyInfo.getSourceClassElement()), dependencyInfo);
}
for (PackageElement pkg : packageToDependencyInfoMap.keySet()) {
// messager.printMessage(Kind.NOTE, String.format("generateProvisionMethodForSet for %s from"
// +
// " %s", key, packageToDependencyInfoMap.get(pkg)));
generateSetTypeProvisionMethodForPackage(key, packageToDependencyInfoMap.get(pkg), suffix);
NewDependencyInfo dependencyInfo = Iterables.getFirst(packageToDependencyInfoMap.get(pkg), null);
Preconditions.checkNotNull(dependencyInfo, String.format("no dependencyInfo for set key %s in module %s", key, pkg));
ClassName packagedInjectorClassName = getPackagedInjectorForNewDependencyInfo(key, dependencyInfo);
methodSpecBuilder.addStatement("setVar = $L.$N().$N()", TOP_LEVEL_INJECTOR_FIELD, Utils.getGetMethodName(packagedInjectorClassName), getProvisionMethodName(key));
methodSpecBuilder.addStatement("result.addAll($L)", "setVar");
}
methodSpecBuilder.addStatement("return result");
componentSpecBuilder.addMethod(methodSpecBuilder.build());
}
use of javax.lang.model.element.PackageElement in project tiger by google.
the class Utils method getPackage.
public PackageElement getPackage(Element element) {
Preconditions.checkArgument(Sets.newHashSet(ElementKind.CLASS, ElementKind.METHOD, ElementKind.CONSTRUCTOR, ElementKind.FIELD, ElementKind.INTERFACE).contains(element.getKind()), "Unexpected element: " + element + " with kind: " + element.getKind());
Element result = element.getEnclosingElement();
ElementKind elementKind = result.getKind();
while (!elementKind.equals(ElementKind.PACKAGE)) {
Preconditions.checkState(elementKind.isClass() || elementKind.isInterface(), String.format("utils.getPackage: unexpected kind: %s for type: %s", elementKind, element));
result = result.getEnclosingElement();
elementKind = result.getKind();
}
return (PackageElement) result;
}
use of javax.lang.model.element.PackageElement in project tiger by google.
the class ProxyGenerator method collectModulesAndInjected.
private void collectModulesAndInjected(PackageElement packageElement, Set<TypeElement> modules, Set<TypeElement> classesWithInject) {
Set<TypeElement> ctorInjectedClasses = new HashSet<>();
Set<TypeElement> injectedClasses = new HashSet<>();
for (Element e : packageElement.getEnclosedElements()) {
if (e instanceof TypeElement) {
PackagedInjectorGenerator.collectFromClassOrInterface((TypeElement) e, modules, ctorInjectedClasses, injectedClasses, utils, env, logger);
}
}
classesWithInject.addAll(ctorInjectedClasses);
classesWithInject.addAll(injectedClasses);
}
Aggregations