From 3531cfda489a5f0e6bb05fb0ce87f6b472071c3f Mon Sep 17 00:00:00 2001 From: Max Medvedev Date: Mon, 3 Jun 2013 16:47:14 +0400 Subject: [PATCH] indent in spock's labels should work in preview --- .../processors/GroovyIndentProcessor.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) 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 0cf6955456b7..a7ab5f118e3c 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 @@ -58,6 +58,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.GrMethod; +import org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement; import org.jetbrains.plugins.groovy.spock.SpockUtils; import static org.jetbrains.plugins.groovy.lang.parser.GroovyElementTypes.*; @@ -165,7 +166,7 @@ public class GroovyIndentProcessor extends GroovyElementVisitor { final GrTypeDefinition clazz = PsiTreeUtil.getParentOfType(place, GrTypeDefinition.class); if (clazz == null) return false; - if (InheritanceUtil.isInheritor(clazz, SpockUtils.SPEC_CLASS_NAME)) { + if (isDirectInheritorOfSpecification(clazz) || InheritanceUtil.isInheritor(clazz, SpockUtils.SPEC_CLASS_NAME)) { return true; } @@ -179,6 +180,19 @@ public class GroovyIndentProcessor extends GroovyElementVisitor { return false; } + private static boolean isDirectInheritorOfSpecification(@NotNull GrTypeDefinition clazz) { + final GrExtendsClause clause = clazz.getExtendsClause(); + if (clause != null) { + final GrCodeReferenceElement[] refs = clause.getReferenceElements(); + for (GrCodeReferenceElement ref : refs) { + if (SpockUtils.SPEC_CLASS_NAME.equals(ref.getClassNameText())) { + return true; + } + } + } + return false; + } + @Override public void visitAnnotation(GrAnnotation annotation) { if (myChildType == ANNOTATION_ARGUMENTS) {