IDEA-95917 Groovy annotation attributes wrong alignment

This commit is contained in:
Max Medvedev
2012-11-29 16:24:28 +04:00
parent 827d5ce271
commit 27c72374b9
5 changed files with 40 additions and 3 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
* Copyright 2000-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -35,6 +35,7 @@ import org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocTag;
import org.jetbrains.plugins.groovy.lang.parser.GroovyElementTypes;
import org.jetbrains.plugins.groovy.lang.psi.GroovyFileBase;
import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrListOrMap;
import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotationArgumentList;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.*;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.branch.GrBreakStatement;
@@ -225,6 +226,9 @@ public class GroovyBlock implements Block, GroovyElementTypes, ASTBlock {
if (psiParent instanceof GrIfStatement || psiParent instanceof GrLoopStatement) {
return new ChildAttributes(Indent.getNormalIndent(), null);
}
if (psiParent instanceof GrAnnotationArgumentList) {
return new ChildAttributes(Indent.getContinuationIndent(), null);
}
return new ChildAttributes(Indent.getNoneIndent(), null);
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -50,7 +50,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMe
*/
public abstract class GroovyIndentProcessor implements GroovyElementTypes {
public static final int GDOC_COMMENT_INDENT = 1;
private static TokenSet GSTRING_TOKENS_INNER = TokenSet.create(mGSTRING_BEGIN,mGSTRING_CONTENT,mGSTRING_END,mDOLLAR);
private static final TokenSet GSTRING_TOKENS_INNER = TokenSet.create(mGSTRING_BEGIN,mGSTRING_CONTENT,mGSTRING_END,mDOLLAR);
/**
* Calculates indent, based on code style, between parent block and child node
@@ -117,6 +117,16 @@ public abstract class GroovyIndentProcessor implements GroovyElementTypes {
return isLabelIndentAbsolute ? Indent.getAbsoluteLabelIndent() : Indent.getLabelIndent();
}
if (parentType == ANNOTATION) {
if (childType == ANNOTATION_ARGUMENTS) return Indent.getContinuationIndent();
return Indent.getNoneIndent();
}
if (parentType == ANNOTATION_ARGUMENTS) {
if (childType == mLPAREN || childType == mRPAREN) return Indent.getNoneIndent();
return Indent.getContinuationIndent();
}
// for control structures
if (psiParent instanceof GrControlStatement) {
return getControlIndent(psiParent, child);
@@ -252,6 +252,9 @@ public class FormatterTest extends GroovyFormatterTestCase {
void testPackageDef1() { doTest() }
void testPackageDef2() { doTest() }
void testAnnotationArgs1() { doTest() }
void testAnnotationArgs2() { doTest() }
private void doGeeseTest() {
GroovyCodeStyleSettings customSettings = myTempSettings.getCustomSettings(GroovyCodeStyleSettings.class);
boolean oldvalue = customSettings.USE_FLYING_GEESE_BRACES;
@@ -0,0 +1,9 @@
@Foo(
arg
)
class Foo{}
-----
@Foo(
arg
)
class Foo {}
@@ -0,0 +1,11 @@
@Foo
(
arg
)
class Foo{}
-----
@Foo
(
arg
)
class Foo {}