Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jdt-apt-dev] Fwd: About TypeDeclaration.getActualTypeArguments()

In addition, I did search up the type hierarchy for the judgement, in a simular example, I was
testing a field of type Set<Integer> vs Collection<Number> and been expecting it return true. I
started with the DeclaredType for Set<Integer> and called getSuperinterfaces() on it to get the
DeclaredType for Collection<Integer>, maybe the getSuperinterfaces() call removed the type
parameter <Integer> and just returned the erased type Collection ??

--- Compl Yue Still <complystill@xxxxxxxxxxxx> wrote:

> Date: Sat, 10 Dec 2005 00:38:03 -0800 (PST)
> From: Compl Yue Still <complystill@xxxxxxxxxxxx>
> Subject: About TypeDeclaration.getActualTypeArguments()
> To: jdt-apt-dev@xxxxxxxxxxx
> 
> Hello buddies,
> 
>    I met some problem with TypeDeclaration.getActualTypeArguments(), I don't know if my
> understand
> is correct that this invocation should return the concrete types substituting the formal type
> parameters as possible.
>    The last straw was that I called Types.isAssignable(TypeMirror, TypeMirror) with a type
> parameter from the generic type of a field declaration, and ended up with a
> ClassCastException:org.eclipse.jdt.apt.core.internal.declaration.TypeParameterDeclarationImpl
> 
>    After some dig, I found the implementation here:
> 
>     public Collection<TypeMirror> getActualTypeArguments()
>     {
>         final ITypeBinding type = getTypeBinding();
>         final ITypeBinding[] typeArgs = type.getTypeArguments();
>         if( typeArgs == null || typeArgs.length == 0 )
>     		return Collections.emptyList();
> 
>         final Collection<TypeMirror> result = new ArrayList<TypeMirror>(typeArgs.length);
>         for( ITypeBinding arg : typeArgs ){
>             final TypeMirror mirror = Factory.createTypeMirror(arg, _env);
>             if(arg == null)
>                 result.add(Factory.createErrorClassType(arg));
>             else
>                 result.add(mirror);
>         }
> 
>         return result;
>     }
> 
>    Is this CORRECT? If it is, please any buddy tell me how to test that whether the type
> parameter
> of a field declaration is sub class of a specific one? Say, when processing annotations, how can
> I
> see whether a field is of type Set<? extends Collection>, but not a Set<String> ? In this case a
> field of type Set<List> should return true while type Set<String> should return false.
> 
>    Thanks in advance to any hint!
> 
> Compl Yue Still
> 
> 
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around 
> http://mail.yahoo.com 
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


Back to the top