You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi. I'm trying to get all elements of some enum.
For the enum, which declaration is present in the source code this works fine:
...
CtTypeReference typeRef = expr.getType();
if (typeRef.isEnum())
{
CtType type = typeRef.getTypeDeclaration();
if (type instanceof CtEnum)
{
System.out.println(((CtEnum) type).getEnumValues());
}
}
But once the enum is not present in the source (i.e. it is located in some .jar), this approach does not work.
For shadowed type reference .isEnum() always returns false, and the actual type of such enum is CtClass (why not CtEnum?).
So, it is impossible to cast it to CtEnum and call .getEnumValues().
Obviously, to get enum values from enum which is located in .jar, I can check if it's parent is java.lang.Enum and then get all the fields, excluding .ENUM$VALUES, name and ordinal.
But it seems to be quite overcomplicated, because I need to use two different approaches for shadowed and non-shadowed enums.
So can you please explain, why is this happening? Is it possible to get shadowed enum values easier?
Furthermore, I'm interested, are there any similar problems with other data types?
But once the enum is not present in the source (i.e. it is located in
some .jar), this approach does not work.
For shadowed type reference |.isEnum()| always returns false, and the
actual type of such enum is |CtClass| (why not |CtEnum|?).
this sounds like a bug. could you propose a failing test case as pull
request? thanks!
Egor18
pushed a commit
to Egor18/spoon
that referenced
this issue
Jan 2, 2018
Hi. I'm trying to get all elements of some enum.
For the enum, which declaration is present in the source code this works fine:
But once the enum is not present in the source (i.e. it is located in some .jar), this approach does not work.
For shadowed type reference
.isEnum()
always returns false, and the actual type of such enum isCtClass
(why notCtEnum
?).So, it is impossible to cast it to
CtEnum
and call.getEnumValues()
.Obviously, to get enum values from enum which is located in .jar, I can check if it's parent is
java.lang.Enum
and then get all the fields, excluding.ENUM$VALUES
,name
andordinal
.But it seems to be quite overcomplicated, because I need to use two different approaches for shadowed and non-shadowed enums.
So can you please explain, why is this happening? Is it possible to get shadowed enum values easier?
Furthermore, I'm interested, are there any similar problems with other data types?
P.S. This partially concerns incremental build.
Thank you.
The text was updated successfully, but these errors were encountered: