Skip to content

Commit 18bc95b

Browse files
committed
8250625: Compiler implementation of Pattern Matching for instanceof (Final)
Reviewed-by: vromero
1 parent 60e4aca commit 18bc95b

File tree

86 files changed

+231
-313
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+231
-313
lines changed

src/java.base/share/classes/jdk/internal/PreviewFeature.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
public boolean essentialAPI() default false;
5555

5656
public enum Feature {
57-
PATTERN_MATCHING_IN_INSTANCEOF,
5857
// 8242284:
5958
// The TEXT_BLOCKS enum constant is not used in the JDK 15 codebase, but
6059
// exists to support the bootcycle build of JDK 15. The bootcycle build

src/java.compiler/share/classes/javax/lang/model/element/ElementKind.java

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -121,20 +121,9 @@ public enum ElementKind {
121121
RECORD_COMPONENT,
122122

123123
/**
124-
* {@preview Associated with pattern matching for {@code
125-
* instanceof}, a preview feature of the Java language.
126-
*
127-
* This enum constant is associated with <i>pattern
128-
* matching for {@code instanceof}</i>, a preview
129-
* feature of the Java language. Preview features
130-
* may be removed in a future release, or upgraded to permanent
131-
* features of the Java language.}
132-
*
133-
* A binding variable in a pattern .
134-
* @since 14
124+
* A binding variable in a pattern.
125+
* @since 16
135126
*/
136-
@jdk.internal.PreviewFeature(feature=jdk.internal.PreviewFeature.Feature.PATTERN_MATCHING_IN_INSTANCEOF,
137-
essentialAPI=false)
138127
BINDING_VARIABLE;
139128

140129
/**

src/jdk.compiler/share/classes/com/sun/source/tree/BindingPatternTree.java

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,34 +25,17 @@
2525

2626
package com.sun.source.tree;
2727

28-
import javax.lang.model.element.Name;
29-
3028
/**
31-
* {@preview Associated with pattern matching for instanceof, a preview feature of
32-
* the Java language.
33-
*
34-
* This interface is associated with <i>pattern matching for instanceof</i>, a preview
35-
* feature of the Java language. Preview features
36-
* may be removed in a future release, or upgraded to permanent
37-
* features of the Java language.}
38-
*
3929
* A binding pattern tree
4030
*
41-
* @since 14
31+
* @since 16
4232
*/
4333
public interface BindingPatternTree extends PatternTree {
4434

4535
/**
46-
* Returns the type of the bind variable.
47-
* @return the type
36+
* Returns the binding variable.
37+
* @return the binding variable
4838
*/
49-
Tree getType();
50-
51-
/**
52-
* A binding variable name.
53-
* @return the name of the binding variable
54-
*/
55-
Name getBinding();
39+
VariableTree getVariable();
5640

5741
}
58-

src/jdk.compiler/share/classes/com/sun/source/tree/InstanceOfTree.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,11 @@ public interface InstanceOfTree extends ExpressionTree {
4949
/**
5050
* Returns the type for which to check.
5151
* @return the type
52+
* @see #getPattern()
5253
*/
5354
Tree getType();
5455

5556
/**
56-
* {@preview Associated with pattern matching for instanceof, a preview feature of
57-
* the Java language.
58-
*
59-
* This method is associated with <i>pattern matching for instanceof</i>, a preview
60-
* feature of the Java language. Preview features
61-
* may be removed in a future release, or upgraded to permanent
62-
* features of the Java language.}
63-
*
6457
* Returns the tested pattern, or null if this instanceof does not use
6558
* a pattern.
6659
*
@@ -77,7 +70,7 @@ public interface InstanceOfTree extends ExpressionTree {
7770
* returns null.
7871
*
7972
* @return the tested pattern, or null if this instanceof does not use a pattern
80-
* @since 14
73+
* @since 16
8174
*/
8275
PatternTree getPattern();
8376
}

src/jdk.compiler/share/classes/com/sun/source/tree/PatternTree.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,9 @@
2626
package com.sun.source.tree;
2727

2828
/**
29-
* {@preview Associated with pattern matching for instanceof, a preview feature of
30-
* the Java language.
31-
*
32-
* This interface is associated with <i>pattern matching for instanceof</i>, a preview
33-
* feature of the Java language. Preview features
34-
* may be removed in a future release, or upgraded to permanent
35-
* features of the Java language.}
36-
*
3729
* A tree node used as the base class for the different kinds of
38-
* statements.
30+
* patterns.
3931
*
40-
* @since 14
32+
* @since 16
4133
*/
4234
public interface PatternTree extends Tree {}

src/jdk.compiler/share/classes/com/sun/source/tree/Tree.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -220,17 +220,9 @@ public enum Kind {
220220
PARENTHESIZED(ParenthesizedTree.class),
221221

222222
/**
223-
* {@preview Associated with pattern matching for instanceof, a preview feature of
224-
* the Java language.
225-
*
226-
* This enum constant is associated with <i>pattern matching for instanceof</i>, a preview
227-
* feature of the Java language. Preview features
228-
* may be removed in a future release, or upgraded to permanent
229-
* features of the Java language.}
230-
*
231223
* Used for instances of {@link BindingPatternTree}.
232224
*
233-
* @since 14
225+
* @since 16
234226
*/
235227
BINDING_PATTERN(BindingPatternTree.class),
236228

src/jdk.compiler/share/classes/com/sun/source/tree/TreeVisitor.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -258,19 +258,11 @@ public interface TreeVisitor<R,P> {
258258
R visitLiteral(LiteralTree node, P p);
259259

260260
/**
261-
* {@preview Associated with pattern matching for instanceof, a preview feature of
262-
* the Java language.
263-
*
264-
* This method is associated with <i>pattern matching for instanceof</i>, a preview
265-
* feature of the Java language. Preview features
266-
* may be removed in a future release, or upgraded to permanent
267-
* features of the Java language.}
268-
*
269261
* Visits an BindingPattern node.
270262
* @param node the node being visited
271263
* @param p a parameter value
272264
* @return a result value
273-
* @since 14
265+
* @since 16
274266
*/
275267
R visitBindingPattern(BindingPatternTree node, P p);
276268

src/jdk.compiler/share/classes/com/sun/source/util/TreeScanner.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ public R visitInstanceOf(InstanceOfTree node, P p) {
691691
*/
692692
@Override
693693
public R visitBindingPattern(BindingPatternTree node, P p) {
694-
return scan(node.getType(), p);
694+
return scan(node.getVariable(), p);
695695
}
696696

697697
/**

src/jdk.compiler/share/classes/com/sun/tools/javac/code/Preview.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,7 @@ public boolean isEnabled() {
165165
* @return true, if given feature is a preview feature.
166166
*/
167167
public boolean isPreview(Feature feature) {
168-
if (feature == Feature.PATTERN_MATCHING_IN_INSTANCEOF ||
169-
feature == Feature.REIFIABLE_TYPES_INSTANCEOF ||
170-
feature == Feature.SEALED_CLASSES)
168+
if (feature == Feature.SEALED_CLASSES)
171169
return true;
172170
//Note: this is a backdoor which allows to optionally treat all features as 'preview' (for testing).
173171
//When real preview features will be added, this method can be implemented to return 'true'

src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symbol.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1855,7 +1855,7 @@ public Name getSimpleName() {
18551855
public static class BindingSymbol extends VarSymbol {
18561856

18571857
public BindingSymbol(Name name, Type type, Symbol owner) {
1858-
super(Flags.FINAL | Flags.HASINIT | Flags.MATCH_BINDING, name, type, owner);
1858+
super(Flags.HASINIT | Flags.MATCH_BINDING, name, type, owner);
18591859
}
18601860

18611861
public boolean isAliasFor(BindingSymbol b) {

0 commit comments

Comments
 (0)