Package javax.lang.model.element

Examples of javax.lang.model.element.TypeParameterElement


    @Test
    public void typeVariable() {
        start(new Callback() {
            @Override protected void test() {
                TypeElement map = elements.getTypeElement(Map.class.getName());
                TypeParameterElement k = map.getTypeParameters().get(0);
                assertThat(
                    target.convert(k.asType()),
                    is((Type) f.newNamedType(f.newSimpleName("K"))));

                TypeElement list = elements.getTypeElement(List.class.getName());
                TypeParameterElement e = list.getTypeParameters().get(0);
                assertThat(
                    target.convert(e.asType()),
                    is((Type) f.newNamedType(f.newSimpleName("E"))));
            }
        });
    }
View Full Code Here


                                }
                                TypeElement te;
                                if (type.getKind() == TypeKind.DECLARED) {
                                    te = (TypeElement) types.asElement(type);
                                } else if (type.getKind() == TypeKind.TYPEVAR) {
                                    TypeParameterElement tpe = (TypeParameterElement) types.asElement(type);
                                    List<? extends TypeMirror> exts = tpe.getBounds();
                                    if (exts.size() == 1) {
                                        type = exts.get(0);
                                        if (type.getKind() == TypeKind.DECLARED) {
                                            te = (TypeElement) types.asElement(type);
                                        } else {
View Full Code Here

    }
    @SupportedAnnotationTypes("*")
    @SupportedSourceVersion(SourceVersion.RELEASE_6)
    static class MyProcessor extends AbstractProcessor {
        void test(TypeElement element, boolean fbound) {
            TypeParameterElement tpe = element.getTypeParameters().iterator().next();
            tpe.getBounds().getClass();
            if (fbound) {
                DeclaredType type = (DeclaredType)tpe.getBounds().get(0);
                if (type.asElement() != element)
                    throw error("%s != %s", type.asElement(), element);
                TypeVariable tv = (TypeVariable)type.getTypeArguments().get(0);
                if (tv.asElement() != tpe)
                    throw error("%s != %s", tv.asElement(), tpe);
View Full Code Here

                        return SpecificCompilerWorkarounds.isSubType( typeUtils, superBound, p ) ||
                            typeUtils.isSameType( p, superBound );

                    case TYPEVAR:

                        TypeParameterElement typeParameter = getTypeParamFromCandidate( superBound );
                        // for example method: <T extends String & Serializable> T method(? super T)
                        if ( !isWithinBounds( p, typeParameter ) ) {
                            // this checks the part? <T extends String & Serializable>
                            return Boolean.FALSE;
                        }
                        // now, it becomes a bit more hairy. We have the relation (? super T). From T we know that
                        // it is a subclass of String & Serializable. However, The Java Language Secification,
                        // Chapter 4.4, states that a bound is either: 'A type variable-', 'A class-' or 'An
                        // interface-' type followed by further interface types. So we must compare with the first
                        // argument in the Expression String & Serializable & ..., so, in this case String.
                        // to check super type, we can simply reverse the argument, but that would initially yield
                        // a result: <type, superType] (so type not included) so we need to check sameType also.
                        TypeMirror superBoundAsDeclared = typeParameter.getBounds().get( 0 );
                        return ( SpecificCompilerWorkarounds.isSubType( typeUtils, superBoundAsDeclared, p ) ||
                            typeUtils.isSameType( p, superBoundAsDeclared ) );
                    default:
                        // does this situation occur?
                        return Boolean.FALSE;
View Full Code Here

        if (typeArg.getKind() == TypeKind.DECLARED) {
          TypeM typeArgElemTypeM = getTypeM(typeArg);
          result.withTypeParameter(typeArgElemTypeM);
        } else if (typeArg.getKind() == TypeKind.TYPEVAR) {
          TypeVariable typeVar = (TypeVariable) typeArg;
          TypeParameterElement typeParamElem = (TypeParameterElement) typeVar.asElement();
          TypeVariableM var = getTypeVariableM(typeParamElem);
          result.withTypeParameter(var);
        }
      }
    }
View Full Code Here

    if (typeParams == null) {
      return new TypeM[0];
    }
    TypeM[] result = new TypeM[typeParams.size()];
    for (int i = 0; i < result.length; ++i) {
      TypeParameterElement typeParameterElement = typeParams.get(i);
      TypeVariableM var = getTypeVariableM(typeParameterElement);
      result[i] = var;
    }
    return result;
  }
View Full Code Here

              .format(
                  "Illegal interface %s! A builder's interface must declare exactly 1 generic type parameter!",
                  interfaceTypeElement.getSimpleName());
      throw new InvalidElementException(message, output.getInput().getAnnotatedElement());
    }
    TypeParameterElement typeParamEl = interfaceTypeElement.getTypeParameters().get(0);
    if (!javaModelAnalyzerUtil.isUpperBoundToObject(typeParamEl)) {
      String message =
          String
              .format(
                  "Illegal interface %s! A builder's interface must declare exactly 1 generic type parameter with an upper bound of Object!",
                  interfaceTypeElement.getSimpleName());
      throw new InvalidElementException(message, output.getInput().getAnnotatedElement());
    }
    interfaceType.getTypeParameters().clear();
    interfaceType.getTypeParameters().add(output.getBuilderModel().getPojoType());

    boolean hasBuildMethod =
        javaModelAnalyzerUtil.hasBuildMethod(interfaceTypeElement, output.getInput()
            .getPojoElement().asType());
    if (hasBuildMethod) {
      output.getBuilderModel().getBuildMethod().setOverrides(true);
    } else {
      String message =
          String
              .format(
                  "Illegal interface %s! A builder's interface must declare a generic method \"%s build()\"!",
                  interfaceTypeElement.getSimpleName(), typeParamEl.getSimpleName());
      throw new InvalidElementException(message, output.getInput().getAnnotatedElement());
    }
    output.getBuilderModel().setInterfaceType(interfaceType);
    output.getInput().getOrginatingElements()
        .add(javaModelAnalyzerUtil.getCompilationUnit(interfaceTypeElement));
View Full Code Here

                .format(
                    "Illegal baseclass %s! A builder's baseclass must not have more than 1 generic type parameter!",
                    baseTypeElement.getSimpleName());
        throw new InvalidElementException(message, output.getInput().getAnnotatedElement());
      }
      TypeParameterElement typeParamEl = baseTypeElement.getTypeParameters().get(0);
      if (!javaModelAnalyzerUtil.matchesUpperBound(pojoTypeElement, typeParamEl)) {
        String message =
            String.format("Illegal baseclass %s! %s can not be assigned to type parameter %s!",
                baseTypeElement.getSimpleName(), pojoTypeElement.getSimpleName(),
                typeParamEl.getSimpleName());
        throw new InvalidElementException(message, output.getInput().getAnnotatedElement());
      }
      baseType.getTypeParameters().clear();
      baseType.getTypeParameters().add(output.getBuilderModel().getPojoType());
    }
View Full Code Here

            throw new AssertionError("Annotation processor failed");
    }
    @SupportedAnnotationTypes("*")
    static class MyProcessor extends AbstractProcessor {
        void test(TypeElement element, boolean fbound) {
            TypeParameterElement tpe = element.getTypeParameters().iterator().next();
            tpe.getBounds().getClass();
            if (fbound) {
                DeclaredType type = (DeclaredType)tpe.getBounds().get(0);
                if (type.asElement() != element)
                    throw error("%s != %s", type.asElement(), element);
                TypeVariable tv = (TypeVariable)type.getTypeArguments().get(0);
                if (tv.asElement() != tpe)
                    throw error("%s != %s", tv.asElement(), tpe);
View Full Code Here

TOP

Related Classes of javax.lang.model.element.TypeParameterElement

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.