mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-170505 Strange formatting of Groovy enum with @Deprecated value
This commit is contained in:
-16
@@ -61,20 +61,4 @@ public class Annotation {
|
||||
annMarker.done(GroovyElementTypes.ANNOTATION);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void parseAnnotationOptional(PsiBuilder builder, GroovyParser parser) {
|
||||
PsiBuilder.Marker annOptMarker = builder.mark();
|
||||
|
||||
boolean hasAnnotations = false;
|
||||
while (parse(builder, parser)) {
|
||||
ParserUtils.getToken(builder, GroovyTokenTypes.mNLS);
|
||||
hasAnnotations = true;
|
||||
}
|
||||
|
||||
if (hasAnnotations) {
|
||||
annOptMarker.done(GroovyElementTypes.MODIFIERS);
|
||||
} else {
|
||||
annOptMarker.rollbackTo();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+6
-1
@@ -35,7 +35,12 @@ import org.jetbrains.plugins.groovy.lang.parser.parsing.util.ParserUtils;
|
||||
*/
|
||||
|
||||
public class Modifiers {
|
||||
|
||||
public static boolean parse(PsiBuilder builder, GroovyParser parser) {
|
||||
return parse(builder, parser, false);
|
||||
}
|
||||
|
||||
public static boolean parse(PsiBuilder builder, GroovyParser parser, boolean annotationsOnly) {
|
||||
|
||||
PsiBuilder.Marker modifiersMarker = builder.mark();
|
||||
boolean hasModifiers = false;
|
||||
@@ -44,7 +49,7 @@ public class Modifiers {
|
||||
final PsiBuilder.Marker modifierListItem = builder.mark();
|
||||
|
||||
if (hasModifiers) ParserUtils.getToken(builder, GroovyTokenTypes.mNLS);
|
||||
final boolean parsed = Annotation.parse(builder, parser) || parseModifier(builder);
|
||||
final boolean parsed = Annotation.parse(builder, parser) || (!annotationsOnly && parseModifier(builder));
|
||||
|
||||
if (parsed) {
|
||||
if (PathExpression.isQualificationDot(builder)) {
|
||||
|
||||
+2
-2
@@ -21,7 +21,7 @@ import org.jetbrains.plugins.groovy.GroovyBundle;
|
||||
import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes;
|
||||
import org.jetbrains.plugins.groovy.lang.parser.GroovyElementTypes;
|
||||
import org.jetbrains.plugins.groovy.lang.parser.GroovyParser;
|
||||
import org.jetbrains.plugins.groovy.lang.parser.parsing.auxiliary.annotations.Annotation;
|
||||
import org.jetbrains.plugins.groovy.lang.parser.parsing.auxiliary.modifiers.Modifiers;
|
||||
import org.jetbrains.plugins.groovy.lang.parser.parsing.statements.expressions.arguments.ArgumentList;
|
||||
import org.jetbrains.plugins.groovy.lang.parser.parsing.statements.typeDefinitions.TypeDefinition;
|
||||
import org.jetbrains.plugins.groovy.lang.parser.parsing.util.ParserUtils;
|
||||
@@ -35,7 +35,7 @@ public class EnumConstant {
|
||||
PsiBuilder.Marker ecMarker = builder.mark();
|
||||
ParserUtils.getToken(builder, GroovyTokenTypes.mNLS);
|
||||
|
||||
Annotation.parseAnnotationOptional(builder, parser);
|
||||
Modifiers.parse(builder, parser, true);
|
||||
|
||||
if (!ParserUtils.getToken(builder, GroovyTokenTypes.mIDENT)) {
|
||||
ecMarker.rollbackTo();
|
||||
|
||||
+6
@@ -55,6 +55,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrImplements
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinitionBody;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrAnnotationMethod;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrEnumConstant;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeArgumentList;
|
||||
@@ -228,6 +229,11 @@ public class GroovyIndentProcessor extends GroovyElementVisitor {
|
||||
myResult = Indent.getContinuationWithoutFirstIndent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitEnumConstant(@NotNull GrEnumConstant enumConstant) {
|
||||
Indent.getNoneIndent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitDocComment(@NotNull GrDocComment comment) {
|
||||
if (myChildType != GroovyDocTokenTypes.mGDOC_COMMENT_START) {
|
||||
|
||||
+5
-1
@@ -317,7 +317,11 @@ public class GroovySpacingProcessor extends GroovyElementVisitor {
|
||||
|
||||
@Override
|
||||
public void visitEnumConstant(@NotNull GrEnumConstant enumConstant) {
|
||||
manageSpaceBeforeCallLParenth();
|
||||
if (myType1 == GroovyElementTypes.MODIFIERS) {
|
||||
createSpaceInCode(true);
|
||||
} else {
|
||||
manageSpaceBeforeCallLParenth();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -688,6 +688,36 @@ def foooo(
|
||||
''')
|
||||
}
|
||||
|
||||
void testEnumAnnotations() {
|
||||
checkFormatting('''\
|
||||
enum GroovyEnum {
|
||||
FOO,
|
||||
@Deprecated
|
||||
BAR(""),
|
||||
DAR
|
||||
}
|
||||
''', '''\
|
||||
enum GroovyEnum {
|
||||
FOO,
|
||||
@Deprecated
|
||||
BAR(""),
|
||||
DAR
|
||||
}
|
||||
''')
|
||||
}
|
||||
|
||||
void testEnumAnnotationsSingleLine() {
|
||||
checkFormatting('''\
|
||||
enum GroovyEnum {
|
||||
@Deprecated BAR("")
|
||||
}
|
||||
''', '''\
|
||||
enum GroovyEnum {
|
||||
@Deprecated BAR("")
|
||||
}
|
||||
''')
|
||||
}
|
||||
|
||||
void testAlignFor() {
|
||||
groovySettings.ALIGN_MULTILINE_FOR = true
|
||||
checkFormatting('''\
|
||||
|
||||
@@ -18,6 +18,8 @@ Groovy script
|
||||
PsiWhiteSpace('\n ')
|
||||
Enumeration constants
|
||||
Enumeration constant
|
||||
Modifiers
|
||||
<empty list>
|
||||
PsiElement(identifier)('CONST')
|
||||
PsiElement(new line)('\n ')
|
||||
Variable definitions
|
||||
|
||||
@@ -20,15 +20,21 @@ Groovy script
|
||||
PsiWhiteSpace('\n ')
|
||||
Enumeration constants
|
||||
Enumeration constant
|
||||
Modifiers
|
||||
<empty list>
|
||||
PsiElement(identifier)('Const1')
|
||||
PsiElement(new line)('\n ')
|
||||
PsiElement(,)(',')
|
||||
PsiWhiteSpace(' ')
|
||||
Enumeration constant
|
||||
Modifiers
|
||||
<empty list>
|
||||
PsiElement(identifier)('Const2')
|
||||
PsiElement(,)(',')
|
||||
Enumeration constant
|
||||
PsiElement(new line)('\n ')
|
||||
Modifiers
|
||||
<empty list>
|
||||
PsiElement(identifier)('Const3')
|
||||
PsiElement(new line)('\n ')
|
||||
Variable definitions
|
||||
|
||||
@@ -17,6 +17,8 @@ Groovy script
|
||||
PsiWhiteSpace('\n ')
|
||||
Enumeration constants
|
||||
Enumeration constant
|
||||
Modifiers
|
||||
<empty list>
|
||||
PsiElement(identifier)('Const')
|
||||
PsiElement(;)(';')
|
||||
PsiWhiteSpace(' ')
|
||||
|
||||
@@ -14,5 +14,7 @@ Groovy script
|
||||
PsiElement({)('{')
|
||||
Enumeration constants
|
||||
Enumeration constant
|
||||
Modifiers
|
||||
<empty list>
|
||||
PsiElement(identifier)('CONST')
|
||||
PsiElement(})('}')
|
||||
@@ -19,6 +19,8 @@ Groovy script
|
||||
PsiWhiteSpace('\n ')
|
||||
Enumeration constants
|
||||
Enumeration constant
|
||||
Modifiers
|
||||
<empty list>
|
||||
PsiElement(identifier)('foo')
|
||||
PsiWhiteSpace(' ')
|
||||
Arguments
|
||||
|
||||
@@ -17,6 +17,8 @@ Groovy script
|
||||
PsiWhiteSpace('\n ')
|
||||
Enumeration constants
|
||||
Enumeration constant
|
||||
Modifiers
|
||||
<empty list>
|
||||
PsiElement(identifier)('foo')
|
||||
PsiElement(new line)('\n')
|
||||
PsiElement(})('}')
|
||||
@@ -18,11 +18,15 @@ Groovy script
|
||||
PsiWhiteSpace('\n ')
|
||||
Enumeration constants
|
||||
Enumeration constant
|
||||
Modifiers
|
||||
<empty list>
|
||||
PsiElement(identifier)('CONST1')
|
||||
PsiElement(new line)('\n ')
|
||||
PsiElement(,)(',')
|
||||
PsiWhiteSpace(' ')
|
||||
Enumeration constant
|
||||
Modifiers
|
||||
<empty list>
|
||||
PsiElement(identifier)('CONST2')
|
||||
PsiElement(new line)('\n')
|
||||
PsiElement(})('}')
|
||||
@@ -17,6 +17,8 @@ Groovy script
|
||||
PsiWhiteSpace('\n ')
|
||||
Enumeration constants
|
||||
Enumeration constant
|
||||
Modifiers
|
||||
<empty list>
|
||||
PsiElement(identifier)('CONST1')
|
||||
PsiErrorElement:';', '}' or new line expected
|
||||
<empty list>
|
||||
|
||||
@@ -37,30 +37,44 @@ Groovy script
|
||||
PsiWhiteSpace('\n ')
|
||||
Enumeration constants
|
||||
Enumeration constant
|
||||
Modifiers
|
||||
<empty list>
|
||||
PsiElement(identifier)('SUNDAY')
|
||||
PsiElement(,)(',')
|
||||
PsiWhiteSpace(' ')
|
||||
Enumeration constant
|
||||
Modifiers
|
||||
<empty list>
|
||||
PsiElement(identifier)('MONDAY')
|
||||
PsiElement(,)(',')
|
||||
PsiWhiteSpace(' ')
|
||||
Enumeration constant
|
||||
Modifiers
|
||||
<empty list>
|
||||
PsiElement(identifier)('TUESDAY')
|
||||
PsiElement(,)(',')
|
||||
PsiWhiteSpace(' ')
|
||||
Enumeration constant
|
||||
Modifiers
|
||||
<empty list>
|
||||
PsiElement(identifier)('WEDNESDAY')
|
||||
PsiElement(,)(',')
|
||||
Enumeration constant
|
||||
PsiElement(new line)('\n ')
|
||||
Modifiers
|
||||
<empty list>
|
||||
PsiElement(identifier)('THURSDAY')
|
||||
PsiElement(,)(',')
|
||||
PsiWhiteSpace(' ')
|
||||
Enumeration constant
|
||||
Modifiers
|
||||
<empty list>
|
||||
PsiElement(identifier)('FRIDAY')
|
||||
PsiElement(,)(',')
|
||||
PsiWhiteSpace(' ')
|
||||
Enumeration constant
|
||||
Modifiers
|
||||
<empty list>
|
||||
PsiElement(identifier)('SATURDAY')
|
||||
PsiElement(new line)('\n ')
|
||||
PsiElement(})('}')
|
||||
|
||||
Reference in New Issue
Block a user