From 251178cb8bc947f824e43ddfb29d4377a768f73f Mon Sep 17 00:00:00 2001 From: Roman Ivanov Date: Wed, 27 Oct 2021 14:56:16 +0200 Subject: [PATCH] [inlays] get back removed docs to AlignmentHelper GitOrigin-RevId: 789501ac3abcb607d643cded52b1043bf3066c9f --- .../formatting/engine/AlignmentHelper.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/platform/code-style-impl/src/com/intellij/formatting/engine/AlignmentHelper.java b/platform/code-style-impl/src/com/intellij/formatting/engine/AlignmentHelper.java index 00077ebe12cc..4c2ce32c749c 100644 --- a/platform/code-style-impl/src/com/intellij/formatting/engine/AlignmentHelper.java +++ b/platform/code-style-impl/src/com/intellij/formatting/engine/AlignmentHelper.java @@ -20,12 +20,34 @@ public class AlignmentHelper { ALIGNMENT_PROCESSORS.put(Alignment.Anchor.RIGHT, new RightEdgeAlignmentProcessor()); } + /** + * There is a possible case that we detect a 'cycled alignment' rules (see {@link #myBackwardShiftedAlignedBlocks}). We want + * just to skip processing for such alignments then. + *

+ * This container holds 'bad alignment' objects that should not be processed. + */ private final Set myAlignmentsToSkip = new HashSet<>(); private final Document myDocument; private final BlockIndentOptions myBlockIndentOptions; private final AlignmentCyclesDetector myCyclesDetector; + /** + * Remembers mappings between backward-shifted aligned block and blocks that cause that shift in order to detect + * infinite cycles that may occur when, for example following alignment is specified: + *

+ *

+   *     int i1     = 1;
+   *     int i2, i3 = 2;
+   * 
+ *

+ * There is a possible case that 'i1', 'i2' and 'i3' blocks re-use + * the same alignment, hence, 'i1' is shifted to right during 'i3' processing but + * that causes 'i2' to be shifted right as wll because it's aligned to 'i1' that + * increases offset of 'i3' that, in turn, causes backward shift of 'i1' etc. + *

+ * This map remembers such backward shifts in order to be able to break such infinite cycles. + */ private final Map> myBackwardShiftedAlignedBlocks = new HashMap<>(); private final Map> myAlignmentMappings = new HashMap<>();