Skip to content

[apex] Provide type information for CastExpression #5567

@adangel

Description

@adangel

Originally posted at ChuckJonas/vscode-apex-pmd#249

Is your feature request related to a problem? Please describe.

With a type cast, there is no information about the type.

If I have this example code

class Test {
	private void main() {
            Id test = (Id) '006D600000ZaBOeIAN';
	}
}

In the AST I would expect the CastExpression to provide a clue about the type, but this is all I get:

<CastExpression DefiningType='Test' Image='' RealLoc='true'>

The full XML for the sample code is as follows.

<?xml version='1.0' encoding='UTF-8' ?>
<ApexFile DefiningType='Test' Image='' RealLoc='true'>
    <UserClass DefiningType='Test' Image='Test' InterfaceNames='[]' Nested='false' RealLoc='true' SimpleName='Test' SuperClassName=''>
        <ModifierNode Abstract='false' DefiningType='Test' DeprecatedTestMethod='false' Final='false' Global='false' Image='' InheritedSharing='false' Modifiers='0' Override='false' Private='false' Protected='false' Public='false' RealLoc='false' Static='false' Test='false' TestOrTestSetup='false' Transient='false' Virtual='false' WebService='false' WithSharing='false' WithoutSharing='false' />
        <Method Arity='0' CanonicalName='main' Constructor='false' DefiningType='Test' Image='main' RealLoc='true' ReturnType='void' StaticInitializer='false'>
            <ModifierNode Abstract='false' DefiningType='Test' DeprecatedTestMethod='false' Final='false' Global='false' Image='' InheritedSharing='false' Modifiers='2' Override='false' Private='true' Protected='false' Public='false' RealLoc='true' Static='false' Test='false' TestOrTestSetup='false' Transient='false' Virtual='false' WebService='false' WithSharing='false' WithoutSharing='false' />
            <BlockStatement CurlyBrace='true' DefiningType='Test' Image='' RealLoc='true'>
                <VariableDeclarationStatements DefiningType='Test' Image='' RealLoc='true'>
                    <ModifierNode Abstract='false' DefiningType='Test' DeprecatedTestMethod='false' Final='false' Global='false' Image='' InheritedSharing='false' Modifiers='0' Override='false' Private='false' Protected='false' Public='false' RealLoc='false' Static='false' Test='false' TestOrTestSetup='false' Transient='false' Virtual='false' WebService='false' WithSharing='false' WithoutSharing='false' />
                    <VariableDeclaration DefiningType='Test' Image='test' RealLoc='true' Type='Id'>
                        <CastExpression DefiningType='Test' Image='' RealLoc='true'>
                            <LiteralExpression Boolean='false' Decimal='false' DefiningType='Test' Double='false' Image='006D600000ZaBOeIAN' Integer='false' LiteralType='STRING' Long='false' Name='' Null='false' RealLoc='true' String='true' />
                        </CastExpression>
                        <VariableExpression DefiningType='Test' Image='test' RealLoc='true'>
                            <EmptyReferenceExpression DefiningType='' Image='' RealLoc='false' />
                        </VariableExpression>
                    </VariableDeclaration>
                </VariableDeclarationStatements>
            </BlockStatement>
        </Method>
    </UserClass>
</ApexFile>

Describe the solution you'd like

Maybe something like

<CastExpression DefiningType='Test' Image='' RealLoc='true' Type='Id'>

Describe alternatives you've considered

Additional context

Metadata

Metadata

Assignees

Labels

an:enhancementAn improvement on existing features / rulesin:grammarAbout the grammar of a lexer or parser, eg, a parse/lex exception

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions