GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [java] Align method and constructor declaration grammar by oowekyala · Pull Request #2034 · pmd/pmd

Conversation

@oowekyala

@oowekyala oowekyala commented Sep 27, 2019 •
edited by adangel
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

This fleshes out ASTMethodOrConstructorDeclaration to abstract what can be abstracted, and align their grammar more closely

Grammar changes

  • Merge ASTAnnotationMethodDeclaration into ASTMethodDeclaration. I don't see the point of having two separate nodes, the only API difference is that annotation methods may have a default value.
    • The removed node had no MethodDeclarator, or FormalParameters, which just introduced more nullability in the API
  • Add an ASTBlock as a child of ASTConstructorDeclaration -> was just inconsistent
  • Replace NameList with ThrowsList
  • Remove MethodDeclarator, former children are direct children of the method declaration. This node just introduced inconsistencies (ConstructorDeclaration didn't have it) and an unnecessary level of nesting.
  • Add many useful methods to ASTMethodOrConstructorDeclaration

API changes

  • Add JavaNode#getEnclosingType, ASTCompilationUnit#{getPackageName, getTypeDeclarations}
  • Rename ASTMethodDeclaration#getBlock to getBody, now shared by constructor declarations
  • Rename ASTConstructorDeclaration#getParameterCount to getArity, now shared by method declarations

Internal changes

  • Reimplement the name fetching routines of JavaRuleViolation so that they don't use the old symbol table anymore. That was completely unnecessary and the old symbol table is broken a bit more by this PR.

TODO on master

  • Deprecate AbstractJavaRule#getDeclaringType (replaced by JavaNode#getEnclosingType)
    • Backport JavaNode#getEnclosingType to master
    • AbstractJavaRule#getDeclaringType is useless, it only cares for class or interface types, it returns a simple string, even though the enclosing type may be anonymous...
    • The new method returns the node instead, and is available everywhere
    • -> a12afd1
  • 04e5619 Deprecate ASTMethodDeclaration#getMethodDeclarator - the methods "getFormalParameters()", "getMethodName()" should be used directly instead.
    • also add "getParameterCount()"/"getArity()" to ASTMethodDeclaration
    • introduce the new aliases for the other renamed methods on master and deprecate the old ones (like what was done for getFormalParameters)
      • ASTMethodDeclaration#getBlock -> getBody
      • ASTConstructorDeclaration#getParameterCount -> getArity

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
oowekyala added 18 commits August 15, 2019 16:46
@oowekyala
Merge branch 'java-grammar' into grammar-receiver
aca7c2e
@oowekyala
Remove MethodDeclarator, align constructor declaration and methodDecl…
4660e22
…aration

* Remove ASTConstructorDeclaration::getParameters -> use getFormalParameters
* Remove ASTConstructorDeclaration::getParameterCount -> use getArity
* Remove MethodDeclarator from MethodDeclaration grammar, deprecate node class
* Add an ASTBlock to ASTConstructorDeclaration grammar and
ASTMethodOrConstructorDeclaration::getBody
* Remove ASTMethodDeclaration::getBlock in favour of getBody
@oowekyala
Test for constructor
36ec136
@oowekyala
Add some doc
86ab494
@oowekyala
Fix tests
953e3a3
@oowekyala
Represent annotation methods directly with method declarations
8d50f35
@oowekyala
Document
8a5f4c4
@oowekyala
Fix rebase
af74c1f
@oowekyala
Fix class cast exceptions
198c621
@oowekyala
Cleanup
a2790fa
@oowekyala
Merge branch 'java-grammar-merged' into grammar-method-alignment
9efe40f
@oowekyala
Fix tests
6fb3d54
@oowekyala
Fix violation names
8a49114
Make JavaRuleViolation not depend on the old symbol table
@oowekyala
Checkstyle
9c90684
@oowekyala
Use throwslist instead of namelist
e3e0911
@oowekyala
Remove AbstractJavaRule#getDeclaringType
9eb1b35
@oowekyala
Test annotated throws list
4644eb1
@oowekyala
Test annotation methods
764f4a1
@oowekyala oowekyala added the in:ast About the AST structure or API, the parsing step label Sep 27, 2019
@oowekyala oowekyala added this to the 7.0.0 milestone Sep 27, 2019
@ghost

ghost commented Sep 27, 2019

Copy link
Copy Markdown
1 Message
📖 No java rules are changed!

Generated by 🚫 Danger

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@adangel
adangel self-requested a review September 30, 2019 17:50
adangel
adangel reviewed Sep 30, 2019
View reviewed changes

@adangel adangel left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to do the deprecations on master first?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread pmd-java/etc/grammar/Java.jjt Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTMethodDeclaration.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/JavaNode.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/AbstractJavaRule.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread pmd-java/src/main/java/net/sourceforge/pmd/lang/java/symboltable/MethodNameDeclaration.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

@adangel

adangel commented Oct 5, 2019

Copy link
Copy Markdown
Member

Maybe, introduce the new aliases for the other renamed methods on master and deprecate the
old ones (like what was done for getFormalParameters)

Which ones do you mean?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@oowekyala

oowekyala commented Oct 5, 2019

Copy link
Copy Markdown
Member Author

Which ones do you mean?

ASTMethodDeclaration#getBlock -> getBody
ASTConstructorDeclaration#getParameterCount -> getArity

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

oowekyala added a commit that referenced this pull request Oct 5, 2019
@oowekyala
Deprecations for #2034
04e5619
Also, replace deprecated method usages
oowekyala added 2 commits October 5, 2019 14:50
@oowekyala
Merge branch 'java-grammar' into grammar-method-alignment
a62ecf0
@oowekyala
Merge branch 'java-grammar' into grammar-method-alignment
3c31b2d
@oowekyala oowekyala mentioned this pull request Oct 6, 2019
[java] Symbol reference framework #1566
Merged
@oowekyala
oowekyala merged commit 3c31b2d into pmd:java-grammar Oct 7, 2019
@oowekyala
oowekyala deleted the grammar-method-alignment branch October 7, 2019 14:50
@adangel adangel mentioned this pull request Oct 13, 2019
[java] Deprecate AbstractJavaRule#getDeclaringType(Node) #2066
Merged
adangel added a commit to adangel/pmd that referenced this pull request Oct 26, 2019
@adangel
[java] Deprecate AbstractJavaRule#getDeclaringType(Node)
752e5f8
Refs pmd#2034
@adangel adangel mentioned this pull request Jan 23, 2023
PMD 7 Tracking Issue #3898
Closed
55 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@adangel adangel adangel left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

in:ast About the AST structure or API, the parsing step

Projects

None yet

Milestone

7.0.0

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@oowekyala @adangel
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.