-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
8324651: Compiler Implementation for Derived Record Creation (Preview) #18509
Changes from 33 commits
588030c
5074587
4212f20
3e04899
a375020
01040f3
e4d0f3b
86e9268
309e629
a8d825d
e4d8aba
6bf29d1
c6806fe
cff0d11
ac0b968
cf80d76
96b4214
871e112
327ab53
969938a
a61682f
e1a6183
73752b9
baaf960
7b706ee
f89501e
910b295
409dc6d
f9b6c40
c91e87f
1465135
e093068
a05480c
16cd427
e8499df
c97eb8e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright (c) 2005, 2022, Oracle and/or its affiliates. All rights reserved. | ||
* Copyright (c) 2005, 2024, Oracle and/or its affiliates. All rights reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
|
@@ -25,6 +25,8 @@ | |
|
||
package javax.lang.model.element; | ||
|
||
import jdk.internal.javac.PreviewFeature; | ||
|
||
/** | ||
* The {@code kind} of an element. | ||
* | ||
|
@@ -121,7 +123,14 @@ public enum ElementKind { | |
* A binding variable in a pattern. | ||
* @since 16 | ||
*/ | ||
BINDING_VARIABLE; | ||
BINDING_VARIABLE, | ||
|
||
/** | ||
* A local component variable in a derived record creation expression. | ||
* @since 23 | ||
*/ | ||
@PreviewFeature(feature=PreviewFeature.Feature.DERIVED_RECORD_CREATION, reflective=true) | ||
COMPONENT_LOCAL_VARIABLE; | ||
|
||
// Maintenance note: check if the default implementation of | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From a quick look, I don't think Elements.getOutermostTypeElement needs updating for COMPONENT_LOCAL_VARIABLE, but it would be good to add a test case. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tests added: e093068 Thanks! |
||
// Elements.getOutermostTypeElement needs updating when new kind | ||
|
@@ -200,7 +209,8 @@ public boolean isInitializer() { | |
* Returns {@code true} if this is a kind of variable: including | ||
* {@code ENUM_CONSTANT}, {@code FIELD}, {@code PARAMETER}, | ||
* {@code LOCAL_VARIABLE}, {@code EXCEPTION_PARAMETER}, | ||
* {@code RESOURCE_VARIABLE}, and {@code BINDING_VARIABLE}. | ||
* {@code RESOURCE_VARIABLE}, {@code BINDING_VARIABLE}, and | ||
* {@code COMPONENT_LOCAL_VARIABLE}. | ||
* | ||
* @return {@code true} if this is a kind of variable | ||
* @since 19 | ||
|
@@ -209,7 +219,7 @@ public boolean isVariable() { | |
return switch(this) { | ||
case ENUM_CONSTANT, FIELD, PARAMETER, | ||
LOCAL_VARIABLE, EXCEPTION_PARAMETER, RESOURCE_VARIABLE, | ||
BINDING_VARIABLE -> true; | ||
BINDING_VARIABLE, COMPONENT_LOCAL_VARIABLE -> true; | ||
default -> false; | ||
}; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,4 +86,21 @@ protected ElementKindVisitorPreview() { | |
protected ElementKindVisitorPreview(R defaultValue) { | ||
super(defaultValue); | ||
} | ||
|
||
/** | ||
* {@inheritDoc ElementKindVisitor6} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If possible, would be good to add some minimal testing/use of the element kind visitors on component local variables. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tests added: e093068 Thanks! |
||
* | ||
* @implSpec This implementation calls {@code defaultAction}. | ||
* | ||
* @param e {@inheritDoc ElementKindVisitor6} | ||
* @param p {@inheritDoc ElementKindVisitor6} | ||
* @return the result of {@code defaultAction} | ||
* | ||
* @since 23 | ||
*/ | ||
@Override | ||
@PreviewFeature(feature=PreviewFeature.Feature.DERIVED_RECORD_CREATION, reflective=true) | ||
public R visitVariableAsComponentLocalVariable(VariableElement e, P p) { | ||
return defaultAction(e, p); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. Oracle designates this | ||
* particular file as subject to the "Classpath" exception as provided | ||
* by Oracle in the LICENSE file that accompanied this code. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
*/ | ||
|
||
package com.sun.source.tree; | ||
|
||
import jdk.internal.javac.PreviewFeature; | ||
|
||
/** | ||
* A tree node for a derived record creation expression. | ||
* | ||
* For example: | ||
* <pre> | ||
* <em>expression</em> with { <em>assignments</em> } | ||
* </pre> | ||
* | ||
* @jls 15.30 Derived Record Creation Expression | ||
* | ||
* @since 23 | ||
*/ | ||
@PreviewFeature(feature=PreviewFeature.Feature.DERIVED_RECORD_CREATION, reflective=true) | ||
public interface DerivedInstanceTree extends ExpressionTree { | ||
/** | ||
* {@return the origin expression of the derived record creation expression.} | ||
*/ | ||
ExpressionTree getExpression(); | ||
|
||
/** | ||
* {@return the reconstruction block.} | ||
*/ | ||
BlockTree getBlock(); | ||
} |
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.
I wonder if we can't just use: LOCAL_VARIABLE
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.
We could, and I was thinking of that. But, then I decided to go with a new kind, as I think it matches better the overall design of the Elements/Kinds. E.g. we have existing
EXCEPTION_PARAMETER
(used incatch
) orBINDING_VARIABLE
, rather than usingLOCAL_VARIABLE
for them.(Also, many of these variable kinds have some small, but significant differences in semantics from
LOCAL_VARIABLE
- e.g. some are never blank/are always definitely assigned.)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.
Given the JLS defines "component local variable" I think it makes sense to have a separate kind