Skip to content

Commit

Permalink
Adding @SInCE, adding PreviewFeature, restoring API method.
Browse files Browse the repository at this point in the history
  • Loading branch information
lahodaj committed Oct 11, 2022
1 parent b00c64f commit cf530ca
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

package com.sun.source.tree;

import jdk.internal.javac.PreviewFeature;

/**
* A tree node for an "enhanced" {@code for} loop statement.
*
Expand All @@ -47,7 +49,10 @@ public interface EnhancedForLoopTree extends StatementTree {
* <li> local variable declarations and
* <li> record patterns
* </ul>
*
* @since 20
*/
@PreviewFeature(feature=PreviewFeature.Feature.RECORD_PATTERNS, reflective=true)
public enum DeclarationKind {
/** enum constant for local variable declarations */
VARDECL,
Expand All @@ -57,8 +62,16 @@ public enum DeclarationKind {

/**
* Returns the control variable for the loop.
* @return the control variable
* @return the control variable, or {@code null} if this enhanced for uses a pattern
*/
Tree getVariable();

/**
* Returns the control variable or pattern for the loop.
* @return the control variable or pattern
* @since 20
*/
@PreviewFeature(feature=PreviewFeature.Feature.RECORD_PATTERNS, reflective=true)
Tree getVariableOrRecordPattern();

/**
Expand All @@ -76,6 +89,8 @@ public enum DeclarationKind {
/**
* Returns the kind of the declaration of the enhanced for.
* @return the kind of the declaration
* @since 20
*/
EnhancedForLoopTree.DeclarationKind getDeclarationKind();
@PreviewFeature(feature=PreviewFeature.Feature.RECORD_PATTERNS, reflective=true)
DeclarationKind getDeclarationKind();
}
Original file line number Diff line number Diff line change
Expand Up @@ -1225,6 +1225,10 @@ protected JCEnhancedForLoop(JCTree varOrRecordPattern, JCExpression expr, JCStat
@DefinedBy(Api.COMPILER_TREE)
public Kind getKind() { return Kind.ENHANCED_FOR_LOOP; }
@DefinedBy(Api.COMPILER_TREE)
public JCVariableDecl getVariable() {
return varOrRecordPattern instanceof JCVariableDecl var ? var : null;
}
@DefinedBy(Api.COMPILER_TREE)
public JCTree getVariableOrRecordPattern() { return varOrRecordPattern; }
@DefinedBy(Api.COMPILER_TREE)
public JCExpression getExpression() { return expr; }
Expand Down

0 comments on commit cf530ca

Please sign in to comment.