Cannot Resolve Symbol - Field class
I have an Apex class called 'Field' defined in my 'classes' directory, but IlluminatedCloud is saying that it cannot resolve the symbol.
Per Scott Wells:
That's almost certainly because ‘Field’ is also an Apex reserved word.
Comments (10)
-
repo owner -
August - are you developing in a scratch org with a namespace by any chance? If so, does your offline table have a Field.cls in a namespaced subdirectory?
I've found the symbol tree to get tricked in multi-module projects against namespaced DX orgs, where IC2 expects the class to be referenced by namespace if it has a symbol in the namespace subfolder. This is typically only a problem for classes defined in a module outside of the default module referencing other classes defined outside the default module.
It's hacky but we've added a build process hook into intellij that clears these symbols from the offline symbol table to get around this.
-
repo owner Jonny, do you mind reaching out to me directly to help me understand this workaround you've had to implement a bit more. I want to make sure that I fix it and you don't have to implement such a workaround. If you've already reported it somewhere, my apologies for letting it slip off my radar; just send me the issue number.
-
Sure - I'll drop you an email
-
I can reproduce this as follows (in 2.2.1.5) - no namespaced org involved.
public class Slack { public class Field {} public class Post { Field[] fields = new List<Field>(); } }
Compiles fine; Per https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_reserved_words.htm,
Field
is not a reserved word. -
repo owner Eric, that still doesn't show as an error for me:
I tried it in both Anonymous Apex and in a dedicated class file, and in both cases there were no errors and all references resolved appropriately. Are you able to do this in 100% isolation of other files in a given project? I'm wondering if something else in the project is being picked up during reference resolution or something.
-
so, perhaps this is the clue --
In the org, there is a managed package
Selector
, namespace =Select
that has a class calledField
. If you look at the readme for that package, you’ll note that the usage is:Select.Field.xxx()
. NotSelect__Field.xxx()
-
OK, I’m not convinced by the above; today in my project I started seeing inner class code inspection errors where the inner class type was not recognized within the same outer class file. So, I attempted to reproduce in anonymous apex:
public class MyOuter { MyInner myInner; public class MyInner{} }
I updated to 2.2.1.6, refreshed OST/rebuilt caches and indexes and the code inspection worked in my real class files but had no effect in the anon apex as shown above.
How I got to this point … For example, in my real class file
SlackService
I had an inner class. All fine with respect to code inspectorpublic class SlackService { public class SomeOtherClass {} public class Text { String text; } public class AnotherClass{} }
then , I edited the file and added a fluent item:
public class SlackService { public class SomeOtherClass {} public class Text { String text; public Text withText(String val) {this.text = val; return this;} } public class AnotherClass{} }
and line 7 suddenly popped up in red with
Text
being an unresolved symbol. Of course it compiles fine. There are no managed package classes namedText
. Rebuilding OST/cache/indices after upgrading to 2.2.1.6 resolved the inspector (but not the anon apex one ^). I wish I could localize this more for you Let me know what else I can provide.UPDATE: So, I’m continuing to edit my
SlackService
outer class which happens to have 30 inner classes.As I add fluent methods within each inner class as in:
public class Inner6 { Inner28 someField; public Inner6 withSomeField(Inner28 val) {this.somefield = val; return this;} } } ... public class Inner28 { .. }
the references to Inner28 suddenly go red - unable to resolve symbol. It seems to be a density of inner class issue??? And, not every further down the class file references to Inner classes go red
These inner class refs go red:
Confirm
,Text
,OptionGroup
These inner class refs do not go red:
Option
,Filter
,Message
To test out the reserved word hypothesis, I renamed the inner class
Confirm
toConfirmX
- this resolved the red symbol not foundThen, I renamed
ConfirmX
back toConfirm
- went back to Red . Hmm - perhaps alleged reserved words are the issue?No … it appears Illuminated Cloud knows about an Apex
Slack
namespace. There seems to be a (undocumented in V54)Slack.Text
class, aSlack.Confirm
class, aSlack.OptionGroup
class. Perhaps your code inspector is confusing my inner classText
with theSlack.Text
class - but only on some weird delayed basis. Doesn’t explain the anon apex example ^ though. -
repo owner I'm still unable to reproduce this behavior. Definitely the best way for me to get to the bottom of it would be a simple standalone project where you can reproduce it (semi-?)consistently shared so I could open the same project.
-
repo owner - changed status to resolved
Issue tracker grooming. If this is still an issue, please feel free to reopen, ideally with a concrete reproduction scenario.
- Log in to comment
August, I'm actually unable to reproduce this:
Can you do me a favor and regenerate your OST to see if that resolves the issue?