Package javax.lang.model.type

Examples of javax.lang.model.type.TypeVariable


            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


      DeclaredType captureOne = (DeclaredType) typeUtil.capture(one.getReturnType());
      assertTrue(typeMirrorSet.add(captureOne));
      DeclaredType captureTwo = (DeclaredType) typeUtil.capture(two.getReturnType());
      assertFalse(typeMirrorSet.add(captureTwo));
      // Reminder: captureOne is Map<?#123 extends T, ?#456 super U>
      TypeVariable extendsT = (TypeVariable) captureOne.getTypeArguments().get(0);
      assertTrue(typeMirrorSet.add(extendsT));
      assertTrue(typeMirrorSet.add(extendsT.getLowerBound()))// NoType
      for (TypeMirror bound : ((TypeParameterElement) extendsT.asElement()).getBounds()) {
        assertTrue(typeMirrorSet.add(bound));
      }
      TypeVariable superU = (TypeVariable) captureOne.getTypeArguments().get(1);
      assertTrue(typeMirrorSet.add(superU));
      assertFalse(typeMirrorSet.add(superU.getLowerBound()))// We already added U
    }
View Full Code Here

  }

  @Override
  public Optional<TypeElement> visitTypeVariable(TypeVariable t, Void p)
  {
    TypeVariable tv = t;
    TypeMirror lb = tv.getLowerBound();
    TypeKind lbk = lb.getKind();
    if (TypeKind.NONE.equals(lbk) == false && TypeKind.NULL.equals(lbk) == false)
    {
      return lb.accept(this, null);
    }
    else
    {
      return tv.getUpperBound().accept(this, null);
    }

  }
View Full Code Here

  }

  @Override
  public String visitTypeVariable(TypeVariable t, Void p)
  {
    TypeVariable tv = t;
    TypeMirror lb = tv.getLowerBound();
    TypeKind lbk = lb.getKind();
    if (TypeKind.NONE.equals(lbk) == false && TypeKind.NULL.equals(lbk) == false)
    {
      return " ? super " + lb.accept(this, null);
    }
    else
    {
      return " ? extends " + tv.getUpperBound().accept(this, null);
    }
  }
View Full Code Here

   * @return the non-variable, non-wildcard upper bound of a type, if it has one, or itself if it has no bounds
   */
  public static TypeMirror upperBound(TypeMirror type) {
    do {
      if (type instanceof TypeVariable) {
        TypeVariable tvar = (TypeVariable) type;
        if (tvar.getUpperBound() != null) {
          type = tvar.getUpperBound();
        } else {
          break;
        }
      } else if (type instanceof WildcardType) {
        WildcardType wc = (WildcardType) type;
View Full Code Here

      if (!actualName.equals(name)) {
        continue;
      }
      TypeMirror actualReturnType = methodEl.getReturnType();
      if (actualReturnType.getKind() == TypeKind.TYPEVAR) {
        TypeVariable tv = (TypeVariable) actualReturnType;
        actualReturnType = tv.getUpperBound();
      }
      if (requiredReturnType != null && !types.isSubtype(requiredReturnType, actualReturnType)) {
        continue;
      }
      if (requiredParamType == null && methodEl.getParameters().size() > 0) {
        continue;
      }
      if (requiredParamType != null) {
        if (methodEl.getParameters().size() != 1) {
          continue;
        }
        TypeMirror actParamType = methodEl.getParameters().get(0).asType();
        if (actParamType.getKind() == TypeKind.TYPEVAR) {
          TypeVariable tv = (TypeVariable) actualReturnType;
          actParamType = tv.getUpperBound();
        }
        if (!types.isSubtype(requiredParamType, actParamType)) {
          continue;
        }
      }
View Full Code Here

    TypeMirror typeParam = typeParamEl.asType();
    if (typeParam.getKind() != TypeKind.TYPEVAR) {
      throw new RuntimeException(String.format("Unexpected kind of type parameter for %s: %s",
          typeParamEl.getSimpleName(), typeParam.getKind()));
    }
    TypeVariable tv = (TypeVariable) typeParam;
    return types.isSubtype(typeElement.asType(), tv.getUpperBound());
  }
View Full Code Here

    TypeMirror typeParam = typeParamEl.asType();
    if (typeParam.getKind() != TypeKind.TYPEVAR) {
      throw new RuntimeException(String.format("Unexpected kind of type parameter for %s: %s",
          typeParamEl.getSimpleName(), typeParam.getKind()));
    }
    TypeVariable tv = (TypeVariable) typeParam;
    TypeElement objectElem = elements.getTypeElement(Object.class.getName());
    return types.isSameType(objectElem.asType(), tv.getUpperBound());
  }
View Full Code Here

      case ARRAY:
        ArrayType arrayType = (ArrayType) typeMirror;
        return new ArrayTypeM(getTypeM(arrayType.getComponentType()));
      case TYPEVAR:
        if (typeMirror instanceof TypeVariable) {
          TypeVariable typeVar = (TypeVariable) typeMirror;
          return getTypeVariableM((TypeParameterElement) typeVar.asElement());
        } else {
          throw new UnresolvedTypeException(String.format("Expected TypeVariable for %s (%s)", typeMirror, typeMirror
              .getClass().getName()));
        }
      case ERROR:
View Full Code Here

      for (TypeMirror typeArg : type.getTypeArguments()) {
        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

TOP

Related Classes of javax.lang.model.type.TypeVariable

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.