Skip to content

[apex] Use apex-parser and Summit AST#4806

Merged
adangel merged 205 commits into
masterfrom
experimental-apex-parser
Feb 22, 2024
Merged

[apex] Use apex-parser and Summit AST#4806
adangel merged 205 commits into
masterfrom
experimental-apex-parser

Conversation

@adangel

@adangel adangel commented Jan 25, 2024

Copy link
Copy Markdown
Member

Describe the PR

These are all the current changes on the branch experimental-apex-parser that need to be reviewed once more.

As far as I know, the rules all work the same, so function-wise this is ready.

Ideally, this will be part of PMD 7.0.0.

Possible open tasks (to be checked):

  • We might need to delete the apex-jorje module and cleanup some (transitive) dependencies.
  • Update migration guide - for any differences in the AST structure
  • Update release notes

Related issues

Ready?

  • Added unit tests for fixed bug/feature
  • Passing all unit tests
  • Complete build ./mvnw clean verify passes (checked automatically by github actions)
  • Added (in-code) documentation (if needed)

eklimo and others added 30 commits August 11, 2022 11:10
- Remove Jorje dependencies
- Add temporary local jar dependency for Summit-AST
- Comment out code until compilation succeeds
Operators
- Create operator enums to wrap internal Jorje operators.
- Create getters returning new operator enums in operator-expression
  nodes. Deprecate old getters.
- Refactor metrics classes to use new operator enums.

Tests
- Remove references to internal Jorje nodes.
- Replace `ApexNode` type arguments with `Void`
- Remove `ApexNode.getNode`
- Remove `ASTCommentContainer` type parameter
- Deprecate `ASTUserClassOrInterface` type parameter
Remove `node` field from `AbstractApexNode` to remove restriction of
wrapping a single node. Create `AbstractApexNode.Single` subclass that
wraps a single node.

Other subclasses can be created as needed for common cases, or
`AbstractApexNode` can be extended directly in irregular cases.
- Add call to `SummitAST` in `ApexParser`
- Fix NPE involving `suppressMap` to allow `ApexTreeBuilder` to run
- Remove unused `TopLevelVisitor`
Replace `CompilationUnit` with `TypeDeclaration` as the top-level node
to match the AST produced by Jorje.
- Replace `ApexTreeBuilder.java` with `ApexTreeBuilder.kt`
- Set up tree builder foundation
- Build `TypeDeclaration` nodes
- Add `AbstractApexNode.Many`
- Add `buildChildren` function to tree builder
- Split `setParent` call from main `build` function into new
  `buildAndSetParent`
- Remove list-based `build` function to decrease complexity
- Improve documentation
- Remove Jorje dependencies
- Add Summit-AST dependency
- Comment out code until compilation succeeds
- Replace `ApexNode` type arguments with `Void`
- Remove `ApexNode.getNode`
- Remove `ASTCommentContainer` type parameter
- Deprecate `ASTUserClassOrInterface` type parameter
Remove `node` field from `AbstractApexNode` to remove restriction of
wrapping a single node. Create `AbstractApexNode.Single` subclass that
wraps a single node.

Other subclasses can be created as needed for common cases, or
`AbstractApexNode` can be extended directly in irregular cases.
- Add call to `SummitAST` in `ApexParser`
- Fix NPE involving `suppressMap` to allow `ApexTreeBuilder` to run
- Remove unused `TopLevelVisitor`
Replace `CompilationUnit` with `TypeDeclaration` as the top-level node
to match the AST produced by Jorje.
- Replace `ApexTreeBuilder.java` with `ApexTreeBuilder.kt`
- Set up tree builder foundation
- Build `TypeDeclaration` nodes
- Add `AbstractApexNode.Many`
- Add `buildChildren` function to tree builder
* Build expression statements
** Build assignment expressions
** Build array expressions
** Build literal expressions
** Build cast expressions
** Build operator expressions
** Build `this`/`super` expressions
** Build type reference expressions
** Build field/variable expressions
** Build method call expressions

* Build ternary expressions
* Refactor `AbstractApexNode`
** Add default implementations for some methods
** Add empty constructor
** Implement `AbstractApexNode.getDefiningType`

* Fix `ASTLiteralExpression.getImage`

* Implement reference types
** Implement `ASTReferenceExpression.isSObjectType`
** Implement `ASTReferenceExpression.hasRealLoc`
** Fix `ASTEmptyReferenceExpression.getDefiningType`

* Implement `ASTMethodCallExpression.getFullMethodName`

* Update `ASTLiteralExpression.getImage`

* Replace `Triple` with `data class`

* Fix `BITWISE_XOR`

* Replace `Identifier.asCodeString` with `getString`

* Fix call expressions
** Only the `receiver` of `CallExpression`s should be flattened

* Fix `referenceTypeOf`
Reference type should only be `STORE` when the variable is the target of
assignment.

* Rename `ASTMethodCallExpression.components`
… part-1

Change-Id: I254208dd5d1b9dbf5335a59a51372ec1d55f8535
Comment thread pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/AbstractApexNode.java Outdated
- keep CONSTRUCTOR_ID and STATIC_INIT_ID private
- update migration documentation
…IfPrimitive

These are helper methods to be used only inside the ast package.
- removed method getContext() - always returned null
  Fixes TODO(b/243906211)
- Verify that getReferenceType() returns the correct values
  Fixes TODO(b/239648780)
This was testing a deprecated XPath attribute,
but that attribute was already removed.
Update release notes/migration guide
@adangel adangel added this to the 7.0.0 milestone Feb 13, 2024
@adangel adangel merged commit 3a7b570 into master Feb 22, 2024
adangel added a commit that referenced this pull request Feb 22, 2024
[apex] Use apex-parser and Summit AST #4806
@adangel adangel deleted the experimental-apex-parser branch September 13, 2024 07:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[apex] Replace Jorje with fully open source front-end

4 participants