Java Code Examples for java.lang.reflect.AnnotatedWildcardType

Following code examples demonstrate how to use java.lang.reflect.AnnotatedWildcardTypefrom java. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use java.lang.reflect.AnnotatedWildcardTypeand various code implementation of this class.

    static <T extends AnnotatedTypeMirror> List<? extends T> mirrorTypes(AnnotatedType... types) {
        List<T> results = new ArrayList<>(types.length);
        for (AnnotatedType type : types) {
            results.add((T) AnnotatedTypeMirror.of(type));
        }
        return results;
    } 


    public void getAttributes(Yield yield, AnnotatedWildcardType value) {
        if (cliOptions.annotation) {
            yield.apply(value.getAnnotatedLowerBounds(), "annotatedLowerBounds");
            yield.apply(value.getAnnotatedUpperBounds(), "annotatedUpperBounds");
        }
    } 

    @Test
    public default void verifyGenericType()
    throws Exception {
        final Class<SUT> sut = createNewSUT();
        assertTrue("This j8unit test interface is used with a generic type that is illegaly not assignable to AnnotatedWildcardType.class!",
                   AnnotatedWildcardType.class.isAssignableFrom(sut));
    } 

    public boolean equals(Object other) {
        if (!(other instanceof AnnotatedWildcardType) || !super.equals(other)) {
            return false;
        }
        return typeArraysEqual(lowerBounds, ((AnnotatedWildcardType) other).getAnnotatedLowerBounds())
                && typeArraysEqual(upperBounds, ((AnnotatedWildcardType) other).getAnnotatedUpperBounds());
    } 

        if (annotatedType instanceof AnnotatedWildcardType) {
            AnnotatedWildcardType wildcard = (AnnotatedWildcardType) annotatedType;
            if (wildcard.getAnnotatedLowerBounds().length > 0)
                return singletonList(wildcard.getAnnotatedLowerBounds()[0]);

            return asList(wildcard.getAnnotatedUpperBounds());
        } 

	protected AnnotatedType visitCaptureType(AnnotatedCaptureType type) {
		AnnotatedCaptureCacheKey key = new AnnotatedCaptureCacheKey(type);
		if (captureCache.containsKey(key)) {
			return captureCache.get(key);
		}
		AnnotatedCaptureType annotatedCapture = new AnnotatedCaptureTypeImpl((CaptureType) type.getType(),
				(AnnotatedWildcardType) transform(type.getAnnotatedWildcardType(), this),
				(AnnotatedTypeVariable) transform(type.getAnnotatedTypeVariable(), this),
				null, type.getAnnotations());
		captureCache.put(key, annotatedCapture);
		AnnotatedType[] upperBounds = Arrays.stream(type.getAnnotatedUpperBounds())
				.map(bound -> transform(bound, this))
				.toArray(AnnotatedType[]::new);
		return annotatedCapture;
	} 

	protected AnnotatedType visitWildcardType(AnnotatedWildcardType type) {
		AnnotatedType[] lowerBounds = Arrays.stream(type.getAnnotatedLowerBounds())
				.map(bound -> transform(bound, this))
				.toArray(AnnotatedType[]::new);
		AnnotatedType[] upperBounds = Arrays.stream(type.getAnnotatedUpperBounds())
				.map(bound -> transform(bound, this))
				.toArray(AnnotatedType[]::new);
		WildcardType inner = new WildcardTypeImpl(
				Arrays.stream(upperBounds).map(AnnotatedType::getType).toArray(Type[]::new),
				Arrays.stream(lowerBounds).map(AnnotatedType::getType).toArray(Type[]::new));
		return new AnnotatedWildcardTypeImpl(inner, type.getAnnotations(),
				lowerBounds, upperBounds);
	} 

  static JavaType of(AnnotatedWildcardType annotatedType) {
    WildcardType result = new WildcardType();
      result.setBoundSuper((ReferenceType) JavaType.of(bound));
    } 

                if (actualTypeArgument instanceof AnnotatedWildcardType) {
                    System.out.println("-- casting to AnnotatedWildcardType --");
                    AnnotatedWildcardType wildcardType = (AnnotatedWildcardType) actualTypeArgument;
                    System.out.println("-- AnnotatedWildcardType#getAnnotatedLowerBounds() --");
                    
                    AnnotatedType[] lowerBounds = wildcardType.getAnnotatedLowerBounds();
                    printAnnotatedType(lowerBounds);
                    
                    System.out.println("-- AnnotatedWildcardType#getAnnotatedUpperBounds() --");
                    AnnotatedType[] upperBounds = wildcardType.getAnnotatedUpperBounds();
                    printAnnotatedType(upperBounds);
                } 

      if (type instanceof AnnotatedParameterizedType) {
         return visitParameterizedType((AnnotatedParameterizedType) type, param);
      } else if (type instanceof AnnotatedArrayType) {
         return visitArrayType((AnnotatedArrayType) type, param);
      } else if (type instanceof AnnotatedWildcardType) {
         return visitWildcardType((AnnotatedWildcardType) type, param);
      } else if (type instanceof AnnotatedTypeVariable) {
         return visitTypeVariable((AnnotatedTypeVariable) type, param);
      } else {
         return defaultAction(type, param);
      } 

            public R visitWildcardType(AnnotatedWildcardType wildcardType, P param) {
               return onWildcard != null
                     ? onWildcard.apply(wildcardType, param)
                     : defaultAction(wildcardType, param);
            } 

                if (actualTypeArgument instanceof AnnotatedWildcardType) {
                    System.out.println("-- casting to AnnotatedWildcardType --");
                    AnnotatedWildcardType wildcardType = (AnnotatedWildcardType) actualTypeArgument;
                    System.out.println("-- AnnotatedWildcardType#getAnnotatedLowerBounds() --");
                    AnnotatedType[] lowerBounds = wildcardType.getAnnotatedLowerBounds();
                    printAnnotatedType(lowerBounds);
                    
                    System.out.println("-- AnnotatedWildcardType#getAnnotatedUpperBounds() --");
                    AnnotatedType[] upperBounds = wildcardType.getAnnotatedUpperBounds();
                    printAnnotatedType(upperBounds);
                } 

   AnnotatedCapturedType(AnnotatedWildcardType wildcard) {
      this.wildcard = wildcard;
      this.typeVariable = new CapturedTypeVariable(wildcard);
   } 

      CapturedTypeVariable(AnnotatedWildcardType wildcard) {
         this.annotatedWildcard = wildcard;
         this.wildcard = (WildcardType) wildcard.getType();
         this.declaration = new CaptureGenericDeclaration(this);
      } 

    public static AnnotatedWildcardDescription create(AnnotatedWildcardType nativeType) {
        AnnotatedWildcardDescription description = new AnnotatedWildcardDescription();
        description.nativeType = nativeType;
        return description;
    } 

    public static void main(String[] args) throws NoSuchFieldException {
        Field field34 = Child.class.getField("field4");
        
        AnnotatedType annotatedType = field34.getAnnotatedType();
        System.out.print("annotatedType真实类型:");
        System.out.println(annotatedType.getClass().getSimpleName());
        
        AnnotatedParameterizedType apt = (AnnotatedParameterizedType)annotatedType;
        AnnotatedType[] ats = apt.getAnnotatedActualTypeArguments();
    
        AnnotatedWildcardType awt1 = (AnnotatedWildcardType)ats[0];
        AnnotatedWildcardType awt2 = (AnnotatedWildcardType)ats[1];
        
        
        System.out.println("==========第一个被注解的通配符 aw1==========");
        System.out.println(awt1.getClass().getSimpleName());
    
        AnnotatedType[] upperBounds = awt1.getAnnotatedUpperBounds();
        
        System.out.print("通配符中被注解的上界:");
        System.out.println(upperBounds[0].getClass().getSimpleName());
    
        System.out.print("被注解的上界的注解:");
        System.out.println(upperBounds[0].getAnnotations()[0]);
    
        System.out.print("被注解的上界的类型:");
        System.out.println(upperBounds[0].getType());
        
        System.out.println("==========第二个被注解的通配符 aw2==========");
        System.out.println(awt2.getClass().getSimpleName());
    
        AnnotatedType[] lowerBounds = awt2.getAnnotatedLowerBounds();
    
        System.out.print("通配符中被注解的下界:");
        System.out.println(lowerBounds[0].getClass().getSimpleName());
    
        System.out.print("被注解的下界的注解:");
        System.out.println(lowerBounds[0].getAnnotations()[0]);
    
        System.out.print("被注解的下界的类型:");
        System.out.println(lowerBounds[0].getType());
    } 

    AnnotatedCaptureTypeImpl(CaptureType type, AnnotatedWildcardType wildcard, AnnotatedTypeVariable variable, AnnotatedType[] upperBounds, Annotation[] annotations) {
        super(type, annotations != null ? annotations : Stream.concat(stream(wildcard.getAnnotations()), stream(variable.getAnnotations())).toArray(Annotation[]::new));
        this.type = type;
        this.wildcard = wildcard;
        this.variable = variable;
        this.lowerBounds = wildcard.getAnnotatedLowerBounds();
        this.upperBounds = upperBounds;
        this.declaredAnnotations = Stream.concat(
                Arrays.stream(wildcard.getDeclaredAnnotations()),
                Arrays.stream(variable.getDeclaredAnnotations())
        ).toArray(Annotation[]::new);
    } 

    AnnotatedType map(AnnotatedType type, MappingMode mappingMode) {
        if (type.getType() instanceof Class) {
            return updateAnnotations(type, ((Class) type.getType()).getAnnotations());
        } else if (type instanceof AnnotatedTypeVariable) {
            TypeVariable<?> tv = (TypeVariable) type.getType();
            if (!map.containsKey(tv)) {
                if (mappingMode.equals(MappingMode.ALLOW_INCOMPLETE)) {
                    AnnotatedTypeVariable variable = (AnnotatedTypeVariable) type;
                    AnnotatedType[] bounds = map(variable.getAnnotatedBounds(), mappingMode);
                    Annotation[] merged = merge(variable.getAnnotations(), tv.getAnnotations());
                    TypeVariableImpl v = new TypeVariableImpl<>(tv, merged, bounds);
                    return new AnnotatedTypeVariableImpl(v, merged);
                } else {
                    throw new UnresolvedTypeVariableException(tv);
                }
            }
            TypeVariable varFromClass = map.keySet().stream().filter(key -> key.equals(tv)).findFirst().get();
            Annotation[] merged = merge(type.getAnnotations(), tv.getAnnotations(), map.get(tv).getAnnotations(), varFromClass.getAnnotations());
            return updateAnnotations(map.get(tv), merged);
        } else if (type instanceof AnnotatedParameterizedType) {
            AnnotatedParameterizedType pType = (AnnotatedParameterizedType) type;
            ParameterizedType inner = (ParameterizedType) pType.getType();
            Class raw = (Class) inner.getRawType();
            AnnotatedType[] typeParameters = new AnnotatedType[raw.getTypeParameters().length];
            for (int i = 0; i < typeParameters.length; i++) {
                AnnotatedType typeParameter = map(pType.getAnnotatedActualTypeArguments()[i], mappingMode);
                typeParameters[i] = updateAnnotations(typeParameter, raw.getTypeParameters()[i].getAnnotations());
            }
            Type[] rawArgs = stream(typeParameters).map(AnnotatedType::getType).toArray(Type[]::new);
	        Type innerOwnerType = inner.getOwnerType() == null ? null : map(annotate(inner.getOwnerType()), mappingMode).getType();
	        ParameterizedType newInner = new ParameterizedTypeImpl((Class) inner.getRawType(), rawArgs, innerOwnerType);
            return new AnnotatedParameterizedTypeImpl(newInner, merge(pType.getAnnotations(), raw.getAnnotations()), typeParameters);
        } else if (type instanceof AnnotatedWildcardType) {
            AnnotatedWildcardType wType = (AnnotatedWildcardType) type;
            AnnotatedType[] up = map(wType.getAnnotatedUpperBounds(), mappingMode);
            AnnotatedType[] lw = map(wType.getAnnotatedLowerBounds(), mappingMode);
            Type[] upperBounds;
            if (up == null || up.length == 0) {
                upperBounds = ((WildcardType) wType.getType()).getUpperBounds();
            } else {
                upperBounds = stream(up).map(AnnotatedType::getType).toArray(Type[]::new);
            }
            WildcardType w = new WildcardTypeImpl(upperBounds, stream(lw).map(AnnotatedType::getType).toArray(Type[]::new));
            return new AnnotatedWildcardTypeImpl(w, wType.getAnnotations(), lw, up);
        } else if (type instanceof AnnotatedArrayType) {
            return AnnotatedArrayTypeImpl.createArrayType(map(((AnnotatedArrayType) type).getAnnotatedGenericComponentType(), mappingMode), type.getAnnotations());
        } else {
            throw new RuntimeException("Not implemented: mapping " + type.getClass() + " (" + type + ")");
        }
    } 

   CoreReflectionWildcardType(AnnotatedWildcardType wildcardType) {
      super(wildcardType);
      this.extendsBound = CoreReflectionTypes.toTypeMirrorOrObject
            (wildcardType.getAnnotatedUpperBounds());
      this.superBound = CoreReflectionTypes.toTypeMirrorOrNull(
            wildcardType.getAnnotatedUpperBounds()); 
   } 

            if (nativeType instanceof AnnotatedWildcardType) {
                AnnotatedWildcardType asAnnotated = (AnnotatedWildcardType) nativeType;
                upperBounds = asAnnotated.getAnnotatedUpperBounds();
                lowerBounds = asAnnotated.getAnnotatedLowerBounds();
            } else if (nativeType instanceof WildcardType) {
                WildcardType asWildcard = (WildcardType) nativeType;
                upperBounds = asWildcard.getUpperBounds();
                lowerBounds = asWildcard.getLowerBounds();
            } else {
                throw new DiamondException("The type[" + nativeType + "] is not a wildcard representation");
            }