Skip to content

Commit 1ffc650

Browse files
committed
add option on 'Alignment of nested structures' (#9, #14)
1 parent 0b25976 commit 1ffc650

File tree

6 files changed

+542
-60
lines changed

6 files changed

+542
-60
lines changed

com.sap.adt.abapcleaner/src/com/sap/adt/abapcleaner/rulehelpers/AlignColumn.java

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@ public class AlignColumn {
1111
public boolean rightAlign;
1212
private boolean forceLineBreakAfter;
1313
private boolean overrideWidthWith1;
14+
private int minimumWidth;
1415
/** the forced indent of the column, to which the basicIndent is added **/
1516
private int forceIndent = -1;
1617

1718
// variables that are updated on .addCell() and may be recalculated with .recalculate()
1819
private boolean isValid;
1920
private int maxMonoLineWidth;
2021
private int maxMultiLineWidth;
21-
22+
2223
// the effective indent is only determined in AlignTable.align()
2324
private int effectiveIndent;
2425

@@ -93,13 +94,13 @@ final void recalculate() {
9394
final int getMaxMonoLineWidthWithSpaceLeft() {
9495
if (!isValid)
9596
recalculate();
96-
return isEmpty() ? 0 : maxMonoLineWidth + 1;
97+
return isEmpty() ? 0 : Math.max(minimumWidth, maxMonoLineWidth) + 1;
9798
}
9899

99100
final int getMaxMultiLineWidthWithSpaceLeft() {
100101
if (!isValid)
101102
recalculate();
102-
return isEmpty() ? 0 : maxMultiLineWidth + 1;
103+
return isEmpty() ? 0 : Math.max(minimumWidth, maxMultiLineWidth) + 1;
103104
}
104105

105106
/**
@@ -209,4 +210,27 @@ public final AlignCell getLastNonEmptyCell() {
209210
}
210211
return null;
211212
}
213+
214+
public final void setMinimumWidth(int minimumWidth) {
215+
this.minimumWidth = minimumWidth;
216+
}
217+
218+
public final boolean isPreviousColumnFixedWidth() {
219+
if (index == 0)
220+
return false;
221+
222+
int minWidth = -1;
223+
int maxWidth = -1;
224+
for (AlignLine line : parentTable.getLines()) {
225+
if (line.getCell(index) == null)
226+
continue;
227+
AlignCell prevCell = line.getCell(index - 1);
228+
if (prevCell == null)
229+
return false;
230+
int width = prevCell.getMultiLineWidth();
231+
minWidth = (minWidth < 0) ? width : Math.min(minWidth, width);
232+
maxWidth = (maxWidth < 0) ? width : Math.max(maxWidth, width);
233+
}
234+
return (minWidth >= 0 && minWidth == maxWidth);
235+
}
212236
}

0 commit comments

Comments
 (0)