Package javax.lang.model.util

Examples of javax.lang.model.util.Types


     */
    private Set<ExecutableElement> matchGetterAndSetter(
        Set<ExecutableElement> getters,  Set<ExecutableElement> setters) {
        Collection<ExecutableElement> unmatched =
            new ArrayList<ExecutableElement>();
        Types typeUtils = processingEnv.getTypeUtils();
       
        for (ExecutableElement getter : getters) {
            String getterName = getter.getSimpleName().toString();
            TypeMirror getterReturnType = getter.getReturnType();
            String expectedSetterName = "set" + getterName.substring(
                (isBooleanGetter(getter) ? "is" : "get").length());
            boolean matched = false;
            for (ExecutableElement setter : setters) {
                TypeMirror setterArgType = setter.getParameters()
                                     .iterator().next().asType();
                String actualSetterName = setter.getSimpleName().toString();
                matched = actualSetterName.equals(expectedSetterName)
                    && typeUtils.isSameType(setterArgType, getterReturnType);
                if (matched)
                    break;
            }
            if (!matched) {
                logger.warn(_loc.get("getter-unmatched", getter,
View Full Code Here


@SupportedSourceVersion(SourceVersion.RELEASE_6)
public class BoundAnnotationChecker extends AbstractProcessor {

  @Override
  public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    final Types types = processingEnv.getTypeUtils();
    final Elements elements = processingEnv.getElementUtils();
    final TypeMirror gwtWidgetType = elements.getTypeElement(TypeNames.GWT_WIDGET).asType();
    final TypeMirror gwtElementType = elements.getTypeElement(TypeNames.GWT_ELEMENT).asType();

    Map<TypeElement, List<Element>> classesWithBoundThings = new HashMap<TypeElement, List<Element>>();
    for (TypeElement annotation : annotations) {
      for (Element target : roundEnv.getElementsAnnotatedWith(annotation)) {
        TypeMirror targetType;
        if (target.getKind() == ElementKind.METHOD) {
          targetType = ((ExecutableElement) target).getReturnType();
        }
        else {
          targetType = target.asType();
        }
        if (!types.isAssignable(targetType, gwtWidgetType) && !types.isAssignable(targetType, gwtElementType)) {
          processingEnv.getMessager().printMessage(
                  Kind.ERROR, "@Bound must target a type assignable to Widget or Element", target);
        }

        TypeElement enclosingClass = getEnclosingTypeElement(target);
View Full Code Here

  /**
   * Returns the set of all bindable property names in the given model.
   */
  private Set<String> getPropertyNames(TypeMirror modelType) {
    final Elements elements = processingEnv.getElementUtils();
    final Types types = processingEnv.getTypeUtils();

    Set<String> result = new HashSet<String>();

    for (Element el : ElementFilter.methodsIn(elements.getAllMembers((TypeElement) types.asElement(modelType)))) {
      String propertyName = AnnotationProcessors.propertyNameOfMethod(el);
      if (propertyName != null) {
        result.add(propertyName);
      }
      // TODO extract type info from methods
View Full Code Here

                String str1 = trees.getOriginalType((ErrorType)typeMirror).toString();
                if (!str1.equals("java.lang.Number")) {
                    throw new AssertionError("Trees.getOriginalType() error!");
                }

                Types types = task.getTypes();

                str1 = types.asElement(trees.getOriginalType((ErrorType)typeMirror)).toString();
                if (!str1.equals("java.lang.Number")) {
                    throw new AssertionError("Types.asElement() error!");
                }

                i++;
              }
              else if (i == 1) {
                String str1 = trees.getOriginalType((ErrorType)typeMirror).toString();
                if (!str1.equals("FooBar")) {
                    throw new AssertionError("Trees.getOriginalType() error!");
                }

                Types types = task.getTypes();

                str1 = types.asElement(trees.getOriginalType((ErrorType)typeMirror)).toString();
                if (!str1.equals("FooBar")) {
                    throw new AssertionError("Types.asElement() error!");
                }
                foundError = true;
              }
View Full Code Here

        }

        // 4942232:
        // check that classes exist for all the parameters of native methods
        private void checkMethodParameters(Set<TypeElement> classes) {
            Types types = processingEnv.getTypeUtils();
            for (TypeElement te: classes) {
                for (ExecutableElement ee: ElementFilter.methodsIn(te.getEnclosedElements())) {
                    for (VariableElement ve: ee.getParameters()) {
                        TypeMirror tm = ve.asType();
                        checkMethodParametersVisitor.visit(tm, types);
View Full Code Here

  private final TypeMirror mapType;

  public TypeUtils(ProcessingEnvironment env) {
    this.env = env;
    Types types = env.getTypeUtils();
    WildcardType wc = types.getWildcardType(null, null);
    this.collectionType = types.getDeclaredType(this.env.getElementUtils()
        .getTypeElement(Collection.class.getName()), wc);
    this.mapType = types.getDeclaredType(
        this.env.getElementUtils().getTypeElement(Map.class.getName()), wc, wc);

  }
View Full Code Here

        Preconditions.checkNotNull(type, "No type found for %s", typeElement);
        type.getClosures().add(closure);
    }

    private TypeElement box(TypeMirror returnType) {
        final Types types = env.getTypeUtils();

        final String name = returnType.toString();
        switch (name) {
            case "byte":
            case "short":
            case "int":
            case "long":
            case "float":
            case "double":
            case "char":
            case "boolean":
                final TypeKind kind = TypeKind.valueOf(name.toUpperCase(Locale.ENGLISH));
                return types.boxedClass(types.getPrimitiveType(kind));
            default:
                return (TypeElement) types.asElement(returnType);
        }
    }
View Full Code Here

  }

  public static String extractClosestRealTypeAsString(TypeMirror type, Context context) {
    if ( type instanceof TypeVariable ) {
      final TypeMirror compositeUpperBound = ( ( TypeVariable ) type ).getUpperBound();
      final Types types = context.getTypeUtils();
      final List<? extends TypeMirror> upperBounds = types.directSupertypes( compositeUpperBound );
      if ( upperBounds.size() == 0 ) {
        return compositeUpperBound.toString();
      }
      else {
        //take the first one
View Full Code Here

    }



    private boolean isSubType(TypeElement subType, TypeElement baseType) {
        Types types = processingEnv.getTypeUtils();
        return types.isSubtype(types.getDeclaredType(subType), types.getDeclaredType(baseType));
    }
View Full Code Here

   * Do some non-trivial operation with {@link TypeMirror} instances because they stop working after
   * compilation stops.
   */
  @Test public void typeMirrorsAreValidAndWorking() {
    Elements elements = compilationRule.getElements();
    Types types = compilationRule.getTypes();
    DeclaredType arrayListOfString = types.getDeclaredType(
        elements.getTypeElement(ArrayList.class.getName()),
        elements.getTypeElement(String.class.getName()).asType());
    DeclaredType listOfExtendsObjectType = types.getDeclaredType(
        elements.getTypeElement(List.class.getName()),
        types.getWildcardType(elements.getTypeElement(Object.class.getName()).asType(), null));
    assertThat(types.isAssignable(arrayListOfString, listOfExtendsObjectType)).isTrue();
  }
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.