Java 8 TypeVariable - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 TypeVariable class.

This code example shows how to use the following methods:asElement
            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);
            } 
        } 
        public boolean process(Set<? extends TypeElement> annotations,
                               RoundEnvironment roundEnv) {
            test(processingEnv.getElementUtils().getTypeElement("Test1"), false);
            test(processingEnv.getElementUtils().getTypeElement("Test2"), true);
            return false; 
        } 
        @Override 
        public SourceVersion getSupportedSourceVersion() {
            return SourceVersion.latest();
        } 
    } 
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:toString
	} 
 
	@Override 
	public R visitTypeVariable(TypeVariable t, P p)
	{ 
		log("visitTypeVariable(TypeVariable=[%s], P p=[%s])", t.toString(), p);
		if (next != null)
			return next.visitTypeVariable(t, p);
		return null; 
	} 
 
	@Override 
	public R visitWildcard(WildcardType t, P p)
	{ 
		log("visitWildcard(WildcardType=[%s], P p=[%s])", t.toString(), p);
		if (next != null)
			return next.visitWildcard(t, p);
		return null; 
	} 
 
4
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getLowerBound, getUpperBound
 
	@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);
		} 
 
	} 
 
	@Override 
	public Optional<TypeElement> visitWildcard(WildcardType t, Void p)
4
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getUpperBound
	} 
 
	@Override 
	public AnnotationMetaAttribute visitTypeVariable(TypeVariable t, Element element) {
		// METAGEN-29 - for a type variable we use the upper bound 
		TypeMirror mirror = t.getUpperBound();
		TypeMirror erasedType = context.getTypeUtils().erasure( mirror );
		return new AnnotationMetaSingleAttribute( 
				entity, element, erasedType.toString()
		); 
	} 
 
	@Override 
	public AnnotationMetaAttribute visitDeclared(DeclaredType declaredType, Element element) {
		AnnotationMetaAttribute metaAttribute = null;
		TypeElement returnedElement = (TypeElement) context.getTypeUtils().asElement( declaredType );
		// WARNING: .toString() is necessary here since Name equals does not compare to String 
		String fqNameOfReturnType = returnedElement.getQualifiedName().toString();
		String collection = Constants.COLLECTIONS.get( fqNameOfReturnType );
		String targetEntity = getTargetEntity( element.getAnnotationMirrors() );
4
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:asElement
            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);
            } 
        } 
        public boolean process(Set<? extends TypeElement> annotations,
                               RoundEnvironment roundEnv) {
            test(processingEnv.getElementUtils().getTypeElement("Test1"), false);
            test(processingEnv.getElementUtils().getTypeElement("Test2"), true);
            return false; 
        } 
    } 
    public static void main(String... args) {
        new T6421111().test(args);
    } 
    public static AssertionError error(String format, Object... args) {
3
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getUpperBound
    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());
  } 
 
  /** 
   * Returns true if the given type parameter has an upper bound of type {@link Object}. 
   *  
   * @param typeParamEl the type parameter 
   * @return true if the given type parameter has an upper bound of type {@link Object} 
   */ 
  public boolean isUpperBoundToObject(TypeParameterElement typeParamEl) {
    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()));
    } 
3
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
See Code Examples for Java 8 TypeVariable Methods: