Search in sources :

Example 76 with DeclaredType

use of javax.lang.model.type.DeclaredType in project tiger by google.

the class NewScopeCalculator method getExplicitScopes.

private Map<NewBindingKey, ? extends NewScopeCalculatingInfo> getExplicitScopes() {
    Map<NewBindingKey, NewScopeCalculatingInfo> result = new HashMap<>();
    for (NewDependencyInfo info : dependencyInfos) {
        NewBindingKey key = info.getDependant();
        Element ele = info.getProvisionMethodElement() != null ? info.getProvisionMethodElement() : info.getSourceClassElement();
        DeclaredType scopeType = Utils.getScopeType(ele);
        if (scopeType != null) {
            if (!info.isUnique()) {
                messager.printMessage(Kind.ERROR, String.format("Non-unique binding must be unscoped: %s", info));
            }
            TypeElement scope = (TypeElement) scopeType.asElement();
            int scopeSize = scopeSizer.getScopeSize(scope);
            result.put(key, new NewScopeCalculatingInfo(scope, scopeSize, new ArrayList<NewBindingKey>()));
        }
    }
    return result;
}
Also used : HashMap(java.util.HashMap) TypeElement(javax.lang.model.element.TypeElement) Element(javax.lang.model.element.Element) TypeElement(javax.lang.model.element.TypeElement) ArrayList(java.util.ArrayList) DeclaredType(javax.lang.model.type.DeclaredType)

Example 77 with DeclaredType

use of javax.lang.model.type.DeclaredType in project tiger by google.

the class TigerDaggerGeneratorProcessor method getComponentDependencies.

/**
   * Returns dependency components of the give component, empty set if none.
   */
private Set<TypeElement> getComponentDependencies(TypeElement component) {
    Set<TypeElement> result = new HashSet<>();
    AnnotationMirror componentAnnotationMirror = Preconditions.checkNotNull(Utils.getAnnotationMirror(component, Component.class), String.format("@Component not found for %s", component));
    AnnotationValue dependenciesAnnotationValue = Utils.getAnnotationValue(componentAnnotationMirror, "dependencies");
    if (dependenciesAnnotationValue == null) {
        return result;
    }
    List<? extends AnnotationValue> dependencies = (List<? extends AnnotationValue>) dependenciesAnnotationValue.getValue();
    for (AnnotationValue dependency : dependencies) {
        result.add((TypeElement) ((DeclaredType) dependency.getValue()).asElement());
    }
    return result;
}
Also used : AnnotationMirror(javax.lang.model.element.AnnotationMirror) TypeElement(javax.lang.model.element.TypeElement) AnnotationValue(javax.lang.model.element.AnnotationValue) ArrayList(java.util.ArrayList) List(java.util.List) Component(dagger.Component) HashSet(java.util.HashSet) DeclaredType(javax.lang.model.type.DeclaredType)

Example 78 with DeclaredType

use of javax.lang.model.type.DeclaredType in project tiger by google.

the class TigerDaggerGeneratorProcessor method getAllModulesOfComponentRecursively.

private Set<TypeElement> getAllModulesOfComponentRecursively(TypeElement component) {
    Set<TypeElement> result = new HashSet<>();
    AnnotationMirror componentAnnotationMirror = Utils.getAnnotationMirror(component, Component.class);
    for (AnnotationValue annotationValue : (List<AnnotationValue>) Utils.getAnnotationValue(componentAnnotationMirror, "modules").getValue()) {
        result.add((TypeElement) ((DeclaredType) annotationValue.getValue()).asElement());
    }
    result = Utils.findAllModulesRecursively(result);
    return result;
}
Also used : AnnotationMirror(javax.lang.model.element.AnnotationMirror) TypeElement(javax.lang.model.element.TypeElement) AnnotationValue(javax.lang.model.element.AnnotationValue) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet) DeclaredType(javax.lang.model.type.DeclaredType)

Example 79 with DeclaredType

use of javax.lang.model.type.DeclaredType in project tiger by google.

the class Utils method isSingletonScoped.

public static boolean isSingletonScoped(Elements elementUtils, Element element) {
    DeclaredType scopeType = Utils.getScopeType(element);
    boolean result = scopeType != null && scopeType.asElement().equals(elementUtils.getTypeElement(Singleton.class.getCanonicalName()));
    return result;
}
Also used : Singleton(javax.inject.Singleton) DeclaredType(javax.lang.model.type.DeclaredType)

Example 80 with DeclaredType

use of javax.lang.model.type.DeclaredType in project tiger by google.

the class Utils method hasAnonymousParentClass.

public static boolean hasAnonymousParentClass(TypeElement cls) {
    Preconditions.checkNotNull(cls);
    do {
        if (cls.getSimpleName().length() == 0) {
            return true;
        }
        TypeMirror parentClass = cls.getSuperclass();
        if (parentClass.getKind().equals(TypeKind.NONE)) {
            return false;
        }
        cls = (TypeElement) ((DeclaredType) parentClass).asElement();
    } while (true);
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) DeclaredType(javax.lang.model.type.DeclaredType)

Aggregations

DeclaredType (javax.lang.model.type.DeclaredType)138 TypeElement (javax.lang.model.element.TypeElement)82 TypeMirror (javax.lang.model.type.TypeMirror)75 ExecutableElement (javax.lang.model.element.ExecutableElement)38 Element (javax.lang.model.element.Element)28 VariableElement (javax.lang.model.element.VariableElement)26 AnnotationMirror (javax.lang.model.element.AnnotationMirror)19 Test (org.junit.Test)19 ArrayType (javax.lang.model.type.ArrayType)15 ArrayList (java.util.ArrayList)14 List (java.util.List)10 Map (java.util.Map)9 AbstractJClass (com.helger.jcodemodel.AbstractJClass)8 HashSet (java.util.HashSet)8 AnnotationValue (javax.lang.model.element.AnnotationValue)8 HashMap (java.util.HashMap)6 TypeParameterElement (javax.lang.model.element.TypeParameterElement)6 Types (javax.lang.model.util.Types)6 Name (javax.lang.model.element.Name)5 PackageElement (javax.lang.model.element.PackageElement)5