Inspector flags value casing on Switch statements for certain types.

Issue #1173 resolved
John De Santiago created an issue

The following code sample compiles fine but in the IC editor, it flags it with a warning citing improper casing (see screenshot).

public String translateDisplayType(Schema.DisplayType dt) {
        //Proper Case
        switch on dt {
            when Boolean {
                return null;
            }
            when Currency, Integer, Double {
                return null;
            }
            when Date, Datetime {
                return null;
            }
            when String {
                return null;
            }
        }

        //All Caps
        switch on dt {
            when BOOLEAN {
                return null;
            }
            when CURRENCY, INTEGER, DOUBLE {
                return null;
            }
            when DATE, DATETIME {
                return null;
            }
            when STRING {
                return null;
            }
        }
    }

Comments (7)

  1. Scott Wells repo owner

    Thanks, John. Easily reproduced, of course. The issue is that IC is incorrectly injecting a reference to the data type in addition to the correct reference to the enum constant:

    Issue1173.png

    Should be easy enough to fix. I'll see if I can slot it into the next build.

  2. Scott Wells repo owner

    By the way, according to Salesforce, the proper case would be the CONSTANT_CASE version, e.g., the following from the OST as designated by Salesforce's Tooling API:

    global enum /*Schema.*/DisplayType 
    {
        ADDRESS,
        ANYTYPE,
        BASE64,
        BOOLEAN,
        COMBOBOX,
        COMPLEXVALUE,
        CURRENCY,
        DATACATEGORYGROUPREFERENCE,
        DATE,
        DATETIME,
        DOUBLE,
        EMAIL,
        ENCRYPTEDSTRING,
        ID,
        INTEGER,
        JSON,
        LOCATION,
        LONG,
        MULTIPICKLIST,
        PERCENT,
        PHONE,
        PICKLIST,
        REFERENCE,
        SOBJECT,
        STRING,
        TEXTAREA,
        TIME,
        URL
    }
    

    I realize that's at odds with what they document online, but that's how the API reports it, and IMO it's more consistent with how enum constants should be defined anyway.

  3. John De Santiago reporter

    Agreed. To me, they are constants within a class and should be all uppercase. I wouldn't mind some underscores in between words but that might just be me :)

  4. Scott Wells repo owner

    Agreed. Unfortunately this is part of the standard Apex system API so it's not at all under my control. I'll take care of the incorrect reference injection which will resolve this code inspection false negative, though.

  5. Log in to comment