[groovy] IDEA-CR-43127 IDEA-202693 Change lambda psi structure for single expression body form

This commit is contained in:
alexey.afanasiev
2019-02-12 16:18:39 +03:00
parent 7a5daa6c8c
commit 109c8d4128
8 changed files with 115 additions and 120 deletions
@@ -1,5 +1,3 @@
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// This is a generated file. Not intended for manual editing.
package org.jetbrains.plugins.groovy.lang.parser;
@@ -72,6 +70,9 @@ public class GroovyGeneratedParser implements PsiParser, LightPsiParser {
else if (t == ASSERT_STATEMENT) {
r = assert_statement(b, 0);
}
else if (t == BLOCK_LAMBDA_BODY) {
r = block_lambda_body(b, 0);
}
else if (t == BLOCK_STATEMENT) {
r = block_statement(b, 0);
}
@@ -144,6 +145,9 @@ public class GroovyGeneratedParser implements PsiParser, LightPsiParser {
else if (t == EXPRESSION) {
r = expression(b, 0, -1);
}
else if (t == EXPRESSION_LAMBDA_BODY) {
r = expression_lambda_body(b, 0);
}
else if (t == EXPRESSION_LIST) {
r = expression_list(b, 0);
}
@@ -174,12 +178,6 @@ public class GroovyGeneratedParser implements PsiParser, LightPsiParser {
else if (t == LABELED_STATEMENT) {
r = labeled_statement(b, 0);
}
else if (t == LAMBDA_BLOCK_FORM_BODY) {
r = lambda_block_form_body(b, 0);
}
else if (t == LAMBDA_EXPRESSION_FORM_BODY) {
r = lambda_expression_form_body(b, 0);
}
else if (t == LEFT_SHIFT_SIGN) {
r = left_shift_sign(b, 0);
}
@@ -1475,6 +1473,21 @@ public class GroovyGeneratedParser implements PsiParser, LightPsiParser {
return r;
}
/* ********************************************************** */
// '{' mb_nl block_levels '}'
public static boolean block_lambda_body(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "block_lambda_body")) return false;
if (!nextTokenIsFast(b, T_LBRACE)) return false;
boolean r;
Marker m = enter_section_(b);
r = consumeTokenFast(b, T_LBRACE);
r = r && mb_nl(b, l + 1);
r = r && block_levels(b, l + 1);
r = r && consumeToken(b, T_RBRACE);
exit_section_(b, m, BLOCK_LAMBDA_BODY, r);
return r;
}
/* ********************************************************** */
// top_level_end | &'}'
static boolean block_level_end(PsiBuilder b, int l) {
@@ -3474,6 +3487,17 @@ public class GroovyGeneratedParser implements PsiParser, LightPsiParser {
return r;
}
/* ********************************************************** */
// expression_or_application
public static boolean expression_lambda_body(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "expression_lambda_body")) return false;
boolean r;
Marker m = enter_section_(b, l, _COLLAPSE_, EXPRESSION_LAMBDA_BODY, "<expression lambda body>");
r = expression_or_application(b, l + 1);
exit_section_(b, l, m, r, false, null);
return r;
}
/* ********************************************************** */
// expression (',' expression)*
public static boolean expression_list(PsiBuilder b, int l) {
@@ -3542,6 +3566,51 @@ public class GroovyGeneratedParser implements PsiParser, LightPsiParser {
return true;
}
/* ********************************************************** */
// <<isParameterizedClosure>> expression_or_application
// | expression_or_application !<<isAfterClosure>>
public static boolean expression_single_parameter_lambda_body(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "expression_single_parameter_lambda_body")) return false;
boolean r;
Marker m = enter_section_(b, l, _COLLAPSE_, EXPRESSION_LAMBDA_BODY, "<expression single parameter lambda body>");
r = expression_single_parameter_lambda_body_0(b, l + 1);
if (!r) r = expression_single_parameter_lambda_body_1(b, l + 1);
exit_section_(b, l, m, r, false, null);
return r;
}
// <<isParameterizedClosure>> expression_or_application
private static boolean expression_single_parameter_lambda_body_0(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "expression_single_parameter_lambda_body_0")) return false;
boolean r;
Marker m = enter_section_(b);
r = isParameterizedClosure(b, l + 1);
r = r && expression_or_application(b, l + 1);
exit_section_(b, m, null, r);
return r;
}
// expression_or_application !<<isAfterClosure>>
private static boolean expression_single_parameter_lambda_body_1(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "expression_single_parameter_lambda_body_1")) return false;
boolean r;
Marker m = enter_section_(b);
r = expression_or_application(b, l + 1);
r = r && expression_single_parameter_lambda_body_1_1(b, l + 1);
exit_section_(b, m, null, r);
return r;
}
// !<<isAfterClosure>>
private static boolean expression_single_parameter_lambda_body_1_1(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "expression_single_parameter_lambda_body_1_1")) return false;
boolean r;
Marker m = enter_section_(b, l, _NOT_);
r = !isAfterClosure(b, l + 1);
exit_section_(b, l, m, r, false, null);
return r;
}
/* ********************************************************** */
// IDENTIFIER
// | '!' | '(' | '+' | '++' | '-' | '--' | '[' | '~'
@@ -4305,39 +4374,24 @@ public class GroovyGeneratedParser implements PsiParser, LightPsiParser {
}
/* ********************************************************** */
// '{' mb_nl block_levels '}'
public static boolean lambda_block_form_body(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "lambda_block_form_body")) return false;
if (!nextTokenIsFast(b, T_LBRACE)) return false;
boolean r;
Marker m = enter_section_(b);
r = consumeTokenFast(b, T_LBRACE);
r = r && mb_nl(b, l + 1);
r = r && block_levels(b, l + 1);
r = r && consumeToken(b, T_RBRACE);
exit_section_(b, m, LAMBDA_BLOCK_FORM_BODY, r);
return r;
}
/* ********************************************************** */
// (!<<isParameterizedClosure>> lazy_lambda_block) | lambda_expression_form_body
// (!<<isParameterizedClosure>> lazy_block_lambda_body) | expression_lambda_body
static boolean lambda_body(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "lambda_body")) return false;
boolean r;
Marker m = enter_section_(b);
r = lambda_body_0(b, l + 1);
if (!r) r = lambda_expression_form_body(b, l + 1);
if (!r) r = expression_lambda_body(b, l + 1);
exit_section_(b, m, null, r);
return r;
}
// !<<isParameterizedClosure>> lazy_lambda_block
// !<<isParameterizedClosure>> lazy_block_lambda_body
private static boolean lambda_body_0(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "lambda_body_0")) return false;
boolean r;
Marker m = enter_section_(b);
r = lambda_body_0_0(b, l + 1);
r = r && lazy_lambda_block(b, l + 1);
r = r && lazy_block_lambda_body(b, l + 1);
exit_section_(b, m, null, r);
return r;
}
@@ -4367,17 +4421,6 @@ public class GroovyGeneratedParser implements PsiParser, LightPsiParser {
return r || p;
}
/* ********************************************************** */
// expression_or_application
public static boolean lambda_expression_form_body(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "lambda_expression_form_body")) return false;
boolean r;
Marker m = enter_section_(b, l, _COLLAPSE_, LAMBDA_EXPRESSION_FORM_BODY, "<lambda expression form body>");
r = expression_or_application(b, l + 1);
exit_section_(b, l, m, r, false, null);
return r;
}
/* ********************************************************** */
// lambda_parameter_list mb_nl '->'
static boolean lambda_expression_head(PsiBuilder b, int l) {
@@ -4439,6 +4482,17 @@ public class GroovyGeneratedParser implements PsiParser, LightPsiParser {
return r;
}
/* ********************************************************** */
// <<parseBlockLazy block_lambda_body 'BLOCK_LAMBDA_BODY'>>
public static boolean lazy_block_lambda_body(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "lazy_block_lambda_body")) return false;
boolean r;
Marker m = enter_section_(b, l, _COLLAPSE_, BLOCK_LAMBDA_BODY, "<lazy block lambda body>");
r = parseBlockLazy(b, l + 1, GroovyGeneratedParser::block_lambda_body, BLOCK_LAMBDA_BODY);
exit_section_(b, l, m, r, false, null);
return r;
}
/* ********************************************************** */
// <<parseBlockLazy constructor_block 'CONSTRUCTOR_BLOCK'>>
public static boolean lazy_constructor_block(PsiBuilder b, int l) {
@@ -4450,17 +4504,6 @@ public class GroovyGeneratedParser implements PsiParser, LightPsiParser {
return r;
}
/* ********************************************************** */
// <<parseBlockLazy lambda_block_form_body 'LAMBDA_BLOCK_FORM_BODY'>>
public static boolean lazy_lambda_block(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "lazy_lambda_block")) return false;
boolean r;
Marker m = enter_section_(b, l, _COLLAPSE_, LAMBDA_BLOCK_FORM_BODY, "<lazy lambda block>");
r = parseBlockLazy(b, l + 1, GroovyGeneratedParser::lambda_block_form_body, LAMBDA_BLOCK_FORM_BODY);
exit_section_(b, l, m, r, false, null);
return r;
}
/* ********************************************************** */
// '<' '<'
public static boolean left_shift_sign(PsiBuilder b, int l) {
@@ -6054,12 +6097,12 @@ public class GroovyGeneratedParser implements PsiParser, LightPsiParser {
}
/* ********************************************************** */
// single_parameter_lambda_expression_form_body | lazy_lambda_block
// expression_single_parameter_lambda_body | lazy_block_lambda_body
static boolean single_parameter_lambda_body(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "single_parameter_lambda_body")) return false;
boolean r;
r = single_parameter_lambda_expression_form_body(b, l + 1);
if (!r) r = lazy_lambda_block(b, l + 1);
r = expression_single_parameter_lambda_body(b, l + 1);
if (!r) r = lazy_block_lambda_body(b, l + 1);
return r;
}
@@ -6077,51 +6120,6 @@ public class GroovyGeneratedParser implements PsiParser, LightPsiParser {
return r || p;
}
/* ********************************************************** */
// <<isParameterizedClosure>> expression_or_application
// | expression_or_application !<<isAfterClosure>>
public static boolean single_parameter_lambda_expression_form_body(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "single_parameter_lambda_expression_form_body")) return false;
boolean r;
Marker m = enter_section_(b, l, _COLLAPSE_, LAMBDA_EXPRESSION_FORM_BODY, "<single parameter lambda expression form body>");
r = single_parameter_lambda_expression_form_body_0(b, l + 1);
if (!r) r = single_parameter_lambda_expression_form_body_1(b, l + 1);
exit_section_(b, l, m, r, false, null);
return r;
}
// <<isParameterizedClosure>> expression_or_application
private static boolean single_parameter_lambda_expression_form_body_0(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "single_parameter_lambda_expression_form_body_0")) return false;
boolean r;
Marker m = enter_section_(b);
r = isParameterizedClosure(b, l + 1);
r = r && expression_or_application(b, l + 1);
exit_section_(b, m, null, r);
return r;
}
// expression_or_application !<<isAfterClosure>>
private static boolean single_parameter_lambda_expression_form_body_1(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "single_parameter_lambda_expression_form_body_1")) return false;
boolean r;
Marker m = enter_section_(b);
r = expression_or_application(b, l + 1);
r = r && single_parameter_lambda_expression_form_body_1_1(b, l + 1);
exit_section_(b, m, null, r);
return r;
}
// !<<isAfterClosure>>
private static boolean single_parameter_lambda_expression_form_body_1_1(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "single_parameter_lambda_expression_form_body_1_1")) return false;
boolean r;
Marker m = enter_section_(b, l, _NOT_);
r = !isAfterClosure(b, l + 1);
exit_section_(b, l, m, r, false, null);
return r;
}
/* ********************************************************** */
// single_parameter_lambda_parameter_list mb_nl '->'
static boolean single_parameter_lambda_expression_head(PsiBuilder b, int l) {
@@ -9,6 +9,7 @@ import org.jetbrains.plugins.groovy.lang.psi.stubs.elements.GrNameValuePairEleme
import org.jetbrains.plugins.groovy.lang.psi.stubs.elements.GrAnnotationMethodElementType;
import org.jetbrains.plugins.groovy.lang.psi.stubs.elements.GrAnnotationDefinitionElementType;
import org.jetbrains.plugins.groovy.lang.psi.stubs.elements.GrAnonymousElementType;
import org.jetbrains.plugins.groovy.lang.parser.GrBlockLambdaBodyElementType;
import org.jetbrains.plugins.groovy.lang.psi.stubs.elements.GrTypeDefinitionBodyElementType;
import org.jetbrains.plugins.groovy.lang.psi.stubs.elements.GrClassDefinitionElementType;
import org.jetbrains.plugins.groovy.lang.parser.GrClosureElementType;
@@ -24,7 +25,6 @@ import org.jetbrains.plugins.groovy.lang.psi.stubs.elements.GrFieldElementType;
import org.jetbrains.plugins.groovy.lang.psi.stubs.elements.GrImplementsClauseElementType;
import org.jetbrains.plugins.groovy.lang.psi.stubs.elements.GrImportStatementElementType;
import org.jetbrains.plugins.groovy.lang.psi.stubs.elements.GrInterfaceDefinitionElementType;
import org.jetbrains.plugins.groovy.lang.parser.GrLambdaBlockFormBodyElementType;
import org.jetbrains.plugins.groovy.lang.psi.stubs.elements.GrMethodElementType;
import org.jetbrains.plugins.groovy.lang.psi.stubs.elements.GrModifierListElementType;
import org.jetbrains.plugins.groovy.lang.parser.GrBlockElementType;
@@ -62,6 +62,7 @@ public interface GroovyElementTypes {
GroovyElementType AS_EXPRESSION = new GroovyElementType("AS_EXPRESSION");
GroovyElementType ATTRIBUTE_EXPRESSION = new GroovyElementType("ATTRIBUTE_EXPRESSION");
GroovyElementType BAND_EXPRESSION = new GroovyElementType("BAND_EXPRESSION");
GrBlockLambdaBodyElementType BLOCK_LAMBDA_BODY = new GrBlockLambdaBodyElementType("BLOCK_LAMBDA_BODY");
GroovyElementType BLOCK_STATEMENT = new GroovyElementType("BLOCK_STATEMENT");
GroovyElementType BOR_EXPRESSION = new GroovyElementType("BOR_EXPRESSION");
GroovyElementType BREAK_STATEMENT = new GroovyElementType("BREAK_STATEMENT");
@@ -91,6 +92,7 @@ public interface GroovyElementTypes {
GrEnumDefinitionElementType ENUM_TYPE_DEFINITION = new GrEnumDefinitionElementType("ENUM_TYPE_DEFINITION");
GroovyElementType EQUALITY_EXPRESSION = new GroovyElementType("EQUALITY_EXPRESSION");
GroovyElementType EXPRESSION = new GroovyElementType("EXPRESSION");
GroovyElementType EXPRESSION_LAMBDA_BODY = new GroovyElementType("EXPRESSION_LAMBDA_BODY");
GroovyElementType EXPRESSION_LIST = new GroovyElementType("EXPRESSION_LIST");
GrExtendsClauseElementType EXTENDS_CLAUSE = new GrExtendsClauseElementType("EXTENDS_CLAUSE");
GrFieldElementType FIELD = new GrFieldElementType("FIELD");
@@ -107,9 +109,7 @@ public interface GroovyElementTypes {
GrInterfaceDefinitionElementType INTERFACE_TYPE_DEFINITION = new GrInterfaceDefinitionElementType("INTERFACE_TYPE_DEFINITION");
GroovyElementType IN_EXPRESSION = new GroovyElementType("IN_EXPRESSION");
GroovyElementType LABELED_STATEMENT = new GroovyElementType("LABELED_STATEMENT");
GrLambdaBlockFormBodyElementType LAMBDA_BLOCK_FORM_BODY = new GrLambdaBlockFormBodyElementType("LAMBDA_BLOCK_FORM_BODY");
GroovyElementType LAMBDA_EXPRESSION = new GroovyElementType("LAMBDA_EXPRESSION");
GroovyElementType LAMBDA_EXPRESSION_FORM_BODY = new GroovyElementType("LAMBDA_EXPRESSION_FORM_BODY");
GroovyElementType LAND_EXPRESSION = new GroovyElementType("LAND_EXPRESSION");
GroovyElementType LEFT_SHIFT_SIGN = new GroovyElementType("LEFT_SHIFT_SIGN");
GroovyElementType LIST_OR_MAP = new GroovyElementType("LIST_OR_MAP");
@@ -3,17 +3,17 @@ package org.jetbrains.plugins.groovy.lang.parser;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.plugins.groovy.lang.psi.impl.statements.blocks.GrBlockImpl;
import org.jetbrains.plugins.groovy.lang.psi.impl.GrLambdaBodyBlockImpl;
import org.jetbrains.plugins.groovy.lang.psi.impl.GrBlockLambdaBodyImpl;
public class GrLambdaBlockFormBodyElementType extends GrCodeBlockElementType {
public class GrBlockLambdaBodyElementType extends GrCodeBlockElementType {
public GrLambdaBlockFormBodyElementType(String debugName) {
public GrBlockLambdaBodyElementType(String debugName) {
super(debugName);
}
@NotNull
@Override
public GrBlockImpl createNode(CharSequence text) {
return new GrLambdaBodyBlockImpl(this, text);
return new GrBlockLambdaBodyImpl(this, text);
}
}
@@ -205,7 +205,7 @@ public class GroovyPsiCreator {
if (elem == ARRAY_DECLARATION) return new GrArrayDeclarationImpl(node);
if (elem == ARRAY_INITIALIZER) return new GrArrayInitializerImpl(node);
if (elem == LAMBDA_EXPRESSION) return new GrLambdaExpressionImpl(node);
if (elem == LAMBDA_EXPRESSION_FORM_BODY) return new GrLambdaBodyExpressionImpl(node);
if (elem == EXPRESSION_LAMBDA_BODY) return new GrExpressionLambdaBodyImpl(node);
//Paths
if (elem == REFERENCE_EXPRESSION) return new GrReferenceExpressionImpl(node);
@@ -948,9 +948,9 @@ lambda_expression ::= lambda_expression_base | clear_variants_and_fail
private lambda_expression_base ::= lambda_expression_head mb_nl lambda_body { pin = 1 }
private lambda_expression_head ::= lambda_parameter_list mb_nl '->' { consumeTokenMethod = 'consumeTokenFast' }
lambda_parameter_list ::= empty_parens | '(' <<comma_list (mb_nl parse_parameter)>> ')' { elementType = parameter_list }
private lambda_body ::= (!<<isParameterizedClosure>> lazy_lambda_block) | lambda_expression_form_body
private lambda_body ::= (!<<isParameterizedClosure>> lazy_block_lambda_body) | expression_lambda_body
lambda_expression_form_body ::= expression_or_application
expression_lambda_body ::= expression_or_application
single_parameter_lambda_expression::= single_parameter_lambda_expression_base | clear_variants_and_fail { elementType = lambda_expression }
private single_parameter_lambda_expression_base ::= single_parameter_lambda_expression_head mb_nl single_parameter_lambda_body { pin = 1 }
@@ -960,19 +960,19 @@ single_parameter_lambda_parameter_list ::= !<<isApplicationArguments>> single_pa
single_parameter_lambda_parameter ::= modifier_list IDENTIFIER {
elementType = parameter
}
private single_parameter_lambda_body ::= single_parameter_lambda_expression_form_body | lazy_lambda_block
single_parameter_lambda_expression_form_body ::= <<isParameterizedClosure>> expression_or_application
private single_parameter_lambda_body ::= expression_single_parameter_lambda_body | lazy_block_lambda_body
expression_single_parameter_lambda_body ::= <<isParameterizedClosure>> expression_or_application
| expression_or_application !<<isAfterClosure>>
{
elementType = lambda_expression_form_body
elementType = expression_lambda_body
}
lazy_lambda_block ::= <<parseBlockLazy lambda_block_form_body 'LAMBDA_BLOCK_FORM_BODY'>> {
elementType = lambda_block_form_body
lazy_block_lambda_body ::= <<parseBlockLazy block_lambda_body 'BLOCK_LAMBDA_BODY'>> {
elementType = block_lambda_body
}
lambda_block_form_body ::= '{' mb_nl block_levels '}' {
elementTypeClass = 'org.jetbrains.plugins.groovy.lang.parser.GrLambdaBlockFormBodyElementType'
block_lambda_body ::= '{' mb_nl block_levels '}' {
elementTypeClass = 'org.jetbrains.plugins.groovy.lang.parser.GrBlockLambdaBodyElementType'
consumeTokenMethod = 'consumeTokenFast'
}
// endregion
@@ -10,7 +10,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.GrLambdaExpression
import org.jetbrains.plugins.groovy.lang.psi.impl.statements.blocks.GrBlockImpl
import org.jetbrains.plugins.groovy.lang.resolve.MethodTypeInferencer
class GrLambdaBodyBlockImpl(type: IElementType, buffer: CharSequence?) : GrBlockImpl(type, buffer), GrLambdaBody {
class GrBlockLambdaBodyImpl(type: IElementType, buffer: CharSequence?) : GrBlockImpl(type, buffer), GrLambdaBody {
override fun getReturnType(): PsiType? = GroovyPsiManager.inferType(this, MethodTypeInferencer(this))
@@ -13,7 +13,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpres
import org.jetbrains.plugins.groovy.lang.psi.controlFlow.Instruction
import org.jetbrains.plugins.groovy.lang.psi.controlFlow.impl.ControlFlowBuilder
class GrLambdaBodyExpressionImpl(node: ASTNode) : GroovyPsiElementImpl(node), GrLambdaBody {
class GrExpressionLambdaBodyImpl(node: ASTNode) : GroovyPsiElementImpl(node), GrLambdaBody {
override fun getReturnType(): PsiType? = getExpression().type
override fun getLambdaExpression(): GrLambdaExpression = requireNotNull(parentOfType())
@@ -29,10 +29,7 @@ class GrLambdaExpressionImpl(node: ASTNode) : GrExpressionImpl(node), GrLambdaEx
override fun isVarArgs(): Boolean = false
override fun getBody(): GrLambdaBody? {
val body = lastChild
return if (body is GrLambdaBody) body else null
}
override fun getBody(): GrLambdaBody? = lastChild as? GrLambdaBody
override fun processDeclarations(processor: PsiScopeProcessor, state: ResolveState, lastParent: PsiElement?, place: PsiElement): Boolean {
return processParameters(processor, state) && processClosureClassMembers(processor, state, lastParent, place)