From 99e96cd031e9af5667569318c579467332f76322 Mon Sep 17 00:00:00 2001 From: Vanol Nguemo Tadoum Date: Thu, 1 Oct 2026 18:43:10 +0200 Subject: [PATCH] refactor: replace deprecated type dispatchers --- .../types3/UglyExpressionsTypeVisitor.java | 10 ++++------ .../types/check/SymTypeExpressionFactory.java | 5 ++--- .../types3/MCStructuralTypesTypeVisitor.java | 16 ++++++---------- .../types3/util/TypeContextCalculator.java | 6 +++--- 4 files changed, 15 insertions(+), 22 deletions(-) diff --git a/monticore-grammar/src/main/java/de/monticore/expressions/uglyexpressions/types3/UglyExpressionsTypeVisitor.java b/monticore-grammar/src/main/java/de/monticore/expressions/uglyexpressions/types3/UglyExpressionsTypeVisitor.java index c2f3a93f1c..5ebc7785f4 100644 --- a/monticore-grammar/src/main/java/de/monticore/expressions/uglyexpressions/types3/UglyExpressionsTypeVisitor.java +++ b/monticore-grammar/src/main/java/de/monticore/expressions/uglyexpressions/types3/UglyExpressionsTypeVisitor.java @@ -149,13 +149,12 @@ public void endVisit(ASTCreatorExpression expr) { * thus we do not need to modify Type4Ast. */ protected SymTypeExpression getCreatorType(ASTCreator creator) { - //todo use TypeDispatcher as soon as it is fixed SymTypeExpression creatorType; - if (creator instanceof ASTClassCreator) { - creatorType = getClassCreatorType((ASTClassCreator) creator); + if (creator instanceof ASTClassCreator classCreator) { + creatorType = getClassCreatorType(classCreator); } - else if (creator instanceof ASTArrayCreator) { - creatorType = getArrayCreatorType((ASTArrayCreator) creator); + else if (creator instanceof ASTArrayCreator arrayCreator) { + creatorType = getArrayCreatorType(arrayCreator); } else { // hint: if the other ASTCreators have been added in another class, @@ -259,7 +258,6 @@ protected SymTypeExpression getArrayCreatorType(ASTArrayCreator creator) { protected Optional getArrayDimensionSpecifierSize( ASTArrayDimensionSpecifier dimSpec) { Optional dimensions; - // todo use typedispatcher as soon as it works if (dimSpec instanceof ASTArrayDimensionByExpression dims) { List expressions = dims.getExpressionList().stream() .map(e -> getType4Ast().getPartialTypeOfExpr(e)) diff --git a/monticore-grammar/src/main/java/de/monticore/types/check/SymTypeExpressionFactory.java b/monticore-grammar/src/main/java/de/monticore/types/check/SymTypeExpressionFactory.java index b54e563478..12f87e5fbe 100644 --- a/monticore-grammar/src/main/java/de/monticore/types/check/SymTypeExpressionFactory.java +++ b/monticore-grammar/src/main/java/de/monticore/types/check/SymTypeExpressionFactory.java @@ -431,9 +431,8 @@ public static SymTypeOfGenerics createGenerics(String name, IBasicSymbolsScope e * whenever appropriate */ public static SymTypeExpression createFromSymbol(TypeSymbol typeSymbol) { - // TODO: use TypeDispatcher as soon as it is fixed - if(typeSymbol instanceof TypeVarSymbol) { - return createTypeVariable((TypeVarSymbol) typeSymbol); + if(typeSymbol instanceof TypeVarSymbol typeVarSymbol) { + return createTypeVariable(typeVarSymbol); } if(typeSymbol.getSpannedScope().getLocalTypeVarSymbols().isEmpty()) { return createTypeObject(typeSymbol); diff --git a/monticore-grammar/src/main/java/de/monticore/types/mcstructuraltypes/types3/MCStructuralTypesTypeVisitor.java b/monticore-grammar/src/main/java/de/monticore/types/mcstructuraltypes/types3/MCStructuralTypesTypeVisitor.java index 14c6466d4f..95dea55aae 100644 --- a/monticore-grammar/src/main/java/de/monticore/types/mcstructuraltypes/types3/MCStructuralTypesTypeVisitor.java +++ b/monticore-grammar/src/main/java/de/monticore/types/mcstructuraltypes/types3/MCStructuralTypesTypeVisitor.java @@ -105,11 +105,9 @@ public void endVisit(ASTMCBracketType bracketType) { */ protected List transformUnionTree2List(ASTMCType mcType) { List result = new ArrayList<>(); - // todo replace with typedispatcher as soon as the issues are fixed - // https://git.rwth-aachen.de/monticore/monticore/-/issues/3525 - if (mcType instanceof ASTMCUnionType) { - result.addAll(transformUnionTree2List(((ASTMCUnionType) mcType).getLeft())); - result.addAll(transformUnionTree2List(((ASTMCUnionType) mcType).getRight())); + if (mcType instanceof ASTMCUnionType unionType) { + result.addAll(transformUnionTree2List(unionType.getLeft())); + result.addAll(transformUnionTree2List(unionType.getRight())); } else { result.add(mcType); @@ -126,11 +124,9 @@ protected List transformUnionTree2List(ASTMCType mcType) { */ protected List transformIntersectionTree2List(ASTMCType mcType) { List result = new ArrayList<>(); - // todo replace with typedispatcher as soon as the issues are fixed - // https://git.rwth-aachen.de/monticore/monticore/-/issues/3525 - if (mcType instanceof ASTMCIntersectionType) { - result.addAll(transformIntersectionTree2List(((ASTMCIntersectionType) mcType).getLeft())); - result.addAll(transformIntersectionTree2List(((ASTMCIntersectionType) mcType).getRight())); + if (mcType instanceof ASTMCIntersectionType intersectionType) { + result.addAll(transformIntersectionTree2List(intersectionType.getLeft())); + result.addAll(transformIntersectionTree2List(intersectionType.getRight())); } else { result.add(mcType); diff --git a/monticore-grammar/src/main/java/de/monticore/types3/util/TypeContextCalculator.java b/monticore-grammar/src/main/java/de/monticore/types3/util/TypeContextCalculator.java index 98fa7d4576..c9ddca1a5d 100644 --- a/monticore-grammar/src/main/java/de/monticore/types3/util/TypeContextCalculator.java +++ b/monticore-grammar/src/main/java/de/monticore/types3/util/TypeContextCalculator.java @@ -39,9 +39,9 @@ protected Optional _getEnclosingType(IScope enclosingScope) { for (IScope scope = enclosingScope; scope != null && enclosingType.isEmpty(); scope = scope.getEnclosingScope()) { - //TODO: use TypeDispatcher as soon as it is fixed - if (scope.isPresentSpanningSymbol() && scope.getSpanningSymbol() instanceof TypeSymbol) { - enclosingType = Optional.of((TypeSymbol) scope.getSpanningSymbol()); + if (scope.isPresentSpanningSymbol() + && scope.getSpanningSymbol() instanceof TypeSymbol typeSymbol) { + enclosingType = Optional.of(typeSymbol); } } return enclosingType;