PsiField is enum
Hi
I need to determine if a field's type is based on an enum.
How do I do this?
Do I really need to get from PsiField => PsiClass and then use PsiClass.isEnum()?
An example:
public enum Planets { EARTH, MARS }
public class SpaceTravel {
private Planets from;
private Planets to;
private Date departure;
}
I want to know that the PsiField from is a enum.
Please sign in to leave a comment.
Hello Claus,
CI> I need to determine if a field's type is based on an enum. How do I
CI> do this?
CI>
CI> Do I really need to get from PsiField => PsiClass and then use
CI> PsiClass.isEnum()?
Yes, that's how it's supposed to be done.
--
Dmitry Jemerov
Software Developer
JetBrains, Inc.
http://www.jetbrains.com
"Develop with pleasure!"
They've made it easier recently. Just use
field instanceof PsiEnumConstant
.
Hello Dave,
DG> They've made it easier recently. Just use
DG>
DG> field instanceof PsiEnumConstant
As far as I understand, this is a different thing. In the example provided
by Claus, 'EARTH' is a PsiEnumConstant, but 'from' is a regular PsiField.
--
Dmitry Jemerov
Software Developer
JetBrains, Inc.
http://www.jetbrains.com
"Develop with pleasure!"
You're right. I misunderstood.
--Dave Griffith
Yeah I wasn't very easy to get from PsiField -> PsiClas.
I can't show the code as I am not connected to the internet at home where I work with the plugin. Here at work I can use the internet.
I remember I basically had to (pseudo code)
As you can see it's not easy and cumbersome. You manually have to check that the type isn't a simple type (int, char etc.). And this is also quite tricky.
I assume there is some code somewhere in IDEA that Jetbrains use to determine this, but it's not open.
Here's an easier way, but not very easy to discover if you don't know the api. This is one of those things that should be documented.
Of course you mean
if (!(type instanceof PsiClassType)) {
return false;
}
;)
Sascha
Doh! That's what I meant.