Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DOM] NaiveASTFlattener should be sync with ASTFlattener of the JDT.UI #3268

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

subyssurendran666
Copy link
Contributor

@subyssurendran666 subyssurendran666 commented Nov 8, 2024

What it does

The unnamed variables and pattern's DOM and ASTRewrite implemented through #2623. Following items should be added along with that.

  • The Javadoc of both APIs i.e. TypePattern.getPatternVariable() and TypePattern.getPatternVariable2() is same and not clear regarding the difference.
  • The methods in JDT UI's ASTFlattener are kept in sync with NaiveASTFlattener(TypePattern). Hence, the change should be done in NaiveASTFlattener as well and then synced to ASTFlattener.

The Problem has reported here: eclipse-jdt/eclipse.jdt.ui#1764 (comment)

How to test

This PR closes #3261

Author checklist

@subyssurendran666
Copy link
Contributor Author

@mpalat could you please review this PR and share your insights on this ?

@mpalat
Copy link
Contributor

mpalat commented Nov 8, 2024

@mpalat could you please review this PR and share your insights on this ?

Will take a look. Meanwhile, please have a look and follow the process at https://github.com/eclipse-platform/eclipse.platform/blob/master/docs/Eclipse_API_Central_Deprecation_Policy.md when you are looking at deprecating APIs

@subyssurendran666 subyssurendran666 force-pushed the NaiveASTFlattener-should-be-sync-with-ASTFlattener-of-jdt-ui-3261 branch from 79aaaaf to 1de89f4 Compare November 12, 2024 09:39
@subyssurendran666 subyssurendran666 force-pushed the NaiveASTFlattener-should-be-sync-with-ASTFlattener-of-jdt-ui-3261 branch from 1de89f4 to 6c23547 Compare November 26, 2024 11:46
@mpalat mpalat added this to the 4.35 M1 milestone Nov 27, 2024
Copy link
Contributor

@mpalat mpalat left a comment

Choose a reason for hiding this comment

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

Suby,
Let us do some additional cleanup here - Refer to MethodDeclaration - modifiers and see how it got changed. Let us do a similar approach here.

@@ -2072,7 +2072,12 @@ public boolean visit(TypeParameter node) {
@Override
public boolean visit(TypePattern node) {
if (DOMASTUtil.isPatternSupported(node.getAST())) {
node.getPatternVariable().accept(this);
if (node.getAST().apiLevel() < AST.JLS22) {
node.getPatternVariable().accept(this);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should not use a deprecated API here

* @exception UnsupportedOperationException if this expression is used with previewEnabled flag as false
* @since 3.39
*/
public VariableDeclaration getPatternVariable2() {
supportedOnlyIn20();
supportedOnlyIn22();
Copy link
Contributor

Choose a reason for hiding this comment

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

Requesting for a cleanup here: Please change this name supportedOnlyIn22() to unSupportedBelow22()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe the supportedOnlyIn22 method can be handle the logic. Please see the method

final void supportedOnlyIn22() {
		if (this.ast.apiLevel < AST.JLS22_INTERNAL) {
			throw new UnsupportedOperationException("Operation only supported in JLS22 AST"); //$NON-NLS-1$
		}
	}

Therefore should I create a new method called unSupportedBelow22 ?

Copy link
Contributor

Choose a reason for hiding this comment

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

you can rename the current method if it's used only here

@@ -276,7 +277,11 @@ boolean subtreeMatch0(ASTMatcher matcher, Object other) {
ASTNode clone0(AST target) {
TypePattern result = new TypePattern(target);
result.setSourceRange(getStartPosition(), getLength());
result.setPatternVariable((VariableDeclaration) getPatternVariable().clone(target));
if (this.ast.apiLevel < AST.JLS22_INTERNAL) {
result.setPatternVariable((VariableDeclaration) getPatternVariable().clone(target));
Copy link
Contributor

Choose a reason for hiding this comment

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

Look at MethodDeclaration.clone0() - see how it has internalSetModifiers() method - this avoids deprecated warnings

if (this.ast.apiLevel < AST.JLS22_INTERNAL) {
result.setPatternVariable((VariableDeclaration) getPatternVariable().clone(target));
} else {
result.setPatternVariable((VariableDeclaration) getPatternVariable2().clone(target));
Copy link
Contributor

Choose a reason for hiding this comment

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

cleanup: refer to MethodDeclaration.modifiers - see how it got changed from int to List. Can we think of using a similar approach here

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.

[DOM] NaiveASTFlattener should be sync with ASTFlattener of the JDT.UI
2 participants