diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/GroovyBlock.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/GroovyBlock.java index bf11e6bde1bd..461613df0222 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/GroovyBlock.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/GroovyBlock.java @@ -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); } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/processors/GroovyIndentProcessor.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/processors/GroovyIndentProcessor.java index 28f1db1db6a3..5b30c3700971 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/processors/GroovyIndentProcessor.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/processors/GroovyIndentProcessor.java @@ -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); diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/formatter/FormatterTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/formatter/FormatterTest.groovy index 90a1d302ccee..020a4119f3be 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/formatter/FormatterTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/formatter/FormatterTest.groovy @@ -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; diff --git a/plugins/groovy/testdata/groovy/formatter/annotationArgs1.test b/plugins/groovy/testdata/groovy/formatter/annotationArgs1.test new file mode 100644 index 000000000000..a3a4f776f9b2 --- /dev/null +++ b/plugins/groovy/testdata/groovy/formatter/annotationArgs1.test @@ -0,0 +1,9 @@ +@Foo( +arg +) +class Foo{} +----- +@Foo( + arg +) +class Foo {} \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/formatter/annotationArgs2.test b/plugins/groovy/testdata/groovy/formatter/annotationArgs2.test new file mode 100644 index 000000000000..ad7907cede6a --- /dev/null +++ b/plugins/groovy/testdata/groovy/formatter/annotationArgs2.test @@ -0,0 +1,11 @@ +@Foo +( +arg +) +class Foo{} +----- +@Foo + ( + arg + ) +class Foo {} \ No newline at end of file