- edited description
Inspection - inner enums
I have:
public class MyClass {
@TestVisible private enum MyPrivateEnum {
VALUE_1,
VALUE_2
}
}
and
@IsTest private class MyClassTest {
private static testMethod void testSomethingWithEnum {
System.assertEquals(MyClass.MyPrivateEnum.VALUE_1, someMethodToTest());
}
}
Trouble is, "VALUE_1" in the test class is showing as not able to be resolved. "MyClass.MyPrivateEnum" is fine, but the value itself is a no-go. Code compiles fine.
I would also like to remind you that you do excellent work and I'm very happy I started going with IJ/IC.
You said in my last ticket that I marked trivial that inspections should be taken seriously, so I'm bumping this up to "minor" lol
Comments (13)
-
reporter -
repo owner This was interesting...I hadn't thought about the fact that enum constants would need to be exposed via their containing type. Done and will be included in the next build.
-
repo owner - changed status to resolved
Delivered in 1.8.2.0 (
@TestVisible
handling only) and 2.0.1.1 (@TestVisible
handling and inspection). -
Is this expected to fix
MyClass.MyPrivateEnum.VALUE_1.name()
as well? IC tells meCannot resolve symbol 'name'
for code just like this, which also uses.name()
on theenum
. If this is unrelated, I can open another bug. -
repo owner Hi, Jon. Note that
name()
is not a real method on an enum constant, though. IC adds it for purposes of code completion since it is part of the language, but there's no physical declaration ofname()
to which you can navigate. That's why you're gettingCannot resolve symbol 'name'
when you try to navigate to it. The same thing is true of other implicit symbols such as theclass
constant for all Apex types (e.g.,String.class
). IC includes those in the body declarations of the parent types even though they're not explicitly part of the type definition.Regards, Scott
-
Hi Scott, understood that you can't necessarily navigate to a declaration, but since it's valid to call
name()
on the constant, it's unexpected thatname()
shows up in red and adds to the count of errors in the file. Happy to open a separate issue here if that's appropriate.Thanks!
-
repo owner Ah, okay. Based on the error message you provided I assumed you were talking about IC1. You should not see this flagged as an unresolvable reference in IC2, though. I just tried to reproduce this and am not seeing any errors in the following:
String enumConstant1Value = UnusedDeclarationTest.InnerEnum.ENUM_CONSTANT1.name();
If you are seeing errors in code like that, could you please create a standalone reproducible example and provide it here so I can try that?
-
Basically the example in this ticket I would imagine would recreate the issue if it used
.name()
in the test. However, I've recreated from scratch with this pair of classes.public class TestClass { @TestVisible private enum TestEnum{A} }
And the error is in the tests for that (poorly named) class:
@isTest private class TestClassTest { @isTest static void test() { // name is red here. On hover, I see `Cannot resolve symbol 'name'` in IC 2. TestClass.TestEnum.A.name(); } }
-
repo owner Ah, okay. I'm being dumb...I wasn't tying together the
@TestVisible
aspect that drove this original ticket. Good lord...I should pay better attention! Okay, it's easily reproduced when I do that. I'll take a look for the next build as I work through some other false negatives. Thanks for bearing with me! -
No worries, thanks for the crazy fast response. You are awesome and IC has changed my life :)
-
repo owner New fix submitted for the next build.
-
reporter Excellent! I also wanted you to know that every time I got an email for this issue - I read "Inner Eardrums" lol.
-
repo owner More complete fix delivered in 2.0.1.2 and 1.8.2.1.
- Log in to comment