From 917749b298c8ea93d8a6c1c372ac7678df80b634 Mon Sep 17 00:00:00 2001 From: lamelizard Date: Fri, 10 Nov 2023 12:07:20 +0100 Subject: [PATCH] remove ExtType extension points --- .../main/grammars/de/monticore/JavaLight.mc4 | 6 +- .../expressions/JavaClassExpressions.mc4 | 38 +- .../expressions/JavaClassExpressions.mlc | 1 + .../grammar/Grammar_WithConcepts.mc4 | 9 - .../grammars/de/monticore/tf/TFBasisExts.mc4 | 8 - .../JavaClassExpressionsFullJavaPrinter.java | 66 - .../JavaClassExpressionsJavaPrinter.java | 18 - ...JavaClassExpressionsFullPrettyPrinter.java | 45 - .../JavaClassExpressionsPrettyPrinter.java | 250 ---- .../prettyprint/AntlrPrettyPrinter.java | 75 -- .../prettyprint/GrammarPrettyPrinter.java | 1193 ----------------- ...Grammar_WithConceptsFullPrettyPrinter.java | 195 --- .../Grammar_WithConceptsPrettyPrinter.java | 135 -- .../JavaLightFullPrettyPrinter.java | 83 -- .../prettyprint/JavaLightPrettyPrinter.java | 214 --- .../DeriveSymTypeOfJavaClassExpressions.java | 110 +- .../grammars/de/monticore/TestJavaLight.mc4 | 7 - .../CombineExpressionsWithLiterals.mc4 | 9 - .../expressions/TestJavaClassExpressions.mc4 | 6 - .../_cocos/NoClassExpressionForGenerics.java | 6 +- ...JavaClassExpressionsPrettyPrinterTest.java | 30 +- .../DeriveSymTypeOfCombineExpressions.java | 65 +- ...riveSymTypeOfJavaClassExpressionsTest.java | 4 +- ...iveFromCombineExpressionsWithLiterals.java | 2 +- ...sionsWithLiteralsTypeTraverserFactory.java | 6 - ...ionsWithLiteralsTypeTraverserProvider.java | 5 - ...ineExpressionsWithLiteralsTypeVisitor.java | 33 - .../mc/basegrammars/MyComplexBaseLanguage.mc4 | 3 - 28 files changed, 123 insertions(+), 2499 deletions(-) delete mode 100644 monticore-grammar/src/main/java/de/monticore/expressions/exptojava/JavaClassExpressionsFullJavaPrinter.java delete mode 100644 monticore-grammar/src/main/java/de/monticore/expressions/exptojava/JavaClassExpressionsJavaPrinter.java delete mode 100644 monticore-grammar/src/main/java/de/monticore/expressions/prettyprint/JavaClassExpressionsFullPrettyPrinter.java delete mode 100644 monticore-grammar/src/main/java/de/monticore/expressions/prettyprint/JavaClassExpressionsPrettyPrinter.java delete mode 100644 monticore-grammar/src/main/java/de/monticore/grammar/prettyprint/AntlrPrettyPrinter.java delete mode 100644 monticore-grammar/src/main/java/de/monticore/grammar/prettyprint/GrammarPrettyPrinter.java delete mode 100644 monticore-grammar/src/main/java/de/monticore/grammar/prettyprint/Grammar_WithConceptsFullPrettyPrinter.java delete mode 100644 monticore-grammar/src/main/java/de/monticore/grammar/prettyprint/Grammar_WithConceptsPrettyPrinter.java delete mode 100644 monticore-grammar/src/main/java/de/monticore/prettyprint/JavaLightFullPrettyPrinter.java delete mode 100644 monticore-grammar/src/main/java/de/monticore/prettyprint/JavaLightPrettyPrinter.java delete mode 100644 monticore-grammar/src/test/java/de/monticore/types3/util/CombineExpressionsWithLiteralsTypeVisitor.java diff --git a/monticore-grammar/src/main/grammars/de/monticore/JavaLight.mc4 b/monticore-grammar/src/main/grammars/de/monticore/JavaLight.mc4 index 670d3382c4..62143b8e80 100644 --- a/monticore-grammar/src/main/grammars/de/monticore/JavaLight.mc4 +++ b/monticore-grammar/src/main/grammars/de/monticore/JavaLight.mc4 @@ -29,8 +29,6 @@ component grammar JavaLight extends AssignmentExpressions, MCArrayStatements, MCReturnStatements { -external ExtTypeParameters; - interface ClassBodyDeclaration; interface InterfaceBodyDeclaration; @@ -47,12 +45,12 @@ symbolrule JavaMethod = isDefault: boolean; MethodDeclaration implements JavaMethod, ClassBodyDeclaration, InterfaceBodyDeclaration - = MCModifier* ExtTypeParameters? + = MCModifier* ("<"(MCTypeArgument||",")+">")? MCReturnType Name FormalParameters (dim:"[" "]")* ("throws" Throws)? (MCJavaBlock | ";"); ConstructorDeclaration implements JavaMethod, ClassBodyDeclaration - = MCModifier* ExtTypeParameters? Name FormalParameters + = MCModifier* ("<"(MCTypeArgument||",")+">")? Name FormalParameters ("throws" Throws)? MCJavaBlock; ConstDeclaration extends LocalVariableDeclarationStatement diff --git a/monticore-grammar/src/main/grammars/de/monticore/expressions/JavaClassExpressions.mc4 b/monticore-grammar/src/main/grammars/de/monticore/expressions/JavaClassExpressions.mc4 index 882c9a5031..a4a6823649 100644 --- a/monticore-grammar/src/main/grammars/de/monticore/expressions/JavaClassExpressions.mc4 +++ b/monticore-grammar/src/main/grammars/de/monticore/expressions/JavaClassExpressions.mc4 @@ -6,6 +6,7 @@ package de.monticore.expressions; import de.monticore.expressions.*; import de.monticore.statements.*; +import de.monticore.types.*; /** * This grammar defines Java specific class expressions like super, @@ -35,26 +36,9 @@ import de.monticore.statements.*; */ component grammar JavaClassExpressions - extends CommonExpressions, MCVarDeclarationStatements { - - - /*=================================================================*/ - - /* - * The following are several extension points that allow to fill in the - * the desired type system: - * e.g. the complete type system of java (extending MCFullGenericType) - * or any smaller variant - */ - - // Types - external ExtType; - - // Types including a void return type - external ExtReturnType; - - // Type arguments - external ExtTypeArgument; + extends CommonExpressions, + MCVarDeclarationStatements, + MCFullGenericTypes { /*=================================================================*/ @@ -75,7 +59,7 @@ component grammar JavaClassExpressions // casting expression uses a type TypeCastExpression implements Expression <230> = - "(" ExtType ")" Expression; + "(" MCType ")" Expression; PrimarySuperExpression implements Expression <330> = "super"; @@ -86,10 +70,10 @@ component grammar JavaClassExpressions interface Creator ; AnonymousClass implements Creator - = ExtType Arguments; + = MCType Arguments; ArrayCreator implements Creator - = ExtType ArrayDimensionSpecifier; + = MCType ArrayDimensionSpecifier; interface ArrayDimensionSpecifier ; @@ -101,11 +85,11 @@ component grammar JavaClassExpressions // access of class object uses a type ClassExpression implements Expression <360> = - ExtReturnType "." "class"; + MCReturnType "." "class"; // generic invocation may specify type arguments PrimaryGenericInvocationExpression implements Expression <370> = - "<"(ExtTypeArgument||",")+">" GenericInvocationSuffix; + "<"(MCTypeArgument||",")+">" GenericInvocationSuffix; GenericInvocationSuffix = ["super"] SuperSuffix @@ -115,14 +99,14 @@ component grammar JavaClassExpressions SuperSuffix = Arguments - | "." ("<"(ExtTypeArgument||",")+">")? Name Arguments? + | "." ("<"(MCTypeArgument||",")+">")? Name Arguments? ; /*=================================================================*/ // instance of needs a type or pattern as argument InstanceofExpression implements Expression <140> = - Expression "instanceof" (ExtType | Pattern); + Expression "instanceof" (MCType | Pattern); interface Pattern; diff --git a/monticore-grammar/src/main/grammars/de/monticore/expressions/JavaClassExpressions.mlc b/monticore-grammar/src/main/grammars/de/monticore/expressions/JavaClassExpressions.mlc index fe140f641d..dcf645b786 100644 --- a/monticore-grammar/src/main/grammars/de/monticore/expressions/JavaClassExpressions.mlc +++ b/monticore-grammar/src/main/grammars/de/monticore/expressions/JavaClassExpressions.mlc @@ -21,5 +21,6 @@ mlc JavaClassExpressions { promote { mlc "de.monticore.expressions.CommonExpressions"; + mlc "de.monticore.types.MCFullGenericTypes" } } diff --git a/monticore-grammar/src/main/grammars/de/monticore/grammar/Grammar_WithConcepts.mc4 b/monticore-grammar/src/main/grammars/de/monticore/grammar/Grammar_WithConcepts.mc4 index a31c383f96..96280f86a2 100644 --- a/monticore-grammar/src/main/grammars/de/monticore/grammar/Grammar_WithConcepts.mc4 +++ b/monticore-grammar/src/main/grammars/de/monticore/grammar/Grammar_WithConcepts.mc4 @@ -29,13 +29,4 @@ grammar Grammar_WithConcepts extends JavaCode = ClassBodyDeclaration*; - ExtType = MCType; - - ExtReturnType = MCReturnType; - - ExtTypeArgument = "<" (MCTypeArgument || ",")+ ">"*; - - // Empty TypeParameters - ExtTypeParameters = ; - } diff --git a/monticore-grammar/src/main/grammars/de/monticore/tf/TFBasisExts.mc4 b/monticore-grammar/src/main/grammars/de/monticore/tf/TFBasisExts.mc4 index d3e1e0d642..b3c0e49d85 100644 --- a/monticore-grammar/src/main/grammars/de/monticore/tf/TFBasisExts.mc4 +++ b/monticore-grammar/src/main/grammars/de/monticore/tf/TFBasisExts.mc4 @@ -4,13 +4,5 @@ package de.monticore.tf; component grammar TFBasisExts extends de.monticore.JavaLight, de.monticore.types.MCSimpleGenericTypes, de.monticore.literals.MCCommonLiterals { - @Override - ExtType = MCType; - @Override - ExtReturnType = MCReturnType; - @Override - ExtTypeArgument = MCTypeArgument; - @Override - ExtTypeParameters = MCType; } diff --git a/monticore-grammar/src/main/java/de/monticore/expressions/exptojava/JavaClassExpressionsFullJavaPrinter.java b/monticore-grammar/src/main/java/de/monticore/expressions/exptojava/JavaClassExpressionsFullJavaPrinter.java deleted file mode 100644 index fb0ce0c493..0000000000 --- a/monticore-grammar/src/main/java/de/monticore/expressions/exptojava/JavaClassExpressionsFullJavaPrinter.java +++ /dev/null @@ -1,66 +0,0 @@ -/* (c) https://github.com/MontiCore/monticore */ -package de.monticore.expressions.exptojava; - -import de.monticore.expressions.javaclassexpressions.JavaClassExpressionsMill; -import de.monticore.expressions.javaclassexpressions._ast.ASTGenericInvocationSuffix; -import de.monticore.expressions.javaclassexpressions._ast.ASTTypePattern; -import de.monticore.expressions.javaclassexpressions._visitor.JavaClassExpressionsTraverser; -import de.monticore.prettyprint.IndentPrinter; -import de.monticore.statements.mcstatementsbasis._prettyprint.MCStatementsBasisPrettyPrinter; -import de.monticore.statements.prettyprint.MCVarDeclarationStatementsPrettyPrinter; -import de.monticore.types.prettyprint.MCBasicTypesPrettyPrinter; - -@Deprecated(forRemoval = true) -public class JavaClassExpressionsFullJavaPrinter extends CommonExpressionsFullJavaPrinter { - - protected JavaClassExpressionsTraverser traverser; - - @Override - public JavaClassExpressionsTraverser getTraverser() { - return traverser; - } - - public void setTraverser(JavaClassExpressionsTraverser traverser) { - this.traverser = traverser; - } - - public JavaClassExpressionsFullJavaPrinter(IndentPrinter printer) { - super(printer); - this.traverser = JavaClassExpressionsMill.traverser(); - - LegacyCommonExpressionsJavaPrinter commonExpression = new LegacyCommonExpressionsJavaPrinter(printer); - traverser.setCommonExpressionsHandler(commonExpression); - traverser.add4CommonExpressions(commonExpression); - ExpressionsBasisJavaPrinter expressionBasis = new ExpressionsBasisJavaPrinter(printer); - traverser.setExpressionsBasisHandler(expressionBasis); - traverser.add4ExpressionsBasis(expressionBasis); - JavaClassExpressionsJavaPrinter javaClassExpression = new JavaClassExpressionsJavaPrinter(printer); - traverser.setJavaClassExpressionsHandler(javaClassExpression); - traverser.add4JavaClassExpressions(javaClassExpression); - - MCBasicTypesPrettyPrinter mcBasicTypes = new MCBasicTypesPrettyPrinter(printer); - traverser.setMCBasicTypesHandler(mcBasicTypes); - traverser.add4MCBasicTypes(mcBasicTypes); - - MCStatementsBasisPrettyPrinter mcStatementsBasis = new MCStatementsBasisPrettyPrinter(printer, true); - traverser.setMCStatementsBasisHandler(mcStatementsBasis); - traverser.add4MCStatementsBasis(mcStatementsBasis); - - MCVarDeclarationStatementsPrettyPrinter mcVarDeclarationStatements = new MCVarDeclarationStatementsPrettyPrinter(printer); - traverser.setMCVarDeclarationStatementsHandler(mcVarDeclarationStatements); - traverser.add4MCVarDeclarationStatements(mcVarDeclarationStatements); - } - - public String print(ASTGenericInvocationSuffix node) { - getPrinter().clearBuffer(); - node.accept(getTraverser()); - return getPrinter().getContent(); - } - - public String print(ASTTypePattern node) { - getPrinter().clearBuffer(); - node.accept(getTraverser()); - return getPrinter().getContent(); - } - -} diff --git a/monticore-grammar/src/main/java/de/monticore/expressions/exptojava/JavaClassExpressionsJavaPrinter.java b/monticore-grammar/src/main/java/de/monticore/expressions/exptojava/JavaClassExpressionsJavaPrinter.java deleted file mode 100644 index b2abe20aa8..0000000000 --- a/monticore-grammar/src/main/java/de/monticore/expressions/exptojava/JavaClassExpressionsJavaPrinter.java +++ /dev/null @@ -1,18 +0,0 @@ -/* (c) https://github.com/MontiCore/monticore */ -package de.monticore.expressions.exptojava;/* (c) https://github.com/MontiCore/monticore */ - -import de.monticore.expressions.prettyprint.JavaClassExpressionsPrettyPrinter; -import de.monticore.prettyprint.IndentPrinter; - -@Deprecated(forRemoval = true) -public class JavaClassExpressionsJavaPrinter extends JavaClassExpressionsPrettyPrinter { - - public JavaClassExpressionsJavaPrinter(IndentPrinter printer) { - super(printer); - } - - public JavaClassExpressionsJavaPrinter() { - super(new IndentPrinter()); - } - -} diff --git a/monticore-grammar/src/main/java/de/monticore/expressions/prettyprint/JavaClassExpressionsFullPrettyPrinter.java b/monticore-grammar/src/main/java/de/monticore/expressions/prettyprint/JavaClassExpressionsFullPrettyPrinter.java deleted file mode 100644 index 99194c2a1d..0000000000 --- a/monticore-grammar/src/main/java/de/monticore/expressions/prettyprint/JavaClassExpressionsFullPrettyPrinter.java +++ /dev/null @@ -1,45 +0,0 @@ -/* (c) https://github.com/MontiCore/monticore */ -package de.monticore.expressions.prettyprint; - -import de.monticore.expressions.javaclassexpressions.JavaClassExpressionsMill; -import de.monticore.expressions.javaclassexpressions._ast.ASTGenericInvocationSuffix; -import de.monticore.expressions.javaclassexpressions._visitor.JavaClassExpressionsTraverser; -import de.monticore.prettyprint.IndentPrinter; -import de.monticore.prettyprint.MCBasicsPrettyPrinter; - -@Deprecated(forRemoval = true) -public class JavaClassExpressionsFullPrettyPrinter extends CommonExpressionsFullPrettyPrinter { - - protected JavaClassExpressionsTraverser traverser; - - @Override - public JavaClassExpressionsTraverser getTraverser() { - return traverser; - } - - public void setTraverser(JavaClassExpressionsTraverser traverser) { - this.traverser = traverser; - } - - public JavaClassExpressionsFullPrettyPrinter(IndentPrinter printer) { - super(printer); - this.traverser = JavaClassExpressionsMill.traverser(); - CommonExpressionsPrettyPrinter commonExpression = new CommonExpressionsPrettyPrinter(printer); - traverser.setCommonExpressionsHandler(commonExpression); - traverser.add4CommonExpressions(commonExpression); - ExpressionsBasisPrettyPrinter expressionBasis = new ExpressionsBasisPrettyPrinter(printer); - traverser.setExpressionsBasisHandler(expressionBasis); - traverser.add4ExpressionsBasis(expressionBasis); - JavaClassExpressionsPrettyPrinter javaClassExpression = new JavaClassExpressionsPrettyPrinter(printer); - traverser.setJavaClassExpressionsHandler(javaClassExpression); - traverser.add4JavaClassExpressions(javaClassExpression); - MCBasicsPrettyPrinter basic = new MCBasicsPrettyPrinter(printer); - traverser.add4MCBasics(basic); - } - - public String prettyprint(ASTGenericInvocationSuffix node){ - getPrinter().clearBuffer(); - node.accept(getTraverser()); - return getPrinter().getContent(); - } -} diff --git a/monticore-grammar/src/main/java/de/monticore/expressions/prettyprint/JavaClassExpressionsPrettyPrinter.java b/monticore-grammar/src/main/java/de/monticore/expressions/prettyprint/JavaClassExpressionsPrettyPrinter.java deleted file mode 100644 index 2ab40162ea..0000000000 --- a/monticore-grammar/src/main/java/de/monticore/expressions/prettyprint/JavaClassExpressionsPrettyPrinter.java +++ /dev/null @@ -1,250 +0,0 @@ -/* (c) https://github.com/MontiCore/monticore */ -package de.monticore.expressions.prettyprint; - -import de.monticore.expressions.expressionsbasis._ast.ASTExpression; -import de.monticore.expressions.javaclassexpressions._ast.*; -import de.monticore.expressions.javaclassexpressions._visitor.JavaClassExpressionsHandler; -import de.monticore.expressions.javaclassexpressions._visitor.JavaClassExpressionsTraverser; -import de.monticore.expressions.javaclassexpressions._visitor.JavaClassExpressionsVisitor2; -import de.monticore.prettyprint.CommentPrettyPrinter; -import de.monticore.prettyprint.IndentPrinter; - -import java.util.List; - -@Deprecated(forRemoval = true) -public class JavaClassExpressionsPrettyPrinter implements JavaClassExpressionsVisitor2, JavaClassExpressionsHandler { - - protected JavaClassExpressionsTraverser traverser; - - @Override - public void setTraverser(JavaClassExpressionsTraverser traverser) { - this.traverser = traverser; - } - - @Override - public JavaClassExpressionsTraverser getTraverser() { - return traverser; - } - - public void setPrinter(IndentPrinter printer) { - this.printer = printer; - } - - protected IndentPrinter printer; - - public JavaClassExpressionsPrettyPrinter(IndentPrinter printer) { - this.printer = printer; - } - - @Override - public void visit(ASTPrimarySuperExpression node) { - CommentPrettyPrinter.printPreComments(node, getPrinter()); - getPrinter().print("super"); - CommentPrettyPrinter.printPostComments(node, getPrinter()); - } - - @Override - public void handle(ASTSuperSuffix node) { - CommentPrettyPrinter.printPreComments(node, getPrinter()); - if (node.isPresentName()) { - getPrinter().print("."); - if (!node.getExtTypeArgumentList().isEmpty()) { - handleTypeArguments(node.getExtTypeArgumentList()); - } - getPrinter().print(node.getName()); - if (node.isPresentArguments()) { - node.getArguments().accept(getTraverser()); - } - } else { - node.getArguments().accept(getTraverser()); - } - CommentPrettyPrinter.printPostComments(node, getPrinter()); - } - - protected void handleTypeArguments(List typeArguments){ - getPrinter().print("<"); - for (int i = 0; i < typeArguments.size(); i++) { - typeArguments.get(i).accept(getTraverser()); - if (i != typeArguments.size() - 1) { - getPrinter().print(","); - } - } - getPrinter().print(">"); - } - - @Override - public void handle(ASTSuperExpression node) { - CommentPrettyPrinter.printPreComments(node, getPrinter()); - node.getExpression().accept(getTraverser()); - getPrinter().print(".super"); - node.getSuperSuffix().accept(getTraverser()); - CommentPrettyPrinter.printPostComments(node, getPrinter()); - } - - @Override - public void handle(ASTClassExpression node) { - CommentPrettyPrinter.printPreComments(node, getPrinter()); - node.getExtReturnType().accept(getTraverser()); - getPrinter().print(".class"); - CommentPrettyPrinter.printPostComments(node, getPrinter()); - } - - @Override - public void handle(ASTTypeCastExpression node) { - CommentPrettyPrinter.printPreComments(node, getPrinter()); - getPrinter().print("("); - node.getExtType().accept(getTraverser()); - getPrinter().print(")"); - node.getExpression().accept(getTraverser()); - CommentPrettyPrinter.printPostComments(node, getPrinter()); - } - - @Override - public void handle(ASTGenericInvocationSuffix node) { - CommentPrettyPrinter.printPreComments(node, getPrinter()); - if (node.isPresentSuperSuffix()) { - if (node.isSuper()) { - getPrinter().print("super"); - } - node.getSuperSuffix().accept(getTraverser()); - } else if (node.isPresentName()) { - getPrinter().print(node.getName()); - node.getArguments().accept(getTraverser()); - } else { - if (node.isThis()) { - getPrinter().print("this"); - } - node.getArguments().accept(getTraverser()); - CommentPrettyPrinter.printPostComments(node, getPrinter()); - } - - } - - @Override - public void handle(ASTGenericInvocationExpression node) { - CommentPrettyPrinter.printPreComments(node, getPrinter()); - node.getExpression().accept(getTraverser()); - getPrinter().print("."); - handle(node.getPrimaryGenericInvocationExpression()); - CommentPrettyPrinter.printPostComments(node, getPrinter()); - } - - @Override - public void handle(ASTPrimaryGenericInvocationExpression node) { - CommentPrettyPrinter.printPreComments(node, getPrinter()); - getPrinter().print("<"); - for (int i = 0; i < node.getExtTypeArgumentList().size(); i++) { - node.getExtTypeArgument(i).accept(getTraverser()); - if (i != node.getExtTypeArgumentList().size() - 1) { - getPrinter().print(","); - } - } - getPrinter().print(">"); - getPrinter().print(" "); - node.getGenericInvocationSuffix().accept(getTraverser()); - CommentPrettyPrinter.printPostComments(node, getPrinter()); - } - - @Override - public void handle(ASTInstanceofExpression node) { - CommentPrettyPrinter.printPreComments(node, getPrinter()); - node.getExpression().accept(getTraverser()); - getPrinter().print(" instanceof "); - - if (node.isPresentExtType()) { - node.getExtType().accept(getTraverser()); - } else { - node.getPattern().accept(getTraverser()); - } - - CommentPrettyPrinter.printPostComments(node, getPrinter()); - } - - @Override - public void handle(ASTThisExpression node) { - CommentPrettyPrinter.printPreComments(node, getPrinter()); - node.getExpression().accept(getTraverser()); - getPrinter().print("."); - getPrinter().print("this"); - CommentPrettyPrinter.printPostComments(node, getPrinter()); - } - - @Override - public void handle(ASTArrayExpression node) { - CommentPrettyPrinter.printPreComments(node, getPrinter()); - node.getExpression().accept(getTraverser()); - getPrinter().print("["); - node.getIndexExpression().accept(getTraverser()); - getPrinter().print("]"); - CommentPrettyPrinter.printPostComments(node, getPrinter()); - } - - @Override - public void visit(ASTPrimaryThisExpression node) { - CommentPrettyPrinter.printPreComments(node, getPrinter()); - getPrinter().print("this"); - CommentPrettyPrinter.printPostComments(node, getPrinter()); - } - - @Override - public void handle(ASTArrayCreator a) { - CommentPrettyPrinter.printPreComments(a, getPrinter()); - a.getExtType().accept(getTraverser()); - a.getArrayDimensionSpecifier().accept(getTraverser()); - CommentPrettyPrinter.printPostComments(a, getPrinter()); - } - - @Override - public void handle(ASTArrayDimensionByExpression a) { - CommentPrettyPrinter.printPreComments(a, getPrinter()); - for (ASTExpression astExpression : a.getExpressionList()) { - getPrinter().print("["); - astExpression.accept(getTraverser()); - getPrinter().print("]"); - } - for (int i = 0; i < a.getDimList().size(); i++) { - getPrinter().print("[]"); - } - CommentPrettyPrinter.printPostComments(a, getPrinter()); - } - - - @Override - public void handle(ASTCreatorExpression a) { - CommentPrettyPrinter.printPreComments(a, getPrinter()); - getPrinter().print(" new "); - a.getCreator().accept(getTraverser()); - CommentPrettyPrinter.printPostComments(a, getPrinter()); - } - - @Override - public void handle(ASTTypePattern node) { - CommentPrettyPrinter.printPreComments(node, getPrinter()); - node.getLocalVariableDeclaration().accept(getTraverser()); - CommentPrettyPrinter.printPostComments(node, getPrinter()); - } - - public IndentPrinter getPrinter() { - return this.printer; - } - - public String prettyprint(ASTExpression node) { - getPrinter().clearBuffer(); - node.accept(getTraverser()); - return getPrinter().getContent(); - } - - public String prettyprint(ASTGenericInvocationSuffix node) { - getPrinter().clearBuffer(); - node.accept(getTraverser()); - return getPrinter().getContent(); - } - - public String prettyprint(ASTSuperSuffix node) { - getPrinter().clearBuffer(); - node.accept(getTraverser()); - return getPrinter().getContent(); - } - - -} diff --git a/monticore-grammar/src/main/java/de/monticore/grammar/prettyprint/AntlrPrettyPrinter.java b/monticore-grammar/src/main/java/de/monticore/grammar/prettyprint/AntlrPrettyPrinter.java deleted file mode 100644 index 89b9a031ef..0000000000 --- a/monticore-grammar/src/main/java/de/monticore/grammar/prettyprint/AntlrPrettyPrinter.java +++ /dev/null @@ -1,75 +0,0 @@ -/* (c) https://github.com/MontiCore/monticore */ - -package de.monticore.grammar.prettyprint; - -import de.monticore.grammar.concepts.antlr.antlr._ast.ASTAntlrLexerAction; -import de.monticore.grammar.concepts.antlr.antlr._ast.ASTAntlrNode; -import de.monticore.grammar.concepts.antlr.antlr._ast.ASTAntlrParserAction; -import de.monticore.grammar.concepts.antlr.antlr._visitor.AntlrHandler; -import de.monticore.grammar.concepts.antlr.antlr._visitor.AntlrTraverser; -import de.monticore.grammar.concepts.antlr.antlr._visitor.AntlrVisitor2; -import de.monticore.prettyprint.CommentPrettyPrinter; -import de.monticore.prettyprint.IndentPrinter; - -@Deprecated(forRemoval = true) -public class AntlrPrettyPrinter implements AntlrVisitor2, AntlrHandler { - - // printer to use - protected IndentPrinter printer = null; - - protected AntlrTraverser traverser; - - public AntlrPrettyPrinter(IndentPrinter out) { - printer = out; - } - - @Override - public void handle(ASTAntlrLexerAction a) { - CommentPrettyPrinter.printPreComments(a, getPrinter()); - getPrinter().print("lexerjava "); - getPrinter().print(" {"); - getPrinter().println(); - getPrinter().indent(); - a.getText().accept(getTraverser()); - getPrinter().unindent(); - getPrinter().print("}"); - CommentPrettyPrinter.printPostComments(a, getPrinter()); - } - - @Override - public void handle(ASTAntlrParserAction a) { - CommentPrettyPrinter.printPreComments(a, getPrinter()); - getPrinter().print("parserjava "); - getPrinter().print(" {"); - getPrinter().println(); - getPrinter().indent(); - a.getText().accept(getTraverser()); - getPrinter().unindent(); - getPrinter().print("}"); - CommentPrettyPrinter.printPostComments(a, getPrinter()); - } - - public String prettyprint(ASTAntlrNode a) { - getPrinter().clearBuffer(); - a.accept(getTraverser()); - return getPrinter().getContent(); - } - - public IndentPrinter getPrinter() { - return printer; - } - - public void setPrinter(IndentPrinter printer) { - this.printer = printer; - } - - @Override - public AntlrTraverser getTraverser() { - return traverser; - } - - @Override - public void setTraverser(AntlrTraverser traverser) { - this.traverser = traverser; - } -} diff --git a/monticore-grammar/src/main/java/de/monticore/grammar/prettyprint/GrammarPrettyPrinter.java b/monticore-grammar/src/main/java/de/monticore/grammar/prettyprint/GrammarPrettyPrinter.java deleted file mode 100644 index 02c7f68097..0000000000 --- a/monticore-grammar/src/main/java/de/monticore/grammar/prettyprint/GrammarPrettyPrinter.java +++ /dev/null @@ -1,1193 +0,0 @@ -/* (c) https://github.com/MontiCore/monticore */ - -package de.monticore.grammar.prettyprint; - -import de.monticore.grammar.grammar._ast.*; -import de.monticore.grammar.grammar._visitor.GrammarHandler; -import de.monticore.grammar.grammar._visitor.GrammarTraverser; -import de.monticore.grammar.grammar._visitor.GrammarVisitor2; -import de.monticore.prettyprint.CommentPrettyPrinter; -import de.monticore.prettyprint.IndentPrinter; -import de.monticore.types.mcbasictypes._ast.ASTMCBasicTypesNode; -import de.monticore.types.mcbasictypes._ast.ASTMCType; -import de.se_rwth.commons.Names; - -import java.util.Iterator; - -@Deprecated(forRemoval = true) -public class GrammarPrettyPrinter implements GrammarVisitor2, GrammarHandler { - - protected static final String QUOTE = "\""; - - protected GrammarTraverser traverser; - - protected IndentPrinter printer; - - public GrammarPrettyPrinter(IndentPrinter printer) { - this.printer = printer; - printer.setIndentLength(2); - } - - @Override - public void handle(ASTSemanticpredicateOrAction a) { - CommentPrettyPrinter.printPreComments(a, getPrinter()); - - if (a.isPresentExpressionPredicate()) { - print(" {"); - getPrinter().println(); - getPrinter().indent(); - a.getExpressionPredicate().accept(getTraverser()); - getPrinter().unindent(); - print("}"); - print(" ?"); - } - if (a.isPresentAction()) { - print(" {"); - getPrinter().println(); - getPrinter().indent(); - a.getAction().accept(getTraverser()); - getPrinter().unindent(); - print("}"); - } - - getPrinter().print(" "); - CommentPrettyPrinter.printPostComments(a, getPrinter()); - - } - - @Override - public void handle(ASTExternalProd a) { - - CommentPrettyPrinter.printPreComments(a, getPrinter()); - printList(a.getGrammarAnnotationList().iterator(), ""); - print("external "); - - printList(a.getSymbolDefinitionList().iterator(), " "); - getPrinter().print(a.getName()); - - if (a.isPresentMCType()) { - a.getMCType().accept(getTraverser()); - } - getPrinter().print(";"); - CommentPrettyPrinter.printPostComments(a, getPrinter()); - getPrinter().println(); - - } - - @Override - public void handle(ASTGrammarOption a) { - CommentPrettyPrinter.printPreComments(a, getPrinter()); - println("options {"); - getPrinter().indent(); - - printList(a.getFollowOptionList().iterator(), ""); - - getPrinter().unindent(); - print("}"); - - CommentPrettyPrinter.printPostComments(a, getPrinter()); - - println(); - println(); - - } - - @Override - public void handle(ASTNonTerminal a) { - CommentPrettyPrinter.printPreComments(a, getPrinter()); - - if (a.isPresentUsageName()) { - print("" + a.getUsageName() + ":"); - } - - print(a.getName()); - if (a.isPresentReferencedSymbol()) { - print("@"); - print(a.getReferencedSymbol()); - } - - if (a.isGenSymbol()) { - print("!!"); - if (a.isPresentSymbolName()) { - print(a.getSymbolName()); - } - } - - if (a.isPlusKeywords()) { - print("& "); - } - - outputIteration(a.getIteration()); - - CommentPrettyPrinter.printPostComments(a, getPrinter()); - - } - - @Override - public void handle(ASTKeyTerminal a) { - CommentPrettyPrinter.printPreComments(a, getPrinter()); - if (a.isPresentUsageName()) { - print("" + a.getUsageName() + ":"); - } - a.getKeyConstant().accept(getTraverser()); - outputIteration(a.getIteration()); - CommentPrettyPrinter.printPostComments(a, getPrinter()); - } - - @Override - public void handle(ASTKeyConstant a) { - print(" key("); - String sep = ""; - for (String name: a.getStringList()) { - print(sep); - print("\"" + name + "\""); - sep = " | "; - } - print(")"); - } - - @Override - public void handle(ASTTokenTerminal a) { - CommentPrettyPrinter.printPreComments(a, getPrinter()); - if (a.isPresentUsageName()) { - print("" + a.getUsageName() + ":"); - } - a.getTokenConstant().accept(getTraverser()); - outputIteration(a.getIteration()); - CommentPrettyPrinter.printPostComments(a, getPrinter()); - } - - @Override - public void handle(ASTTokenConstant a) { - print(" token("); - print(a.getString()); - print(")"); - } - - @Override - public void handle(ASTSplitRule a) { - CommentPrettyPrinter.printPreComments(a, getPrinter()); - print("split_token "); - String sep = ""; - for (String s: a.getStringList()) { - print(sep); - sep = ", "; - print(s); - } - println (";"); - CommentPrettyPrinter.printPostComments(a, getPrinter()); - } - - @Override - public void handle(ASTReplaceRule a) { - CommentPrettyPrinter.printPreComments(a, getPrinter()); - print("additionalkeyword "); - print(a.getKeyword()); - String sep = ""; - for (String s: a.getReplacedKeyWordList()) { - print(sep); - sep = ", "; - print(s); - } - println (";"); - CommentPrettyPrinter.printPostComments(a, getPrinter()); - } - - @Override - public void handle(ASTKeywordRule a) { - CommentPrettyPrinter.printPreComments(a, getPrinter()); - print("nokeyword "); - String sep = ""; - for (String s: a.getStringList()) { - print(sep); - sep = ", "; - print("\""); - print(s); - print("\""); - } - println (";"); - CommentPrettyPrinter.printPostComments(a, getPrinter()); - } - - @Override - public void handle(ASTTerminal a) { - CommentPrettyPrinter.printPreComments(a, getPrinter()); - // output("ASTTerminal Iteration " + a.getIteration()); - if (a.isPresentUsageName()) { - print("" + a.getUsageName() + ":"); - } - print("\"" + a.getName() + "\""); - outputIteration(a.getIteration()); - CommentPrettyPrinter.printPostComments(a, getPrinter()); - } - - @Override - public void handle(ASTBlock a) { - CommentPrettyPrinter.printPreComments(a, getPrinter()); - print("("); - - if (a.isPresentOption()) { - print("options {"); - - for (ASTOptionValue x : a.getOption().getOptionValueList()) { - print(x.getKey() + "=" + x.getValue() + ";"); - } - - print("} "); - } - - if (a.isPresentInitAction()) { - getPrinter().print("init "); - print(" {"); - getPrinter().println(); - getPrinter().indent(); - a.getInitAction().accept(getTraverser()); - getPrinter().unindent(); - print("}"); - } - - if (a.isPresentInitAction() || a.isPresentOption()) { - print(": "); - } - - printList(a.getAltList().iterator(), "| "); - print(")"); - outputIteration(a.getIteration()); - - CommentPrettyPrinter.printPostComments(a, getPrinter()); - - getPrinter().optionalBreak(); - - } - - /** - * Visiting an ASTConcept #not sure for complete children methods - * - * @param a - */ - @Override - public void handle(ASTConcept a) { - CommentPrettyPrinter.printPreComments(a, getPrinter()); - println("concept " + a.getName() + "{ "); - - a.getConcept().accept(getTraverser()); - - CommentPrettyPrinter.printPostComments(a, getPrinter()); - println("}"); - } - - /** - * #complete children calls - * - * @param a - */ - @Override - public void handle(ASTConstant a) { - CommentPrettyPrinter.printPreComments(a, getPrinter()); - if (a.isPresentUsageName()) { - print(a.getUsageName() + ":"); - } - if (a.isPresentKeyConstant()) { - a.getKeyConstant().accept(getTraverser()); - }else if (a.isPresentTokenConstant()) { - a.getTokenConstant().accept(getTraverser()); - } else { - print(QUOTE + a.getName() + QUOTE); - } - CommentPrettyPrinter.printPostComments(a, getPrinter()); - } - - /** - * #complete children calls is usagename ever used?? - * - * @param a - */ - @Override - public void handle(ASTConstantGroup a) { - CommentPrettyPrinter.printPreComments(a, getPrinter()); - if (a.isPresentUsageName()) { - print(a.getUsageName()); - print(":"); - } - print("["); - printList(a.getConstantList().iterator(), " | "); - print("]"); - outputIteration(a.getIteration()); - CommentPrettyPrinter.printPostComments(a, getPrinter()); - } - - /** - * #complete children calls - * - * @param a - */ - @Override - public void handle(ASTAlt a) { - CommentPrettyPrinter.printPreComments(a, getPrinter()); - if (a.isRightAssoc()) { - getPrinter().print(" "); - } - if (a.isPresentGrammarAnnotation()) { - a.getGrammarAnnotation().accept(getTraverser()); - } - printList(a.getComponentList().iterator(), " "); - CommentPrettyPrinter.printPostComments(a, getPrinter()); - } - - @Override - public void handle(ASTInterfaceProd a) { - CommentPrettyPrinter.printPreComments(a, getPrinter()); - - printList(a.getGrammarAnnotationList().iterator(), ""); - print("interface "); - - printList(a.getSymbolDefinitionList().iterator(), " "); - - print(a.getName()); - - if (!a.getSuperInterfaceRuleList().isEmpty()) { - getPrinter().print(" extends "); - String comma = ""; - for (ASTRuleReference x : a.getSuperInterfaceRuleList()) { - getPrinter().print(comma); - x.accept(getTraverser()); - comma = ", "; - } - } - - if (!a.getASTSuperInterfaceList().isEmpty()) { - getPrinter().print(" astextends "); - String comma = ""; - for (ASTMCType x : a.getASTSuperInterfaceList()) { - getPrinter().print(comma); - x.accept(getTraverser()); - comma = ", "; - } - } - - if (!a.getAltList().isEmpty()) { - println(" ="); - - getPrinter().indent(); - printList(a.getAltList().iterator(), " | "); - } - - getPrinter().print(";"); - CommentPrettyPrinter.printPostComments(a, getPrinter()); - getPrinter().println(); - getPrinter().println(); - - } - - @Override - public void handle(ASTEnumProd a) { - CommentPrettyPrinter.printPreComments(a, getPrinter()); - printList(a.getGrammarAnnotationList().iterator(), ""); - print("enum "); - print(a.getName()); - - getPrinter().print(" = "); - String sep = ""; - for (ASTConstant ref : a.getConstantList()) { - print(sep); - ref.accept(getTraverser()); - sep = " | "; - } - getPrinter().print(" "); - - getPrinter().print(";"); - CommentPrettyPrinter.printPostComments(a, getPrinter()); - getPrinter().println(); - getPrinter().println(); - - } - - @Override - public void handle(ASTASTRule a) { - CommentPrettyPrinter.printPreComments(a, getPrinter()); - print("astrule "); - - print(a.getType()); - - if (!a.getASTSuperClassList().isEmpty()) { - getPrinter().print(" astextends "); - String comma = ""; - for (ASTMCType x : a.getASTSuperClassList()) { - getPrinter().print(comma); - x.accept(getTraverser()); - comma = ", "; - } - } - - if (!a.getASTSuperInterfaceList().isEmpty()) { - getPrinter().print(" astimplements "); - String comma = ""; - for (ASTMCType x : a.getASTSuperInterfaceList()) { - getPrinter().print(comma); - x.accept(getTraverser()); - comma = ", "; - } - } - - if (!a.getGrammarMethodList().isEmpty() || !a.getAdditionalAttributeList().isEmpty()) { - - println(" = "); - getPrinter().indent(); - printList(a.getAdditionalAttributeList().iterator(), ""); - printList(a.getGrammarMethodList().iterator(), ""); - } - - getPrinter().print(";"); - getPrinter().unindent(); - CommentPrettyPrinter.printPostComments(a, getPrinter()); - getPrinter().println(); - - } - - @Override - public void handle(ASTSymbolRule a) { - CommentPrettyPrinter.printPreComments(a, getPrinter()); - print("symbolrule "); - - print(a.getType()); - - if (!a.getSuperClassList().isEmpty()) { - getPrinter().print(" extends "); - String comma = ""; - for (ASTMCType x : a.getSuperClassList()) { - getPrinter().print(comma); - x.accept(getTraverser()); - comma = ", "; - } - } - - if (!a.getSuperInterfaceList().isEmpty()) { - getPrinter().print(" astimplements "); - String comma = ""; - for (ASTMCType x : a.getSuperInterfaceList()) { - getPrinter().print(comma); - x.accept(getTraverser()); - comma = ", "; - } - } - - if (!a.getGrammarMethodList().isEmpty() || !a.getAdditionalAttributeList().isEmpty()) { - - println(" = "); - getPrinter().indent(); - printList(a.getAdditionalAttributeList().iterator(), ""); - printList(a.getGrammarMethodList().iterator(), ""); - } - - getPrinter().print(";"); - getPrinter().unindent(); - CommentPrettyPrinter.printPostComments(a, getPrinter()); - getPrinter().println(); - getPrinter().println(); - - } - - @Override - public void handle(ASTScopeRule a) { - CommentPrettyPrinter.printPreComments(a, getPrinter()); - print("scoperule "); - - if (!a.getSuperClassList().isEmpty()) { - getPrinter().print(" extends "); - String comma = ""; - for (ASTMCType x : a.getSuperClassList()) { - getPrinter().print(comma); - x.accept(getTraverser()); - comma = ", "; - } - } - - if (!a.getSuperInterfaceList().isEmpty()) { - getPrinter().print(" astimplements "); - String comma = ""; - for (ASTMCType x : a.getSuperInterfaceList()) { - getPrinter().print(comma); - x.accept(getTraverser()); - comma = ", "; - } - } - - if (!a.getGrammarMethodList().isEmpty() || !a.getAdditionalAttributeList().isEmpty()) { - - println(" = "); - getPrinter().indent(); - printList(a.getAdditionalAttributeList().iterator(), ""); - printList(a.getGrammarMethodList().iterator(), ""); - } - - getPrinter().print(";"); - getPrinter().unindent(); - CommentPrettyPrinter.printPostComments(a, getPrinter()); - getPrinter().println(); - getPrinter().println(); - - } - - @Override - public void handle(ASTGrammarMethod a) { - CommentPrettyPrinter.printPreComments(a, getPrinter()); - print("method "); - - if (a.isFinal()) { - print("final "); - } - if (a.isStatic()) { - print("static "); - } - if (a.isPrivate()) { - print("private "); - } - if (a.isPublic()) { - print("public "); - } - if (a.isProtected()) { - print("protected "); - } - - a.getMCReturnType().accept(getTraverser()); - - print(" " + a.getName() + "("); - - String comma = ""; - for (ASTMethodParameter x : a.getMethodParameterList()) { - getPrinter().print(comma); - x.getType().accept(getTraverser()); - getPrinter().print(" " + x.getName()); - comma = ", "; - } - - print(")"); - - if (!a.getExceptionList().isEmpty()) { - - print("throws "); - comma = ""; - for (ASTMCType x : a.getExceptionList()) { - getPrinter().print(comma); - x.accept(getTraverser()); - comma = ", "; - } - - } - - // a.getBody()); - print(" {"); - getPrinter().println(); - getPrinter().indent(); - a.getBody().accept(getTraverser()); - getPrinter().unindent(); - print("}"); - - CommentPrettyPrinter.printPostComments(a, getPrinter()); - getPrinter().println(); - - } - - @Override - public void handle(ASTNonTerminalSeparator node) { - if (node.isPresentUsageName()) { - getPrinter().print(node.getUsageName()); - getPrinter().print(":"); - } - getPrinter().print(" ("); - getPrinter().print(node.getName()); - if (node.isPresentReferencedSymbol()) { - getPrinter().print("@"); - getPrinter().print(node.getReferencedSymbol()); - } - if (node.isPlusKeywords()) { - getPrinter().print("&"); - } - getPrinter().print(" || \""); - getPrinter().print(node.getSeparator()); - getPrinter().print("\" )"); - outputIteration(node.getIteration()); - } - - @Override - public void visit(ASTMethodParameter a) { - a.accept(getTraverser()); - print(a.getName()); - } - - @Override - public void handle(ASTAdditionalAttribute a) { - - if (a.isPresentName()) { - getPrinter().print(a.getName()); - getPrinter().print(":"); - } - a.getMCType().accept(getTraverser()); - if (a.isPresentCard()) { - ASTCard card = a.getCard(); - if (card.getIteration() != ASTConstantsGrammar.DEFAULT) { - outputIteration(card.getIteration()); - } - if (card.isPresentMin()) { - print(" min = " + card.getMin()); - } - if (card.isPresentMax()) { - print(" max = " + card.getMax()); - } - } - println(); - } - - /** - * Visiting an ASTRule #complete children calls - * - * @param a - */ - @Override - public void handle(ASTClassProd a) { - - CommentPrettyPrinter.printPreComments(a, getPrinter()); - printList(a.getGrammarAnnotationList().iterator(), ""); - printList(a.getSymbolDefinitionList().iterator(), " "); - getPrinter().print(a.getName()); - - if (!a.getSuperRuleList().isEmpty()) { - getPrinter().print(" extends "); - printList(a.getSuperRuleList().iterator(), " "); - } - - if (!a.getSuperInterfaceRuleList().isEmpty()) { - getPrinter().print(" implements "); - printList(a.getSuperInterfaceRuleList().iterator(), ", "); - } - - if (!a.getASTSuperClassList().isEmpty()) { - getPrinter().print(" astextends "); - printMCSimpleGenericList(a.getASTSuperClassList().iterator(), ""); - } - - if (!a.getASTSuperInterfaceList().isEmpty()) { - getPrinter().print(" astimplements "); - printMCSimpleGenericList(a.getASTSuperInterfaceList().iterator(), ", "); - } - - if (a.isPresentAction()) { - print(" {"); - getPrinter().println(); - getPrinter().indent(); - a.getAction().accept(getTraverser()); - getPrinter().unindent(); - print("}"); - } - - if (!a.getAltList().isEmpty()) { - println(" ="); - - getPrinter().indent(); - printList(a.getAltList().iterator(), " | "); - } - println(";"); - - CommentPrettyPrinter.printPostComments(a, getPrinter()); - getPrinter().unindent(); - getPrinter().println(); - } - - /** - * Visiting a LexRule #complete children calls - * - * @param a the LexRule - */ - @Override - public void handle(ASTLexProd a) { - - printList(a.getGrammarAnnotationList().iterator(), ""); - - if (a.isFragment()) { - print("fragment "); - } - CommentPrettyPrinter.printPreComments(a, getPrinter()); - print("token "); - - println(a.getName()); - getPrinter().indent(); - - if (a.isPresentMode()) { - print("("); - print(a.getMode()); - print(")"); - } - - if (a.isPresentLexOption()) { - a.getLexOption().accept(getTraverser()); - } - if (a.isPresentInitAction()) { - print(" {"); - getPrinter().println(); - getPrinter().indent(); - a.getInitAction().accept(getTraverser()); - getPrinter().unindent(); - print("}"); - } - - getPrinter().print("="); - - printList(a.getAltList().iterator(), " | "); - - if (a.isPresentLexerCommand() || a.isPresentEndAction() || a.isPresentVariable()) { - getPrinter().print(" : "); - - if(a.isPresentLexerCommand()) { - getPrinter().print("->"); - getPrinter().print(a.getLexerCommand()); - } - - if (a.isPresentEndAction()) { - print(" {"); - getPrinter().println(); - getPrinter().indent(); - a.getEndAction().accept(getTraverser()); - getPrinter().unindent(); - print("}"); - } - - if (a.isPresentVariable()) { - getPrinter().print(a.getVariable()); - - if (!a.getTypeList().isEmpty()) { - getPrinter().print("->"); - getPrinter().print(Names.getQualifiedName(a.getTypeList())); - - if (a.isPresentBlock()) { - getPrinter().print(":"); - if (a.isPresentBlock()) { - print(" {"); - getPrinter().println(); - getPrinter().indent(); - a.getBlock().accept(getTraverser()); - getPrinter().unindent(); - print("}"); - } - } - - } - - } - - - } - - - print(";"); - - CommentPrettyPrinter.printPostComments(a, getPrinter()); - - println(); - getPrinter().unindent(); - println(); - } - - @Override - public void handle(ASTLexBlock a) { - CommentPrettyPrinter.printPreComments(a, getPrinter()); - if (a.isNegate()) { - getPrinter().print("~ "); - } - - print("("); - if (a.isPresentOption()) { - print("options {"); - print(a.getOption().getID() + "=" + a.getOption().getValue() + ";"); - print("} "); - } - - if (a.isPresentInitAction()) { - getPrinter().print("init "); - print(" {"); - getPrinter().println(); - getPrinter().indent(); - a.getInitAction().accept(getTraverser()); - getPrinter().unindent(); - print("}"); - } - - if (a.isPresentInitAction() || a.isPresentOption()) { - print(": "); - } - - printList(a.getLexAltList().iterator(), " | "); - print(")"); - outputIteration(a.getIteration()); - - CommentPrettyPrinter.printPostComments(a, getPrinter()); - - getPrinter().optionalBreak(); - - } - - /** - * Visit method for the ASTGrammar (the root object) we have to use the handle method because - * neither the visit/endVisit nor the traverseOrder merhods allow us to visit Packagename before - * the AstGrammar itself #complete children calls - * - * @param a The ASTGrammar - */ - @Override - public void handle(ASTMCGrammar a) { - CommentPrettyPrinter.printPreComments(a, getPrinter()); - - if (a.isPresentGrammarAnnotation()) { - a.getGrammarAnnotation().accept(getTraverser()); - } - - if (!a.getPackageList().isEmpty()) { - print("package "); - print(Names.getQualifiedName(a.getPackageList())); - println(";"); - } - - println(); - if (a.isComponent()) { - print("component "); - } - print("grammar " + a.getName()); - - if (!a.getSupergrammarList().isEmpty()) { - print(" extends "); - String comma = ""; - for (ASTGrammarReference sgrammar : a.getSupergrammarList()) { - print(comma + Names.getQualifiedName(sgrammar.getNameList())); - comma = ", "; - } - } - println(" {"); - getPrinter().indent(); - if (a.isPresentGrammarOption()) { - a.getGrammarOption().accept(getTraverser()); - } - printList(a.getLexProdList().iterator(), ""); - printList(a.getClassProdList().iterator(), ""); - printList(a.getExternalProdList().iterator(), ""); - printList(a.getEnumProdList().iterator(), ""); - printList(a.getInterfaceProdList().iterator(), ""); - printList(a.getAbstractProdList().iterator(), ""); - printList(a.getASTRuleList().iterator(), ""); - printList(a.getConceptList().iterator(), ""); - if (a.isPresentStartRule()) { - a.getStartRule().accept(getTraverser()); - } - printList(a.getSymbolRuleList().iterator(), ""); - if (a.isPresentScopeRule()) { - a.getScopeRule().accept(getTraverser()); - } - - getPrinter().unindent(); - print("}"); - CommentPrettyPrinter.printPostComments(a, getPrinter()); - - println(); - } - - // helper fuctions - - /** - * returns the right String for the Iteration value - * - * @param i .getIteration() value - */ - protected void outputIteration(int i) { - if (i == ASTConstantsGrammar.QUESTION) { - print("?"); - } - else if (i == ASTConstantsGrammar.STAR) { - print("*"); - } - else if (i == ASTConstantsGrammar.PLUS) { - print("+"); - } - else { - print(""); - } - } - - protected void print(String o) { - getPrinter().print(o); - } - - protected void println(String o) { - getPrinter().println(o); - } - - protected void println() { - getPrinter().println(); - } - - @Override - public void handle(ASTLexAlt a) { - CommentPrettyPrinter.printPreComments(a, getPrinter()); - - String sep = ""; - for (ASTLexComponent c : a.getLexComponentList()) { - print(sep); - c.accept(getTraverser()); - sep = " "; - } - CommentPrettyPrinter.printPostComments(a, getPrinter()); - } - - @Override - public void handle(ASTLexChar a) { - CommentPrettyPrinter.printPreComments(a, getPrinter()); - - if (a.isNegate()) { - getPrinter().print("~"); - } - - getPrinter().print("'" + a.getChar() + "'"); - - CommentPrettyPrinter.printPostComments(a, getPrinter()); - } - - @Override - public void handle(ASTLexAnyChar a) { - CommentPrettyPrinter.printPreComments(a, getPrinter()); - - getPrinter().print("."); - - CommentPrettyPrinter.printPostComments(a, getPrinter()); - } - - @Override - public void handle(ASTLexCharRange a) { - CommentPrettyPrinter.printPreComments(a, getPrinter()); - - if (a.isNegate()) { - getPrinter().print("~"); - } - - getPrinter().print("'" + a.getLowerChar() + "'.."); - getPrinter().print("'" + a.getUpperChar() + "' "); - - CommentPrettyPrinter.printPostComments(a, getPrinter()); - } - - @Override - public void handle(ASTRuleReference a) { - if (a.isPresentSemanticpredicateOrAction()) { - a.getSemanticpredicateOrAction().accept(getTraverser()); - } - getPrinter().print(a.getName()); - if (a.isPresentPrio()) { - getPrinter().print(" <" + a.getPrio() + "> "); - } - } - - public void handle(ASTLexString a) { - CommentPrettyPrinter.printPreComments(a, getPrinter()); - - getPrinter().print("\"" + a.getString() + "\""); - - CommentPrettyPrinter.printPostComments(a, getPrinter()); - - } - - @Override - public void endVisit(ASTLexSimpleIteration a) { - outputIteration(a.getIteration()); - if(a.isQuestion()) { - getPrinter().print("?"); - } - } - - @Override - public void handle(ASTLexActionOrPredicate a) { - CommentPrettyPrinter.printPreComments(a, getPrinter()); - - print(" {"); - getPrinter().println(); - getPrinter().indent(); - a.getExpressionPredicate().accept(getTraverser()); - getPrinter().unindent(); - print("}"); - - if (a.isPredicate()) { - print("?"); - } - - CommentPrettyPrinter.printPostComments(a, getPrinter()); - - } - - @Override - public void handle(ASTLexNonTerminal a) { - CommentPrettyPrinter.printPreComments(a, getPrinter()); - - getPrinter().print(a.getName()); - - CommentPrettyPrinter.printPostComments(a, getPrinter()); - - } - - @Override - public void handle(ASTLexOption a) { - CommentPrettyPrinter.printPreComments(a, getPrinter()); - - getPrinter().print("options "); - - getPrinter().print("{" + a.getID() + "=" + a.getValue() + ";}"); - - CommentPrettyPrinter.printPostComments(a, getPrinter()); - - } - - @Override - public void handle(ASTAbstractProd a) { - CommentPrettyPrinter.printPreComments(a, getPrinter()); - - printList(a.getGrammarAnnotationList().iterator(), ""); - getPrinter().print("abstract "); - printList(a.getSymbolDefinitionList().iterator(), " "); - getPrinter().print(a.getName() + " "); - if (!a.getSuperRuleList().isEmpty()) { - getPrinter().print("extends "); - printList(a.getSuperRuleList().iterator(), " "); - getPrinter().print(" "); - } - if (!a.getSuperInterfaceRuleList().isEmpty()) { - getPrinter().print("implements "); - printList(a.getSuperInterfaceRuleList().iterator(), ", "); - getPrinter().print(" "); - } - if (!a.getASTSuperClassList().isEmpty()) { - getPrinter().print("astextends "); - printMCSimpleGenericList(a.getASTSuperClassList().iterator(), " "); - getPrinter().print(" "); - } - if (!a.getASTSuperInterfaceList().isEmpty()) { - getPrinter().print("astimplements "); - printMCSimpleGenericList(a.getASTSuperInterfaceList().iterator(), ", "); - getPrinter().print(" "); - } - - if (!a.getAltList().isEmpty()) { - println(" ="); - - getPrinter().indent(); - printList(a.getAltList().iterator(), " | "); - } - - getPrinter().println(";"); - - CommentPrettyPrinter.printPostComments(a, getPrinter()); - getPrinter().println(); - } - - - @Override - public void handle(ASTFollowOption a) { - CommentPrettyPrinter.printPreComments(a, getPrinter()); - print("follow " + a.getProdName() + " "); - a.getAlt().accept(getTraverser()); - println(";"); - CommentPrettyPrinter.printPostComments(a, getPrinter()); - } - - @Override - public void handle(ASTSymbolDefinition node) { - if (node.isGenSymbol()) { - getPrinter().print(" symbol "); - } - if (node.isGenScope()) { - getPrinter().print(" scope "); - if (node.isOrdered() || node.isShadowing() || node.isNon_exporting()) { - getPrinter().print("("); - if (node.isOrdered()) { - getPrinter().print(" ordered "); - } - if (node.isShadowing()) { - getPrinter().print(" shadowing "); - } - if (node.isNon_exporting()) { - getPrinter().print(" non_exporting "); - } - getPrinter().print(")"); - } - } - } - - public void handle(ASTGrammarAnnotation node) { - if (node.isOverride()) { - getPrinter().println("@Override"); - } else if (node.isDeprecated()) { - getPrinter().print("@Deprecated"); - if (node.isPresentMessage()) { - getPrinter().print(("(\"")); - getPrinter().print(node.getMessage()); - getPrinter().print("\")"); - } - getPrinter().println(); - } - } - - - @Override - public void handle(ASTStartRule node) { - getPrinter().println(" start " + node.getName() + ";"); - } - - public String prettyprint(ASTGrammarNode a) { - getPrinter().clearBuffer(); - a.accept(getTraverser()); - return getPrinter().getContent(); - } - - /** - * Prints a list - * - * @param iter iterator for the list - * @param seperator string for seperating list - */ - protected void printList(Iterator iter, String seperator) { - // print by iterate through all items - String sep = ""; - while (iter.hasNext()) { - getPrinter().print(sep); - iter.next().accept(getTraverser()); - sep = seperator; - } - } - /** - * Prints a list - * - * @param iter iterator for the list - * @param seperator string for seperating list - */ - protected void printMCSimpleGenericList(Iterator iter, String seperator) { - // print by iterate through all items - String sep = ""; - while (iter.hasNext()) { - getPrinter().print(sep); - iter.next().accept(getTraverser()); - sep = seperator; - } - } - - @Override - public GrammarTraverser getTraverser() { - return traverser; - } - - @Override - public void setTraverser(GrammarTraverser traverser) { - this.traverser = traverser; - } - - public IndentPrinter getPrinter() { - return printer; - } - - public void setPrinter(IndentPrinter printer) { - this.printer = printer; - } - -} diff --git a/monticore-grammar/src/main/java/de/monticore/grammar/prettyprint/Grammar_WithConceptsFullPrettyPrinter.java b/monticore-grammar/src/main/java/de/monticore/grammar/prettyprint/Grammar_WithConceptsFullPrettyPrinter.java deleted file mode 100644 index 130c606e1f..0000000000 --- a/monticore-grammar/src/main/java/de/monticore/grammar/prettyprint/Grammar_WithConceptsFullPrettyPrinter.java +++ /dev/null @@ -1,195 +0,0 @@ -/* (c) https://github.com/MontiCore/monticore */ -package de.monticore.grammar.prettyprint; - - -import de.monticore.expressions.assignmentexpressions._ast.ASTAssignmentExpressionsNode; -import de.monticore.expressions.bitexpressions._ast.ASTBitExpressionsNode; -import de.monticore.expressions.commonexpressions._ast.ASTCommonExpressionsNode; -import de.monticore.expressions.expressionsbasis._ast.ASTExpressionsBasisNode; -import de.monticore.expressions.javaclassexpressions._ast.ASTJavaClassExpressionsNode; -import de.monticore.expressions.prettyprint.*; -import de.monticore.grammar.concepts.antlr.antlr._ast.ASTAntlrNode; -import de.monticore.grammar.grammar._ast.ASTGrammarNode; -import de.monticore.grammar.grammar_withconcepts.Grammar_WithConceptsMill; -import de.monticore.grammar.grammar_withconcepts._ast.ASTGrammar_WithConceptsNode; -import de.monticore.grammar.grammar_withconcepts._visitor.Grammar_WithConceptsTraverser; -import de.monticore.javalight._ast.ASTJavaLightNode; -import de.monticore.literals.prettyprint.MCCommonLiteralsPrettyPrinter; -import de.monticore.prettyprint.IndentPrinter; -import de.monticore.prettyprint.JavaLightPrettyPrinter; -import de.monticore.prettyprint.MCBasicsPrettyPrinter; -import de.monticore.statements.mccommonstatements._ast.ASTMCCommonStatementsNode; -import de.monticore.statements.mcstatementsbasis._ast.ASTMCStatementsBasisNode; -import de.monticore.statements.prettyprint.*; -import de.monticore.types.prettyprint.MCBasicTypesPrettyPrinter; -import de.monticore.types.prettyprint.MCCollectionTypesPrettyPrinter; -import de.monticore.types.prettyprint.MCSimpleGenericTypesPrettyPrinter; - -@Deprecated(forRemoval = true) -public class Grammar_WithConceptsFullPrettyPrinter { - - - protected IndentPrinter printer; - - protected Grammar_WithConceptsTraverser traverser; - - public Grammar_WithConceptsFullPrettyPrinter(IndentPrinter printer) { - this.printer = printer; - printer.setIndentLength(2); - traverser = Grammar_WithConceptsMill.traverser(); - - AntlrPrettyPrinter antlr = new AntlrPrettyPrinter(printer); - traverser.add4Antlr(antlr); - traverser.setAntlrHandler(antlr); - - GrammarPrettyPrinter grammar = new GrammarPrettyPrinter(printer); - traverser.add4Grammar(grammar); - traverser.setGrammarHandler(grammar); - - AssignmentExpressionsPrettyPrinter assigments = new AssignmentExpressionsPrettyPrinter(printer); - traverser.add4AssignmentExpressions(assigments); - traverser.setAssignmentExpressionsHandler(assigments); - - ExpressionsBasisPrettyPrinter basisExpr = new ExpressionsBasisPrettyPrinter(printer); - traverser.add4ExpressionsBasis(basisExpr); - traverser.setExpressionsBasisHandler(basisExpr); - - CommonExpressionsPrettyPrinter commonExpr = new CommonExpressionsPrettyPrinter(printer); - traverser.add4CommonExpressions(commonExpr); - traverser.setCommonExpressionsHandler(commonExpr); - - JavaClassExpressionsPrettyPrinter classExpr = new JavaClassExpressionsPrettyPrinter(printer); - traverser.add4JavaClassExpressions(classExpr); - traverser.setJavaClassExpressionsHandler(classExpr); - - BitExpressionsPrettyPrinter bitExpr = new BitExpressionsPrettyPrinter(printer); - traverser.add4BitExpressions(bitExpr); - traverser.setBitExpressionsHandler(bitExpr); - - MCBasicsPrettyPrinter basics = new MCBasicsPrettyPrinter(printer); - traverser.add4MCBasics(basics); - - MCCommonLiteralsPrettyPrinter commonLiterals = new MCCommonLiteralsPrettyPrinter(printer); - traverser.add4MCCommonLiterals(commonLiterals); - traverser.setMCCommonLiteralsHandler(commonLiterals); - - MCBasicTypesPrettyPrinter basicTypes = new MCBasicTypesPrettyPrinter(printer); - traverser.add4MCBasicTypes(basicTypes); - traverser.setMCBasicTypesHandler(basicTypes); - - MCCollectionTypesPrettyPrinter collectionTypes = new MCCollectionTypesPrettyPrinter(printer); - traverser.add4MCCollectionTypes(collectionTypes); - traverser.setMCCollectionTypesHandler(collectionTypes); - - MCSimpleGenericTypesPrettyPrinter simpleGenerics = new MCSimpleGenericTypesPrettyPrinter(printer); - traverser.add4MCSimpleGenericTypes(simpleGenerics); - traverser.setMCSimpleGenericTypesHandler(simpleGenerics); - - MCExceptionStatementsPrettyPrinter exceptionStS = new MCExceptionStatementsPrettyPrinter(printer); - traverser.add4MCExceptionStatements(exceptionStS); - traverser.setMCExceptionStatementsHandler(exceptionStS); - - MCReturnStatementsPrettyPrinter returnSts = new MCReturnStatementsPrettyPrinter(printer); - traverser.add4MCReturnStatements(returnSts); - traverser.setMCReturnStatementsHandler(returnSts); - - MCCommonStatementsPrettyPrinter commonSts = new MCCommonStatementsPrettyPrinter(printer); - traverser.add4MCCommonStatements(commonSts); - traverser.setMCCommonStatementsHandler(commonSts); - - MCVarDeclarationStatementsPrettyPrinter varDeclSts = new MCVarDeclarationStatementsPrettyPrinter(printer); - traverser.add4MCVarDeclarationStatements(varDeclSts); - traverser.setMCVarDeclarationStatementsHandler(varDeclSts); - - MCArrayStatementsPrettyPrinter arraySts = new MCArrayStatementsPrettyPrinter(printer); - traverser.add4MCArrayStatements(arraySts); - traverser.setMCArrayStatementsHandler(arraySts); - - JavaLightPrettyPrinter javaLight = new JavaLightPrettyPrinter(printer); - traverser.add4JavaLight(javaLight); - traverser.setJavaLightHandler(javaLight); - } - - public String prettyprint(ASTGrammar_WithConceptsNode a) { - printer.clearBuffer(); - a.accept(getTraverser()); - return printer.getContent(); - } - - public String prettyprint(ASTGrammarNode a) { - printer.clearBuffer(); - a.accept(getTraverser()); - return printer.getContent(); - } - - public String prettyprint(ASTAntlrNode a) { - printer.clearBuffer(); - a.accept(getTraverser()); - return printer.getContent(); - } - - public String prettyprint(ASTJavaLightNode a) { - printer.clearBuffer(); - a.accept(getTraverser()); - return printer.getContent(); - } - - public IndentPrinter getPrinter() { - return printer; - } - - public void setPrinter(IndentPrinter printer) { - this.printer = printer; - } - - public Grammar_WithConceptsTraverser getTraverser() { - return traverser; - } - - public void setTraverser(Grammar_WithConceptsTraverser traverser) { - this.traverser = traverser; - } - - public String prettyprint(ASTMCCommonStatementsNode a) { - printer.clearBuffer(); - a.accept(getTraverser()); - return printer.getContent(); - } - - public String prettyprint(ASTExpressionsBasisNode a) { - printer.clearBuffer(); - a.accept(getTraverser()); - return printer.getContent(); - } - - public String prettyprint(ASTBitExpressionsNode a) { - printer.clearBuffer(); - a.accept(getTraverser()); - return printer.getContent(); - } - - public String prettyprint(ASTCommonExpressionsNode a) { - printer.clearBuffer(); - a.accept(getTraverser()); - return printer.getContent(); - } - - public String prettyprint(ASTAssignmentExpressionsNode a) { - printer.clearBuffer(); - a.accept(getTraverser()); - return printer.getContent(); - } - - public String prettyprint(ASTJavaClassExpressionsNode a) { - printer.clearBuffer(); - a.accept(getTraverser()); - return printer.getContent(); - } - - public String prettyprint(ASTMCStatementsBasisNode a) { - printer.clearBuffer(); - a.accept(getTraverser()); - return printer.getContent(); - } - -} diff --git a/monticore-grammar/src/main/java/de/monticore/grammar/prettyprint/Grammar_WithConceptsPrettyPrinter.java b/monticore-grammar/src/main/java/de/monticore/grammar/prettyprint/Grammar_WithConceptsPrettyPrinter.java deleted file mode 100644 index 27c65e066e..0000000000 --- a/monticore-grammar/src/main/java/de/monticore/grammar/prettyprint/Grammar_WithConceptsPrettyPrinter.java +++ /dev/null @@ -1,135 +0,0 @@ -/* (c) https://github.com/MontiCore/monticore */ - -package de.monticore.grammar.prettyprint; - - -import de.monticore.expressions.assignmentexpressions._ast.ASTAssignmentExpressionsNode; -import de.monticore.expressions.bitexpressions._ast.ASTBitExpressionsNode; -import de.monticore.expressions.commonexpressions._ast.ASTCommonExpressionsNode; -import de.monticore.expressions.expressionsbasis._ast.ASTExpressionsBasisNode; -import de.monticore.expressions.javaclassexpressions._ast.ASTJavaClassExpressionsNode; -import de.monticore.grammar.grammar_withconcepts._ast.*; -import de.monticore.grammar.grammar_withconcepts._visitor.Grammar_WithConceptsHandler; -import de.monticore.grammar.grammar_withconcepts._visitor.Grammar_WithConceptsTraverser; -import de.monticore.grammar.grammar_withconcepts._visitor.Grammar_WithConceptsVisitor2; -import de.monticore.prettyprint.CommentPrettyPrinter; -import de.monticore.prettyprint.IndentPrinter; -import de.monticore.statements.mccommonstatements._ast.ASTMCCommonStatementsNode; -import de.monticore.statements.mcstatementsbasis._ast.ASTMCStatementsBasisNode; -import de.monticore.types.mccollectiontypes._ast.ASTMCTypeArgument; - - -@Deprecated(forRemoval = true) -public class Grammar_WithConceptsPrettyPrinter implements Grammar_WithConceptsVisitor2, - Grammar_WithConceptsHandler { - - protected IndentPrinter printer; - - protected Grammar_WithConceptsTraverser traverser; - - - public Grammar_WithConceptsPrettyPrinter(IndentPrinter out) { - printer = out; - out.setIndentLength(2); - } - - public String prettyprint(ASTGrammar_WithConceptsNode a) { - printer.clearBuffer(); - a.accept(getTraverser()); - return printer.getContent(); - } - - @Override - public void handle(ASTExtReturnType node) { - CommentPrettyPrinter.printPreComments(node, printer); - node.getMCReturnType().accept(getTraverser()); - CommentPrettyPrinter.printPostComments(node, printer); - } - - @Override - public void handle(ASTExtType node) { - CommentPrettyPrinter.printPreComments(node, printer); - node.getMCType().accept(getTraverser()); - CommentPrettyPrinter.printPostComments(node, printer); - } - - @Override - public void handle(ASTAction node) { - CommentPrettyPrinter.printPreComments(node, printer); - node.getMCBlockStatementList().stream().forEach(a -> a.accept(getTraverser())); - CommentPrettyPrinter.printPostComments(node, printer); - } - - @Override - public void handle(ASTExtTypeArgument node) { - CommentPrettyPrinter.printPreComments(node, printer); - printer.print("<"); - String sep = ""; - for (ASTMCTypeArgument t :node.getMCTypeArgumentList()) { - printer.print(sep); - t.accept(getTraverser()); - sep = ", "; - } - CommentPrettyPrinter.printPostComments(node, printer); - } - - public String prettyprint(ASTMCCommonStatementsNode a) { - printer.clearBuffer(); - a.accept(getTraverser()); - return printer.getContent(); - } - - public String prettyprint(ASTExpressionsBasisNode a) { - printer.clearBuffer(); - a.accept(getTraverser()); - return printer.getContent(); - } - - public String prettyprint(ASTBitExpressionsNode a) { - printer.clearBuffer(); - a.accept(getTraverser()); - return printer.getContent(); - } - - public String prettyprint(ASTCommonExpressionsNode a) { - printer.clearBuffer(); - a.accept(getTraverser()); - return printer.getContent(); - } - - public String prettyprint(ASTAssignmentExpressionsNode a) { - printer.clearBuffer(); - a.accept(getTraverser()); - return printer.getContent(); - } - - public String prettyprint(ASTJavaClassExpressionsNode a) { - printer.clearBuffer(); - a.accept(getTraverser()); - return printer.getContent(); - } - - public String prettyprint(ASTMCStatementsBasisNode a) { - printer.clearBuffer(); - a.accept(getTraverser()); - return printer.getContent(); - } - - public IndentPrinter getPrinter() { - return printer; - } - - public void setPrinter(IndentPrinter printer) { - this.printer = printer; - } - - @Override - public Grammar_WithConceptsTraverser getTraverser() { - return traverser; - } - - @Override - public void setTraverser(Grammar_WithConceptsTraverser traverser) { - this.traverser = traverser; - } -} diff --git a/monticore-grammar/src/main/java/de/monticore/prettyprint/JavaLightFullPrettyPrinter.java b/monticore-grammar/src/main/java/de/monticore/prettyprint/JavaLightFullPrettyPrinter.java deleted file mode 100644 index c48c267063..0000000000 --- a/monticore-grammar/src/main/java/de/monticore/prettyprint/JavaLightFullPrettyPrinter.java +++ /dev/null @@ -1,83 +0,0 @@ -/* (c) https://github.com/MontiCore/monticore */ -package de.monticore.prettyprint; - -import de.monticore.expressions.prettyprint.AssignmentExpressionsPrettyPrinter; -import de.monticore.expressions.prettyprint.ExpressionsBasisPrettyPrinter; -import de.monticore.expressions.prettyprint.JavaClassExpressionsPrettyPrinter; -import de.monticore.javalight.JavaLightMill; -import de.monticore.javalight._ast.ASTJavaLightNode; -import de.monticore.javalight._visitor.JavaLightTraverser; -import de.monticore.statements.prettyprint.MCArrayStatementsPrettyPrinter; -import de.monticore.statements.prettyprint.MCCommonStatementsPrettyPrinter; -import de.monticore.statements.prettyprint.MCReturnStatementsPrettyPrinter; -import de.monticore.statements.prettyprint.MCVarDeclarationStatementsPrettyPrinter; -import de.monticore.types.prettyprint.MCBasicTypesPrettyPrinter; - -@Deprecated(forRemoval = true) -public class JavaLightFullPrettyPrinter { - - protected JavaLightTraverser traverser; - - protected IndentPrinter printer; - - public JavaLightFullPrettyPrinter(IndentPrinter printer) { - this.printer = printer; - this.traverser = JavaLightMill.traverser(); - - MCBasicTypesPrettyPrinter basicTypes = new MCBasicTypesPrettyPrinter(printer); - traverser.add4MCBasicTypes(basicTypes); - traverser.setMCBasicTypesHandler(basicTypes); - - ExpressionsBasisPrettyPrinter expressionsBasis = new ExpressionsBasisPrettyPrinter(printer); - traverser.add4ExpressionsBasis(expressionsBasis); - traverser.setExpressionsBasisHandler(expressionsBasis); - - MCCommonStatementsPrettyPrinter commonStatements = new MCCommonStatementsPrettyPrinter(printer); - traverser.add4MCCommonStatements(commonStatements); - traverser.setMCCommonStatementsHandler(commonStatements); - - AssignmentExpressionsPrettyPrinter assignmentExpressions = new AssignmentExpressionsPrettyPrinter(printer); - traverser.add4AssignmentExpressions(assignmentExpressions); - traverser.setAssignmentExpressionsHandler(assignmentExpressions); - - MCVarDeclarationStatementsPrettyPrinter varDecl = new MCVarDeclarationStatementsPrettyPrinter(printer); - traverser.add4MCVarDeclarationStatements(varDecl); - traverser.setMCVarDeclarationStatementsHandler(varDecl); - - JavaLightPrettyPrinter javaLight = new JavaLightPrettyPrinter(printer); - traverser.add4JavaLight(javaLight); - traverser.setJavaLightHandler(javaLight); - - JavaClassExpressionsPrettyPrinter javaClassExpressions = new JavaClassExpressionsPrettyPrinter(printer); - traverser.add4JavaClassExpressions(javaClassExpressions); - traverser.setJavaClassExpressionsHandler(javaClassExpressions); - - MCArrayStatementsPrettyPrinter arrayStatements = new MCArrayStatementsPrettyPrinter(printer); - traverser.add4MCArrayStatements(arrayStatements); - traverser.setMCArrayStatementsHandler(arrayStatements); - - MCReturnStatementsPrettyPrinter returnStatements = new MCReturnStatementsPrettyPrinter(printer); - traverser.add4MCReturnStatements(returnStatements); - traverser.setMCReturnStatementsHandler(returnStatements); - - traverser.add4MCBasics(new MCBasicsPrettyPrinter(printer)); - } - - public IndentPrinter getPrinter() { - return this.printer; - } - - public String prettyprint(ASTJavaLightNode a) { - getPrinter().clearBuffer(); - a.accept(getTraverser()); - return getPrinter().getContent(); - } - - public JavaLightTraverser getTraverser() { - return traverser; - } - - public void setTraverser(JavaLightTraverser traverser) { - this.traverser = traverser; - } -} diff --git a/monticore-grammar/src/main/java/de/monticore/prettyprint/JavaLightPrettyPrinter.java b/monticore-grammar/src/main/java/de/monticore/prettyprint/JavaLightPrettyPrinter.java deleted file mode 100644 index d139b3cdf7..0000000000 --- a/monticore-grammar/src/main/java/de/monticore/prettyprint/JavaLightPrettyPrinter.java +++ /dev/null @@ -1,214 +0,0 @@ -/* (c) https://github.com/MontiCore/monticore */ - -package de.monticore.prettyprint; - -import de.monticore.javalight._ast.*; -import de.monticore.javalight._visitor.JavaLightHandler; -import de.monticore.javalight._visitor.JavaLightTraverser; -import de.monticore.javalight._visitor.JavaLightVisitor2; -import de.monticore.statements.mccommonstatements._ast.ASTMCCommonStatementsNode; - -import java.util.Iterator; - -@Deprecated(forRemoval = true) -public class JavaLightPrettyPrinter implements - JavaLightVisitor2, JavaLightHandler { - - protected JavaLightTraverser traverser; - - protected IndentPrinter printer; - - public JavaLightPrettyPrinter(IndentPrinter out) { - this.printer = out; - } - - @Override - public JavaLightTraverser getTraverser() { - return traverser; - } - - @Override - public void setTraverser(JavaLightTraverser traverser) { - this.traverser = traverser; - } - - public IndentPrinter getPrinter() { - return this.printer; - } - - protected void printNode(String s) { - getPrinter().print(s); - } - - @Override - public void handle(ASTMethodDeclaration a) { - CommentPrettyPrinter.printPreComments(a, getPrinter()); - a.getMCModifierList().stream().forEach(m -> {getPrinter().print(" "); m.accept(getTraverser()); getPrinter().print(" ");}); - if (a.isPresentExtTypeParameters()) { - a.getExtTypeParameters().accept(getTraverser()); - } - a.getMCReturnType().accept(getTraverser()); - getPrinter().print(" "); - printNode(a.getName()); - a.getFormalParameters().accept(getTraverser()); - for (int i = 0; i < a.getDimList().size(); i++) { - getPrinter().print("[]"); - } - if (a.isPresentThrows()) { - getPrinter().print(" throws "); - a.getThrows().accept(getTraverser()); - } - if (a.isPresentMCJavaBlock()) { - a.getMCJavaBlock().accept(getTraverser()); - } else { - getPrinter().println(";"); - } - CommentPrettyPrinter.printPostComments(a, getPrinter()); - } - - - @Override - public void handle(ASTThrows a) { - for (int i = 0; i < a.getMCQualifiedNameList().size(); i++) { - if (i != 0) { - getPrinter().print(", "); - } - a.getMCQualifiedName(i).accept(getTraverser()); - } - } - - - @Override - public void handle(ASTConstructorDeclaration a) { - CommentPrettyPrinter.printPreComments(a, getPrinter()); - getPrinter().println(); - a.getMCModifierList().stream().forEach(m -> {getPrinter().print(" "); m.accept(getTraverser()); getPrinter().print(" ");}); - if (a.isPresentExtTypeParameters()) { - a.getExtTypeParameters().accept(getTraverser()); - } - printNode(a.getName()); - a.getFormalParameters().accept(getTraverser()); - - if (a.isPresentThrows()) { - getPrinter().print(" throws "); - a.getThrows().accept(getTraverser()); - } - a.getMCJavaBlock().accept(getTraverser()); - CommentPrettyPrinter.printPostComments(a, getPrinter()); - } - - @Override - public void handle(ASTConstDeclaration a) { - CommentPrettyPrinter.printPreComments(a, getPrinter()); - a.getLocalVariableDeclaration().accept(getTraverser()); - getPrinter().println(";"); - CommentPrettyPrinter.printPostComments(a, getPrinter()); - } - - @Override - public void handle(ASTFormalParameters a) { - CommentPrettyPrinter.printPreComments(a, getPrinter()); - getPrinter().print("("); - if (a.isPresentFormalParameterListing()) { - a.getFormalParameterListing().accept(getTraverser()); - } - getPrinter().print(")"); - CommentPrettyPrinter.printPostComments(a, getPrinter()); - } - - @Override - public void handle(ASTFormalParameterListing a) { - CommentPrettyPrinter.printPreComments(a, getPrinter()); - printSeparated(a.getFormalParameterList().iterator(), ","); - if (!a.getFormalParameterList().isEmpty() && a.isPresentLastFormalParameter()) { - getPrinter().print(","); - } - if (a.isPresentLastFormalParameter()) { - a.getLastFormalParameter().accept(getTraverser()); - } - CommentPrettyPrinter.printPostComments(a, getPrinter()); - } - - @Override - public void handle(ASTLastFormalParameter a) { - CommentPrettyPrinter.printPreComments(a, getPrinter()); - printSeparated(a.getJavaModifierList().iterator(), " "); - a.getMCType().accept(getTraverser()); - getPrinter().print(" ... "); - a.getDeclaratorId().accept(getTraverser()); - CommentPrettyPrinter.printPostComments(a, getPrinter()); - } - - @Override - public void handle(ASTAnnotation a) { - getPrinter().print("@"); - a.getAnnotationName().accept(getTraverser()); - if (a.isPresentAnnotationArguments()) { - getPrinter().print("("); - a.getAnnotationArguments().accept(getTraverser()); - getPrinter().print(")"); - } - } - - @Override - public void handle(ASTAnnotationPairArguments a) { - CommentPrettyPrinter.printPreComments(a, getPrinter()); - printJavaLightList(a.getElementValuePairList().iterator(), ", "); - CommentPrettyPrinter.printPostComments(a, getPrinter()); - } - - @Override - public void handle(ASTElementValuePair a) { - CommentPrettyPrinter.printPreComments(a, getPrinter()); - printNode(a.getName()); - getPrinter().print(" = "); - a.getElementValueOrExpr().accept(getTraverser()); - CommentPrettyPrinter.printPostComments(a, getPrinter()); - } - - @Override - public void handle(ASTElementValueArrayInitializer a) { - CommentPrettyPrinter.printPreComments(a, getPrinter()); - getPrinter().print("{"); - for (int i = 0; i < a.getElementValueOrExprList().size(); i++) { - if (i != 0) { - getPrinter().print(", "); - } - a.getElementValueOrExpr(i).accept(getTraverser()); - } - getPrinter().print("}"); - CommentPrettyPrinter.printPostComments(a, getPrinter()); - } - - @Override - public void handle(ASTArrayDimensionByInitializer a) { - CommentPrettyPrinter.printPreComments(a, getPrinter()); - for (int i = 0; i < a.getDimList().size(); i++) { - getPrinter().print("[]"); - } - getPrinter().print(" "); - a.getArrayInit().accept(getTraverser()); - CommentPrettyPrinter.printPostComments(a, getPrinter()); - } - - protected void printJavaLightList(Iterator iter, String separator) { - // print by iterate through all items - String sep = ""; - while (iter.hasNext()) { - getPrinter().print(sep); - iter.next().accept(getTraverser()); - sep = separator; - } - } - - protected void printSeparated(Iterator iter, String separator) { - // print by iterate through all items - String sep = ""; - while (iter.hasNext()) { - getPrinter().print(sep); - iter.next().accept(getTraverser()); - sep = separator; - } - } - -} diff --git a/monticore-grammar/src/main/java/de/monticore/types/check/DeriveSymTypeOfJavaClassExpressions.java b/monticore-grammar/src/main/java/de/monticore/types/check/DeriveSymTypeOfJavaClassExpressions.java index 018d51b750..15ddaa6f2c 100644 --- a/monticore-grammar/src/main/java/de/monticore/types/check/DeriveSymTypeOfJavaClassExpressions.java +++ b/monticore-grammar/src/main/java/de/monticore/types/check/DeriveSymTypeOfJavaClassExpressions.java @@ -14,6 +14,9 @@ import de.monticore.symbols.oosymbols._symboltable.MethodSymbol; import de.monticore.symbols.oosymbols._symboltable.OOTypeSymbol; import de.monticore.symboltable.modifiers.AccessModifier; +import de.monticore.types.mcbasictypes._ast.ASTMCReturnType; +import de.monticore.types.mcbasictypes._ast.ASTMCType; +import de.monticore.types.mccollectiontypes._ast.ASTMCTypeArgument; import de.se_rwth.commons.logging.Log; import java.util.List; @@ -31,6 +34,18 @@ public class DeriveSymTypeOfJavaClassExpressions extends AbstractDeriveFromExpre protected JavaClassExpressionsTraverser traverser; + protected ISynthesize synthesize; + + @Deprecated + public DeriveSymTypeOfJavaClassExpressions() { + // default behaviour, as this class had no synthezises beforehand + synthesize = new FullSynthesizeFromMCFullGenericTypes(); + } + + public DeriveSymTypeOfJavaClassExpressions(ISynthesize synthesize) { + this.synthesize = synthesize; + } + @Override public JavaClassExpressionsTraverser getTraverser() { return traverser; @@ -175,7 +190,7 @@ public void traverse(ASTClassExpression node) { SymTypeExpression wholeResult = SymTypeExpressionFactory.createObscureType(); SymTypeExpression innerResult = SymTypeExpressionFactory.createObscureType(); - node.getExtReturnType().accept(getTraverser()); + deprecated_traverse(node.getMCReturnType()); if(getTypeCheckResult().isPresentResult()){ innerResult = getTypeCheckResult().getResult(); wholeResult = SymTypeExpressionFactory.createGenerics("Class", getScope(node.getEnclosingScope()), innerResult); @@ -236,7 +251,7 @@ protected SymTypeExpression calculateSuperExpression(ASTSuperExpression node, Sy protected SymTypeExpression handleSuperSuffix(ASTSuperSuffix superSuffix, SymTypeExpression superClass){ if (superSuffix.isPresentArguments()) { //case 1 -> Expression.super.Method(Args) - List typeArgsList = calculateTypeArguments(superSuffix.getExtTypeArgumentList()); + List typeArgsList = calculateTypeArguments(superSuffix.getMCTypeArgumentList()); List methods = superClass.getMethodList(superSuffix.getName(), false, AccessModifier.ALL_INCLUSION); if (!methods.isEmpty() && null != superSuffix.getArguments()) { //check if the methods fit and return the right returntype @@ -272,13 +287,14 @@ public void traverse(ASTTypeCastExpression node) { SymTypeExpression castResult; //castResult is the type in the brackets -> (ArrayList) list - node.getExtType().accept(getTraverser()); + + deprecated_traverse(node.getMCType()); if(getTypeCheckResult().isPresentResult()){ castResult = getTypeCheckResult().getResult(); }else{ getTypeCheckResult().reset(); getTypeCheckResult().setResult(SymTypeExpressionFactory.createObscureType()); - Log.error("0xA0265 the type at source position "+node.getExtType().get_SourcePositionStart()+" cannot be calculated"); + Log.error("0xA0265 the type at source position "+node.getMCType().get_SourcePositionStart()+" cannot be calculated"); return; } @@ -313,13 +329,13 @@ public void traverse(ASTInstanceofExpression node) { SymTypeExpression typeResult = SymTypeExpressionFactory.createObscureType(); //calculate right type: type that the expression should be an instance of - node.getExtType().accept(getTraverser()); + deprecated_traverse(node.getMCType()); if(getTypeCheckResult().isPresentResult()){ if(!getTypeCheckResult().isType()) { if(!getTypeCheckResult().getResult().isObscureType()) { getTypeCheckResult().reset(); getTypeCheckResult().setResult(SymTypeExpressionFactory.createObscureType()); - Log.error("0xA0269 the expression at source position " + node.getExtType().get_SourcePositionStart() + " must be a type"); + Log.error("0xA0269 the expression at source position " + node.getMCType().get_SourcePositionStart() + " must be a type"); return; } }else{ @@ -412,7 +428,7 @@ protected SymTypeExpression calculateGenericInvocationExpression(ASTGenericInvoc //the only case where you can calculate a result is Expression.method() //because the other cases of the GenericInvocationSuffix can only be calculated if the expression //is a PrimaryGenericInvocationExpression - List typeArgsList = calculateTypeArguments(node.getPrimaryGenericInvocationExpression().getExtTypeArgumentList()); + List typeArgsList = calculateTypeArguments(node.getPrimaryGenericInvocationExpression().getMCTypeArgumentList()); //search in the scope of the type that before the "." for a method that has the right name if(node.getPrimaryGenericInvocationExpression().getGenericInvocationSuffix().isPresentName()) { @@ -434,17 +450,17 @@ protected List filterStaticMethodSymbols(List fi return fittingMethods.stream().filter(m -> m instanceof MethodSymbol).filter(m -> ((MethodSymbol) m).isIsStatic()).collect(Collectors.toList()); } - protected List calculateTypeArguments(List extTypeArgumentList) { + protected List calculateTypeArguments(List extTypeArgumentList) { //calculate each TypeArgument and return the results in a list List typeArgsList = Lists.newArrayList(); - for (ASTExtTypeArgumentExt astExtTypeArgumentExt : extTypeArgumentList) { - astExtTypeArgumentExt.accept(getTraverser()); + for (ASTMCTypeArgument astMCTypeArgument : extTypeArgumentList) { + deprecated_traverse(astMCTypeArgument); if (getTypeCheckResult().isPresentResult()) { typeArgsList.add(getTypeCheckResult().getResult()); } else { getTypeCheckResult().reset(); typeArgsList.add(SymTypeExpressionFactory.createObscureType()); - Log.error("0xA0283 the type argument at source position " + astExtTypeArgumentExt.get_SourcePositionStart() + " cannot be calculated"); + Log.error("0xA0283 the type argument at source position " + astMCTypeArgument.get_SourcePositionStart() + " cannot be calculated"); } } return typeArgsList; @@ -539,7 +555,7 @@ public void traverse(ASTPrimaryGenericInvocationExpression node) { if(!methods.isEmpty() && node.getGenericInvocationSuffix().isPresentArguments()){ //check if the methods fit and return the right returntype ASTArguments args = node.getGenericInvocationSuffix().getArguments(); - List typeArgsList = calculateTypeArguments(node.getExtTypeArgumentList()); + List typeArgsList = calculateTypeArguments(node.getMCTypeArgumentList()); if(!typeArgsList.isEmpty()){ getTypeCheckResult().unsetType(); } @@ -556,7 +572,7 @@ public void traverse(ASTPrimaryGenericInvocationExpression node) { if (!methods.isEmpty() && null != node.getGenericInvocationSuffix().getArguments()) { //check if the constructors fit and return the right returntype ASTArguments args = node.getGenericInvocationSuffix().getArguments(); - List typeArgsList = calculateTypeArguments(node.getExtTypeArgumentList()); + List typeArgsList = calculateTypeArguments(node.getMCTypeArgumentList()); wholeResult = checkMethodsAndReplaceTypeVariables(methods, args, typeArgsList); } } @@ -574,7 +590,7 @@ public void traverse(ASTPrimaryGenericInvocationExpression node) { if(!methods.isEmpty() && superSuffix.isPresentArguments()){ //check if the constructors fit and return the right returntype ASTArguments args = superSuffix.getArguments(); - List typeArgsList = calculateTypeArguments(node.getExtTypeArgumentList()); + List typeArgsList = calculateTypeArguments(node.getMCTypeArgumentList()); wholeResult = checkMethodsAndReplaceTypeVariables(methods,args,typeArgsList); } } @@ -601,13 +617,13 @@ protected Optional searchForTypeSymbolSpanningEnclosingScope(IBasicS public void traverse(ASTAnonymousClass creator){ SymTypeExpression extType; SymTypeExpression wholeResult = SymTypeExpressionFactory.createObscureType(); - creator.getExtType().accept(getTraverser()); + deprecated_traverse(creator.getMCType()); if(getTypeCheckResult().isPresentResult()){ extType = getTypeCheckResult().getResult(); }else{ getTypeCheckResult().reset(); getTypeCheckResult().setResult(wholeResult); - logError("0xA1311",creator.getExtType().get_SourcePositionStart()); + logError("0xA1311",creator.getMCType().get_SourcePositionStart()); return; } @@ -639,18 +655,18 @@ public void traverse(ASTArrayCreator creator){ SymTypeExpression extTypeResult; SymTypeExpression wholeResult = SymTypeExpressionFactory.createObscureType(); - creator.getExtType().accept(getTraverser()); + deprecated_traverse(creator.getMCType()); if(getTypeCheckResult().isPresentResult()){ extTypeResult = getTypeCheckResult().getResult(); }else{ getTypeCheckResult().reset(); getTypeCheckResult().setResult(wholeResult); - logError("0xA0314", creator.getExtType().get_SourcePositionStart()); + logError("0xA0314", creator.getMCType().get_SourcePositionStart()); return; } if(!extTypeResult.isObscureType()) { - //the definition of the Arrays are based on the assumption that ExtType is not an array + //the definition of the Arrays are based on the assumption that MCType is not an array if (!extTypeResult.isArrayType()) { if (creator.getArrayDimensionSpecifier() instanceof ASTArrayDimensionByExpression) { ASTArrayDimensionByExpression arrayInitializer = (ASTArrayDimensionByExpression) creator.getArrayDimensionSpecifier(); @@ -725,4 +741,60 @@ protected boolean testForCorrectArguments(List constructors, AST } return false; } + + // Warning: deprecated and wrong behavior + // (it does not set whether it's an expression or type identifier) + // this is fixed in typecheck 3 + // and exists only here like this to not change the behaviour of typecheck1 + + @Deprecated + public void deprecated_traverse(ASTMCType type){ + SymTypeExpression wholeResult = null; + TypeCheckResult result = synthesize.synthesizeType(type); + if(result.isPresentResult()){ + wholeResult=result.getResult(); + } + if(wholeResult!=null){ + getTypeCheckResult().setResult(wholeResult); + getTypeCheckResult().setType(); + }else{ + getTypeCheckResult().reset(); + } + } + + @Deprecated + public void deprecated_traverse(ASTMCReturnType returnType){ + SymTypeExpression wholeResult = null; + if(returnType.isPresentMCVoidType()){ + wholeResult = SymTypeExpressionFactory.createTypeVoid(); + }else if(returnType.isPresentMCType()){ + TypeCheckResult res = synthesize.synthesizeType(returnType); + if(res.isPresentResult()){ + wholeResult = res.getResult(); + } + } + if(wholeResult!=null){ + getTypeCheckResult().setResult(wholeResult); + getTypeCheckResult().setType(); + }else{ + getTypeCheckResult().reset(); + } + } + + @Deprecated + public void deprecated_traverse(ASTMCTypeArgument typeArgument){ + SymTypeExpression wholeResult = null; + if(typeArgument.getMCTypeOpt().isPresent()){ + TypeCheckResult res = synthesize.synthesizeType(typeArgument.getMCTypeOpt().get()); + if(res.isPresentResult()){ + wholeResult = res.getResult(); + } + } + if(wholeResult!=null){ + getTypeCheckResult().setResult(wholeResult); + getTypeCheckResult().setType(); + }else{ + getTypeCheckResult().reset(); + } + } } diff --git a/monticore-grammar/src/test/grammars/de/monticore/TestJavaLight.mc4 b/monticore-grammar/src/test/grammars/de/monticore/TestJavaLight.mc4 index af31d14426..b93994b703 100644 --- a/monticore-grammar/src/test/grammars/de/monticore/TestJavaLight.mc4 +++ b/monticore-grammar/src/test/grammars/de/monticore/TestJavaLight.mc4 @@ -5,11 +5,4 @@ package de.monticore; grammar TestJavaLight extends de.monticore.JavaLight, de.monticore.literals.MCCommonLiterals, de.monticore.types.MCCollectionTypes, de.monticore.types.MCArrayTypes { start JavaMethod; - ExtTypeParameters = MCTypeArgument; - - ExtType = MCType; - - ExtReturnType = MCReturnType; - - ExtTypeArgument = MCTypeArgument; } diff --git a/monticore-grammar/src/test/grammars/de/monticore/expressions/CombineExpressionsWithLiterals.mc4 b/monticore-grammar/src/test/grammars/de/monticore/expressions/CombineExpressionsWithLiterals.mc4 index 0760e01e55..676c726d86 100644 --- a/monticore-grammar/src/test/grammars/de/monticore/expressions/CombineExpressionsWithLiterals.mc4 +++ b/monticore-grammar/src/test/grammars/de/monticore/expressions/CombineExpressionsWithLiterals.mc4 @@ -17,15 +17,6 @@ grammar CombineExpressionsWithLiterals extends Foo="bar" Expression; - @Override - ExtType = MCType; - - @Override - ExtReturnType = MCReturnType; - - @Override - ExtTypeArgument = MCTypeArgument; - TModifier implements MCModifier = "private" | "static"; } diff --git a/monticore-grammar/src/test/grammars/de/monticore/expressions/TestJavaClassExpressions.mc4 b/monticore-grammar/src/test/grammars/de/monticore/expressions/TestJavaClassExpressions.mc4 index fc9d5ed5c7..e4244504c9 100644 --- a/monticore-grammar/src/test/grammars/de/monticore/expressions/TestJavaClassExpressions.mc4 +++ b/monticore-grammar/src/test/grammars/de/monticore/expressions/TestJavaClassExpressions.mc4 @@ -7,12 +7,6 @@ grammar TestJavaClassExpressions extends de.monticore.expressions.JavaClassExpre start Expression; - ExtType = MCType; - - ExtReturnType = MCReturnType; - - ExtTypeArgument = MCTypeArgument; - TModifier implements MCModifier = "private" | "static"; } diff --git a/monticore-grammar/src/test/java/de/monticore/expressions/combineexpressionswithliterals/_cocos/NoClassExpressionForGenerics.java b/monticore-grammar/src/test/java/de/monticore/expressions/combineexpressionswithliterals/_cocos/NoClassExpressionForGenerics.java index 6ebdef226b..47d4947c15 100644 --- a/monticore-grammar/src/test/java/de/monticore/expressions/combineexpressionswithliterals/_cocos/NoClassExpressionForGenerics.java +++ b/monticore-grammar/src/test/java/de/monticore/expressions/combineexpressionswithliterals/_cocos/NoClassExpressionForGenerics.java @@ -1,7 +1,6 @@ /* (c) https://github.com/MontiCore/monticore */ package de.monticore.expressions.combineexpressionswithliterals._cocos; -import de.monticore.expressions.combineexpressionswithliterals._ast.ASTExtReturnType; import de.monticore.expressions.javaclassexpressions._ast.ASTClassExpression; import de.monticore.expressions.javaclassexpressions._cocos.JavaClassExpressionsASTClassExpressionCoCo; import de.monticore.prettyprint.IndentPrinter; @@ -23,12 +22,11 @@ public class NoClassExpressionForGenerics implements JavaClassExpressionsASTClas @Override public void check(ASTClassExpression node) { - checkNoGeneric((ASTExtReturnType) node.getExtReturnType()); + checkNoGeneric(node.getMCReturnType()); } - private void checkNoGeneric(ASTExtReturnType extreturnType){ + private void checkNoGeneric(ASTMCReturnType returnType){ MCSimpleGenericTypesFullPrettyPrinter prettyPrinter = new MCSimpleGenericTypesFullPrettyPrinter(new IndentPrinter()); - ASTMCReturnType returnType = extreturnType.getMCReturnType(); if(returnType.isPresentMCType()){ ASTMCType type = returnType.getMCType(); if(type instanceof ASTMCGenericType){ diff --git a/monticore-grammar/src/test/java/de/monticore/expressions/prettyprint/JavaClassExpressionsPrettyPrinterTest.java b/monticore-grammar/src/test/java/de/monticore/expressions/prettyprint/JavaClassExpressionsPrettyPrinterTest.java index 43e740eca0..8c8ea90b52 100644 --- a/monticore-grammar/src/test/java/de/monticore/expressions/prettyprint/JavaClassExpressionsPrettyPrinterTest.java +++ b/monticore-grammar/src/test/java/de/monticore/expressions/prettyprint/JavaClassExpressionsPrettyPrinterTest.java @@ -6,10 +6,10 @@ import de.monticore.expressions.javaclassexpressions._ast.*; import de.monticore.expressions.javaclassexpressions._prettyprint.JavaClassExpressionsFullPrettyPrinter; import de.monticore.expressions.testjavaclassexpressions.TestJavaClassExpressionsMill; -import de.monticore.expressions.testjavaclassexpressions._ast.ASTExtType; import de.monticore.expressions.testjavaclassexpressions._parser.TestJavaClassExpressionsParser; import de.monticore.prettyprint.IndentPrinter; import de.monticore.symbols.basicsymbols.BasicSymbolsMill; +import de.monticore.types.mcbasictypes._ast.ASTMCType; import de.se_rwth.commons.logging.Log; import de.se_rwth.commons.logging.LogStub; import org.junit.Before; @@ -99,9 +99,7 @@ public void testClassExpression() throws IOException { String output = prettyPrinter.prettyprint(ast); - // does not print 'Integer' because functionality for type printing has to be added over delegation form - // prettyprinter of langauge that fills the external - assertEquals(".class", output); + assertEquals("Integer.class", output); } @Test @@ -113,27 +111,23 @@ public void testPrimaryGenericInvocationExpressionExpression() throws IOExceptio String output = prettyPrinter.prettyprint(ast); - // does not print 'Integer' because functionality for type printing has to be added over delegation form - // prettyprinter of langauge that fills the external - assertEquals("<>super(a)", output); + assertEquals("super(a)", output); } @Test public void testInstanceofExpression() throws IOException { Optional a = parser.parse_StringExpression("a"); - Optional type = parser.parse_StringExtType("Integer"); + Optional type = parser.parse_StringMCType("Integer"); assertFalse(parser.hasErrors()); assertTrue(a.isPresent()); assertTrue(type.isPresent()); ASTInstanceofExpression result = JavaClassExpressionsMill.instanceofExpressionBuilder() .setExpression(a.get()) - .setExtType(type.get()) + .setMCType(type.get()) .build(); String output = prettyPrinter.prettyprint(result); - // does not print 'Integer' because functionality for type printing has to be added over delegation form - // prettyprinter of langauge that fills the external - assertEquals("a instanceof", output); + assertEquals("a instanceof Integer", output); } @Test @@ -203,9 +197,7 @@ public void testGenericInvocationExpressionExpression() throws IOException { String output = prettyPrinter.prettyprint(result); - // does not print 'd' because functionality for type printing has to be added over delegation form - // prettyprinter of langauge that fills the external - assertEquals("a.<>c(b)", output); + assertEquals("a.c(b)", output); } @Test @@ -271,9 +263,7 @@ public void testCreatorExpression() throws IOException { String output = prettyPrinter.prettyprint(ast); - // does not print 'Integer' because functionality for type printing has to be added over delegation from - // prettyprinter of language that fills the external - assertEquals("new(a,b)", output); + assertEquals("new Integer(a,b)", output); } @Test @@ -283,8 +273,6 @@ public void testCreatorExpression2() throws IOException { assertTrue(result.isPresent()); ASTCreatorExpression ast = result.get(); String output = prettyPrinter.prettyprint(ast); - // does not print 'double' because functionality for type printing has to be added over delegation from - // prettyprinter of language that fills the external - assertEquals("new[a][]", output); + assertEquals("new double[a][]", output); } } diff --git a/monticore-grammar/src/test/java/de/monticore/types/check/DeriveSymTypeOfCombineExpressions.java b/monticore-grammar/src/test/java/de/monticore/types/check/DeriveSymTypeOfCombineExpressions.java index b338b09af3..1291f3e1d7 100644 --- a/monticore-grammar/src/test/java/de/monticore/types/check/DeriveSymTypeOfCombineExpressions.java +++ b/monticore-grammar/src/test/java/de/monticore/types/check/DeriveSymTypeOfCombineExpressions.java @@ -1,21 +1,16 @@ /* (c) https://github.com/MontiCore/monticore */ package de.monticore.types.check; -import de.monticore.expressions.combineexpressionswithliterals._ast.ASTExtReturnType; -import de.monticore.expressions.combineexpressionswithliterals._ast.ASTExtType; -import de.monticore.expressions.combineexpressionswithliterals._ast.ASTExtTypeArgument; import de.monticore.expressions.combineexpressionswithliterals._visitor.CombineExpressionsWithLiteralsHandler; import de.monticore.expressions.combineexpressionswithliterals._visitor.CombineExpressionsWithLiteralsTraverser; import de.monticore.expressions.combineexpressionswithliterals._visitor.CombineExpressionsWithLiteralsVisitor2; +/** + * @deprecated is empty and does not do anything + */ +@Deprecated public class DeriveSymTypeOfCombineExpressions extends AbstractDeriveFromExpression implements CombineExpressionsWithLiteralsVisitor2, CombineExpressionsWithLiteralsHandler { - private FullSynthesizeFromCombineExpressionsWithLiterals synthesizer; - - public FullSynthesizeFromCombineExpressionsWithLiterals getSynthesizer() { - return synthesizer; - } - protected CombineExpressionsWithLiteralsTraverser traverser; @Override @@ -29,58 +24,6 @@ public void setTraverser(CombineExpressionsWithLiteralsTraverser traverser) { } public DeriveSymTypeOfCombineExpressions(FullSynthesizeFromCombineExpressionsWithLiterals synthesizer){ - this.synthesizer = synthesizer; - } - - @Override - public void traverse(ASTExtType type){ - SymTypeExpression wholeResult = null; - TypeCheckResult result = getSynthesizer().synthesizeType(type.getMCType()); - if(result.isPresentResult()){ - wholeResult=result.getResult(); - } - if(wholeResult!=null){ - getTypeCheckResult().setResult(wholeResult); - getTypeCheckResult().setType(); - }else{ - getTypeCheckResult().reset(); - } - } - - @Override - public void traverse(ASTExtReturnType returnType){ - SymTypeExpression wholeResult = null; - if(returnType.getMCReturnType().isPresentMCVoidType()){ - wholeResult = SymTypeExpressionFactory.createTypeVoid(); - }else if(returnType.getMCReturnType().isPresentMCType()){ - TypeCheckResult res = getSynthesizer().synthesizeType(returnType.getMCReturnType()); - if(res.isPresentResult()){ - wholeResult = res.getResult(); - } - } - if(wholeResult!=null){ - getTypeCheckResult().setResult(wholeResult); - getTypeCheckResult().setType(); - }else{ - getTypeCheckResult().reset(); - } - } - - @Override - public void traverse(ASTExtTypeArgument typeArgument){ - SymTypeExpression wholeResult = null; - if(typeArgument.getMCTypeArgument().getMCTypeOpt().isPresent()){ - TypeCheckResult res = getSynthesizer().synthesizeType(typeArgument.getMCTypeArgument().getMCTypeOpt().get()); - if(res.isPresentResult()){ - wholeResult = res.getResult(); - } - } - if(wholeResult!=null){ - getTypeCheckResult().setResult(wholeResult); - getTypeCheckResult().setType(); - }else{ - getTypeCheckResult().reset(); - } } } diff --git a/monticore-grammar/src/test/java/de/monticore/types/check/DeriveSymTypeOfJavaClassExpressionsTest.java b/monticore-grammar/src/test/java/de/monticore/types/check/DeriveSymTypeOfJavaClassExpressionsTest.java index a72d4f3c85..404cd31165 100644 --- a/monticore-grammar/src/test/java/de/monticore/types/check/DeriveSymTypeOfJavaClassExpressionsTest.java +++ b/monticore-grammar/src/test/java/de/monticore/types/check/DeriveSymTypeOfJavaClassExpressionsTest.java @@ -1205,8 +1205,8 @@ public void testDeriveSymTypeOfCreatorExpressionArrayCreator() throws IOExceptio @Test public void failDeriveFromCreatorExpressionArrayCreator1() throws IOException { - //Test mit ArrayInitByExpression, keine ganzzahl in Array (z.B. new String[3.4]) - checkError("new String[3.4]", "0xA0315"); + //Test mit ArrayInitByExpression, keine ganzzahl in Array (z.B. new int[3.4]) + checkError("new int[3.4]", "0xA0315"); } } diff --git a/monticore-grammar/src/test/java/de/monticore/types/check/FullDeriveFromCombineExpressionsWithLiterals.java b/monticore-grammar/src/test/java/de/monticore/types/check/FullDeriveFromCombineExpressionsWithLiterals.java index 2ff9ab1e51..899ce7de1d 100644 --- a/monticore-grammar/src/test/java/de/monticore/types/check/FullDeriveFromCombineExpressionsWithLiterals.java +++ b/monticore-grammar/src/test/java/de/monticore/types/check/FullDeriveFromCombineExpressionsWithLiterals.java @@ -63,8 +63,8 @@ public void init(CombineExpressionsWithLiteralsTraverser traverser) { deriveSymTypeOfExpression = new DeriveSymTypeOfExpression(); deriveSymTypeOfLiterals = new DeriveSymTypeOfLiterals(); deriveSymTypeOfBitExpressions = new DeriveSymTypeOfBitExpressions(); - deriveSymTypeOfJavaClassExpressions = new DeriveSymTypeOfJavaClassExpressions(); synthesizer = new FullSynthesizeFromCombineExpressionsWithLiterals(); + deriveSymTypeOfJavaClassExpressions = new DeriveSymTypeOfJavaClassExpressions(synthesizer); deriveSymTypeOfLambdaExpressions = new DeriveSymTypeOfLambdaExpressions(); deriveSymTypeOfLambdaExpressions.setSynthesize(synthesizer); deriveSymTypeOfCombineExpressions = new DeriveSymTypeOfCombineExpressions(synthesizer); diff --git a/monticore-grammar/src/test/java/de/monticore/types3/util/CombineExpressionsWithLiteralsTypeTraverserFactory.java b/monticore-grammar/src/test/java/de/monticore/types3/util/CombineExpressionsWithLiteralsTypeTraverserFactory.java index 307c4a3f34..1a99fe9e43 100644 --- a/monticore-grammar/src/test/java/de/monticore/types3/util/CombineExpressionsWithLiteralsTypeTraverserFactory.java +++ b/monticore-grammar/src/test/java/de/monticore/types3/util/CombineExpressionsWithLiteralsTypeTraverserFactory.java @@ -62,7 +62,6 @@ protected void setType4Ast(VisitorList visitors, Type4Ast type4Ast) { visitors.derCommonExpressions.setType4Ast(type4Ast); visitors.derExpressionBasis.setType4Ast(type4Ast); visitors.derLambdaExpressions.setType4Ast(type4Ast); - visitors.derCombineExpressionsWithLiterals.setType4Ast(type4Ast); visitors.derOfMCCommonLiterals.setType4Ast(type4Ast); // MCTypes visitors.synMCArrayTypes.setType4Ast(type4Ast); @@ -84,8 +83,6 @@ protected VisitorList constructVisitors() { visitors.derCommonExpressions = new CommonExpressionsTypeVisitor(); visitors.derExpressionBasis = new ExpressionBasisTypeVisitor(); visitors.derLambdaExpressions = new LambdaExpressionsTypeVisitor(); - visitors.derCombineExpressionsWithLiterals = - new CombineExpressionsWithLiteralsTypeVisitor(); visitors.derOfMCCommonLiterals = new MCCommonLiteralsTypeVisitor(); // MCTypes visitors.synMCArrayTypes = new MCArrayTypesTypeVisitor(); @@ -151,7 +148,6 @@ protected void populateTraverser( traverser.setCommonExpressionsHandler(visitors.derCommonExpressions); traverser.add4ExpressionsBasis(visitors.derExpressionBasis); traverser.add4LambdaExpressions(visitors.derLambdaExpressions); - traverser.add4CombineExpressionsWithLiterals(visitors.derCombineExpressionsWithLiterals); traverser.add4MCCommonLiterals(visitors.derOfMCCommonLiterals); // MCTypes traverser.add4MCArrayTypes(visitors.synMCArrayTypes); @@ -180,8 +176,6 @@ protected static class VisitorList { public LambdaExpressionsTypeVisitor derLambdaExpressions; - public CombineExpressionsWithLiteralsTypeVisitor derCombineExpressionsWithLiterals; - public MCCommonLiteralsTypeVisitor derOfMCCommonLiterals; // MCTypes diff --git a/monticore-grammar/src/test/java/de/monticore/types3/util/CombineExpressionsWithLiteralsTypeTraverserProvider.java b/monticore-grammar/src/test/java/de/monticore/types3/util/CombineExpressionsWithLiteralsTypeTraverserProvider.java index e54d5e6714..6c00cf5099 100644 --- a/monticore-grammar/src/test/java/de/monticore/types3/util/CombineExpressionsWithLiteralsTypeTraverserProvider.java +++ b/monticore-grammar/src/test/java/de/monticore/types3/util/CombineExpressionsWithLiteralsTypeTraverserProvider.java @@ -34,8 +34,6 @@ public class CombineExpressionsWithLiteralsTypeTraverserProvider { protected LambdaExpressionsTypeVisitor derLambdaExpressions; - protected CombineExpressionsWithLiteralsTypeVisitor derCombineExpressionsWithLiterals; - protected MCCommonLiteralsTypeVisitor derOfMCCommonLiterals; // MCTypes @@ -63,7 +61,6 @@ protected void init() { derCommonExpressions = new CommonExpressionsTypeVisitor(); derExpressionBasis = new ExpressionBasisTypeVisitor(); derLambdaExpressions = new LambdaExpressionsTypeVisitor(); - derCombineExpressionsWithLiterals = new CombineExpressionsWithLiteralsTypeVisitor(); derOfMCCommonLiterals = new MCCommonLiteralsTypeVisitor(); // MCTypes synMCArrayTypes = new MCArrayTypesTypeVisitor(); @@ -109,7 +106,6 @@ public CombineExpressionsWithLiteralsTraverser init( traverser.setCommonExpressionsHandler(derCommonExpressions); traverser.add4ExpressionsBasis(derExpressionBasis); traverser.add4LambdaExpressions(derLambdaExpressions); - traverser.add4CombineExpressionsWithLiterals(derCombineExpressionsWithLiterals); traverser.add4MCCommonLiterals(derOfMCCommonLiterals); // MCTypes traverser.add4MCArrayTypes(synMCArrayTypes); @@ -129,7 +125,6 @@ public void setType4Ast(Type4Ast type4Ast) { derCommonExpressions.setType4Ast(type4Ast); derExpressionBasis.setType4Ast(type4Ast); derLambdaExpressions.setType4Ast(type4Ast); - derCombineExpressionsWithLiterals.setType4Ast(type4Ast); derOfMCCommonLiterals.setType4Ast(type4Ast); // MCTypes synMCArrayTypes.setType4Ast(type4Ast); diff --git a/monticore-grammar/src/test/java/de/monticore/types3/util/CombineExpressionsWithLiteralsTypeVisitor.java b/monticore-grammar/src/test/java/de/monticore/types3/util/CombineExpressionsWithLiteralsTypeVisitor.java deleted file mode 100644 index 8f353674b8..0000000000 --- a/monticore-grammar/src/test/java/de/monticore/types3/util/CombineExpressionsWithLiteralsTypeVisitor.java +++ /dev/null @@ -1,33 +0,0 @@ -/* (c) https://github.com/MontiCore/monticore */ -package de.monticore.types3.util; - -import de.monticore.expressions.combineexpressionswithliterals._ast.ASTExtReturnType; -import de.monticore.expressions.combineexpressionswithliterals._ast.ASTExtType; -import de.monticore.expressions.combineexpressionswithliterals._visitor.CombineExpressionsWithLiteralsVisitor2; -import de.monticore.types3.AbstractTypeVisitor; - -/** - * @deprecated only used because of the ASTExtType not being a MCType, etc. - * to be changed - */ -@Deprecated -public class CombineExpressionsWithLiteralsTypeVisitor extends AbstractTypeVisitor - implements CombineExpressionsWithLiteralsVisitor2 { - - @Override - public void endVisit(ASTExtType type){ - getType4Ast().internal_setTypeOfTypeIdentifier2( - type, - getType4Ast().internal_getPartialTypeOfTypeId2(type.getMCType()) - ); - } - - @Override - public void endVisit(ASTExtReturnType returnType){ - getType4Ast().internal_setTypeOfTypeIdentifier2( - returnType, - getType4Ast().getPartialTypeOfTypeId(returnType.getMCReturnType()) - ); - } - -} diff --git a/monticore-test/monticore-grammar-it/src/main/grammars/mc/basegrammars/MyComplexBaseLanguage.mc4 b/monticore-test/monticore-grammar-it/src/main/grammars/mc/basegrammars/MyComplexBaseLanguage.mc4 index 51f6e29d03..04b7b3d86e 100644 --- a/monticore-test/monticore-grammar-it/src/main/grammars/mc/basegrammars/MyComplexBaseLanguage.mc4 +++ b/monticore-test/monticore-grammar-it/src/main/grammars/mc/basegrammars/MyComplexBaseLanguage.mc4 @@ -9,7 +9,4 @@ grammar MyComplexBaseLanguage extends de.monticore.statements.MCFullJavaStatements, de.monticore.literals.MCJavaLiterals { - ExtType = MCType; - ExtReturnType = MCReturnType; - ExtTypeArgument = MCTypeArgument; } \ No newline at end of file