From f8c56a59e56780f8ff1ad924bcd0d40be5d65d68 Mon Sep 17 00:00:00 2001 From: Jordan Kiesel Date: Wed, 1 May 2024 00:58:58 -0600 Subject: [PATCH] fix: align with JDK 22 spec --- packages/java-parser/api.d.ts | 284 ++++++++++-------- .../java-parser/src/productions/arrays.js | 4 +- .../src/productions/blocks-and-statements.js | 118 ++++---- .../java-parser/src/productions/classes.js | 142 ++++----- .../src/productions/expressions.js | 89 ++++-- .../java-parser/src/productions/interfaces.js | 83 +++-- .../src/productions/lexical-structure.js | 8 +- packages/java-parser/src/productions/names.js | 14 +- .../src/productions/packages-and-modules.js | 26 +- .../productions/types-values-and-variables.js | 39 +-- .../unnamed-variables-and-patterns-spec.js | 16 + packages/prettier-plugin-java/src/options.js | 32 +- .../src/printers/blocks-and-statements.ts | 23 +- .../src/printers/classes.ts | 42 +-- .../src/printers/expressions.ts | 62 ++-- .../src/printers/interfaces.ts | 59 ++-- .../src/printers/printer-utils.ts | 2 +- .../_input.java | 2 +- .../_output.java | 2 +- .../annotation_interface_declaration-spec.ts} | 0 .../_input.java | 2 +- .../_output.java | 2 +- 22 files changed, 575 insertions(+), 476 deletions(-) rename packages/prettier-plugin-java/test/unit-test/{annotation_type_declaration => annotation_interface_declaration}/_input.java (90%) rename packages/prettier-plugin-java/test/unit-test/{annotation_type_declaration => annotation_interface_declaration}/_output.java (91%) rename packages/prettier-plugin-java/test/unit-test/{annotation_type_declaration/annotation_type_declaration-spec.ts => annotation_interface_declaration/annotation_interface_declaration-spec.ts} (100%) diff --git a/packages/java-parser/api.d.ts b/packages/java-parser/api.d.ts index c1c3f35b..ac035a8d 100644 --- a/packages/java-parser/api.d.ts +++ b/packages/java-parser/api.d.ts @@ -1,8 +1,8 @@ import { CstNode as ChevrotainCstNode, + IToken as ChevrotainIToken, CstNodeLocation, - ICstVisitor, - IToken as ChevrotainIToken + ICstVisitor } from "chevrotain"; export interface CstNode extends ChevrotainCstNode { @@ -88,8 +88,8 @@ export abstract class JavaCstVisitor implements ICstVisitor { classModifier(ctx: ClassModifierCtx, param?: IN): OUT; typeParameters(ctx: TypeParametersCtx, param?: IN): OUT; typeParameterList(ctx: TypeParameterListCtx, param?: IN): OUT; - superclass(ctx: SuperclassCtx, param?: IN): OUT; - superinterfaces(ctx: SuperinterfacesCtx, param?: IN): OUT; + classExtends(ctx: ClassExtendsCtx, param?: IN): OUT; + classImplements(ctx: ClassImplementsCtx, param?: IN): OUT; interfaceTypeList(ctx: InterfaceTypeListCtx, param?: IN): OUT; classPermits(ctx: ClassPermitsCtx, param?: IN): OUT; classBody(ctx: ClassBodyCtx, param?: IN): OUT; @@ -192,7 +192,7 @@ export abstract class JavaCstVisitor implements ICstVisitor { param?: IN ): OUT; interfaceModifier(ctx: InterfaceModifierCtx, param?: IN): OUT; - extendsInterfaces(ctx: ExtendsInterfacesCtx, param?: IN): OUT; + interfaceExtends(ctx: InterfaceExtendsCtx, param?: IN): OUT; interfacePermits(ctx: InterfacePermitsCtx, param?: IN): OUT; interfaceBody(ctx: InterfaceBodyCtx, param?: IN): OUT; interfaceMemberDeclaration( @@ -206,18 +206,21 @@ export abstract class JavaCstVisitor implements ICstVisitor { param?: IN ): OUT; interfaceMethodModifier(ctx: InterfaceMethodModifierCtx, param?: IN): OUT; - annotationTypeDeclaration(ctx: AnnotationTypeDeclarationCtx, param?: IN): OUT; - annotationTypeBody(ctx: AnnotationTypeBodyCtx, param?: IN): OUT; - annotationTypeMemberDeclaration( - ctx: AnnotationTypeMemberDeclarationCtx, + annotationInterfaceDeclaration( + ctx: AnnotationInterfaceDeclarationCtx, param?: IN ): OUT; - annotationTypeElementDeclaration( - ctx: AnnotationTypeElementDeclarationCtx, + annotationInterfaceBody(ctx: AnnotationInterfaceBodyCtx, param?: IN): OUT; + annotationInterfaceMemberDeclaration( + ctx: AnnotationInterfaceMemberDeclarationCtx, param?: IN ): OUT; - annotationTypeElementModifier( - ctx: AnnotationTypeElementModifierCtx, + annotationInterfaceElementDeclaration( + ctx: AnnotationInterfaceElementDeclarationCtx, + param?: IN + ): OUT; + annotationInterfaceElementModifier( + ctx: AnnotationInterfaceElementModifierCtx, param?: IN ): OUT; defaultValue(ctx: DefaultValueCtx, param?: IN): OUT; @@ -258,6 +261,7 @@ export abstract class JavaCstVisitor implements ICstVisitor { switchLabel(ctx: SwitchLabelCtx, param?: IN): OUT; switchRule(ctx: SwitchRuleCtx, param?: IN): OUT; caseConstant(ctx: CaseConstantCtx, param?: IN): OUT; + casePattern(ctx: CasePatternCtx, param?: IN): OUT; whileStatement(ctx: WhileStatementCtx, param?: IN): OUT; doStatement(ctx: DoStatementCtx, param?: IN): OUT; forStatement(ctx: ForStatementCtx, param?: IN): OUT; @@ -291,19 +295,17 @@ export abstract class JavaCstVisitor implements ICstVisitor { param?: IN ): OUT; lambdaParameterList(ctx: LambdaParameterListCtx, param?: IN): OUT; - inferredLambdaParameterList( - ctx: InferredLambdaParameterListCtx, - param?: IN - ): OUT; - explicitLambdaParameterList( - ctx: ExplicitLambdaParameterListCtx, + conciseLambdaParameterList( + ctx: ConciseLambdaParameterListCtx, param?: IN ): OUT; - lambdaParameter(ctx: LambdaParameterCtx, param?: IN): OUT; + normalLambdaParameterList(ctx: NormalLambdaParameterListCtx, param?: IN): OUT; + normalLambdaParameter(ctx: LambdaParameterCtx, param?: IN): OUT; regularLambdaParameter(ctx: RegularLambdaParameterCtx, param?: IN): OUT; lambdaParameterType(ctx: LambdaParameterTypeCtx, param?: IN): OUT; + conciseLambdaParameter(ctx: ConciseLambdaParameterCtx, param?: IN): OUT; lambdaBody(ctx: LambdaBodyCtx, param?: IN): OUT; - ternaryExpression(ctx: TernaryExpressionCtx, param?: IN): OUT; + conditionalExpression(ctx: ConditionalExpressionCtx, param?: IN): OUT; binaryExpression(ctx: BinaryExpressionCtx, param?: IN): OUT; unaryExpression(ctx: UnaryExpressionCtx, param?: IN): OUT; unaryExpressionNotPlusMinus( @@ -338,12 +340,12 @@ export abstract class JavaCstVisitor implements ICstVisitor { methodInvocationSuffix(ctx: MethodInvocationSuffixCtx, param?: IN): OUT; argumentList(ctx: ArgumentListCtx, param?: IN): OUT; arrayCreationExpression(ctx: ArrayCreationExpressionCtx, param?: IN): OUT; - arrayCreationDefaultInitSuffix( - ctx: ArrayCreationDefaultInitSuffixCtx, + arrayCreationExpressionWithoutInitializerSuffix( + ctx: ArrayCreationExpressionWithoutInitializerSuffixCtx, param?: IN ): OUT; - arrayCreationExplicitInitSuffix( - ctx: ArrayCreationExplicitInitSuffixCtx, + arrayCreationWithInitializerSuffix( + ctx: ArrayCreationWithInitializerSuffixCtx, param?: IN ): OUT; dimExprs(ctx: DimExprsCtx, param?: IN): OUT; @@ -361,7 +363,7 @@ export abstract class JavaCstVisitor implements ICstVisitor { recordPattern(ctx: RecordPatternCtx, param?: IN): OUT; componentPatternList(ctx: ComponentPatternListCtx, param?: IN): OUT; componentPattern(ctx: ComponentPatternCtx, param?: IN): OUT; - unnamedPattern(ctx: UnnamedPatternCtx, param?: IN): OUT; + matchAllPattern(ctx: MatchAllPatternCtx, param?: IN): OUT; guard(ctx: GuardCtx, param?: IN): OUT; isRefTypeInMethodRef(ctx: IsRefTypeInMethodRefCtx, param?: IN): OUT; } @@ -414,8 +416,8 @@ export abstract class JavaCstVisitorWithDefaults classModifier(ctx: ClassModifierCtx, param?: IN): OUT; typeParameters(ctx: TypeParametersCtx, param?: IN): OUT; typeParameterList(ctx: TypeParameterListCtx, param?: IN): OUT; - superclass(ctx: SuperclassCtx, param?: IN): OUT; - superinterfaces(ctx: SuperinterfacesCtx, param?: IN): OUT; + classExtends(ctx: ClassExtendsCtx, param?: IN): OUT; + classImplements(ctx: ClassImplementsCtx, param?: IN): OUT; interfaceTypeList(ctx: InterfaceTypeListCtx, param?: IN): OUT; classPermits(ctx: ClassPermitsCtx, param?: IN): OUT; classBody(ctx: ClassBodyCtx, param?: IN): OUT; @@ -518,7 +520,7 @@ export abstract class JavaCstVisitorWithDefaults param?: IN ): OUT; interfaceModifier(ctx: InterfaceModifierCtx, param?: IN): OUT; - extendsInterfaces(ctx: ExtendsInterfacesCtx, param?: IN): OUT; + interfaceExtends(ctx: InterfaceExtendsCtx, param?: IN): OUT; interfacePermits(ctx: InterfacePermitsCtx, param?: IN): OUT; interfaceBody(ctx: InterfaceBodyCtx, param?: IN): OUT; interfaceMemberDeclaration( @@ -532,18 +534,21 @@ export abstract class JavaCstVisitorWithDefaults param?: IN ): OUT; interfaceMethodModifier(ctx: InterfaceMethodModifierCtx, param?: IN): OUT; - annotationTypeDeclaration(ctx: AnnotationTypeDeclarationCtx, param?: IN): OUT; - annotationTypeBody(ctx: AnnotationTypeBodyCtx, param?: IN): OUT; - annotationTypeMemberDeclaration( - ctx: AnnotationTypeMemberDeclarationCtx, + annotationInterfaceDeclaration( + ctx: AnnotationInterfaceDeclarationCtx, param?: IN ): OUT; - annotationTypeElementDeclaration( - ctx: AnnotationTypeElementDeclarationCtx, + annotationInterfaceBody(ctx: AnnotationInterfaceBodyCtx, param?: IN): OUT; + annotationInterfaceMemberDeclaration( + ctx: AnnotationInterfaceMemberDeclarationCtx, param?: IN ): OUT; - annotationTypeElementModifier( - ctx: AnnotationTypeElementModifierCtx, + annotationInterfaceElementDeclaration( + ctx: AnnotationInterfaceElementDeclarationCtx, + param?: IN + ): OUT; + annotationInterfaceElementModifier( + ctx: AnnotationInterfaceElementModifierCtx, param?: IN ): OUT; defaultValue(ctx: DefaultValueCtx, param?: IN): OUT; @@ -584,6 +589,7 @@ export abstract class JavaCstVisitorWithDefaults switchLabel(ctx: SwitchLabelCtx, param?: IN): OUT; switchRule(ctx: SwitchRuleCtx, param?: IN): OUT; caseConstant(ctx: CaseConstantCtx, param?: IN): OUT; + casePattern(ctx: CasePatternCtx, param?: IN): OUT; whileStatement(ctx: WhileStatementCtx, param?: IN): OUT; doStatement(ctx: DoStatementCtx, param?: IN): OUT; forStatement(ctx: ForStatementCtx, param?: IN): OUT; @@ -617,19 +623,17 @@ export abstract class JavaCstVisitorWithDefaults param?: IN ): OUT; lambdaParameterList(ctx: LambdaParameterListCtx, param?: IN): OUT; - inferredLambdaParameterList( - ctx: InferredLambdaParameterListCtx, + conciseLambdaParameterList( + ctx: ConciseLambdaParameterListCtx, param?: IN ): OUT; - explicitLambdaParameterList( - ctx: ExplicitLambdaParameterListCtx, - param?: IN - ): OUT; - lambdaParameter(ctx: LambdaParameterCtx, param?: IN): OUT; + normalLambdaParameterList(ctx: NormalLambdaParameterListCtx, param?: IN): OUT; + normalLambdaParameter(ctx: LambdaParameterCtx, param?: IN): OUT; regularLambdaParameter(ctx: RegularLambdaParameterCtx, param?: IN): OUT; lambdaParameterType(ctx: LambdaParameterTypeCtx, param?: IN): OUT; + conciseLambdaParameter(ctx: ConciseLambdaParameterCtx, param?: IN): OUT; lambdaBody(ctx: LambdaBodyCtx, param?: IN): OUT; - ternaryExpression(ctx: TernaryExpressionCtx, param?: IN): OUT; + conditionalExpression(ctx: ConditionalExpressionCtx, param?: IN): OUT; binaryExpression(ctx: BinaryExpressionCtx, param?: IN): OUT; unaryExpression(ctx: UnaryExpressionCtx, param?: IN): OUT; unaryExpressionNotPlusMinus( @@ -664,12 +668,12 @@ export abstract class JavaCstVisitorWithDefaults methodInvocationSuffix(ctx: MethodInvocationSuffixCtx, param?: IN): OUT; argumentList(ctx: ArgumentListCtx, param?: IN): OUT; arrayCreationExpression(ctx: ArrayCreationExpressionCtx, param?: IN): OUT; - arrayCreationDefaultInitSuffix( - ctx: ArrayCreationDefaultInitSuffixCtx, + arrayCreationExpressionWithoutInitializerSuffix( + ctx: ArrayCreationExpressionWithoutInitializerSuffixCtx, param?: IN ): OUT; - arrayCreationExplicitInitSuffix( - ctx: ArrayCreationExplicitInitSuffixCtx, + arrayCreationWithInitializerSuffix( + ctx: ArrayCreationWithInitializerSuffixCtx, param?: IN ): OUT; dimExprs(ctx: DimExprsCtx, param?: IN): OUT; @@ -687,7 +691,7 @@ export abstract class JavaCstVisitorWithDefaults recordPattern(ctx: RecordPatternCtx, param?: IN): OUT; componentPatternList(ctx: ComponentPatternListCtx, param?: IN): OUT; componentPattern(ctx: ComponentPatternCtx, param?: IN): OUT; - unnamedPattern(ctx: UnnamedPatternCtx, param?: IN): OUT; + matchAllPattern(ctx: MatchAllPatternCtx, param?: IN): OUT; guard(ctx: GuardCtx, param?: IN): OUT; isRefTypeInMethodRef(ctx: IsRefTypeInMethodRefCtx, param?: IN): OUT; } @@ -1042,8 +1046,8 @@ export type NormalClassDeclarationCtx = { Class: IToken[]; typeIdentifier: TypeIdentifierCstNode[]; typeParameters?: TypeParametersCstNode[]; - superclass?: SuperclassCstNode[]; - superinterfaces?: SuperinterfacesCstNode[]; + classExtends?: ClassExtendsCstNode[]; + classImplements?: ClassImplementsCstNode[]; classPermits?: ClassPermitsCstNode[]; classBody: ClassBodyCstNode[]; }; @@ -1087,22 +1091,22 @@ export type TypeParameterListCtx = { Comma?: IToken[]; }; -export interface SuperclassCstNode extends CstNode { - name: "superclass"; - children: SuperclassCtx; +export interface ClassExtendsCstNode extends CstNode { + name: "classExtends"; + children: ClassExtendsCtx; } -export type SuperclassCtx = { +export type ClassExtendsCtx = { Extends: IToken[]; classType: ClassTypeCstNode[]; }; -export interface SuperinterfacesCstNode extends CstNode { - name: "superinterfaces"; - children: SuperinterfacesCtx; +export interface ClassImplementsCstNode extends CstNode { + name: "classImplements"; + children: ClassImplementsCtx; } -export type SuperinterfacesCtx = { +export type ClassImplementsCtx = { Implements: IToken[]; interfaceTypeList: InterfaceTypeListCstNode[]; }; @@ -1551,7 +1555,7 @@ export interface SimpleTypeNameCstNode extends CstNode { } export type SimpleTypeNameCtx = { - Identifier: IToken[]; + TypeIdentifier: TypeIdentifierCstNode[]; }; export interface ConstructorBodyCstNode extends CstNode { @@ -1617,7 +1621,7 @@ export type EnumDeclarationCtx = { classModifier?: ClassModifierCstNode[]; Enum: IToken[]; typeIdentifier: TypeIdentifierCstNode[]; - superinterfaces?: SuperinterfacesCstNode[]; + classImplements?: ClassImplementsCstNode[]; enumBody: EnumBodyCstNode[]; }; @@ -1687,7 +1691,7 @@ export type RecordDeclarationCtx = { typeIdentifier: TypeIdentifierCstNode[]; typeParameters?: TypeParametersCstNode[]; recordHeader: RecordHeaderCstNode[]; - superinterfaces?: SuperinterfacesCstNode[]; + classImplements?: ClassImplementsCstNode[]; recordBody: RecordBodyCstNode[]; }; @@ -1991,7 +1995,7 @@ export interface InterfaceDeclarationCstNode extends CstNode { export type InterfaceDeclarationCtx = { interfaceModifier?: InterfaceModifierCstNode[]; normalInterfaceDeclaration?: NormalInterfaceDeclarationCstNode[]; - annotationTypeDeclaration?: AnnotationTypeDeclarationCstNode[]; + annotationInterfaceDeclaration?: AnnotationInterfaceDeclarationCstNode[]; }; export interface NormalInterfaceDeclarationCstNode extends CstNode { @@ -2003,7 +2007,7 @@ export type NormalInterfaceDeclarationCtx = { Interface: IToken[]; typeIdentifier: TypeIdentifierCstNode[]; typeParameters?: TypeParametersCstNode[]; - extendsInterfaces?: ExtendsInterfacesCstNode[]; + interfaceExtends?: InterfaceExtendsCstNode[]; interfacePermits?: InterfacePermitsCstNode[]; interfaceBody: InterfaceBodyCstNode[]; }; @@ -2025,12 +2029,12 @@ export type InterfaceModifierCtx = { Strictfp?: IToken[]; }; -export interface ExtendsInterfacesCstNode extends CstNode { - name: "extendsInterfaces"; - children: ExtendsInterfacesCtx; +export interface InterfaceExtendsCstNode extends CstNode { + name: "interfaceExtends"; + children: InterfaceExtendsCtx; } -export type ExtendsInterfacesCtx = { +export type InterfaceExtendsCtx = { Extends: IToken[]; interfaceTypeList: InterfaceTypeListCstNode[]; }; @@ -2120,49 +2124,49 @@ export type InterfaceMethodModifierCtx = { Strictfp?: IToken[]; }; -export interface AnnotationTypeDeclarationCstNode extends CstNode { - name: "annotationTypeDeclaration"; - children: AnnotationTypeDeclarationCtx; +export interface AnnotationInterfaceDeclarationCstNode extends CstNode { + name: "annotationInterfaceDeclaration"; + children: AnnotationInterfaceDeclarationCtx; } -export type AnnotationTypeDeclarationCtx = { +export type AnnotationInterfaceDeclarationCtx = { At: IToken[]; Interface: IToken[]; typeIdentifier: TypeIdentifierCstNode[]; - annotationTypeBody: AnnotationTypeBodyCstNode[]; + annotationInterfaceBody: AnnotationInterfaceBodyCstNode[]; }; -export interface AnnotationTypeBodyCstNode extends CstNode { - name: "annotationTypeBody"; - children: AnnotationTypeBodyCtx; +export interface AnnotationInterfaceBodyCstNode extends CstNode { + name: "annotationInterfaceBody"; + children: AnnotationInterfaceBodyCtx; } -export type AnnotationTypeBodyCtx = { +export type AnnotationInterfaceBodyCtx = { LCurly: IToken[]; - annotationTypeMemberDeclaration?: AnnotationTypeMemberDeclarationCstNode[]; + annotationInterfaceMemberDeclaration?: AnnotationInterfaceMemberDeclarationCstNode[]; RCurly: IToken[]; }; -export interface AnnotationTypeMemberDeclarationCstNode extends CstNode { - name: "annotationTypeMemberDeclaration"; - children: AnnotationTypeMemberDeclarationCtx; +export interface AnnotationInterfaceMemberDeclarationCstNode extends CstNode { + name: "annotationInterfaceMemberDeclaration"; + children: AnnotationInterfaceMemberDeclarationCtx; } -export type AnnotationTypeMemberDeclarationCtx = { - annotationTypeElementDeclaration?: AnnotationTypeElementDeclarationCstNode[]; +export type AnnotationInterfaceMemberDeclarationCtx = { + annotationInterfaceElementDeclaration?: AnnotationInterfaceElementDeclarationCstNode[]; constantDeclaration?: ConstantDeclarationCstNode[]; classDeclaration?: ClassDeclarationCstNode[]; interfaceDeclaration?: InterfaceDeclarationCstNode[]; Semicolon?: IToken[]; }; -export interface AnnotationTypeElementDeclarationCstNode extends CstNode { - name: "annotationTypeElementDeclaration"; - children: AnnotationTypeElementDeclarationCtx; +export interface AnnotationInterfaceElementDeclarationCstNode extends CstNode { + name: "annotationInterfaceElementDeclaration"; + children: AnnotationInterfaceElementDeclarationCtx; } -export type AnnotationTypeElementDeclarationCtx = { - annotationTypeElementModifier?: AnnotationTypeElementModifierCstNode[]; +export type AnnotationInterfaceElementDeclarationCtx = { + annotationInterfaceElementModifier?: AnnotationInterfaceElementModifierCstNode[]; unannType: UnannTypeCstNode[]; Identifier: IToken[]; LBrace: IToken[]; @@ -2172,12 +2176,12 @@ export type AnnotationTypeElementDeclarationCtx = { Semicolon: IToken[]; }; -export interface AnnotationTypeElementModifierCstNode extends CstNode { - name: "annotationTypeElementModifier"; - children: AnnotationTypeElementModifierCtx; +export interface AnnotationInterfaceElementModifierCstNode extends CstNode { + name: "annotationInterfaceElementModifier"; + children: AnnotationInterfaceElementModifierCtx; } -export type AnnotationTypeElementModifierCtx = { +export type AnnotationInterfaceElementModifierCtx = { annotation?: AnnotationCstNode[]; Public?: IToken[]; Abstract?: IToken[]; @@ -2491,7 +2495,7 @@ export type SwitchLabelCtx = { Comma?: IToken[]; Null?: IToken[]; Default?: IToken[]; - pattern?: PatternCstNode[]; + casePattern?: CasePatternCstNode[]; guard?: GuardCstNode[]; caseConstant?: CaseConstantCstNode[]; }; @@ -2516,7 +2520,16 @@ export interface CaseConstantCstNode extends CstNode { } export type CaseConstantCtx = { - ternaryExpression: TernaryExpressionCstNode[]; + conditionalExpression: ConditionalExpressionCstNode[]; +}; + +export interface CasePatternCstNode extends CstNode { + name: "casePattern"; + children: CasePatternCtx; +} + +export type CasePatternCtx = { + pattern: PatternCstNode[]; }; export interface WhileStatementCstNode extends CstNode { @@ -2610,9 +2623,7 @@ export interface EnhancedForStatementCstNode extends CstNode { export type EnhancedForStatementCtx = { For: IToken[]; LBrace: IToken[]; - variableModifier?: VariableModifierCstNode[]; - localVariableType: LocalVariableTypeCstNode[]; - variableDeclaratorId: VariableDeclaratorIdCstNode[]; + localVariableDeclaration: LocalVariableDeclarationCstNode[]; Colon: IToken[]; expression: ExpressionCstNode[]; RBrace: IToken[]; @@ -2815,7 +2826,7 @@ export interface ExpressionCstNode extends CstNode { export type ExpressionCtx = { lambdaExpression?: LambdaExpressionCstNode[]; - ternaryExpression?: TernaryExpressionCstNode[]; + conditionalExpression?: ConditionalExpressionCstNode[]; }; export interface LambdaExpressionCstNode extends CstNode { @@ -2857,32 +2868,32 @@ export interface LambdaParameterListCstNode extends CstNode { } export type LambdaParameterListCtx = { - inferredLambdaParameterList?: InferredLambdaParameterListCstNode[]; - explicitLambdaParameterList?: ExplicitLambdaParameterListCstNode[]; + conciseLambdaParameterList?: ConciseLambdaParameterListCstNode[]; + normalLambdaParameterList?: NormalLambdaParameterListCstNode[]; }; -export interface InferredLambdaParameterListCstNode extends CstNode { - name: "inferredLambdaParameterList"; - children: InferredLambdaParameterListCtx; +export interface ConciseLambdaParameterListCstNode extends CstNode { + name: "conciseLambdaParameterList"; + children: ConciseLambdaParameterListCtx; } -export type InferredLambdaParameterListCtx = { - Identifier: IToken[]; +export type ConciseLambdaParameterListCtx = { + conciseLambdaParameter: ConciseLambdaParameterCstNode[]; Comma?: IToken[]; }; -export interface ExplicitLambdaParameterListCstNode extends CstNode { - name: "explicitLambdaParameterList"; - children: ExplicitLambdaParameterListCtx; +export interface NormalLambdaParameterListCstNode extends CstNode { + name: "normalLambdaParameterList"; + children: NormalLambdaParameterListCtx; } -export type ExplicitLambdaParameterListCtx = { - lambdaParameter: LambdaParameterCstNode[]; +export type NormalLambdaParameterListCtx = { + normalLambdaParameter: LambdaParameterCstNode[]; Comma?: IToken[]; }; export interface LambdaParameterCstNode extends CstNode { - name: "lambdaParameter"; + name: "normalLambdaParameter"; children: LambdaParameterCtx; } @@ -2912,6 +2923,16 @@ export type LambdaParameterTypeCtx = { Var?: IToken[]; }; +export interface ConciseLambdaParameterCstNode extends CstNode { + name: "conciseLambdaParameter"; + children: ConciseLambdaParameterCtx; +} + +export type ConciseLambdaParameterCtx = { + Identifier?: IToken[]; + Underscore?: IToken[]; +}; + export interface LambdaBodyCstNode extends CstNode { name: "lambdaBody"; children: LambdaBodyCtx; @@ -2922,12 +2943,12 @@ export type LambdaBodyCtx = { block?: BlockCstNode[]; }; -export interface TernaryExpressionCstNode extends CstNode { - name: "ternaryExpression"; - children: TernaryExpressionCtx; +export interface ConditionalExpressionCstNode extends CstNode { + name: "conditionalExpression"; + children: ConditionalExpressionCtx; } -export type TernaryExpressionCtx = { +export type ConditionalExpressionCtx = { binaryExpression: BinaryExpressionCstNode[]; QuestionMark?: IToken[]; expression?: ExpressionCstNode[]; @@ -3197,26 +3218,27 @@ export type ArrayCreationExpressionCtx = { New: IToken[]; primitiveType?: PrimitiveTypeCstNode[]; classOrInterfaceType?: ClassOrInterfaceTypeCstNode[]; - arrayCreationDefaultInitSuffix?: ArrayCreationDefaultInitSuffixCstNode[]; - arrayCreationExplicitInitSuffix?: ArrayCreationExplicitInitSuffixCstNode[]; + arrayCreationExpressionWithoutInitializerSuffix?: ArrayCreationExpressionWithoutInitializerSuffixCstNode[]; + arrayCreationWithInitializerSuffix?: ArrayCreationWithInitializerSuffixCstNode[]; }; -export interface ArrayCreationDefaultInitSuffixCstNode extends CstNode { - name: "arrayCreationDefaultInitSuffix"; - children: ArrayCreationDefaultInitSuffixCtx; +export interface ArrayCreationExpressionWithoutInitializerSuffixCstNode + extends CstNode { + name: "arrayCreationExpressionWithoutInitializerSuffix"; + children: ArrayCreationExpressionWithoutInitializerSuffixCtx; } -export type ArrayCreationDefaultInitSuffixCtx = { +export type ArrayCreationExpressionWithoutInitializerSuffixCtx = { dimExprs: DimExprsCstNode[]; dims?: DimsCstNode[]; }; -export interface ArrayCreationExplicitInitSuffixCstNode extends CstNode { - name: "arrayCreationExplicitInitSuffix"; - children: ArrayCreationExplicitInitSuffixCtx; +export interface ArrayCreationWithInitializerSuffixCstNode extends CstNode { + name: "arrayCreationWithInitializerSuffix"; + children: ArrayCreationWithInitializerSuffixCtx; } -export type ArrayCreationExplicitInitSuffixCtx = { +export type ArrayCreationWithInitializerSuffixCtx = { dims: DimsCstNode[]; arrayInitializer: ArrayInitializerCstNode[]; }; @@ -3379,15 +3401,15 @@ export interface ComponentPatternCstNode extends CstNode { export type ComponentPatternCtx = { pattern?: PatternCstNode[]; - unnamedPattern?: UnnamedPatternCstNode[]; + matchAllPattern?: MatchAllPatternCstNode[]; }; -export interface UnnamedPatternCstNode extends CstNode { - name: "unnamedPattern"; - children: UnnamedPatternCtx; +export interface MatchAllPatternCstNode extends CstNode { + name: "matchAllPattern"; + children: MatchAllPatternCtx; } -export type UnnamedPatternCtx = { +export type MatchAllPatternCtx = { Underscore: IToken[]; }; diff --git a/packages/java-parser/src/productions/arrays.js b/packages/java-parser/src/productions/arrays.js index 37000803..55231b33 100644 --- a/packages/java-parser/src/productions/arrays.js +++ b/packages/java-parser/src/productions/arrays.js @@ -1,7 +1,7 @@ import { tokenMatcher } from "chevrotain"; export function defineRules($, t) { - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-10.html#jls-ArrayInitializer + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-10.html#jls-ArrayInitializer $.RULE("arrayInitializer", () => { $.CONSUME(t.LCurly); $.OPTION(() => { @@ -13,7 +13,7 @@ export function defineRules($, t) { $.CONSUME(t.RCurly); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-10.html#jls-VariableInitializerList + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-10.html#jls-VariableInitializerList $.RULE("variableInitializerList", () => { $.SUBRULE($.variableInitializer); $.MANY({ diff --git a/packages/java-parser/src/productions/blocks-and-statements.js b/packages/java-parser/src/productions/blocks-and-statements.js index 814cb266..e3b09135 100644 --- a/packages/java-parser/src/productions/blocks-and-statements.js +++ b/packages/java-parser/src/productions/blocks-and-statements.js @@ -4,7 +4,7 @@ import { tokenMatcher } from "chevrotain"; // the dangling else is resolved by attaching an "else" block // to the nearest "if" export function defineRules($, t) { - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-14.html#jls-Block + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-14.html#jls-Block $.RULE("block", () => { $.CONSUME(t.LCurly); $.OPTION(() => { @@ -13,7 +13,7 @@ export function defineRules($, t) { $.CONSUME(t.RCurly); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-14.html#jls-BlockStatements + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-14.html#jls-BlockStatements $.RULE("blockStatements", () => { $.SUBRULE($.blockStatement); $.MANY(() => { @@ -21,7 +21,7 @@ export function defineRules($, t) { }); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-14.html#jls-BlockStatement + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-14.html#jls-BlockStatement $.RULE("blockStatement", () => { $.OR({ DEF: [ @@ -34,13 +34,13 @@ export function defineRules($, t) { }); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-14.html#jls-LocalVariableDeclarationStatement + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-14.html#jls-LocalVariableDeclarationStatement $.RULE("localVariableDeclarationStatement", () => { $.SUBRULE($.localVariableDeclaration); $.CONSUME(t.Semicolon); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-14.html#jls-LocalVariableDeclaration + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-14.html#jls-LocalVariableDeclaration $.RULE("localVariableDeclaration", () => { $.MANY(() => { $.SUBRULE($.variableModifier); @@ -49,7 +49,7 @@ export function defineRules($, t) { $.SUBRULE($.variableDeclaratorList); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-14.html#jls-LocalVariableType + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-14.html#jls-LocalVariableType $.RULE("localVariableType", () => { $.OR({ DEF: [ @@ -60,7 +60,7 @@ export function defineRules($, t) { }); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-14.html#jls-Statement + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-14.html#jls-Statement $.RULE("statement", () => { $.OR([ { ALT: () => $.SUBRULE($.statementWithoutTrailingSubstatement) }, @@ -72,7 +72,7 @@ export function defineRules($, t) { ]); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-14.html#jls-StatementWithoutTrailingSubstatement + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-14.html#jls-StatementWithoutTrailingSubstatement $.RULE("statementWithoutTrailingSubstatement", () => { $.OR({ DEF: [ @@ -97,25 +97,25 @@ export function defineRules($, t) { }); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-14.html#jls-EmptyStatement + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-14.html#jls-EmptyStatement $.RULE("emptyStatement", () => { $.CONSUME(t.Semicolon); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-14.html#jls-LabeledStatement + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-14.html#jls-LabeledStatement $.RULE("labeledStatement", () => { $.CONSUME(t.Identifier); $.CONSUME(t.Colon); $.SUBRULE($.statement); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-14.html#jls-ExpressionStatement + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-14.html#jls-ExpressionStatement $.RULE("expressionStatement", () => { $.SUBRULE($.statementExpression); $.CONSUME(t.Semicolon); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-14.html#jls-StatementExpression + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-14.html#jls-StatementExpression $.RULE("statementExpression", () => { // Spec deviation: The many alternatives here were replaced with // the "expression" rule as it contains them all, @@ -126,8 +126,8 @@ export function defineRules($, t) { }); // Spec deviation: combined "IfThenStatement" and "IfThenElseStatement" - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-14.html#jls-IfThenStatement - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-14.html#jls-IfThenElseStatement + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-14.html#jls-IfThenStatement + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-14.html#jls-IfThenElseStatement $.RULE("ifStatement", () => { $.CONSUME(t.If); $.CONSUME(t.LBrace); @@ -140,7 +140,7 @@ export function defineRules($, t) { }); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-14.html#jls-AssertStatement + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-14.html#jls-AssertStatement $.RULE("assertStatement", () => { $.CONSUME(t.Assert); $.SUBRULE($.expression); @@ -151,7 +151,7 @@ export function defineRules($, t) { $.CONSUME(t.Semicolon); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-14.html#jls-SwitchStatement + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-14.html#jls-SwitchStatement $.RULE("switchStatement", () => { $.CONSUME(t.Switch); $.CONSUME(t.LBrace); @@ -160,16 +160,22 @@ export function defineRules($, t) { $.SUBRULE($.switchBlock); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-14.html#jls-SwitchBlock + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-14.html#jls-SwitchBlock $.RULE("switchBlock", () => { $.CONSUME(t.LCurly); $.OR([ - { ALT: () => $.MANY(() => $.SUBRULE($.switchBlockStatementGroup)) }, - { ALT: () => $.MANY2(() => $.SUBRULE($.switchRule)) } + { + ALT: () => { + $.SUBRULE($.switchRule); + $.MANY(() => $.SUBRULE2($.switchRule)); + } + }, + { ALT: () => $.MANY2(() => $.SUBRULE($.switchBlockStatementGroup)) } ]); $.CONSUME(t.RCurly); }); + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-14.html#jls-SwitchBlockStatementGroup $.RULE("switchBlockStatementGroup", () => { $.SUBRULE($.switchLabel); $.CONSUME(t.Colon); @@ -178,7 +184,7 @@ export function defineRules($, t) { }); }); - // https://docs.oracle.com/javase/specs/jls/se21/html/jls-14.html#jls-SwitchLabel + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-14.html#jls-SwitchLabel $.RULE("switchLabel", () => { $.OR([ { @@ -196,10 +202,10 @@ export function defineRules($, t) { }, { ALT: () => { - $.SUBRULE($.pattern); + $.SUBRULE($.casePattern); $.MANY(() => { $.CONSUME(t.Comma); - $.SUBRULE2($.pattern); + $.SUBRULE2($.casePattern); }); $.OPTION(() => { $.SUBRULE($.guard); @@ -223,7 +229,7 @@ export function defineRules($, t) { ]); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-14.html#jls-SwitchRule + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-14.html#jls-SwitchRule $.RULE("switchRule", () => { $.SUBRULE($.switchLabel); $.CONSUME(t.Arrow); @@ -239,12 +245,17 @@ export function defineRules($, t) { ]); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-14.html#jls-EnumConstantName + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-14.html#jls-CaseConstant $.RULE("caseConstant", () => { - $.SUBRULE($.ternaryExpression); + $.SUBRULE($.conditionalExpression); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-14.html#jls-WhileStatement + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-14.html#jls-CasePattern + $.RULE("casePattern", () => { + $.SUBRULE($.pattern); + }); + + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-14.html#jls-WhileStatement $.RULE("whileStatement", () => { $.CONSUME(t.While); $.CONSUME(t.LBrace); @@ -253,7 +264,7 @@ export function defineRules($, t) { $.SUBRULE($.statement); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-14.html#jls-DoStatement + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-14.html#jls-DoStatement $.RULE("doStatement", () => { $.CONSUME(t.Do); $.SUBRULE($.statement); @@ -263,7 +274,8 @@ export function defineRules($, t) { $.CONSUME(t.RBrace); $.CONSUME(t.Semicolon); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-14.html#jls-ForStatement + + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-14.html#jls-ForStatement $.RULE("forStatement", () => { $.OR([ { ALT: () => $.SUBRULE($.basicForStatement) }, @@ -271,7 +283,7 @@ export function defineRules($, t) { ]); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-14.html#jls-BasicForStatement + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-14.html#jls-BasicForStatement $.RULE("basicForStatement", () => { $.CONSUME(t.For); $.CONSUME(t.LBrace); @@ -290,7 +302,7 @@ export function defineRules($, t) { $.SUBRULE($.statement); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-14.html#jls-ForInit + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-14.html#jls-ForInit $.RULE("forInit", () => { $.OR([ { ALT: () => $.SUBRULE($.localVariableDeclaration) }, @@ -298,12 +310,12 @@ export function defineRules($, t) { ]); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-14.html#jls-ForUpdate + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-14.html#jls-ForUpdate $.RULE("forUpdate", () => { $.SUBRULE($.statementExpressionList); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-14.html#jls-StatementExpressionList + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-14.html#jls-StatementExpressionList $.RULE("statementExpressionList", () => { $.SUBRULE($.statementExpression); $.MANY(() => { @@ -312,22 +324,18 @@ export function defineRules($, t) { }); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-14.html#jls-EnhancedForStatement + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-14.html#jls-EnhancedForStatement $.RULE("enhancedForStatement", () => { $.CONSUME(t.For); $.CONSUME(t.LBrace); - $.MANY(() => { - $.SUBRULE($.variableModifier); - }); - $.SUBRULE($.localVariableType); - $.SUBRULE($.variableDeclaratorId); + $.SUBRULE($.localVariableDeclaration); $.CONSUME(t.Colon); $.SUBRULE($.expression); $.CONSUME(t.RBrace); $.SUBRULE($.statement); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-14.html#jls-BreakStatement + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-14.html#jls-BreakStatement $.RULE("breakStatement", () => { $.CONSUME(t.Break); $.OPTION(() => { @@ -336,7 +344,7 @@ export function defineRules($, t) { $.CONSUME(t.Semicolon); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-14.html#jls-ContinueStatement + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-14.html#jls-ContinueStatement $.RULE("continueStatement", () => { $.CONSUME(t.Continue); $.OPTION(() => { @@ -345,7 +353,7 @@ export function defineRules($, t) { $.CONSUME(t.Semicolon); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-14.html#jls-ReturnStatement + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-14.html#jls-ReturnStatement $.RULE("returnStatement", () => { $.CONSUME(t.Return); $.OPTION(() => { @@ -354,14 +362,14 @@ export function defineRules($, t) { $.CONSUME(t.Semicolon); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-14.html#jls-ThrowStatement + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-14.html#jls-ThrowStatement $.RULE("throwStatement", () => { $.CONSUME(t.Throw); $.SUBRULE($.expression); $.CONSUME(t.Semicolon); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-14.html#jls-SynchronizedStatement + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-14.html#jls-SynchronizedStatement $.RULE("synchronizedStatement", () => { $.CONSUME(t.Synchronized); $.CONSUME(t.LBrace); @@ -370,7 +378,7 @@ export function defineRules($, t) { $.SUBRULE($.block); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-14.html#jls-TryStatement + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-14.html#jls-TryStatement $.RULE("tryStatement", () => { $.OR([ { @@ -394,7 +402,7 @@ export function defineRules($, t) { ]); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-14.html#jls-Catches + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-14.html#jls-Catches $.RULE("catches", () => { $.SUBRULE($.catchClause); $.MANY(() => { @@ -402,7 +410,7 @@ export function defineRules($, t) { }); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-14.html#jls-CatchClause + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-14.html#jls-CatchClause $.RULE("catchClause", () => { $.CONSUME(t.Catch); $.CONSUME(t.LBrace); @@ -411,7 +419,7 @@ export function defineRules($, t) { $.SUBRULE($.block); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-14.html#jls-CatchFormalParameter + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-14.html#jls-CatchFormalParameter $.RULE("catchFormalParameter", () => { $.MANY(() => { $.SUBRULE($.variableModifier); @@ -420,7 +428,7 @@ export function defineRules($, t) { $.SUBRULE($.variableDeclaratorId); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-14.html#jls-CatchType + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-14.html#jls-CatchType $.RULE("catchType", () => { $.SUBRULE($.unannClassType); $.MANY(() => { @@ -429,13 +437,13 @@ export function defineRules($, t) { }); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-14.html#jls-Finally + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-14.html#jls-Finally $.RULE("finally", () => { $.CONSUME(t.Finally); $.SUBRULE($.block); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-14.html#jls-TryWithResourcesStatement + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-14.html#jls-TryWithResourcesStatement $.RULE("tryWithResourcesStatement", () => { $.CONSUME(t.Try); $.SUBRULE($.resourceSpecification); @@ -448,7 +456,7 @@ export function defineRules($, t) { }); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-14.html#jls-ResourceSpecification + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-14.html#jls-ResourceSpecification $.RULE("resourceSpecification", () => { $.CONSUME(t.LBrace); $.SUBRULE($.resourceList); @@ -458,7 +466,7 @@ export function defineRules($, t) { $.CONSUME(t.RBrace); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-14.html#jls-ResourceList + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-14.html#jls-ResourceList $.RULE("resourceList", () => { $.SUBRULE($.resource); $.MANY({ @@ -470,7 +478,7 @@ export function defineRules($, t) { }); }); - // https://docs.oracle.com/javase/specs/jls/se21/html/jls-14.html#jls-Resource + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-14.html#jls-Resource $.RULE("resource", () => { $.OR([ { ALT: () => $.SUBRULE($.localVariableDeclaration) }, @@ -478,14 +486,14 @@ export function defineRules($, t) { ]); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-14.html#jls-YieldStatement + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-14.html#jls-YieldStatement $.RULE("yieldStatement", () => { $.CONSUME(t.Yield); $.SUBRULE($.expression); $.CONSUME(t.Semicolon); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-14.html#jls-VariableAccess + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-14.html#jls-VariableAccess $.RULE("variableAccess", () => { // Spec Deviation: both "expressionName" and "fieldAccess" can be parsed // by the "primary" rule diff --git a/packages/java-parser/src/productions/classes.js b/packages/java-parser/src/productions/classes.js index 8ed02e43..0a82db89 100644 --- a/packages/java-parser/src/productions/classes.js +++ b/packages/java-parser/src/productions/classes.js @@ -1,7 +1,7 @@ import { tokenMatcher } from "chevrotain"; export function defineRules($, t) { - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-8.html#jls-ClassDeclaration + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-8.html#jls-ClassDeclaration $.RULE("classDeclaration", () => { // Spec Deviation: extracted common "{classModifier}" prefix // extraction is safe because there are no other references to @@ -16,7 +16,7 @@ export function defineRules($, t) { ]); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-8.html#jls-NormalClassDeclaration + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-8.html#jls-NormalClassDeclaration $.RULE("normalClassDeclaration", () => { // Spec Deviation: extracted common "{classModifier}" to "classDeclaration" $.CONSUME(t.Class); @@ -25,10 +25,10 @@ export function defineRules($, t) { $.SUBRULE($.typeParameters); }); $.OPTION2(() => { - $.SUBRULE($.superclass); + $.SUBRULE($.classExtends); }); $.OPTION3(() => { - $.SUBRULE($.superinterfaces); + $.SUBRULE($.classImplements); }); $.OPTION4(() => { $.SUBRULE($.classPermits); @@ -36,7 +36,7 @@ export function defineRules($, t) { $.SUBRULE($.classBody); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-8.html#jls-ClassModifier + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-8.html#jls-ClassModifier $.RULE("classModifier", () => { $.OR([ { ALT: () => $.SUBRULE($.annotation) }, @@ -52,14 +52,14 @@ export function defineRules($, t) { ]); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-8.html#jls-TypeParameters + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-8.html#jls-TypeParameters $.RULE("typeParameters", () => { $.CONSUME(t.Less); $.SUBRULE($.typeParameterList); $.CONSUME(t.Greater); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-8.html#jls-TypeParameterList + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-8.html#jls-TypeParameterList $.RULE("typeParameterList", () => { $.SUBRULE($.typeParameter); $.MANY(() => { @@ -68,19 +68,19 @@ export function defineRules($, t) { }); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-8.html#jls-ClassExtends - $.RULE("superclass", () => { + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-8.html#jls-ClassExtends + $.RULE("classExtends", () => { $.CONSUME(t.Extends); $.SUBRULE($.classType); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-8.html#jls-ClassImplements - $.RULE("superinterfaces", () => { + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-8.html#jls-ClassImplements + $.RULE("classImplements", () => { $.CONSUME(t.Implements); $.SUBRULE($.interfaceTypeList); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-8.html#jls-InterfaceTypeList + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-8.html#jls-InterfaceTypeList $.RULE("interfaceTypeList", () => { $.SUBRULE($.interfaceType); $.MANY(() => { @@ -89,7 +89,7 @@ export function defineRules($, t) { }); }); - // https://docs.oracle.com/javase/specs/jls/se16/preview/specs/sealed-classes-jls.html + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-8.html#jls-ClassPermits $.RULE("classPermits", () => { $.CONSUME(t.Permits); $.SUBRULE($.typeName); @@ -99,7 +99,7 @@ export function defineRules($, t) { }); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-8.html#jls-ClassBody + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-8.html#jls-ClassBody $.RULE("classBody", () => { $.CONSUME(t.LCurly); $.MANY(() => { @@ -108,7 +108,7 @@ export function defineRules($, t) { $.CONSUME(t.RCurly); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-8.html#jls-ClassBodyDeclaration + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-8.html#jls-ClassBodyDeclaration $.RULE("classBodyDeclaration", () => { $.OR([ { ALT: () => $.SUBRULE($.classMemberDeclaration) }, @@ -118,7 +118,7 @@ export function defineRules($, t) { ]); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-8.html#jls-ClassMemberDeclaration + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-8.html#jls-ClassMemberDeclaration $.RULE("classMemberDeclaration", () => { $.OR([ { ALT: () => $.SUBRULE($.fieldDeclaration) }, @@ -129,7 +129,7 @@ export function defineRules($, t) { ]); }); - // // https://docs.oracle.com/javase/specs/jls/se16/html/jls-8.html#jls-FieldDeclaration + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-8.html#jls-FieldDeclaration $.RULE("fieldDeclaration", () => { $.MANY(() => { $.SUBRULE($.fieldModifier); @@ -139,7 +139,7 @@ export function defineRules($, t) { $.CONSUME(t.Semicolon); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-8.html#jls-FieldModifier + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-8.html#jls-FieldModifier $.RULE("fieldModifier", () => { $.OR([ { ALT: () => $.SUBRULE($.annotation) }, @@ -153,12 +153,14 @@ export function defineRules($, t) { ]); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-8.html#jls-VariableDeclaratorList + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-8.html#jls-VariableDeclaratorList $.RULE("variableDeclaratorList", () => { $.SUBRULE($.variableDeclarator); $.MANY({ // required to distinguish from patternList - GATE: () => !tokenMatcher(this.LA(3).tokenType, t.Identifier), + GATE: () => + !tokenMatcher(this.LA(3), t.Identifier) && + !tokenMatcher(this.LA(3), t.Underscore), DEF: () => { $.CONSUME(t.Comma); $.SUBRULE2($.variableDeclarator); @@ -166,7 +168,7 @@ export function defineRules($, t) { }); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-8.html#jls-VariableDeclarator + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-8.html#jls-VariableDeclarator $.RULE("variableDeclarator", () => { $.SUBRULE($.variableDeclaratorId); $.OPTION(() => { @@ -175,7 +177,7 @@ export function defineRules($, t) { }); }); - // https://docs.oracle.com/javase/specs/jls/se21/html/jls-8.html#jls-VariableDeclaratorId + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-8.html#jls-VariableDeclaratorId $.RULE("variableDeclaratorId", () => { $.OR([ { @@ -190,7 +192,7 @@ export function defineRules($, t) { ]); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-8.html#jls-VariableInitializer + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-8.html#jls-VariableInitializer $.RULE("variableInitializer", () => { $.OR([ { ALT: () => $.SUBRULE($.expression) }, @@ -198,7 +200,7 @@ export function defineRules($, t) { ]); }); - // // https://docs.oracle.com/javase/specs/jls/se16/html/jls-8.html#jls-UnannType + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-8.html#jls-UnannType $.RULE("unannType", () => { $.OR([ // Spec Deviation: The array type "dims" suffix was extracted to this rule @@ -216,7 +218,7 @@ export function defineRules($, t) { }); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-8.html#jls-UnannPrimitiveType + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-8.html#jls-UnannPrimitiveType $.RULE("unannPrimitiveType", () => { $.OR([ { ALT: () => $.SUBRULE($.numericType) }, @@ -224,7 +226,7 @@ export function defineRules($, t) { ]); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-8.html#jls-UnannReferenceType + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-8.html#jls-UnannReferenceType $.RULE("unannReferenceType", () => { $.SUBRULE($.unannClassOrInterfaceType); $.OPTION({ @@ -233,7 +235,6 @@ export function defineRules($, t) { }); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-8.html#jls-UnannClassType $.RULE("unannClassOrInterfaceType", () => { // Spec Deviation: The spec says: "UnannClassType | UnannInterfaceType" but "UnannInterfaceType" // is not mentioned in the parser because it is identical to "UnannClassType" @@ -241,6 +242,7 @@ export function defineRules($, t) { $.SUBRULE($.unannClassType); }); + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-8.html#jls-UnannClassType $.RULE("unannClassType", () => { // Spec Deviation: Refactored left recursion and alternation to iterations $.CONSUME(t.Identifier); @@ -260,18 +262,19 @@ export function defineRules($, t) { }); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-8.html#jls-UnannInterfaceType + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-8.html#jls-UnannInterfaceType $.RULE("unannInterfaceType", () => { $.SUBRULE($.unannClassType); }); + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-8.html#jls-UnannTypeVariable $.RULE("unannTypeVariable", () => { // TODO: Semantic Check: This Identifier cannot be "var" // TODO: or define as token type? $.CONSUME(t.Identifier); }); - // // https://docs.oracle.com/javase/specs/jls/se16/html/jls-8.html#jls-MethodDeclaration + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-8.html#jls-MethodDeclaration $.RULE("methodDeclaration", () => { $.MANY(() => { $.SUBRULE($.methodModifier); @@ -280,7 +283,7 @@ export function defineRules($, t) { $.SUBRULE($.methodBody); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-8.html#jls-MethodModifier + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-8.html#jls-MethodModifier $.RULE("methodModifier", () => { $.OR([ { ALT: () => $.SUBRULE($.annotation) }, @@ -296,7 +299,7 @@ export function defineRules($, t) { ]); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-8.html#jls-MethodHeader + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-8.html#jls-MethodHeader $.RULE("methodHeader", () => { // Spec Deviation: extracted common prefix from both alternatives $.OPTION(() => { @@ -312,7 +315,7 @@ export function defineRules($, t) { }); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-8.html#jls-Result + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-8.html#jls-Result $.RULE("result", () => { $.OR([ { ALT: () => $.SUBRULE($.unannType) }, @@ -320,7 +323,7 @@ export function defineRules($, t) { ]); }); - // https://docs.oracle.com/javase/specs/jls/se21/html/jls-8.html#jls-MethodDeclarator + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-8.html#jls-MethodDeclarator $.RULE("methodDeclarator", () => { $.CONSUME(t.Identifier); $.CONSUME(t.LBrace); @@ -342,7 +345,7 @@ export function defineRules($, t) { }); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-8.html#jls-ReceiverParameter + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-8.html#jls-ReceiverParameter $.RULE("receiverParameter", () => { $.MANY(() => { $.SUBRULE($.annotation); @@ -355,7 +358,7 @@ export function defineRules($, t) { $.CONSUME(t.This); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-8.html#jls-FormalParameterList + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-8.html#jls-FormalParameterList $.RULE("formalParameterList", () => { $.SUBRULE($.formalParameter); $.MANY(() => { @@ -364,7 +367,7 @@ export function defineRules($, t) { }); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-8.html#jls-FormalParameter + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-8.html#jls-FormalParameter $.RULE("formalParameter", () => { $.OR([ // Spec Deviation: extracted to "variableParaRegularParameter" @@ -382,7 +385,7 @@ export function defineRules($, t) { $.SUBRULE($.variableDeclaratorId); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-8.html#jls-VariableArityParameter + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-8.html#jls-VariableArityParameter $.RULE("variableArityParameter", () => { $.MANY(() => { $.SUBRULE($.variableModifier); @@ -395,7 +398,7 @@ export function defineRules($, t) { $.CONSUME(t.Identifier); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-8.html#jls-VariableModifier + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-8.html#jls-VariableModifier $.RULE("variableModifier", () => { $.OR([ { ALT: () => $.SUBRULE($.annotation) }, @@ -403,13 +406,13 @@ export function defineRules($, t) { ]); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-8.html#jls-Throws + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-8.html#jls-Throws $.RULE("throws", () => { $.CONSUME(t.Throws); $.SUBRULE($.exceptionTypeList); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-8.html#jls-ExceptionTypeList + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-8.html#jls-ExceptionTypeList $.RULE("exceptionTypeList", () => { $.SUBRULE($.exceptionType); $.MANY(() => { @@ -418,14 +421,14 @@ export function defineRules($, t) { }); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-8.html#jls-ExceptionType + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-8.html#jls-ExceptionType $.RULE("exceptionType", () => { // Spec Deviation: "typeVariable" alternative is missing because // it is contained in classType. $.SUBRULE($.classType); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-8.html#jls-MethodBody + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-8.html#jls-MethodBody $.RULE("methodBody", () => { $.OR([ { ALT: () => $.SUBRULE($.block) }, @@ -433,18 +436,18 @@ export function defineRules($, t) { ]); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-8.html#jls-InstanceInitializer + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-8.html#jls-InstanceInitializer $.RULE("instanceInitializer", () => { $.SUBRULE($.block); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-8.html#jls-StaticInitializer + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-8.html#jls-StaticInitializer $.RULE("staticInitializer", () => { $.CONSUME(t.Static); $.SUBRULE($.block); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-8.html#jls-ConstructorDeclaration + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-8.html#jls-ConstructorDeclaration $.RULE("constructorDeclaration", () => { $.MANY(() => { $.SUBRULE($.constructorModifier); @@ -456,7 +459,7 @@ export function defineRules($, t) { $.SUBRULE($.constructorBody); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-8.html#jls-ConstructorModifier + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-8.html#jls-ConstructorModifier $.RULE("constructorModifier", () => { $.OR([ { ALT: () => $.SUBRULE($.annotation) }, @@ -466,7 +469,7 @@ export function defineRules($, t) { ]); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-8.html#jls-ConstructorDeclarator + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-8.html#jls-ConstructorDeclarator $.RULE("constructorDeclarator", () => { $.OPTION(() => { $.SUBRULE($.typeParameters); @@ -488,13 +491,13 @@ export function defineRules($, t) { $.CONSUME(t.RBrace); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-8.html#jls-SimpleTypeName + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-8.html#jls-SimpleTypeName $.RULE("simpleTypeName", () => { // TODO: implement: Identifier but not var - $.CONSUME(t.Identifier); + $.SUBRULE($.typeIdentifier); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-8.html#jls-ConstructorBody + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-8.html#jls-ConstructorBody $.RULE("constructorBody", () => { $.CONSUME(t.LCurly); $.OPTION(() => { @@ -506,13 +509,11 @@ export function defineRules($, t) { $.CONSUME(t.RCurly); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-8.html#jls-ExplicitConstructorInvocation + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-8.html#jls-ExplicitConstructorInvocation $.RULE("explicitConstructorInvocation", () => { // Spec Deviation: split into two separate sub rules. $.OR([ - { - ALT: () => $.SUBRULE($.unqualifiedExplicitConstructorInvocation) - }, + { ALT: () => $.SUBRULE($.unqualifiedExplicitConstructorInvocation) }, { ALT: () => $.SUBRULE($.qualifiedExplicitConstructorInvocation) } ]); }); @@ -560,7 +561,7 @@ export function defineRules($, t) { $.CONSUME(t.Semicolon); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-8.html#jls-EnumDeclaration + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-8.html#jls-EnumDeclaration $.RULE("enumDeclaration", () => { $.MANY(() => { $.SUBRULE($.classModifier); @@ -568,12 +569,12 @@ export function defineRules($, t) { $.CONSUME(t.Enum); $.SUBRULE($.typeIdentifier); $.OPTION(() => { - $.SUBRULE($.superinterfaces); + $.SUBRULE($.classImplements); }); $.SUBRULE($.enumBody); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-8.html#jls-EnumBody + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-8.html#jls-EnumBody $.RULE("enumBody", () => { $.CONSUME(t.LCurly); $.OPTION(() => { @@ -588,7 +589,7 @@ export function defineRules($, t) { $.CONSUME(t.RCurly); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-8.html#jls-EnumConstantList + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-8.html#jls-EnumConstantList $.RULE("enumConstantList", () => { $.SUBRULE($.enumConstant); $.MANY({ @@ -605,7 +606,7 @@ export function defineRules($, t) { }); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-8.html#jls-EnumConstant + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-8.html#jls-EnumConstant $.RULE("enumConstant", () => { $.MANY(() => { $.SUBRULE($.enumConstantModifier); @@ -623,12 +624,12 @@ export function defineRules($, t) { }); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-8.html#jls-EnumConstantModifier + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-8.html#jls-EnumConstantModifier $.RULE("enumConstantModifier", () => { $.SUBRULE($.annotation); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-8.html#jls-EnumBodyDeclarations + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-8.html#jls-EnumBodyDeclarations $.RULE("enumBodyDeclarations", () => { $.CONSUME(t.Semicolon); $.MANY(() => { @@ -636,7 +637,7 @@ export function defineRules($, t) { }); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-8.html#jls-RecordHeader + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-8.html#jls-RecordHeader $.RULE("recordDeclaration", () => { $.CONSUME(t.Record); $.SUBRULE($.typeIdentifier); @@ -645,11 +646,12 @@ export function defineRules($, t) { }); $.SUBRULE($.recordHeader); $.OPTION2(() => { - $.SUBRULE($.superinterfaces); + $.SUBRULE($.classImplements); }); $.SUBRULE($.recordBody); }); + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-8.html#jls-RecordHeader $.RULE("recordHeader", () => { $.CONSUME(t.LBrace); $.OPTION(() => { @@ -658,7 +660,7 @@ export function defineRules($, t) { $.CONSUME(t.RBrace); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-8.html#jls-RecordComponentList + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-8.html#jls-RecordComponentList $.RULE("recordComponentList", () => { $.SUBRULE($.recordComponent); $.MANY(() => { @@ -667,7 +669,7 @@ export function defineRules($, t) { }); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-8.html#jls-RecordComponent + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-8.html#jls-RecordComponent $.RULE("recordComponent", () => { // Spec Deviation: extracted common "{recordComponentModifier} unannType" prefix // extraction is safe because there are no other references to @@ -682,7 +684,7 @@ export function defineRules($, t) { ]); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-8.html#jls-VariableArityRecordComponent + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-8.html#jls-VariableArityRecordComponent // Spec Deviation: common "{recordComponentModifier} unannType" prefix was extracted in "recordComponent" $.RULE("variableArityRecordComponent", () => { $.MANY(() => { @@ -692,12 +694,12 @@ export function defineRules($, t) { $.CONSUME(t.Identifier); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-8.html#jls-RecordComponentModifier + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-8.html#jls-RecordComponentModifier $.RULE("recordComponentModifier", () => { $.SUBRULE($.annotation); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-8.html#jls-RecordBody + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-8.html#jls-RecordBody $.RULE("recordBody", () => { $.CONSUME(t.LCurly); $.MANY(() => { @@ -706,7 +708,7 @@ export function defineRules($, t) { $.CONSUME(t.RCurly); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-8.html#jls-RecordBodyDeclaration + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-8.html#jls-RecordBodyDeclaration $.RULE("recordBodyDeclaration", () => { $.OR([ { ALT: () => $.SUBRULE($.compactConstructorDeclaration) }, @@ -714,7 +716,7 @@ export function defineRules($, t) { ]); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-8.html#jls-CompactConstructorDeclaration + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-8.html#jls-CompactConstructorDeclaration $.RULE("compactConstructorDeclaration", () => { $.MANY(() => { $.SUBRULE($.constructorModifier); diff --git a/packages/java-parser/src/productions/expressions.js b/packages/java-parser/src/productions/expressions.js index 47322e65..ce665a22 100644 --- a/packages/java-parser/src/productions/expressions.js +++ b/packages/java-parser/src/productions/expressions.js @@ -1,19 +1,21 @@ import { tokenMatcher } from "chevrotain"; export function defineRules($, t) { + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-15.html#jls-Expression $.RULE("expression", () => { $.OR([ { ALT: () => $.SUBRULE($.lambdaExpression) }, - { ALT: () => $.SUBRULE($.ternaryExpression) } + { ALT: () => $.SUBRULE($.conditionalExpression) } ]); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-15.html#jls-LambdaExpression + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-15.html#jls-LambdaExpression $.RULE("lambdaExpression", () => { $.SUBRULE($.lambdaParameters); $.CONSUME(t.Arrow); $.SUBRULE($.lambdaBody); }); + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-15.html#jls-LambdaParameters $.RULE("lambdaParameters", () => { $.OR([ { ALT: () => $.SUBRULE($.lambdaParametersWithBraces) }, @@ -30,6 +32,7 @@ export function defineRules($, t) { $.CONSUME(t.RBrace); }); + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-15.html#jls-LambdaParameterList $.RULE("lambdaParameterList", () => { $.OR([ { @@ -37,34 +40,36 @@ export function defineRules($, t) { const nextTokType = this.LA(1).tokenType; const nextNextTokType = this.LA(2).tokenType; return ( - tokenMatcher(nextTokType, t.Identifier) && + (tokenMatcher(nextTokType, t.Identifier) || + tokenMatcher(nextTokType, t.Underscore)) && (tokenMatcher(nextNextTokType, t.RBrace) || tokenMatcher(nextNextTokType, t.Comma)) ); }, - ALT: () => $.SUBRULE($.inferredLambdaParameterList) + ALT: () => $.SUBRULE($.conciseLambdaParameterList) }, - { ALT: () => $.SUBRULE($.explicitLambdaParameterList) } + { ALT: () => $.SUBRULE($.normalLambdaParameterList) } ]); }); - $.RULE("inferredLambdaParameterList", () => { - $.CONSUME(t.Identifier); + $.RULE("conciseLambdaParameterList", () => { + $.SUBRULE($.conciseLambdaParameter); $.MANY(() => { $.CONSUME(t.Comma); - $.CONSUME2(t.Identifier); + $.SUBRULE2($.conciseLambdaParameter); }); }); - $.RULE("explicitLambdaParameterList", () => { - $.SUBRULE($.lambdaParameter); + $.RULE("normalLambdaParameterList", () => { + $.SUBRULE($.normalLambdaParameter); $.MANY(() => { $.CONSUME(t.Comma); - $.SUBRULE2($.lambdaParameter); + $.SUBRULE2($.normalLambdaParameter); }); }); - $.RULE("lambdaParameter", () => { + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-15.html#jls-NormalLambdaParameter + $.RULE("normalLambdaParameter", () => { $.OR([ { ALT: () => $.SUBRULE($.regularLambdaParameter) }, { ALT: () => $.SUBRULE($.variableArityParameter) } @@ -79,6 +84,7 @@ export function defineRules($, t) { $.SUBRULE($.variableDeclaratorId); }); + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-15.html#jls-LambdaParameterType $.RULE("lambdaParameterType", () => { $.OR({ DEF: [ @@ -89,6 +95,15 @@ export function defineRules($, t) { }); }); + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-15.html#jls-ConciseLambdaParameter + $.RULE("conciseLambdaParameter", () => { + $.OR([ + { ALT: () => $.CONSUME(t.Identifier) }, + { ALT: () => $.CONSUME(t.Underscore) } + ]); + }); + + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-15.html#jls-LambdaBody $.RULE("lambdaBody", () => { $.OR([ { ALT: () => $.SUBRULE($.expression) }, @@ -96,7 +111,8 @@ export function defineRules($, t) { ]); }); - $.RULE("ternaryExpression", () => { + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-15.html#jls-ConditionalExpression + $.RULE("conditionalExpression", () => { $.SUBRULE($.binaryExpression); $.OPTION(() => { $.CONSUME(t.QuestionMark); @@ -173,6 +189,7 @@ export function defineRules($, t) { }); }); + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-15.html#jls-UnaryExpression $.RULE("unaryExpression", () => { $.MANY(() => { $.CONSUME(t.UnaryPrefixOperator); @@ -183,6 +200,7 @@ export function defineRules($, t) { }); }); + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-15.html#jls-UnaryExpressionNotPlusMinus $.RULE("unaryExpressionNotPlusMinus", () => { $.MANY(() => { $.CONSUME(t.UnaryPrefixOperatorNotPlusMinus); @@ -193,6 +211,7 @@ export function defineRules($, t) { }); }); + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-15.html#jls-Primary $.RULE("primary", () => { $.SUBRULE($.primaryPrefix); $.MANY(() => { @@ -338,6 +357,7 @@ export function defineRules($, t) { $.CONSUME(t.RBrace); }); + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-15.html#jls-CastExpression $.RULE("castExpression", () => { $.OR([ { ALT: () => $.SUBRULE($.primitiveCastExpression) }, @@ -372,7 +392,7 @@ export function defineRules($, t) { ]); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-15.html#jls-UnqualifiedClassInstanceCreationExpression + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-15.html#jls-UnqualifiedClassInstanceCreationExpression $.RULE("unqualifiedClassInstanceCreationExpression", () => { $.CONSUME(t.New); $.OPTION(() => { @@ -389,6 +409,7 @@ export function defineRules($, t) { }); }); + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-15.html#jls-ClassOrInterfaceTypeToInstantiate $.RULE("classOrInterfaceTypeToInstantiate", () => { $.MANY(() => { $.SUBRULE($.annotation); @@ -406,6 +427,7 @@ export function defineRules($, t) { }); }); + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-15.html#jls-TypeArgumentsOrDiamond $.RULE("typeArgumentsOrDiamond", () => { $.OR([ { ALT: () => $.SUBRULE($.diamond) }, @@ -418,6 +440,7 @@ export function defineRules($, t) { $.CONSUME(t.Greater); }); + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-15.html#jls-MethodInvocation $.RULE("methodInvocationSuffix", () => { $.CONSUME(t.LBrace); $.OPTION2(() => { @@ -426,6 +449,7 @@ export function defineRules($, t) { $.CONSUME(t.RBrace); }); + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-15.html#jls-ArgumentList $.RULE("argumentList", () => { $.SUBRULE($.expression); $.MANY(() => { @@ -434,7 +458,7 @@ export function defineRules($, t) { }); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-15.html#jls-15.10.1 + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-15.html#jls-ArrayCreationExpression $.RULE("arrayCreationExpression", () => { $.CONSUME(t.New); $.OR([ @@ -443,24 +467,28 @@ export function defineRules($, t) { ]); $.OR2([ - { ALT: () => $.SUBRULE($.arrayCreationDefaultInitSuffix) }, - { ALT: () => $.SUBRULE($.arrayCreationExplicitInitSuffix) } + { + ALT: () => $.SUBRULE($.arrayCreationExpressionWithoutInitializerSuffix) + }, + { ALT: () => $.SUBRULE($.arrayCreationWithInitializerSuffix) } ]); }); - $.RULE("arrayCreationDefaultInitSuffix", () => { + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-15.html#jls-ArrayCreationExpressionWithoutInitializer + $.RULE("arrayCreationExpressionWithoutInitializerSuffix", () => { $.SUBRULE($.dimExprs); $.OPTION(() => { $.SUBRULE($.dims); }); }); - $.RULE("arrayCreationExplicitInitSuffix", () => { + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-15.html#jls-ArrayCreationExpressionWithInitializer + $.RULE("arrayCreationWithInitializerSuffix", () => { $.SUBRULE($.dims); $.SUBRULE($.arrayInitializer); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-15.html#jls-DimExprs + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-15.html#jls-DimExprs $.RULE("dimExprs", () => { $.SUBRULE($.dimExpr); $.MANY({ @@ -473,7 +501,7 @@ export function defineRules($, t) { }); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-15.html#jls-DimExpr + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-15.html#jls-DimExpr $.RULE("dimExpr", () => { $.MANY(() => { $.SUBRULE($.annotation); @@ -483,6 +511,7 @@ export function defineRules($, t) { $.CONSUME(t.RSquare); }); + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-15.html#jls-ClassLiteral $.RULE("classLiteralSuffix", () => { $.MANY(() => { $.CONSUME(t.LSquare); @@ -492,12 +521,14 @@ export function defineRules($, t) { $.CONSUME(t.Class); }); + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-15.html#jls-ArrayAccess $.RULE("arrayAccessSuffix", () => { $.CONSUME(t.LSquare); $.SUBRULE($.expression); $.CONSUME(t.RSquare); }); + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-15.html#jls-MethodReference $.RULE("methodReferenceSuffix", () => { $.CONSUME(t.ColonColon); $.OPTION(() => { @@ -554,7 +585,7 @@ export function defineRules($, t) { }); }); - // https://docs.oracle.com/javase/specs/jls/se21/html/jls-14.html#jls-Pattern + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-14.html#jls-Pattern $.RULE("pattern", () => { $.OR([ { ALT: () => $.SUBRULE($.typePattern) }, @@ -562,12 +593,12 @@ export function defineRules($, t) { ]); }); - // https://docs.oracle.com/javase/specs/jls/se21/html/jls-14.html#jls-TypePattern + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-14.html#jls-TypePattern $.RULE("typePattern", () => { $.SUBRULE($.localVariableDeclaration); }); - // https://docs.oracle.com/javase/specs/jls/se21/html/jls-14.html#jls-RecordPattern + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-14.html#jls-RecordPattern $.RULE("recordPattern", () => { $.SUBRULE($.referenceType); $.CONSUME(t.LBrace); @@ -577,7 +608,7 @@ export function defineRules($, t) { $.CONSUME(t.RBrace); }); - // https://docs.oracle.com/javase/specs/jls/se21/html/jls-14.html#jls-PatternList + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-14.html#jls-ComponentPatternList $.RULE("componentPatternList", () => { $.SUBRULE($.componentPattern); $.MANY(() => { @@ -586,18 +617,20 @@ export function defineRules($, t) { }); }); + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-14.html#jls-ComponentPattern $.RULE("componentPattern", () => { $.OR([ { ALT: () => $.SUBRULE($.pattern) }, - { ALT: () => $.SUBRULE($.unnamedPattern) } + { ALT: () => $.SUBRULE($.matchAllPattern) } ]); }); - $.RULE("unnamedPattern", () => { + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-14.html#jls-MatchAllPattern + $.RULE("matchAllPattern", () => { $.CONSUME(t.Underscore); }); - // https://docs.oracle.com/javase/specs/jls/se21/html/jls-14.html#jls-Guard + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-14.html#jls-Guard $.RULE("guard", () => { $.CONSUME(t.When); $.SUBRULE($.expression); diff --git a/packages/java-parser/src/productions/interfaces.js b/packages/java-parser/src/productions/interfaces.js index 1362d368..46d420f8 100644 --- a/packages/java-parser/src/productions/interfaces.js +++ b/packages/java-parser/src/productions/interfaces.js @@ -1,7 +1,7 @@ import { tokenMatcher } from "chevrotain"; export function defineRules($, t) { - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-9.html#jls-InterfaceDeclaration + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-9.html#jls-InterfaceDeclaration $.RULE("interfaceDeclaration", () => { // Spec Deviation: extracted the common "interfaceModifier" prefix to avoid backtracking. $.MANY(() => { @@ -10,11 +10,11 @@ export function defineRules($, t) { $.OR([ { ALT: () => $.SUBRULE($.normalInterfaceDeclaration) }, - { ALT: () => $.SUBRULE($.annotationTypeDeclaration) } + { ALT: () => $.SUBRULE($.annotationInterfaceDeclaration) } ]); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-9.html#jls-NormalInterfaceDeclaration + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-9.html#jls-NormalInterfaceDeclaration $.RULE("normalInterfaceDeclaration", () => { // Spec Deviation: The "interfaceModifier" prefix was extracted to the "interfaceDeclaration" $.CONSUME(t.Interface); @@ -23,7 +23,7 @@ export function defineRules($, t) { $.SUBRULE($.typeParameters); }); $.OPTION2(() => { - $.SUBRULE($.extendsInterfaces); + $.SUBRULE($.interfaceExtends); }); $.OPTION3(() => { $.SUBRULE($.interfacePermits); @@ -31,7 +31,7 @@ export function defineRules($, t) { $.SUBRULE($.interfaceBody); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-9.html#jls-InterfaceModifier + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-9.html#jls-InterfaceModifier $.RULE("interfaceModifier", () => { $.OR([ { ALT: () => $.SUBRULE($.annotation) }, @@ -46,13 +46,13 @@ export function defineRules($, t) { ]); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-9.html#jls-InterfaceExtends - $.RULE("extendsInterfaces", () => { + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-9.html#jls-InterfaceExtends + $.RULE("interfaceExtends", () => { $.CONSUME(t.Extends); $.SUBRULE($.interfaceTypeList); }); - // https://docs.oracle.com/javase/specs/jls/se16/preview/specs/sealed-classes-jls.html + // https://docs.oracle.com/javase/specs/jls/se22/preview/specs/sealed-classes-jls.html $.RULE("interfacePermits", () => { $.CONSUME(t.Permits); $.SUBRULE($.typeName); @@ -62,7 +62,7 @@ export function defineRules($, t) { }); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-9.html#jls-InterfaceBody + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-9.html#jls-InterfaceBody $.RULE("interfaceBody", () => { $.CONSUME(t.LCurly); $.MANY(() => { @@ -71,7 +71,7 @@ export function defineRules($, t) { $.CONSUME(t.RCurly); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-9.html#jls-InterfaceMemberDeclaration + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-9.html#jls-InterfaceMemberDeclaration $.RULE("interfaceMemberDeclaration", () => { $.OR([ { ALT: () => $.SUBRULE($.constantDeclaration) }, @@ -82,7 +82,7 @@ export function defineRules($, t) { ]); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-9.html#jls-ConstantDeclaration + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-9.html#jls-ConstantDeclaration $.RULE("constantDeclaration", () => { $.MANY(() => { $.SUBRULE($.constantModifier); @@ -92,7 +92,7 @@ export function defineRules($, t) { $.CONSUME(t.Semicolon); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-9.html#jls-ConstantModifier + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-9.html#jls-ConstantModifier $.RULE("constantModifier", () => { $.OR([ { ALT: () => $.SUBRULE($.annotation) }, @@ -102,7 +102,7 @@ export function defineRules($, t) { ]); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-9.html#jls-InterfaceMethodDeclaration + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-9.html#jls-InterfaceMethodDeclaration $.RULE("interfaceMethodDeclaration", () => { $.MANY(() => { $.SUBRULE($.interfaceMethodModifier); @@ -111,7 +111,7 @@ export function defineRules($, t) { $.SUBRULE($.methodBody); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-9.html#jls-InterfaceMethodModifier + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-9.html#jls-InterfaceMethodModifier $.RULE("interfaceMethodModifier", () => { $.OR([ { ALT: () => $.SUBRULE($.annotation) }, @@ -124,28 +124,28 @@ export function defineRules($, t) { ]); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-9.html#jls-AnnotationTypeDeclaration - $.RULE("annotationTypeDeclaration", () => { + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-9.html#jls-AnnotationInterfaceDeclaration + $.RULE("annotationInterfaceDeclaration", () => { // Spec Deviation: The "interfaceModifier" prefix was extracted to the "interfaceDeclaration" $.CONSUME(t.At); $.CONSUME(t.Interface); $.SUBRULE($.typeIdentifier); - $.SUBRULE($.annotationTypeBody); + $.SUBRULE($.annotationInterfaceBody); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-9.html#jls-AnnotationTypeBody - $.RULE("annotationTypeBody", () => { + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-9.html#jls-AnnotationInterfaceBody + $.RULE("annotationInterfaceBody", () => { $.CONSUME(t.LCurly); $.MANY(() => { - $.SUBRULE($.annotationTypeMemberDeclaration); + $.SUBRULE($.annotationInterfaceMemberDeclaration); }); $.CONSUME(t.RCurly); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-9.html#jls-InterfaceMemberDeclaration - $.RULE("annotationTypeMemberDeclaration", () => { + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-9.html#jls-AnnotationInterfaceMemberDeclaration + $.RULE("annotationInterfaceMemberDeclaration", () => { $.OR([ - { ALT: () => $.SUBRULE($.annotationTypeElementDeclaration) }, + { ALT: () => $.SUBRULE($.annotationInterfaceElementDeclaration) }, { ALT: () => $.SUBRULE($.constantDeclaration) }, { ALT: () => $.SUBRULE($.classDeclaration) }, { ALT: () => $.SUBRULE($.interfaceDeclaration) }, @@ -153,10 +153,10 @@ export function defineRules($, t) { ]); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-9.html#jls-AnnotationTypeElementDeclaration - $.RULE("annotationTypeElementDeclaration", () => { + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-9.html#jls-AnnotationInterfaceElementDeclaration + $.RULE("annotationInterfaceElementDeclaration", () => { $.MANY(() => { - $.SUBRULE($.annotationTypeElementModifier); + $.SUBRULE($.annotationInterfaceElementModifier); }); $.SUBRULE($.unannType); $.CONSUME(t.Identifier); @@ -171,8 +171,8 @@ export function defineRules($, t) { $.CONSUME(t.Semicolon); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-9.html#jls-AnnotationTypeElementModifier - $.RULE("annotationTypeElementModifier", () => { + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-9.html#jls-AnnotationInterfaceElementModifier + $.RULE("annotationInterfaceElementModifier", () => { $.OR([ { ALT: () => $.SUBRULE($.annotation) }, { ALT: () => $.CONSUME(t.Public) }, @@ -180,13 +180,13 @@ export function defineRules($, t) { ]); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-9.html#jls-DefaultValue + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-9.html#jls-DefaultValue $.RULE("defaultValue", () => { $.CONSUME(t.Default); $.SUBRULE($.elementValue); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-9.html#jls-Annotation + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-9.html#jls-Annotation $.RULE("annotation", () => { // Spec Deviation: The common prefix for all three annotation types was extracted to this rule. // This was done to avoid the use of backtracking for performance reasons. @@ -194,17 +194,15 @@ export function defineRules($, t) { $.SUBRULE($.typeName); // If this optional grammar was not invoked we have a markerAnnotation - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-9.html#jls-MarkerAnnotation + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-9.html#jls-MarkerAnnotation $.OPTION(() => { $.CONSUME(t.LBrace); $.OR({ DEF: [ - // normal annotation - https://docs.oracle.com/javase/specs/jls/se16/html/jls-9.html#jls-NormalAnnotation + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-9.html#jls-NormalAnnotation { ALT: () => $.SUBRULE($.elementValuePairList) }, - // Single Element Annotation - https://docs.oracle.com/javase/specs/jls/se16/html/jls-9.html#jls-SingleElementAnnotation - { - ALT: () => $.SUBRULE($.elementValue) - }, + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-9.html#jls-SingleElementAnnotation + { ALT: () => $.SUBRULE($.elementValue) }, { ALT: () => { /* empty normal annotation contents */ @@ -217,7 +215,7 @@ export function defineRules($, t) { }); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-9.html#jls-ElementValuePairList + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-9.html#jls-ElementValuePairList $.RULE("elementValuePairList", () => { $.SUBRULE($.elementValuePair); $.MANY(() => { @@ -226,24 +224,23 @@ export function defineRules($, t) { }); }); + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-9.html#jls-ElementValuePair $.RULE("elementValuePair", () => { $.CONSUME(t.Identifier); $.CONSUME(t.Equals); $.SUBRULE($.elementValue); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-9.html#jls-ElementValue + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-9.html#jls-ElementValue $.RULE("elementValue", () => { $.OR([ - // Spec Deviation: "conditionalExpression" replaced with "expression" - // Because we cannot differentiate between the two using fixed lookahead. - { ALT: () => $.SUBRULE($.expression) }, + { ALT: () => $.SUBRULE($.conditionalExpression) }, { ALT: () => $.SUBRULE($.elementValueArrayInitializer) }, { ALT: () => $.SUBRULE($.annotation) } ]); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-9.html#jls-ElementValueArrayInitializer + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-9.html#jls-ElementValueArrayInitializer $.RULE("elementValueArrayInitializer", () => { $.CONSUME(t.LCurly); $.OPTION(() => { @@ -255,7 +252,7 @@ export function defineRules($, t) { $.CONSUME(t.RCurly); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-9.html#jls-ElementValueList + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-9.html#jls-ElementValueList $.RULE("elementValueList", () => { $.SUBRULE($.elementValue); $.MANY({ diff --git a/packages/java-parser/src/productions/lexical-structure.js b/packages/java-parser/src/productions/lexical-structure.js index b99dacfe..6cdb6bda 100644 --- a/packages/java-parser/src/productions/lexical-structure.js +++ b/packages/java-parser/src/productions/lexical-structure.js @@ -1,5 +1,5 @@ export function defineRules($, t) { - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-3.html#jls-Literal + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-3.html#jls-Literal $.RULE("literal", () => { $.OR([ { ALT: () => $.SUBRULE($.integerLiteral) }, @@ -12,7 +12,7 @@ export function defineRules($, t) { ]); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-3.html#jls-IntegerLiteral + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-3.html#jls-IntegerLiteral $.RULE("integerLiteral", () => { $.OR([ { ALT: () => $.CONSUME(t.DecimalLiteral) }, @@ -22,7 +22,7 @@ export function defineRules($, t) { ]); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-3.html#jls-FloatingPointLiteral + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-3.html#jls-FloatingPointLiteral $.RULE("floatingPointLiteral", () => { $.OR([ { ALT: () => $.CONSUME(t.FloatLiteral) }, @@ -30,7 +30,7 @@ export function defineRules($, t) { ]); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-3.html#jls-BooleanLiteral + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-3.html#jls-BooleanLiteral $.RULE("booleanLiteral", () => { $.OR([{ ALT: () => $.CONSUME(t.True) }, { ALT: () => $.CONSUME(t.False) }]); }); diff --git a/packages/java-parser/src/productions/names.js b/packages/java-parser/src/productions/names.js index b4e599ff..7eafe29d 100644 --- a/packages/java-parser/src/productions/names.js +++ b/packages/java-parser/src/productions/names.js @@ -1,6 +1,6 @@ import { tokenMatcher } from "chevrotain"; export function defineRules($, t) { - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-6.html#jls-ModuleName + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-6.html#jls-ModuleName $.RULE("moduleName", () => { $.CONSUME(t.Identifier); $.MANY(() => { @@ -9,7 +9,7 @@ export function defineRules($, t) { }); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-6.html#jls-PackageName + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-6.html#jls-PackageName $.RULE("packageName", () => { $.CONSUME(t.Identifier); $.MANY(() => { @@ -18,7 +18,7 @@ export function defineRules($, t) { }); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-6.html#jls-TypeName + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-6.html#jls-TypeName $.RULE("typeName", () => { // Spec Deviation: The last Identifier in a "typeName" may not be be "var" // But the parser does not check for that. @@ -32,7 +32,7 @@ export function defineRules($, t) { }); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-6.html#jls-ExpressionName + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-6.html#jls-ExpressionName $.RULE("expressionName", () => { // Spec Deviation: in-lined "ambiguousName" to be LL(K) $.CONSUME(t.Identifier); @@ -48,12 +48,12 @@ export function defineRules($, t) { }); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-6.html#jls-MethodName + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-6.html#jls-MethodName $.RULE("methodName", () => { $.CONSUME(t.Identifier); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-6.html#jls-PackageOrTypeName + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-6.html#jls-PackageOrTypeName $.RULE("packageOrTypeName", () => { $.CONSUME(t.Identifier); $.MANY({ @@ -70,7 +70,7 @@ export function defineRules($, t) { }); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-6.html#jls-AmbiguousName + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-6.html#jls-AmbiguousName $.RULE("ambiguousName", () => { $.CONSUME(t.Identifier); $.MANY(() => { diff --git a/packages/java-parser/src/productions/packages-and-modules.js b/packages/java-parser/src/productions/packages-and-modules.js index 0d31df26..f5733737 100644 --- a/packages/java-parser/src/productions/packages-and-modules.js +++ b/packages/java-parser/src/productions/packages-and-modules.js @@ -6,8 +6,8 @@ export function defineRules($, t) { * both can have multiple class or interface declarations, both were combined * in the ordinaryCompilationUnit rule * - * https://docs.oracle.com/javase/specs/jls/se21/html/jls-7.html#jls-7.3 - * https://docs.oracle.com/javase/specs/jls/se21/preview/specs/unnamed-classes-instance-main-methods-jls.html + * https://docs.oracle.com/javase/specs/jls/se22/html/jls-7.html#jls-CompilationUnit + * https://docs.oracle.com/javase/specs/jls/se22/preview/specs/implicitly-declared-classes-instance-main-methods-jls.html */ $.RULE("compilationUnit", () => { $.OR([ @@ -18,7 +18,7 @@ export function defineRules($, t) { $.CONSUME(EOF); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-7.html#jls-OrdinaryCompilationUnit + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-7.html#jls-OrdinaryCompilationUnit $.RULE("ordinaryCompilationUnit", () => { $.OPTION(() => $.SUBRULE($.packageDeclaration)); $.MANY(() => { @@ -29,7 +29,7 @@ export function defineRules($, t) { }); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-7.html#jls-ModularCompilationUnit + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-7.html#jls-ModularCompilationUnit $.RULE("modularCompilationUnit", () => { $.MANY(() => { $.SUBRULE($.importDeclaration); @@ -37,7 +37,7 @@ export function defineRules($, t) { $.SUBRULE($.moduleDeclaration); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-7.html#jls-PackageDeclaration + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-7.html#jls-PackageDeclaration $.RULE("packageDeclaration", () => { $.MANY(() => { $.SUBRULE($.packageModifier); @@ -51,12 +51,12 @@ export function defineRules($, t) { $.CONSUME2(t.Semicolon); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-7.html#jls-PackageModifier + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-7.html#jls-PackageModifier $.RULE("packageModifier", () => { $.SUBRULE($.annotation); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-7.html#jls-ImportDeclaration + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-7.html#jls-ImportDeclaration $.RULE("importDeclaration", () => { // Spec Deviation: The spec defines four different kinds of import declarations. // Our grammar however combines those into a single rule due to difficulties @@ -96,8 +96,8 @@ export function defineRules($, t) { * As a result, the typeDeclaration combine TopLevelClassOrInterfaceDeclaration and includes fields and method declarations as well * to handle unnamed class compilation unit * - * https://docs.oracle.com/javase/specs/jls/se21/html/jls-7.html#jls-TopLevelClassOrInterfaceDeclaration - * https://docs.oracle.com/javase/specs/jls/se21/preview/specs/unnamed-classes-instance-main-methods-jls.html + * https://docs.oracle.com/javase/specs/jls/se22/html/jls-7.html#jls-TopLevelClassOrInterfaceDeclaration + * https://docs.oracle.com/javase/specs/jls/se22/preview/specs/implicitly-declared-classes-instance-main-methods-jls.html */ $.RULE("typeDeclaration", () => { $.OR([ @@ -109,7 +109,7 @@ export function defineRules($, t) { ]); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-7.html#jls-ModuleDeclaration + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-7.html#jls-ModuleDeclaration $.RULE("moduleDeclaration", () => { $.MANY(() => { $.SUBRULE($.annotation); @@ -130,7 +130,7 @@ export function defineRules($, t) { $.CONSUME(t.RCurly); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-7.html#jls-ModuleDirective + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-7.html#jls-ModuleDirective $.RULE("moduleDirective", () => { // Spec Deviation: Each of the alternatives of "moduleDirective" was extracted // to its own nonTerminal, to reduce verbosity. @@ -149,7 +149,7 @@ export function defineRules($, t) { $.MANY({ GATE: () => { /** - * https://docs.oracle.com/javase/specs/jls/se16/html/jls-3.html#jls-3.9 - + * https://docs.oracle.com/javase/specs/jls/se22/html/jls-3.html#jls-3.9 - * There is one exception: immediately to the right of the character sequence `requires` in the ModuleDirective production, * the character sequence `transitive` is tokenized as a keyword unless it is followed by a separator, * in which case it is tokenized as an identifier. @@ -217,7 +217,7 @@ export function defineRules($, t) { $.CONSUME(t.Semicolon); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-7.html#jls-RequiresModifier + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-7.html#jls-RequiresModifier $.RULE("requiresModifier", () => { $.OR([ { ALT: () => $.CONSUME(t.Transitive) }, diff --git a/packages/java-parser/src/productions/types-values-and-variables.js b/packages/java-parser/src/productions/types-values-and-variables.js index 12589041..3adadebe 100644 --- a/packages/java-parser/src/productions/types-values-and-variables.js +++ b/packages/java-parser/src/productions/types-values-and-variables.js @@ -3,7 +3,7 @@ export function defineRules($, t) { // Productions from ยง4 (Types, Values, and Variables) // --------------------- - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-4.html#jls-PrimitiveType + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-4.html#jls-PrimitiveType $.RULE("primitiveType", () => { $.MANY(() => { $.SUBRULE($.annotation); @@ -14,7 +14,7 @@ export function defineRules($, t) { ]); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-4.html#jls-NumericType + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-4.html#jls-NumericType $.RULE("numericType", () => { $.OR([ { ALT: () => $.SUBRULE($.integralType) }, @@ -22,7 +22,7 @@ export function defineRules($, t) { ]); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-4.html#jls-IntegralType + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-4.html#jls-IntegralType $.RULE("integralType", () => { $.OR([ { ALT: () => $.CONSUME(t.Byte) }, @@ -33,7 +33,7 @@ export function defineRules($, t) { ]); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-4.html#jls-FloatingPointType + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-4.html#jls-FloatingPointType $.RULE("floatingPointType", () => { $.OR([ { ALT: () => $.CONSUME(t.Float) }, @@ -41,7 +41,7 @@ export function defineRules($, t) { ]); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-4.html#jls-ReferenceType + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-4.html#jls-ReferenceType $.RULE("referenceType", () => { $.MANY(() => { // Spec Deviation: by extracting the common "annotation" prefix @@ -75,7 +75,7 @@ export function defineRules($, t) { }); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-4.html#jls-ClassOrInterfaceType + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-4.html#jls-ClassOrInterfaceType $.RULE("classOrInterfaceType", () => { // Spec Deviation: The spec says: "classType | interfaceType" but "interfaceType" // is not mentioned in the parser because it is identical to "classType" @@ -83,7 +83,7 @@ export function defineRules($, t) { $.SUBRULE($.classType); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-4.html#jls-ClassType + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-4.html#jls-ClassType $.RULE("classType", () => { // Spec Deviation: Refactored left recursion and alternation to iterations $.MANY(() => { @@ -104,11 +104,12 @@ export function defineRules($, t) { }); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-4.html#jls-InterfaceType + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-4.html#jls-InterfaceType $.RULE("interfaceType", () => { $.SUBRULE($.classType); }); + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-4.html#jls-TypeVariable $.RULE("typeVariable", () => { $.MANY(() => { $.SUBRULE($.annotation); @@ -117,7 +118,7 @@ export function defineRules($, t) { $.CONSUME(t.Identifier); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-4.html#jls-Dims + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-4.html#jls-Dims $.RULE("dims", () => { $.MANY(() => { $.SUBRULE($.annotation); @@ -136,7 +137,7 @@ export function defineRules($, t) { }); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-4.html#jls-TypeParameter + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-4.html#jls-TypeParameter $.RULE("typeParameter", () => { $.MANY(() => { $.SUBRULE($.typeParameterModifier); @@ -147,36 +148,36 @@ export function defineRules($, t) { }); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-4.html#jls-TypeParameterModifier + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-4.html#jls-TypeParameterModifier $.RULE("typeParameterModifier", () => { $.SUBRULE($.annotation); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-4.html#jls-TypeBound + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-4.html#jls-TypeBound $.RULE("typeBound", () => { $.CONSUME(t.Extends); // Spec Deviation: The alternative with "TypeVariable" is not specified // because it's syntax is included in "classOrInterfaceType" $.SUBRULE($.classOrInterfaceType); - $.MANY2(() => { + $.MANY(() => { $.SUBRULE($.additionalBound); }); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-4.html#jls-AdditionalBound + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-4.html#jls-AdditionalBound $.RULE("additionalBound", () => { $.CONSUME(t.And); $.SUBRULE($.interfaceType); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-4.html#jls-TypeArguments + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-4.html#jls-TypeArguments $.RULE("typeArguments", () => { $.CONSUME(t.Less); $.SUBRULE($.typeArgumentList); $.CONSUME(t.Greater); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-4.html#jls-TypeArgumentList + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-4.html#jls-TypeArgumentList $.RULE("typeArgumentList", () => { $.SUBRULE($.typeArgument); $.MANY(() => { @@ -185,7 +186,7 @@ export function defineRules($, t) { }); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-4.html#jls-TypeArgument + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-4.html#jls-TypeArgument $.RULE("typeArgument", () => { // TODO: performance: evaluate flipping the order of alternatives $.OR([ @@ -194,7 +195,7 @@ export function defineRules($, t) { ]); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-4.html#jls-Wildcard + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-4.html#jls-Wildcard $.RULE("wildcard", () => { $.MANY(() => { $.SUBRULE($.annotation); @@ -205,7 +206,7 @@ export function defineRules($, t) { }); }); - // https://docs.oracle.com/javase/specs/jls/se16/html/jls-4.html#jls-WildcardBounds + // https://docs.oracle.com/javase/specs/jls/se22/html/jls-4.html#jls-WildcardBounds $.RULE("wildcardBounds", () => { // TODO: consider in-lining suffix into the alternatives to match the spec more strongly $.OR([ diff --git a/packages/java-parser/test/pattern-matching/unnamed-variables-and-patterns-spec.js b/packages/java-parser/test/pattern-matching/unnamed-variables-and-patterns-spec.js index a2526a0f..bfe5524d 100644 --- a/packages/java-parser/test/pattern-matching/unnamed-variables-and-patterns-spec.js +++ b/packages/java-parser/test/pattern-matching/unnamed-variables-and-patterns-spec.js @@ -134,4 +134,20 @@ describe("Unnamed Variables & Patterns", () => { `; expect(() => javaParser.parse(input, "switchStatement")).to.not.throw(); }); + + it("should parse switch label with multiple unnamed patterns", () => { + const input = ` + switch (this) { + case A _, B _, C _ -> "A lot"; + } + `; + expect(() => javaParser.parse(input, "switchStatement")).to.not.throw(); + }); + + it("should parse lambda expression with multiple unnamed parameters", () => { + const input = ` + (_, _) -> {} + `; + expect(() => javaParser.parse(input, "lambdaExpression")).to.not.throw(); + }); }); diff --git a/packages/prettier-plugin-java/src/options.js b/packages/prettier-plugin-java/src/options.js index ce87489e..67595f7a 100644 --- a/packages/prettier-plugin-java/src/options.js +++ b/packages/prettier-plugin-java/src/options.js @@ -27,6 +27,7 @@ export default { { value: "switchLabel" }, { value: "switchRule" }, { value: "caseConstant" }, + { value: "casePattern" }, { value: "whileStatement" }, { value: "doStatement" }, { value: "forStatement" }, @@ -57,8 +58,8 @@ export default { { value: "classModifier" }, { value: "typeParameters" }, { value: "typeParameterList" }, - { value: "superclass" }, - { value: "superinterfaces" }, + { value: "classExtends" }, + { value: "classImplements" }, { value: "interfaceTypeList" }, { value: "classPermits" }, { value: "classBody" }, @@ -124,13 +125,14 @@ export default { { value: "lambdaParameters" }, { value: "lambdaParametersWithBraces" }, { value: "lambdaParameterList" }, - { value: "inferredLambdaParameterList" }, - { value: "explicitLambdaParameterList" }, - { value: "lambdaParameter" }, + { value: "conciseLambdaParameterList" }, + { value: "normalLambdaParameterList" }, + { value: "normalLambdaParameter" }, { value: "regularLambdaParameter" }, { value: "lambdaParameterType" }, + { value: "conciseLambdaParameter" }, { value: "lambdaBody" }, - { value: "ternaryExpression" }, + { value: "conditionalExpression" }, { value: "binaryExpression" }, { value: "unaryExpression" }, { value: "unaryExpressionNotPlusMinus" }, @@ -153,8 +155,8 @@ export default { { value: "methodInvocationSuffix" }, { value: "argumentList" }, { value: "arrayCreationExpression" }, - { value: "arrayCreationDefaultInitSuffix" }, - { value: "arrayCreationExplicitInitSuffix" }, + { value: "arrayCreationExpressionWithoutInitializerSuffix" }, + { value: "arrayCreationWithInitializerSuffix" }, { value: "dimExprs" }, { value: "dimExpr" }, { value: "classLiteralSuffix" }, @@ -170,13 +172,13 @@ export default { { value: "recordPattern" }, { value: "componentPatternList" }, { value: "componentPattern" }, - { value: "unnamedPattern" }, + { value: "matchAllPattern" }, { value: "guard" }, { value: "isRefTypeInMethodRef" }, { value: "interfaceDeclaration" }, { value: "normalInterfaceDeclaration" }, { value: "interfaceModifier" }, - { value: "extendsInterfaces" }, + { value: "interfaceExtends" }, { value: "interfacePermits" }, { value: "interfaceBody" }, { value: "interfaceMemberDeclaration" }, @@ -184,11 +186,11 @@ export default { { value: "constantModifier" }, { value: "interfaceMethodDeclaration" }, { value: "interfaceMethodModifier" }, - { value: "annotationTypeDeclaration" }, - { value: "annotationTypeBody" }, - { value: "annotationTypeMemberDeclaration" }, - { value: "annotationTypeElementDeclaration" }, - { value: "annotationTypeElementModifier" }, + { value: "annotationInterfaceDeclaration" }, + { value: "annotationInterfaceBody" }, + { value: "annotationInterfaceMemberDeclaration" }, + { value: "annotationInterfaceElementDeclaration" }, + { value: "annotationInterfaceElementModifier" }, { value: "defaultValue" }, { value: "annotation" }, { value: "elementValuePairList" }, diff --git a/packages/prettier-plugin-java/src/printers/blocks-and-statements.ts b/packages/prettier-plugin-java/src/printers/blocks-and-statements.ts index 9d70fe16..8b7cda35 100644 --- a/packages/prettier-plugin-java/src/printers/blocks-and-statements.ts +++ b/packages/prettier-plugin-java/src/printers/blocks-and-statements.ts @@ -25,6 +25,7 @@ import { BlockStatementsCtx, BreakStatementCtx, CaseConstantCtx, + CasePatternCtx, CatchClauseCtx, CatchesCtx, CatchFormalParameterCtx, @@ -292,14 +293,14 @@ export class BlocksAndStatementPrettierVisitor extends BaseCstPrettierPrinter { return group( indent(join(" ", [Case!, rejectAndJoinSeps(commas, caseConstants)])) ); - } else if (ctx.pattern) { - const patterns = this.mapVisit(ctx.pattern); + } else if (ctx.casePattern) { + const casePatterns = this.mapVisit(ctx.casePattern); const guard = this.visit(ctx.guard); - const multiplePatterns = ctx.pattern.length > 1; + const multiplePatterns = ctx.casePattern.length > 1; const separator = multiplePatterns ? line : " "; const contents = join(separator, [ Case!, - rejectAndJoinSeps(commas, patterns) + rejectAndJoinSeps(commas, casePatterns) ]); return group( rejectAndJoin(separator, [ @@ -330,6 +331,10 @@ export class BlocksAndStatementPrettierVisitor extends BaseCstPrettierPrinter { return this.visitSingle(ctx); } + casePattern(ctx: CasePatternCtx) { + return this.visitSingle(ctx); + } + whileStatement(ctx: WhileStatementCtx) { const expression = this.visit(ctx.expression); const statement = this.visit(ctx.statement[0], { @@ -415,9 +420,7 @@ export class BlocksAndStatementPrettierVisitor extends BaseCstPrettierPrinter { } enhancedForStatement(ctx: EnhancedForStatementCtx) { - const variableModifiers = this.mapVisit(ctx.variableModifier); - const localVariableType = this.visit(ctx.localVariableType); - const variableDeclaratorId = this.visit(ctx.variableDeclaratorId); + const localVariableDeclaration = this.visit(ctx.localVariableDeclaration); const expression = this.visit(ctx.expression); const statement = this.visit(ctx.statement[0], { allowEmptyStatement: true @@ -426,11 +429,7 @@ export class BlocksAndStatementPrettierVisitor extends BaseCstPrettierPrinter { return rejectAndConcat([ rejectAndJoin(" ", [ctx.For[0], ctx.LBrace[0]]), - rejectAndJoin(" ", [ - rejectAndJoin(" ", variableModifiers), - localVariableType, - variableDeclaratorId - ]), + localVariableDeclaration, concat([" ", ctx.Colon[0], " "]), expression, concat([ctx.RBrace[0], statementSeparator]), diff --git a/packages/prettier-plugin-java/src/printers/classes.ts b/packages/prettier-plugin-java/src/printers/classes.ts index 8c906fb9..5cde0be6 100644 --- a/packages/prettier-plugin-java/src/printers/classes.ts +++ b/packages/prettier-plugin-java/src/printers/classes.ts @@ -31,6 +31,8 @@ import { ClassBodyCtx, ClassBodyDeclarationCtx, ClassDeclarationCtx, + ClassExtendsCtx, + ClassImplementsCtx, ClassMemberDeclarationCtx, ClassModifierCtx, ClassPermitsCtx, @@ -73,8 +75,6 @@ import { ResultCtx, SimpleTypeNameCtx, StaticInitializerCtx, - SuperclassCtx, - SuperinterfacesCtx, ThrowsCtx, TypeParameterListCtx, TypeParametersCtx, @@ -128,20 +128,20 @@ export class ClassesPrettierVisitor extends BaseCstPrettierPrinter { normalClassDeclaration(ctx: NormalClassDeclarationCtx) { const name = this.visit(ctx.typeIdentifier); const optionalTypeParams = this.visit(ctx.typeParameters); - const optionalSuperClasses = this.visit(ctx.superclass); - const optionalSuperInterfaces = this.visit(ctx.superinterfaces); + const optionalClassExtends = this.visit(ctx.classExtends); + const optionalClassImplements = this.visit(ctx.classImplements); const optionalClassPermits = this.visit(ctx.classPermits); const body = this.visit(ctx.classBody, { isNormalClassDeclaration: true }); let superClassesPart: Doc = ""; - if (optionalSuperClasses) { - superClassesPart = indent(rejectAndConcat([line, optionalSuperClasses])); + if (optionalClassExtends) { + superClassesPart = indent(rejectAndConcat([line, optionalClassExtends])); } let superInterfacesPart: Doc = ""; - if (optionalSuperInterfaces) { + if (optionalClassImplements) { superInterfacesPart = indent( - rejectAndConcat([line, optionalSuperInterfaces]) + rejectAndConcat([line, optionalClassImplements]) ); } @@ -190,11 +190,11 @@ export class ClassesPrettierVisitor extends BaseCstPrettierPrinter { return group(rejectAndJoinSeps(commas, typeParameter)); } - superclass(ctx: SuperclassCtx) { + classExtends(ctx: ClassExtendsCtx) { return join(" ", [ctx.Extends[0], this.visit(ctx.classType)]); } - superinterfaces(ctx: SuperinterfacesCtx) { + classImplements(ctx: ClassImplementsCtx) { const interfaceTypeList = this.visit(ctx.interfaceTypeList); return group( @@ -333,9 +333,9 @@ export class ClassesPrettierVisitor extends BaseCstPrettierPrinter { .lambdaExpression !== undefined || // Ternary Expression (ctx.variableInitializer![0].children.expression![0].children - .ternaryExpression !== undefined && + .conditionalExpression !== undefined && ctx.variableInitializer![0].children.expression![0].children - .ternaryExpression[0].children.QuestionMark !== undefined) + .conditionalExpression[0].children.QuestionMark !== undefined) ) { const groupId = Symbol("assignment"); return group([ @@ -350,11 +350,11 @@ export class ClassesPrettierVisitor extends BaseCstPrettierPrinter { if ( ctx.variableInitializer![0].children.expression![0].children - .ternaryExpression !== undefined + .conditionalExpression !== undefined ) { const unaryExpressions = ctx.variableInitializer![0].children.expression![0].children - .ternaryExpression[0].children.binaryExpression[0].children + .conditionalExpression[0].children.binaryExpression[0].children .unaryExpression; const firstPrimary = unaryExpressions[0].children.primary[0]; @@ -398,7 +398,7 @@ export class ClassesPrettierVisitor extends BaseCstPrettierPrinter { .methodInvocationSuffix !== undefined; const isUniqueUnaryExpression = ctx.variableInitializer![0].children.expression![0].children - .ternaryExpression[0].children.binaryExpression[0].children + .conditionalExpression[0].children.binaryExpression[0].children .unaryExpression.length === 1; const isUniqueMethodInvocation = @@ -753,7 +753,7 @@ export class ClassesPrettierVisitor extends BaseCstPrettierPrinter { } simpleTypeName(ctx: SimpleTypeNameCtx) { - return printTokenWithComments(this.getSingle(ctx) as IToken); + return this.visitSingle(ctx); } constructorBody(ctx: ConstructorBodyCtx) { @@ -817,14 +817,14 @@ export class ClassesPrettierVisitor extends BaseCstPrettierPrinter { enumDeclaration(ctx: EnumDeclarationCtx) { const classModifier = this.mapVisit(ctx.classModifier); const typeIdentifier = this.visit(ctx.typeIdentifier); - const superinterfaces = this.visit(ctx.superinterfaces); + const classImplements = this.visit(ctx.classImplements); const enumBody = this.visit(ctx.enumBody); return rejectAndJoin(" ", [ join(" ", classModifier), ctx.Enum[0], typeIdentifier, - superinterfaces, + classImplements, enumBody ]); } @@ -937,10 +937,10 @@ export class ClassesPrettierVisitor extends BaseCstPrettierPrinter { const recordHeader = this.visit(ctx.recordHeader); let superInterfacesPart: Doc = ""; - const optionalSuperInterfaces = this.visit(ctx.superinterfaces); - if (optionalSuperInterfaces) { + const optionalClassImplements = this.visit(ctx.classImplements); + if (optionalClassImplements) { superInterfacesPart = indent( - rejectAndConcat([line, optionalSuperInterfaces]) + rejectAndConcat([line, optionalClassImplements]) ); } diff --git a/packages/prettier-plugin-java/src/printers/expressions.ts b/packages/prettier-plugin-java/src/printers/expressions.ts index e3bd9742..c30ad086 100644 --- a/packages/prettier-plugin-java/src/printers/expressions.ts +++ b/packages/prettier-plugin-java/src/printers/expressions.ts @@ -1,27 +1,28 @@ import { ArgumentListCtx, ArrayAccessSuffixCtx, - ArrayCreationDefaultInitSuffixCtx, - ArrayCreationExplicitInitSuffixCtx, ArrayCreationExpressionCtx, + ArrayCreationWithInitializerSuffixCtx, + ArrayCreationExpressionWithoutInitializerSuffixCtx, BinaryExpressionCtx, CastExpressionCtx, ClassLiteralSuffixCtx, ClassOrInterfaceTypeToInstantiateCtx, ComponentPatternListCtx, ComponentPatternCtx, + ConciseLambdaParameterCtx, + ConciseLambdaParameterListCtx, + ConditionalExpressionCtx, DiamondCtx, DimExprCtx, DimExprsCtx, EmbeddedExpressionCtx, - ExplicitLambdaParameterListCtx, ExpressionCtx, FqnOrRefTypeCtx, FqnOrRefTypePartCommonCtx, FqnOrRefTypePartFirstCtx, FqnOrRefTypePartRestCtx, GuardCtx, - InferredLambdaParameterListCtx, IToken, LambdaBodyCtx, LambdaExpressionCtx, @@ -30,9 +31,11 @@ import { LambdaParametersCtx, LambdaParametersWithBracesCtx, LambdaParameterTypeCtx, + MatchAllPatternCtx, MethodInvocationSuffixCtx, MethodReferenceSuffixCtx, NewExpressionCtx, + NormalLambdaParameterListCtx, ParenthesisExpressionCtx, PatternCtx, PrimaryCtx, @@ -45,13 +48,11 @@ import { StringTemplateCtx, TemplateArgumentCtx, TemplateCtx, - TernaryExpressionCtx, TextBlockTemplateCtx, TypeArgumentsOrDiamondCtx, TypePatternCtx, UnaryExpressionCtx, UnaryExpressionNotPlusMinusCtx, - UnnamedPatternCtx, UnqualifiedClassInstanceCreationExpressionCtx } from "java-parser/api"; @@ -65,7 +66,7 @@ import { handleCommentsBinaryExpression, handleCommentsParameters } from "./comments/handle-comments.js"; -import { concat, dedent, group, indent, join } from "./prettier-builder.js"; +import { concat, dedent, group, indent } from "./prettier-builder.js"; import { binary, findDeepElementInPartsArray, @@ -129,10 +130,10 @@ export class ExpressionsPrettierVisitor extends BaseCstPrettierPrinter { lambdaParametersWithBraces(ctx: LambdaParametersWithBracesCtx) { const lambdaParameters = - ctx.lambdaParameterList?.[0].children.explicitLambdaParameterList?.[0] - .children.lambdaParameter ?? - ctx.lambdaParameterList?.[0].children.inferredLambdaParameterList?.[0] - .children.Identifier ?? + ctx.lambdaParameterList?.[0].children.normalLambdaParameterList?.[0] + .children.normalLambdaParameter ?? + ctx.lambdaParameterList?.[0].children.conciseLambdaParameterList?.[0] + .children.conciseLambdaParameter ?? []; handleCommentsParameters(ctx.LBrace[0], lambdaParameters, ctx.RBrace[0]); const lambdaParameterList = this.visit(ctx.lambdaParameterList); @@ -170,18 +171,19 @@ export class ExpressionsPrettierVisitor extends BaseCstPrettierPrinter { return this.visitSingle(ctx); } - inferredLambdaParameterList(ctx: InferredLambdaParameterListCtx) { + conciseLambdaParameterList(ctx: ConciseLambdaParameterListCtx) { + const conciseLambdaParameters = this.mapVisit(ctx.conciseLambdaParameter); const commas = ctx.Comma?.map(comma => concat([comma, line])); - return rejectAndJoinSeps(commas, ctx.Identifier); + return rejectAndJoinSeps(commas, conciseLambdaParameters); } - explicitLambdaParameterList(ctx: ExplicitLambdaParameterListCtx) { - const lambdaParameter = this.mapVisit(ctx.lambdaParameter); + normalLambdaParameterList(ctx: NormalLambdaParameterListCtx) { + const normalLambdaParameter = this.mapVisit(ctx.normalLambdaParameter); const commas = ctx.Comma?.map(comma => concat([comma, line])); - return rejectAndJoinSeps(commas, lambdaParameter); + return rejectAndJoinSeps(commas, normalLambdaParameter); } - lambdaParameter(ctx: LambdaParameterCtx) { + normalLambdaParameter(ctx: LambdaParameterCtx) { return this.visitSingle(ctx); } @@ -204,11 +206,15 @@ export class ExpressionsPrettierVisitor extends BaseCstPrettierPrinter { return printTokenWithComments(this.getSingle(ctx) as IToken); } + conciseLambdaParameter(ctx: ConciseLambdaParameterCtx) { + return printTokenWithComments(this.getSingle(ctx) as IToken); + } + lambdaBody(ctx: LambdaBodyCtx) { return this.visitSingle(ctx); } - ternaryExpression(ctx: TernaryExpressionCtx, params: any) { + conditionalExpression(ctx: ConditionalExpressionCtx, params: any) { const binaryExpression = this.visit(ctx.binaryExpression, params); if (ctx.QuestionMark) { const expression1 = this.visit(ctx.expression![0]); @@ -671,20 +677,24 @@ export class ExpressionsPrettierVisitor extends BaseCstPrettierPrinter { const type = ctx.primitiveType ? this.visit(ctx.primitiveType) : this.visit(ctx.classOrInterfaceType); - const suffix = ctx.arrayCreationDefaultInitSuffix - ? this.visit(ctx.arrayCreationDefaultInitSuffix) - : this.visit(ctx.arrayCreationExplicitInitSuffix); + const suffix = ctx.arrayCreationExpressionWithoutInitializerSuffix + ? this.visit(ctx.arrayCreationExpressionWithoutInitializerSuffix) + : this.visit(ctx.arrayCreationWithInitializerSuffix); return rejectAndConcat([concat([ctx.New[0], " "]), type, suffix]); } - arrayCreationDefaultInitSuffix(ctx: ArrayCreationDefaultInitSuffixCtx) { + arrayCreationExpressionWithoutInitializerSuffix( + ctx: ArrayCreationExpressionWithoutInitializerSuffixCtx + ) { const dimExprs = this.visit(ctx.dimExprs); const dims = this.visit(ctx.dims); return rejectAndConcat([dimExprs, dims]); } - arrayCreationExplicitInitSuffix(ctx: ArrayCreationExplicitInitSuffixCtx) { + arrayCreationWithInitializerSuffix( + ctx: ArrayCreationWithInitializerSuffixCtx + ) { const dims = this.visit(ctx.dims); const arrayInitializer = this.visit(ctx.arrayInitializer); @@ -800,7 +810,7 @@ export class ExpressionsPrettierVisitor extends BaseCstPrettierPrinter { return this.visitSingle(ctx); } - unnamedPattern(ctx: UnnamedPatternCtx) { + matchAllPattern(ctx: MatchAllPatternCtx) { return printTokenWithComments(ctx.Underscore[0]); } @@ -823,7 +833,7 @@ export class ExpressionsPrettierVisitor extends BaseCstPrettierPrinter { lastArgument?.children.lambdaExpression?.[0].children.lambdaBody[0] .children.expression?.[0].children; const lastArgumentLambdaBodyTernaryExpression = - lastArgumentLambdaBodyExpression?.ternaryExpression?.[0].children; + lastArgumentLambdaBodyExpression?.conditionalExpression?.[0].children; return ( !lastArgument?.leadingComments && !lastArgument?.trailingComments && @@ -844,7 +854,7 @@ export class ExpressionsPrettierVisitor extends BaseCstPrettierPrinter { return [ arrayCreationExpression?.classOrInterfaceType?.[0].children.classType[0] .children.typeArguments, - arrayCreationExpression?.arrayCreationExplicitInitSuffix?.[0].children + arrayCreationExpression?.arrayCreationWithInitializerSuffix?.[0].children .arrayInitializer[0].children.variableInitializerList, classInstanceCreationExpression?.classOrInterfaceTypeToInstantiate[0] .children.typeArgumentsOrDiamond?.[0].children.typeArguments, diff --git a/packages/prettier-plugin-java/src/printers/interfaces.ts b/packages/prettier-plugin-java/src/printers/interfaces.ts index ae00d687..4bcd9bac 100644 --- a/packages/prettier-plugin-java/src/printers/interfaces.ts +++ b/packages/prettier-plugin-java/src/printers/interfaces.ts @@ -17,11 +17,11 @@ import { builders } from "prettier/doc"; import { BaseCstPrettierPrinter } from "../base-cst-printer.js"; import { AnnotationCtx, - AnnotationTypeBodyCtx, - AnnotationTypeDeclarationCtx, - AnnotationTypeElementDeclarationCtx, - AnnotationTypeElementModifierCtx, - AnnotationTypeMemberDeclarationCtx, + AnnotationInterfaceBodyCtx, + AnnotationInterfaceDeclarationCtx, + AnnotationInterfaceElementDeclarationCtx, + AnnotationInterfaceElementModifierCtx, + AnnotationInterfaceMemberDeclarationCtx, ConstantDeclarationCtx, ConstantModifierCtx, DefaultValueCtx, @@ -30,9 +30,9 @@ import { ElementValueListCtx, ElementValuePairCtx, ElementValuePairListCtx, - ExtendsInterfacesCtx, InterfaceBodyCtx, InterfaceDeclarationCtx, + InterfaceExtendsCtx, InterfaceMemberDeclarationCtx, InterfaceMethodDeclarationCtx, InterfaceMethodModifierCtx, @@ -53,7 +53,7 @@ export class InterfacesPrettierVisitor extends BaseCstPrettierPrinter { const declaration = ctx.normalInterfaceDeclaration ? this.visit(ctx.normalInterfaceDeclaration) - : this.visit(ctx.annotationTypeDeclaration); + : this.visit(ctx.annotationInterfaceDeclaration); return rejectAndJoin(hardline, [ rejectAndJoin(hardline, firstAnnotations), @@ -64,14 +64,14 @@ export class InterfacesPrettierVisitor extends BaseCstPrettierPrinter { normalInterfaceDeclaration(ctx: NormalInterfaceDeclarationCtx) { const typeIdentifier = this.visit(ctx.typeIdentifier); const typeParameters = this.visit(ctx.typeParameters); - const extendsInterfaces = this.visit(ctx.extendsInterfaces); + const interfaceExtends = this.visit(ctx.interfaceExtends); const optionalInterfacePermits = this.visit(ctx.interfacePermits); const interfaceBody = this.visit(ctx.interfaceBody); - let extendsInterfacesPart: Doc = ""; - if (extendsInterfaces) { - extendsInterfacesPart = indent( - rejectAndConcat([softline, extendsInterfaces]) + let interfaceExtendsPart: Doc = ""; + if (interfaceExtends) { + interfaceExtendsPart = indent( + rejectAndConcat([softline, interfaceExtends]) ); } @@ -87,7 +87,7 @@ export class InterfacesPrettierVisitor extends BaseCstPrettierPrinter { rejectAndJoin(" ", [ ctx.Interface[0], concat([typeIdentifier, typeParameters]), - extendsInterfacesPart, + interfaceExtendsPart, interfacePermits ]) ), @@ -102,7 +102,7 @@ export class InterfacesPrettierVisitor extends BaseCstPrettierPrinter { return printTokenWithComments(this.getSingle(ctx) as IToken); } - extendsInterfaces(ctx: ExtendsInterfacesCtx) { + interfaceExtends(ctx: InterfaceExtendsCtx) { const interfaceTypeList = this.visit(ctx.interfaceTypeList); return group( @@ -199,42 +199,49 @@ export class InterfacesPrettierVisitor extends BaseCstPrettierPrinter { return printTokenWithComments(this.getSingle(ctx) as IToken); } - annotationTypeDeclaration(ctx: AnnotationTypeDeclarationCtx) { + annotationInterfaceDeclaration(ctx: AnnotationInterfaceDeclarationCtx) { const typeIdentifier = this.visit(ctx.typeIdentifier); - const annotationTypeBody = this.visit(ctx.annotationTypeBody); + const annotationInterfaceBody = this.visit(ctx.annotationInterfaceBody); return rejectAndJoin(" ", [ concat([ctx.At[0], ctx.Interface[0]]), typeIdentifier, - annotationTypeBody + annotationInterfaceBody ]); } - annotationTypeBody(ctx: AnnotationTypeBodyCtx) { - const annotationTypeMemberDeclaration = this.mapVisit( - ctx.annotationTypeMemberDeclaration + annotationInterfaceBody(ctx: AnnotationInterfaceBodyCtx) { + const annotationInterfaceMemberDeclaration = this.mapVisit( + ctx.annotationInterfaceMemberDeclaration ); return rejectAndJoin(line, [ indent( rejectAndJoin(line, [ ctx.LCurly[0], - rejectAndJoin(concat([line, line]), annotationTypeMemberDeclaration) + rejectAndJoin( + concat([line, line]), + annotationInterfaceMemberDeclaration + ) ]) ), ctx.RCurly[0] ]); } - annotationTypeMemberDeclaration(ctx: AnnotationTypeMemberDeclarationCtx) { + annotationInterfaceMemberDeclaration( + ctx: AnnotationInterfaceMemberDeclarationCtx + ) { if (ctx.Semicolon) { return printTokenWithComments(this.getSingle(ctx) as IToken); } return this.visitSingle(ctx); } - annotationTypeElementDeclaration(ctx: AnnotationTypeElementDeclarationCtx) { - const modifiers = sortModifiers(ctx.annotationTypeElementModifier); + annotationInterfaceElementDeclaration( + ctx: AnnotationInterfaceElementDeclarationCtx + ) { + const modifiers = sortModifiers(ctx.annotationInterfaceElementModifier); const firstAnnotations = this.mapVisit(modifiers[0]); const otherModifiers = this.mapVisit(modifiers[1]); @@ -261,7 +268,9 @@ export class InterfacesPrettierVisitor extends BaseCstPrettierPrinter { ]); } - annotationTypeElementModifier(ctx: AnnotationTypeElementModifierCtx) { + annotationInterfaceElementModifier( + ctx: AnnotationInterfaceElementModifierCtx + ) { if (ctx.annotation) { return this.visitSingle(ctx); } diff --git a/packages/prettier-plugin-java/src/printers/printer-utils.ts b/packages/prettier-plugin-java/src/printers/printer-utils.ts index 75232c0f..e2cd213f 100644 --- a/packages/prettier-plugin-java/src/printers/printer-utils.ts +++ b/packages/prettier-plugin-java/src/printers/printer-utils.ts @@ -312,7 +312,7 @@ export function isExplicitLambdaParameter(ctx: LambdaParametersWithBracesCtx) { ctx.lambdaParameterList && ctx.lambdaParameterList[0] && ctx.lambdaParameterList[0].children && - ctx.lambdaParameterList[0].children.explicitLambdaParameterList + ctx.lambdaParameterList[0].children.normalLambdaParameterList ); } diff --git a/packages/prettier-plugin-java/test/unit-test/annotation_type_declaration/_input.java b/packages/prettier-plugin-java/test/unit-test/annotation_interface_declaration/_input.java similarity index 90% rename from packages/prettier-plugin-java/test/unit-test/annotation_type_declaration/_input.java rename to packages/prettier-plugin-java/test/unit-test/annotation_interface_declaration/_input.java index b5b39ffa..fd130fe9 100644 --- a/packages/prettier-plugin-java/test/unit-test/annotation_type_declaration/_input.java +++ b/packages/prettier-plugin-java/test/unit-test/annotation_interface_declaration/_input.java @@ -1,4 +1,4 @@ -public @interface AnnotationTypeDeclaration { +public @interface AnnotationInterfaceDeclaration { public String value() default ""; @RandomAnnotation Integer[][] annotatedArray = (Integer[][]) new Object[4][2]; @RandomBreakingAnnotation(one = "One", two = "Two", three = "Three", four = "Four", five = "Five") diff --git a/packages/prettier-plugin-java/test/unit-test/annotation_type_declaration/_output.java b/packages/prettier-plugin-java/test/unit-test/annotation_interface_declaration/_output.java similarity index 91% rename from packages/prettier-plugin-java/test/unit-test/annotation_type_declaration/_output.java rename to packages/prettier-plugin-java/test/unit-test/annotation_interface_declaration/_output.java index 2eebb8d3..a60d64b9 100644 --- a/packages/prettier-plugin-java/test/unit-test/annotation_type_declaration/_output.java +++ b/packages/prettier-plugin-java/test/unit-test/annotation_interface_declaration/_output.java @@ -1,4 +1,4 @@ -public @interface AnnotationTypeDeclaration { +public @interface AnnotationInterfaceDeclaration { public String value() default ""; @RandomAnnotation diff --git a/packages/prettier-plugin-java/test/unit-test/annotation_type_declaration/annotation_type_declaration-spec.ts b/packages/prettier-plugin-java/test/unit-test/annotation_interface_declaration/annotation_interface_declaration-spec.ts similarity index 100% rename from packages/prettier-plugin-java/test/unit-test/annotation_type_declaration/annotation_type_declaration-spec.ts rename to packages/prettier-plugin-java/test/unit-test/annotation_interface_declaration/annotation_interface_declaration-spec.ts diff --git a/packages/prettier-plugin-java/test/unit-test/unnamed-variables-and-patterns/_input.java b/packages/prettier-plugin-java/test/unit-test/unnamed-variables-and-patterns/_input.java index c2ad37f2..079c4f4b 100644 --- a/packages/prettier-plugin-java/test/unit-test/unnamed-variables-and-patterns/_input.java +++ b/packages/prettier-plugin-java/test/unit-test/unnamed-variables-and-patterns/_input.java @@ -86,7 +86,7 @@ void instanceofExpressions() { if (r instanceof ColoredPoint(Point(int x, _), _)) {} } - void switchLabelWithUnnamedPattern() { + void switchLabelWithMatchAllPattern() { switch (box) { case Box(RedBall _), Box(BlueBall _) -> processBox(box); case Box(GreenBall _) -> stopProcessing(); diff --git a/packages/prettier-plugin-java/test/unit-test/unnamed-variables-and-patterns/_output.java b/packages/prettier-plugin-java/test/unit-test/unnamed-variables-and-patterns/_output.java index 9c2376a6..1a2d4e53 100644 --- a/packages/prettier-plugin-java/test/unit-test/unnamed-variables-and-patterns/_output.java +++ b/packages/prettier-plugin-java/test/unit-test/unnamed-variables-and-patterns/_output.java @@ -84,7 +84,7 @@ void instanceofExpressions() { if (r instanceof ColoredPoint(Point(int x, _), _)) {} } - void switchLabelWithUnnamedPattern() { + void switchLabelWithMatchAllPattern() { switch (box) { case Box(RedBall _), Box(BlueBall _) -> processBox(box); case Box(GreenBall _) -> stopProcessing();