Package javax.lang.model.util

Examples of javax.lang.model.util.Types


        }
    }

    public void checkTypeAgreesWithName(final TypeElement annotationElement, final ExecutableElement methodElement)
    {
        Types typeUtils = processingEnv.getTypeUtils();

        String methodName = methodElement.getSimpleName().toString();

        if((methodName.startsWith("is") || methodName.startsWith("has"))
            && !(methodElement.getReturnType().getKind() == TypeKind.BOOLEAN
                 || typeUtils.isSameType(typeUtils.boxedClass(typeUtils.getPrimitiveType(TypeKind.BOOLEAN)).asType(), methodElement.getReturnType())))
        {
            processingEnv.getMessager()
                    .printMessage(Diagnostic.Kind.ERROR,
                                  "@"
                                  + annotationElement.getSimpleName()
View Full Code Here


        }
    }

    public void checkInterfaceExtendsConfiguredObject(final TypeElement annotationElement, final Element e)
    {
        Types typeUtils = processingEnv.getTypeUtils();
        TypeMirror configuredObjectType = getErasure("org.apache.qpid.server.model.ConfiguredObject");
        TypeElement parent = (TypeElement) e.getEnclosingElement();


        if (!typeUtils.isAssignable(typeUtils.erasure(parent.asType()), configuredObjectType))
        {
            processingEnv.getMessager()
                    .printMessage(Diagnostic.Kind.ERROR,
                                  "@"
                                  + annotationElement.getSimpleName()
View Full Code Here

        }
    }

    private boolean isValidType(final TypeMirror type)
    {
        Types typeUtils = processingEnv.getTypeUtils();
        Elements elementUtils = processingEnv.getElementUtils();
        Element typeElement = typeUtils.asElement(type);

        if (VALID_PRIMITIVE_TYPES.contains(type.getKind()))
        {
            return true;
        }
        for(TypeKind primitive : VALID_PRIMITIVE_TYPES)
        {
            if(typeUtils.isSameType(type, typeUtils.boxedClass(typeUtils.getPrimitiveType(primitive)).asType()))
            {
                return true;
            }
        }
        if(typeElement.getKind()==ElementKind.ENUM)
        {
            return true;
        }

        String className = "org.apache.qpid.server.model.ConfiguredObject";
        TypeMirror configuredObjectType = getErasure(className);

        if(typeUtils.isAssignable(typeUtils.erasure(type), configuredObjectType))
        {
            return true;
        }

        if(typeUtils.isSameType(type, elementUtils.getTypeElement("java.lang.String").asType()))
        {
            return true;
        }


        if(typeUtils.isSameType(type,elementUtils.getTypeElement("java.util.UUID").asType()))
        {
            return true;
        }

        TypeMirror erasedType = typeUtils.erasure(type);
        if(typeUtils.isSameType(erasedType, getErasure("java.util.List"))
                || typeUtils.isSameType(erasedType, getErasure("java.util.Set"))
                || typeUtils.isSameType(erasedType, getErasure("java.util.Collection")))
        {


            for(TypeMirror paramType : ((DeclaredType)type).getTypeArguments())
            {

                if(!isValidType(paramType))
                {
                    return false;
                }
            }
            return true;
        }

        if(typeUtils.isSameType(erasedType, getErasure("java.util.Map")))
        {
            List<? extends TypeMirror> args = ((DeclaredType) type).getTypeArguments();
            if (args.size() != 2)
            {
                throw new IllegalArgumentException("Map types " + type + " must have exactly two type arguments");
            }
            return isValidType(args.get(0)) && (isValidType(args.get(1)) || typeUtils.isSameType(args.get(1), getErasure("java.lang.Object")));
        }


        return false;
    }
View Full Code Here

        return false;
    }

    private TypeMirror getErasure(final String className)
    {
        final Types typeUtils = processingEnv.getTypeUtils();
        final Elements elementUtils = processingEnv.getElementUtils();
        return typeUtils.erasure(elementUtils.getTypeElement(className).asType());
    }
View Full Code Here

    @Override
    public boolean process(final Set<? extends TypeElement> annotations, final RoundEnvironment roundEnv)
    {
        Elements elementUtils = processingEnv.getElementUtils();
        Types typeUtils = processingEnv.getTypeUtils();

        TypeElement annotationElement = elementUtils.getTypeElement(MANAGED_ATTRIBUTE_FIELD_CLASS_NAME);
        for (Element e : roundEnv.getElementsAnnotatedWith(annotationElement))
        {
            for(AnnotationMirror am : e.getAnnotationMirrors())
            {
                if(typeUtils.isSameType(am.getAnnotationType(), annotationElement.asType()))
                {
                    for(Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : am.getElementValues().entrySet())
                    {
                        String elementName = entry.getKey().getSimpleName().toString();
                        if(elementName.equals("beforeSet") || elementName.equals("afterSet"))
View Full Code Here

    // ------------------------------------------------------ collect methods

    private void collectData(final RoundEnvironment roundEnv) throws Exception {

        final Messager messager = processingEnv.getMessager();
        final Types typeUtils = processingEnv.getTypeUtils();
        final Elements elementUtils = processingEnv.getElementUtils();

        for (Element e : roundEnv.getElementsAnnotatedWith(Store.class)) {
            TypeElement storeElement = (TypeElement) e;
            PackageElement packageElement = (PackageElement) storeElement.getEnclosingElement();

            final String packageName = packageElement.getQualifiedName().toString();
            final String storeDelegate = storeElement.getSimpleName().toString();
            final boolean changeSupport = typeUtils.isAssignable(storeElement.asType(),
                    elementUtils.getTypeElement(ChangeSupport.class.getName()).asType());
            final String storeClassName = GenerationUtil.storeImplementation(storeDelegate);
            messager.printMessage(NOTE,
                    String.format("Discovered annotated store [%s]", storeElement.getQualifiedName()));
View Full Code Here

    }

    static List<ExecutableElement> findGetter(final TypeElement originalClassElement, final ProcessingEnvironment processingEnvironment,
                                              final TypeMirror requiredReturnType, final String name) {

        final Types typeUtils = processingEnvironment.getTypeUtils();
        final String getter = "get" + name.substring(0, 1).toUpperCase() + name.substring(1);

        TypeElement classElement = originalClassElement;
        while (true) {
            final List<ExecutableElement> methods = ElementFilter.methodsIn(classElement.getEnclosedElements());

            List<ExecutableElement> matches = new ArrayList<>();
            for (ExecutableElement e : methods) {
                if (!e.getSimpleName().toString().equals(getter)) {
                    continue;
                }
                final TypeMirror actualReturnType = e.getReturnType();
                if (!typeUtils.isAssignable(actualReturnType, requiredReturnType)) {
                    continue;
                }
                if (e.getModifiers().contains(Modifier.STATIC)) {
                    continue;
                }
View Full Code Here

    static List<ExecutableElement> getAnnotatedMethods(final TypeElement originalClassElement,
            final ProcessingEnvironment processingEnvironment, final String annotationName,
            final TypeMirror requiredReturnType, final String[] requiredParameterTypes) {

        final Types typeUtils = processingEnvironment.getTypeUtils();
        final Elements elementUtils = processingEnvironment.getElementUtils();

        TypeElement classElement = originalClassElement;
        while (true) {
            final List<ExecutableElement> methods = ElementFilter.methodsIn(classElement.getEnclosedElements());

            List<ExecutableElement> matches = new ArrayList<>();
            for (ExecutableElement e : methods) {
                final TypeMirror actualReturnType = e.getReturnType();
                if (getAnnotation(elementUtils, e, annotationName) == null) {
                    continue;
                }
                if (!typeUtils.isAssignable(actualReturnType, requiredReturnType)) {
                    continue;
                }
                if (!doParametersMatch(typeUtils, elementUtils, e, requiredParameterTypes)) {
                    continue;
                }
View Full Code Here

      }
    }

    Elements elements = processingEnv.getElementUtils();
    TypeMirror type = arg.getElement().asType();
    Types types = processingEnv.getTypeUtils();
    String[] arrayListTypes = new String[] {
        String.class.getName(), Integer.class.getName(), CharSequence.class.getName()
    };
    String[] arrayListOps =
        new String[] { "StringArrayList", "IntegerArrayList", "CharSequenceArrayList" };
    for (int i = 0; i < arrayListTypes.length; i++) {
      TypeMirror tm = getArrayListType(arrayListTypes[i]);
      if (types.isAssignable(type, tm)) {
        return arrayListOps[i];
      }
    }

    if (types.isAssignable(type,
        getWildcardType(ArrayList.class.getName(), "android.os.Parcelable"))) {
      return "ParcelableArrayList";
    }
    TypeMirror sparseParcelableArray =
        getWildcardType("android.util.SparseArray", "android.os.Parcelable");

    if (types.isAssignable(type, sparseParcelableArray)) {
      return "SparseParcelableArray";
    }

    if (types.isAssignable(type, elements.getTypeElement(Serializable.class.getName()).asType())) {
      return "Serializable";
    }

    if (types.isAssignable(type, elements.getTypeElement("android.os.Parcelable").asType())) {
      return "Parcelable";
    }

    return null;
  }
View Full Code Here

  @Override
  public boolean process(Set<? extends TypeElement> type, RoundEnvironment env) {

    Elements elementUtils = processingEnv.getElementUtils();
    Types typeUtils = processingEnv.getTypeUtils();
    Filer filer = processingEnv.getFiler();
    TypeElement fragmentType = elementUtils.getTypeElement("android.app.Fragment");
    TypeElement supportFragmentType =
        elementUtils.getTypeElement("android.support.v4.app.Fragment");
    Map<TypeElement, Set<Element>> fieldsByType = new HashMap<TypeElement, Set<Element>>(100);

    Element[] origHelper = null;

    for (Element element : env.getElementsAnnotatedWith(Arg.class)) {
      TypeElement enclosingElement = (TypeElement) element.getEnclosingElement();

      // Check if its a fragment
      if (!((fragmentType != null && typeUtils.isSubtype(enclosingElement.asType(),
          fragmentType.asType())) || (supportFragmentType != null && typeUtils.isSubtype(
          enclosingElement.asType(), supportFragmentType.asType())))) {
        error(element, "@Arg can only be used on fragment fields (%s.%s)",
            enclosingElement.getQualifiedName(), element);
        continue;
      }

      if (element.getModifiers().contains(Modifier.FINAL) || element.getModifiers()
          .contains(Modifier.STATIC) || element.getModifiers().contains(Modifier.PRIVATE) || element
          .getModifiers()
          .contains(Modifier.PROTECTED)) {
        error(element, "@Arg fields must not be private, protected, final or static (%s.%s)",
            enclosingElement.getQualifiedName(), element);
        continue;
      }

      Set<Element> fields = fieldsByType.get(enclosingElement);
      if (fields == null) {
        fields = new LinkedHashSet<Element>(10);
        fieldsByType.put(enclosingElement, fields);
      }
      fields.add(element);
    }

    // Store the key - value for the generated FragmentArtMap class
    Map<String, String> autoMapping = new HashMap<String, String>();

    for (Map.Entry<TypeElement, Set<Element>> entry : fieldsByType.entrySet()) {
      try {
        // Skip abstract classes
        if (entry.getKey().getModifiers().contains(Modifier.ABSTRACT)) {
          continue;
        }

        String builder = entry.getKey().getSimpleName() + "Builder";
        List<Element> originating = new ArrayList<Element>(10);
        originating.add(entry.getKey());
        TypeMirror superClass = entry.getKey().getSuperclass();
        while (superClass.getKind() != TypeKind.NONE) {
          TypeElement element = (TypeElement) typeUtils.asElement(superClass);
          if (element.getQualifiedName().toString().startsWith("android.")) {
            break;
          }
          originating.add(element);
          superClass = element.getSuperclass();
View Full Code Here

TOP

Related Classes of javax.lang.model.util.Types

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.