-
CSR
-
Resolution: Approved
-
P4
-
None
-
source
-
minimal
-
Java API
Summary
The javax.lang.model.element.ElementKind models various local variables, but, with the recent addition of binding variables (for pattern matching), a new ElementKind was not added. The proposal here is to add a new ElementKind for binding variables.
Problem
Various types of variables local to methods have their own enum constant in ElementKind, but binding variables don't.
Solution
A new enum constant, BINDING_VARIABLE, is added into the ElementKind.
Specification
diff --git a/src/java.compiler/share/classes/javax/lang/model/element/ElementKind.java b/src/java.compiler/share/classes/javax/lang/model/element/ElementKind.java
--- a/src/java.compiler/share/classes/javax/lang/model/element/ElementKind.java
+++ b/src/java.compiler/share/classes/javax/lang/model/element/ElementKind.java
@@ -137,7 +137,24 @@
*/
@jdk.internal.PreviewFeature(feature=jdk.internal.PreviewFeature.Feature.RECORDS,
essentialAPI=false)
- RECORD_COMPONENT;
+ RECORD_COMPONENT,
+
+ /**
+ * {@preview Associated with pattern matching for {@code
+ * instanceof}, a preview feature of the Java language.
+ *
+ * This enum constant is associated with <i>pattern
+ * matching for {@code instanceof}</i>, a preview
+ * feature of the Java language. Preview features
+ * may be removed in a future release, or upgraded to permanent
+ * features of the Java language.}
+ *
+ * A binding variable in a pattern .
+ * @since 14
+ */
+ @jdk.internal.PreviewFeature(feature=jdk.internal.PreviewFeature.Feature.PATTERN_MATCHING_IN_INSTANCEOF,
+ essentialAPI=false)
+ BINDING_VARIABLE;
/**
* Returns {@code true} if this is a kind of class:
diff --git a/src/java.compiler/share/classes/javax/lang/model/util/ElementKindVisitor14.java b/src/java.compiler/share/classes/javax/lang/model/util/ElementKindVisitor14.java
--- a/src/java.compiler/share/classes/javax/lang/model/util/ElementKindVisitor14.java
+++ b/src/java.compiler/share/classes/javax/lang/model/util/ElementKindVisitor14.java
@@ -136,4 +136,20 @@
public R visitTypeAsRecord(TypeElement e, P p) {
return defaultAction(e, p);
}
+
+ /**
+ * Visits a {@code BINDING_VARIABLE} variable element.
+ *
+ * @implSpec This implementation calls {@code defaultAction}.
+ *
+ * @param e {@inheritDoc}
+ * @param p {@inheritDoc}
+ * @return the result of {@code defaultAction}
+ *
+ * @since 14
+ */
+ @Override
+ public R visitVariableAsBindingVariable(VariableElement e, P p) {
+ return defaultAction(e, p);
+ }
}
diff --git a/src/java.compiler/share/classes/javax/lang/model/util/ElementKindVisitor6.java b/src/java.compiler/share/classes/javax/lang/model/util/ElementKindVisitor6.java
--- a/src/java.compiler/share/classes/javax/lang/model/util/ElementKindVisitor6.java
+++ b/src/java.compiler/share/classes/javax/lang/model/util/ElementKindVisitor6.java
@@ -360,6 +363,21 @@
}
/**
+ * Visits a {@code BINDING_VARIABLE} variable element.
+ *
+ * @implSpec This implementation calls {@code visitUnknown}.
+ *
+ * @param e the element to visit
+ * @param p a visitor-specified parameter
+ * @return the result of {@code visitUnknown}
+ *
+ * @since 14
+ */
+ public R visitVariableAsBindingVariable(VariableElement e, P p) {
+ return visitUnknown(e, p);
+ }
+
+ /**
* {@inheritDoc}
*
* @implSpec This implementation dispatches to the visit method
A specdiff is also attached, and also available at the following location for convenience: http://cr.openjdk.java.net/~jlahoda/8235541/specdiff.00/overview-summary.html
- csr of
-
JDK-8235541 Extend javax.lang.model to cover binding variables
- Resolved