@@ -390,42 +390,55 @@ public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int
390390 }
391391
392392 private void resolveImportPlaceholders (Constraint constraint , FeatureModel featureModel ) {
393- if (constraint instanceof AndConstraint || constraint instanceof OrConstraint || constraint instanceof NotConstraint || constraint instanceof ImplicationConstraint || constraint instanceof ParenthesisConstraint || constraint instanceof EquivalenceConstraint ) {
394- for (Constraint subPart : constraint .getConstraintSubParts ()) {
395- resolveImportPlaceholders (subPart , featureModel );
393+ final Deque <Constraint > stack = new ArrayDeque <>();
394+ stack .push (constraint );
395+
396+ while (!stack .isEmpty ()) {
397+ final Constraint current = stack .pop ();
398+
399+ if (current instanceof ExpressionConstraint ) {
400+ ExpressionConstraint expressionConstraint = (ExpressionConstraint ) current ;
401+ resolveImportPlaceholders (expressionConstraint .getLeft (), featureModel );
402+ resolveImportPlaceholders (expressionConstraint .getRight (), featureModel );
403+ } else if (current instanceof LiteralConstraint ) {
404+ LiteralConstraint literalConstraint = (LiteralConstraint ) current ;
405+ if (literalConstraint .getReference () instanceof ImportedVariablePlaceholder ) {
406+ ImportedVariablePlaceholder placeholder = (ImportedVariablePlaceholder ) literalConstraint .getReference ();
407+ literalConstraint .setReference (resolvePlaceholder (placeholder , featureModel ));
408+ }
396409 }
397- } else if (constraint instanceof ExpressionConstraint ) {
398- ExpressionConstraint expressionConstraint = (ExpressionConstraint ) constraint ;
399- resolveImportPlaceholders (expressionConstraint .getLeft (), featureModel );
400- resolveImportPlaceholders (expressionConstraint .getRight (), featureModel );
401- } else if (constraint instanceof LiteralConstraint ) {
402- LiteralConstraint literalConstraint = (LiteralConstraint ) constraint ;
403- if (literalConstraint .getReference () instanceof ImportedVariablePlaceholder ) {
404- ImportedVariablePlaceholder placeholder = (ImportedVariablePlaceholder ) literalConstraint .getReference ();
405- literalConstraint .setReference (resolvePlaceholder (placeholder , featureModel ));
410+
411+ final List <Constraint > subConstraints = current .getConstraintSubParts ();
412+ for (int i = subConstraints .size () - 1 ; i >= 0 ; i --) {
413+ stack .push (subConstraints .get (i ));
406414 }
407415 }
408416 }
409417
410418 private void resolveImportPlaceholders (Expression expression , FeatureModel featureModel ) {
411- if (expression instanceof BinaryExpression ) {
412- BinaryExpression binaryExpression = (BinaryExpression ) expression ;
413- resolveImportPlaceholders (binaryExpression .getLeft (), featureModel );
414- resolveImportPlaceholders (binaryExpression .getRight (), featureModel );
415- } else if (expression instanceof ParenthesisExpression ) {
416- ParenthesisExpression parenthesisExpression = (ParenthesisExpression ) expression ;
417- resolveImportPlaceholders (parenthesisExpression .getContent (), featureModel );
418- } else if (expression instanceof LengthAggregateFunctionExpression ) {
419- LengthAggregateFunctionExpression lengthAggregateFunctionExpression = (LengthAggregateFunctionExpression ) expression ;
420- if (lengthAggregateFunctionExpression .getReference () instanceof ImportedVariablePlaceholder ) {
421- ImportedVariablePlaceholder placeholder = (ImportedVariablePlaceholder ) lengthAggregateFunctionExpression .getReference ();
422- lengthAggregateFunctionExpression .setReference (resolvePlaceholder (placeholder , featureModel ));
419+ final Deque <Expression > stack = new ArrayDeque <>();
420+ stack .push (expression );
421+
422+ while (!stack .isEmpty ()) {
423+ final Expression current = stack .pop ();
424+
425+ if (current instanceof LengthAggregateFunctionExpression ) {
426+ LengthAggregateFunctionExpression lengthAggregateFunctionExpression = (LengthAggregateFunctionExpression ) current ;
427+ if (lengthAggregateFunctionExpression .getReference () instanceof ImportedVariablePlaceholder ) {
428+ ImportedVariablePlaceholder placeholder = (ImportedVariablePlaceholder ) lengthAggregateFunctionExpression .getReference ();
429+ lengthAggregateFunctionExpression .setReference (resolvePlaceholder (placeholder , featureModel ));
430+ }
431+ } else if (current instanceof LiteralExpression ) {
432+ LiteralExpression literalExpression = (LiteralExpression ) current ;
433+ if (literalExpression .getContent () instanceof ImportedVariablePlaceholder ) {
434+ ImportedVariablePlaceholder placeholder = (ImportedVariablePlaceholder ) literalExpression .getContent ();
435+ literalExpression .setContent (resolvePlaceholder (placeholder , featureModel ));
436+ }
423437 }
424- } else if (expression instanceof LiteralExpression ) {
425- LiteralExpression literalExpression = (LiteralExpression ) expression ;
426- if (literalExpression .getContent () instanceof ImportedVariablePlaceholder ) {
427- ImportedVariablePlaceholder placeholder = (ImportedVariablePlaceholder ) literalExpression .getContent ();
428- literalExpression .setContent (resolvePlaceholder (placeholder , featureModel ));
438+
439+ final List <Expression > subExpressions = current .getExpressionSubParts ();
440+ for (int i = subExpressions .size () - 1 ; i >= 0 ; i --) {
441+ stack .push (subExpressions .get (i ));
429442 }
430443 }
431444 }
0 commit comments