IDEA-87415 Formatter: cyclic alignment resolution

1. Skip cycled backward alignments instead of reporting an error;
2. Green code policy;
This commit is contained in:
Denis.Zhdanov
2012-07-02 08:58:56 +04:00
parent cb19f049ac
commit b40cedf906
7 changed files with 34 additions and 26 deletions
@@ -536,7 +536,7 @@ public abstract class AbstractJavaBlock extends AbstractBlock implements JavaBlo
}
else {
AlignmentStrategy alignmentStrategyToUse = AlignmentStrategy.wrap(arrangeChildAlignment(child, alignmentStrategy));
if (myAlignmentStrategy != null && myAlignmentStrategy.getAlignment(nodeType, childType) != null
if (myAlignmentStrategy.getAlignment(nodeType, childType) != null
&& (nodeType == JavaElementType.IMPLEMENTS_LIST || nodeType == JavaElementType.CLASS))
{
alignmentStrategyToUse = myAlignmentStrategy;
@@ -991,7 +991,7 @@ public abstract class AbstractJavaBlock extends AbstractBlock implements JavaBlo
// The whole idea of variable declarations alignment is that complete declaration blocks which children are to be aligned hold
// reference to the same AlignmentStrategy object, hence, reuse the same Alignment objects. So, there is no point in checking
// if it's necessary to align sub-blocks if shared strategy is not defined.
if (myAlignmentStrategy == null || !mySettings.ALIGN_GROUP_FIELD_DECLARATIONS) {
if (!mySettings.ALIGN_GROUP_FIELD_DECLARATIONS) {
return 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.
@@ -36,7 +36,8 @@ public class LeafBlock implements ASTBlock{
public LeafBlock(final ASTNode node,
final Wrap wrap,
final Alignment alignment,
Indent indent) {
Indent indent)
{
myNode = node;
myWrap = wrap;
myAlignment = alignment;
@@ -68,7 +68,8 @@ public class SimpleJavaBlock extends AbstractJavaBlock {
while (child != null) {
if (!FormatterUtil.containsWhiteSpacesOnly(child) && child.getTextLength() > 0){
final ASTNode astNode = child;
AlignmentStrategy alignmentStrategyToUse = ALIGN_IN_COLUMNS_ELEMENT_TYPES.contains(myNode.getElementType()) ? myAlignmentStrategy
AlignmentStrategy alignmentStrategyToUse = ALIGN_IN_COLUMNS_ELEMENT_TYPES.contains(myNode.getElementType())
? myAlignmentStrategy
: AlignmentStrategy.wrap(chooseAlignment(myReservedAlignment, myReservedAlignment2, child));
child = processChild(result, astNode, alignmentStrategyToUse, childWrap, indent, offset);
if (astNode != child && child != null) {