1414import java .lang .reflect .Method ;
1515import java .lang .reflect .ParameterizedType ;
1616import java .lang .reflect .Type ;
17+ import java .util .ArrayDeque ;
1718import java .util .Collection ;
1819import java .util .Collections ;
1920import java .util .Comparator ;
21+ import java .util .Deque ;
2022import java .util .HashMap ;
2123import java .util .HashSet ;
24+ import java .util .LinkedList ;
2225import java .util .List ;
2326import java .util .Map ;
2427import java .util .Set ;
25- import java .util .Stack ;
2628
2729import org .apache .logging .log4j .LogManager ;
2830import org .apache .logging .log4j .Logger ;
7072public class ExtendedFormattingConfigBasedStream extends FormattingConfigBasedStream implements IDelegatingTokenStream {
7173
7274 private static final Logger LOGGER = LogManager .getLogger (ExtendedFormattingConfigBasedStream .class );
73- private final Stack <Integer > columnIndents = new Stack <Integer >(); // NOPMD LooseCoupling, ReplaceVectorWithList
74- private final Stack <Integer > initialIndents = new Stack <Integer >(); // NOPMD LooseCoupling, ReplaceVectorWithList
75+ private final LinkedList <Integer > columnIndents = new LinkedList <Integer >(); // NOPMD LooseCoupling
76+ private final Deque <Integer > initialIndents = new ArrayDeque <Integer >();
7577 private final Set <NoFormatLocator > noFormatLocators = new HashSet <NoFormatLocator >();
7678
7779 private INode currentNode ;
@@ -197,8 +199,8 @@ public LineEntry createLineEntry(final EObject grammarElement, final String valu
197199 * @return
198200 * top element or 0 if stack empty
199201 */
200- private int emptySafeStackPeek (final Stack <Integer > stack ) { // NOPMD LooseCoupling
201- if (!stack .empty ()) {
202+ private int emptySafeStackPeek (final Deque <Integer > stack ) {
203+ if (!stack .isEmpty ()) {
202204 return stack .peek ();
203205 }
204206 return 0 ;
@@ -210,9 +212,9 @@ private int emptySafeStackPeek(final Stack<Integer> stack) { // NOPMD LooseCoupl
210212 * @param stack
211213 * stack of integers
212214 */
213- private void emptySafeStackPop (final Stack <Integer > stack ) { // NOPMD LooseCoupling
214- if (!stack .empty ()) {
215- stack .pop ();
215+ private void emptySafeStackPop (final Deque <Integer > stack ) {
216+ if (!stack .isEmpty ()) {
217+ stack .pollFirst ()
216218 }
217219 }
218220
@@ -517,8 +519,8 @@ public boolean containsOpposite(final List<ElementLocator> locators, final Eleme
517519 boolean isSameIndentColumnLocator = candidateLocator instanceof FixedLocator
518520 && ((FixedLocator ) candidateLocator ).getColumn () == ((FixedLocator ) locator ).getColumn ();
519521 if (isSameIndentColumnLocator ) {
520- boolean isOppositeToAfter = (( FixedLocator ) candidateLocator ) .getRight () != null && (( FixedLocator ) locator ) .getRight () == null ;
521- boolean isOppositeToBefore = (( FixedLocator ) candidateLocator ) .getLeft () != null && (( FixedLocator ) locator ) .getLeft () == null ;
522+ boolean isOppositeToAfter = candidateLocator .getRight () != null && locator .getRight () == null ;
523+ boolean isOppositeToBefore = candidateLocator .getLeft () != null && locator .getLeft () == null ;
522524 if (isOppositeToAfter || isOppositeToBefore ) {
523525 return true ;
524526 }
@@ -573,14 +575,15 @@ public int compare(final ElementLocator o1, final ElementLocator o2) {
573575 private void processColumnLocators (final List <ElementLocator > locators ) {
574576 Set <Integer > duplicatedColumnLocatorsIndicator = new HashSet <Integer >();
575577 for (ElementLocator locator : locators ) {
576- if (locator instanceof FixedLocator ) {
577- if (locator .getRight () != null && !duplicatedColumnLocatorsIndicator .contains (((FixedLocator ) locator ).getColumn ())) {
578+ if (locator instanceof FixedLocator fixedLocator ) {
579+ Integer column = fixedLocator .getColumn ();
580+ if (locator .getRight () != null && !duplicatedColumnLocatorsIndicator .contains (column )) {
578581 initialIndents .push (indentationLevel );
579- columnIndents .push ((( FixedLocator ) locator ). getColumn () );
580- duplicatedColumnLocatorsIndicator .add ((( FixedLocator ) locator ). getColumn () );
582+ columnIndents .push (column );
583+ duplicatedColumnLocatorsIndicator .add (column );
581584 }
582585 if (locator .getLeft () != null ) {
583- int locatorIndexOnStack = columnIndents .lastIndexOf ((( FixedLocator ) locator ). getColumn () );
586+ int locatorIndexOnStack = columnIndents .lastIndexOf (column );
584587 if (locatorIndexOnStack != -1 ) {
585588 columnIndents .remove (locatorIndexOnStack );
586589 initialIndents .remove (locatorIndexOnStack );
0 commit comments