diff --git a/RDLCodeGenerator/src/main/java/ast/ASTNode.java b/RDLCodeGenerator/src/main/java/ast/ASTNode.java
deleted file mode 100644
index 4c18ffe..0000000
--- a/RDLCodeGenerator/src/main/java/ast/ASTNode.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package ast;
-
-public abstract class ASTNode {
- private ASTNode parent;
-
- public ASTNode getParent() {
- return parent;
- }
-
- public void setParent(ASTNode parent) {
- this.parent = parent;
- }
-}
diff --git a/RDLCodeGenerator/src/main/java/ast/AbstractTypeDeclaration.java b/RDLCodeGenerator/src/main/java/ast/AbstractTypeDeclaration.java
deleted file mode 100644
index 1ede942..0000000
--- a/RDLCodeGenerator/src/main/java/ast/AbstractTypeDeclaration.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package ast;
-
-public class AbstractTypeDeclaration extends BodyDeclaration {
- protected String typeName = null;
-
- public String getTypeName() {
- return typeName;
- }
-
- public void setTypeName(String typeName) {
- this.typeName = typeName;
- }
-}
diff --git a/RDLCodeGenerator/src/main/java/ast/AnnotatableType.java b/RDLCodeGenerator/src/main/java/ast/AnnotatableType.java
deleted file mode 100644
index aa016e8..0000000
--- a/RDLCodeGenerator/src/main/java/ast/AnnotatableType.java
+++ /dev/null
@@ -1,26 +0,0 @@
-package ast;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Represents an abstract base class for AST types that can have annotations.
- * This class extends the functionality of {@link Type} by introducing support
- * for attaching annotations to the type.
- *
- * Subclasses of this class represent specific kinds of types in the AST that
- * allow annotations, such as primitive types or other specialized types.
- *
- * @author s-yamagiwa
- */
-public abstract class AnnotatableType extends Type {
- private final List annotations = new ArrayList<>();
-
- public void addAnnotation(Annotation annotation) {
- annotations.add(annotation);
- }
-
- public List getAnnotations() {
- return annotations;
- }
-}
diff --git a/RDLCodeGenerator/src/main/java/ast/Annotation.java b/RDLCodeGenerator/src/main/java/ast/Annotation.java
deleted file mode 100644
index 80d4a32..0000000
--- a/RDLCodeGenerator/src/main/java/ast/Annotation.java
+++ /dev/null
@@ -1,57 +0,0 @@
-package ast;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-
-public class Annotation extends ASTNode {
- private String name = null;
- private Map keyValueMap = null;
-
- public Annotation(String name) {
- this.name = name;
- keyValueMap = new HashMap<>();
- }
-
- public Annotation(String name, String value) {
- this.name = name;
- keyValueMap = new HashMap<>();
- keyValueMap.put("value", value);
- }
-
- public String getElementName() {
- return name;
- }
-
- public Map getParams() {
- return keyValueMap;
- }
-
- public Object getValue(String key) {
- return keyValueMap.get(key);
- }
-
- public void addParam(String key, Object value) {
- keyValueMap.put(key, value);
- }
-
- public String toString() {
- String code = "@" + name;
- Set keySet = keyValueMap.keySet();
- if (keySet.size() == 0) {
- return code;
- } else if (keySet.size() == 1 && keySet.iterator().next().equals("value")) {
- code += "(" + keyValueMap.get("value").toString() + ")";
- } else {
- code += "(";
- String delimitar = "";
- for (String key: keySet) {
- Object value = keyValueMap.get(key);
- code += delimitar + key + " = \"" + value.toString() + "\"";
- delimitar = ", ";
- }
- code += ")";
- }
- return code;
- }
-}
diff --git a/RDLCodeGenerator/src/main/java/ast/Assignment.java b/RDLCodeGenerator/src/main/java/ast/Assignment.java
deleted file mode 100644
index 78cc19e..0000000
--- a/RDLCodeGenerator/src/main/java/ast/Assignment.java
+++ /dev/null
@@ -1,42 +0,0 @@
-package ast;
-
-/**
- * Represents an assignment expression node in AST (Abstract Syntax Tree)
- *
- * @author s-yamagiwa
- */
-public class Assignment extends Expression {
- private Expression left;
- private Expression right;
-
- public Assignment(Expression left, Expression right) {
- this.left = left;
- this.right = right;
- }
-
- @Override
- public Expression replace(Variable variable, Expression expression) {
- return new Assignment(left.replace(variable, expression), right.replace(variable, expression));
- }
-
- public Expression getLeft() {
- return left;
- }
-
- public void setLeft(Expression left) {
- this.left = left;
- }
-
- public Expression getRight() {
- return right;
- }
-
- public void setRight(Expression right) {
- this.right = right;
- }
-
- @Override
- public String toString() {
- return left.toString() + " " + "=" + " " + right.toString();
- }
-}
diff --git a/RDLCodeGenerator/src/main/java/ast/Block.java b/RDLCodeGenerator/src/main/java/ast/Block.java
deleted file mode 100644
index be707b1..0000000
--- a/RDLCodeGenerator/src/main/java/ast/Block.java
+++ /dev/null
@@ -1,107 +0,0 @@
-package ast;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class Block extends Statement {
- private List statements = new ArrayList<>();
-
- public List getStatements2() {
- return statements;
- }
-
- public void setStatements(List statements) {
- this.statements = statements;
- }
-
- public void addFirstStatement(Statement statement) {
- statements.add(0, statement);
- }
-
- public void addStatement(Statement statement) {
- statements.add(statement);
- }
-
- public void addFirstStatements(List statements) {
- this.statements.addAll(0, statements);
- }
-
- public void addStatements(List statements) {
- this.statements.addAll(statements);
- }
-
- public boolean contains(List statements) {
- if (statements.size() == 0) return true;
- for (int i = 0; i < this.statements.size(); i++) {
- Statement st = this.statements.get(i);
- if (st.equals(statements.get(0))) {
- if (statements.size() == 1) return true;
- int j = 1;
- for (int k = i + 1; k < this.statements.size(); k++) {
- Statement st2 = this.statements.get(k);
- if (st2.equals(statements.get(j))) {
- j++;
- if (j == statements.size()) return true;
- }
- }
- }
- }
- return false;
- }
-
- //====================================================
- //TODO: CodeGenerator修正後削除
-
- public List getStatements() {
- List strings = new ArrayList<>();
- for (Statement stmt : statements) {
- if (stmt != null) {
- strings.add(stmt.toString());
- }
- }
- return strings;
- }
-
- public void addFirstStatement(String statement) {
- if (statement != null) {
- this.addFirstStatement(new Statement() {
- @Override
- public String toString() {
- return statement;
- }
- });
- }
- }
-
- public void addStatement(String statement) {
- if (statement != null) {
- this.addStatement(new PlainStatement(statement));
- }
- }
-
- //====================================================
-
-
- @Override
- public String toString() {
- StringBuilder sb = new StringBuilder();
- sb.append("{\n");
-
- for (Statement statement : statements) {
- if (statement != null) {
- String content = statement.toString();
-
- // split statement
- String[] lines = content.split("\n");
-
- // Tab
- for (String line : lines) {
- sb.append("\t").append(line).append("\n");
- }
- }
- }
-
- sb.append("}");
- return sb.toString();
- }
-}
diff --git a/RDLCodeGenerator/src/main/java/ast/BodyDeclaration.java b/RDLCodeGenerator/src/main/java/ast/BodyDeclaration.java
deleted file mode 100644
index 6a5eece..0000000
--- a/RDLCodeGenerator/src/main/java/ast/BodyDeclaration.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package ast;
-
-public abstract class BodyDeclaration extends ASTNode {
- private int modifiers = 0;
-
- public int getModifiers() {
- return modifiers;
- }
-
- public void setModifiers(int modifiers) {
- this.modifiers = modifiers;
- }
-}
diff --git a/RDLCodeGenerator/src/main/java/ast/ClassInstanceCreation.java b/RDLCodeGenerator/src/main/java/ast/ClassInstanceCreation.java
deleted file mode 100644
index 98841af..0000000
--- a/RDLCodeGenerator/src/main/java/ast/ClassInstanceCreation.java
+++ /dev/null
@@ -1,71 +0,0 @@
-package ast;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class ClassInstanceCreation extends Expression {
- private Type type;
-
- private List arguments;
-
- public ClassInstanceCreation(Type type) {
- this(type, List.of());
- }
-
- public ClassInstanceCreation(Type type, List arguments) {
- this.type = type;
- this.arguments = arguments;
- }
-
- @Override
- public Expression replace(Variable variable, Expression expression) {
- List replacedExpressions = new ArrayList<>();
-
- for (Expression argument : arguments) {
- replacedExpressions.add(argument.replace(variable, expression));
- }
-
- return new ClassInstanceCreation(type, replacedExpressions);
- }
-
- public Type getType() {
- return type;
- }
-
- public void setType(Type type) {
- this.type = type;
- }
-
- public List getArguments() {
- return arguments;
- }
-
- public void setArguments(List arguments) {
- this.arguments = arguments;
- }
-
- public void addArgument(Expression expression) {
- arguments.add(expression);
- }
-
- @Override
- public String toString() {
- StringBuilder builder = new StringBuilder();
-
- builder.append("new ");
- builder.append(type.toString());
- builder.append("(");
- for (int i = 0; i < arguments.size(); i++) {
- Expression argument = arguments.get(i);
-
- builder.append(argument.toString());
-
- if (i < arguments.size() - 1) {
- builder.append(", ");
- }
- }
- builder.append(")");
-
- return builder.toString();
- }
-}
diff --git a/RDLCodeGenerator/src/main/java/ast/CodeUtil.java b/RDLCodeGenerator/src/main/java/ast/CodeUtil.java
deleted file mode 100644
index 09c1c76..0000000
--- a/RDLCodeGenerator/src/main/java/ast/CodeUtil.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package ast;
-
-public class CodeUtil {
-
- public static String insertTab(String code) {
- String newString = "";
- String[] lines = code.split("\n");
- for (String line: lines) {
- newString = newString + "\t" + line + "\n";
- }
- return newString;
- }
-}
diff --git a/RDLCodeGenerator/src/main/java/ast/CompilationUnit.java b/RDLCodeGenerator/src/main/java/ast/CompilationUnit.java
deleted file mode 100644
index f4af142..0000000
--- a/RDLCodeGenerator/src/main/java/ast/CompilationUnit.java
+++ /dev/null
@@ -1,67 +0,0 @@
-package ast;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class CompilationUnit extends ASTNode {
- private String fileName = null;
- private List imports = new ArrayList<>();
- private List types = new ArrayList<>();
- private List interfaces = new ArrayList<>();
-
- public CompilationUnit(TypeDeclaration type) {
- types.add(type);
- if(type.getTypeName().contains("<"))
- fileName = type.getTypeName().split("<")[0] + ".java";
- else
- fileName = type.getTypeName() + ".java";
- }
-
- public CompilationUnit(InterfaceDeclaration interfaceDeclaration) {
- interfaces.add(interfaceDeclaration);
- fileName = interfaceDeclaration.getTypeName() + ".java";
- }
-
- public List imports() {
- return imports;
- }
-
- public List types() {
- return types;
- }
-
- public void addImport(ImportDeclaration imp) {
- imports.add(imp);
- }
-
- public void addType(TypeDeclaration type) {
- types.add(type);
- }
-
- public List interfaces() {
- return interfaces;
- }
-
- public void addInterface(InterfaceDeclaration interfaceDeclaration) {
- interfaces.add(interfaceDeclaration);
- }
-
- public String getFileName() {
- return fileName;
- }
-
- public String toString() {
- String result = "";
- for (ImportDeclaration imp: imports) {
- result += imp.toString();
- }
- result +="\n";
- for (TypeDeclaration type: types) {
- result += type.toString();
- }
- for (InterfaceDeclaration iDec: interfaces) {
- result += iDec.toString();
- }
- return result;
- }
-}
\ No newline at end of file
diff --git a/RDLCodeGenerator/src/main/java/ast/Constant.java b/RDLCodeGenerator/src/main/java/ast/Constant.java
deleted file mode 100644
index 0c56081..0000000
--- a/RDLCodeGenerator/src/main/java/ast/Constant.java
+++ /dev/null
@@ -1,32 +0,0 @@
-package ast;
-
-/**
- * Represents a constant in the AST (Abstract Syntax Tree)
- *
- * @author s-yamagiwa
- */
-public class Constant extends Expression {
- private String value;
-
- public Constant(String value) {
- this.value = value;
- }
-
- @Override
- public Expression replace(Variable variable, Expression expression) {
- return this;
- }
-
- public String getValue() {
- return value;
- }
-
- public void setValue(String value) {
- this.value = value;
- }
-
- @Override
- public String toString() {
- return value;
- }
-}
diff --git a/RDLCodeGenerator/src/main/java/ast/EnhancedForStatement.java b/RDLCodeGenerator/src/main/java/ast/EnhancedForStatement.java
deleted file mode 100644
index c6b9cbd..0000000
--- a/RDLCodeGenerator/src/main/java/ast/EnhancedForStatement.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package ast;
-
-public class EnhancedForStatement extends Statement {
-
- private VariableDeclaration singleVariableDeclaration;
- private Expression expression;
- private Statement body;
-
- public VariableDeclaration getParameter() { return singleVariableDeclaration; }
- public void setParameter(VariableDeclaration parameter) { this.singleVariableDeclaration = parameter; }
-
- public Expression getExpression() { return expression; }
- public void setExpression(Expression expression) { this.expression = expression; }
-
- public Statement getBody() { return body; }
- public void setBody(Statement body) { this.body = body; }
-
- @Override
- public String toString() {
- String typeName = singleVariableDeclaration.getType().toString();
- return "for (" + typeName + " " + singleVariableDeclaration.getName() + " : " + expression + ") " + body;
- }
-}
diff --git a/RDLCodeGenerator/src/main/java/ast/Expression.java b/RDLCodeGenerator/src/main/java/ast/Expression.java
deleted file mode 100644
index bcf593b..0000000
--- a/RDLCodeGenerator/src/main/java/ast/Expression.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package ast;
-
-/**
- * Abstract base class for all expression nodes in the abstract syntax tree (AST).
- *
- * @author s-yamagiwa
- */
-public abstract class Expression extends ASTNode {
- /**
- * Replace {@code variable} with {@code expression} in AST.
- *
- * @param variable The variable to be replaced
- * @param expression The expression that {@code variable} is replaced to
- * @return A duplicated expression that is replaced with a given {@code expression}
- * @implNote The instance of any member must be immutable
- * @apiNote All variables match to the given one will be replaced with the given {@code expression}
- */
- public abstract Expression replace(Variable variable, Expression expression);
-}
diff --git a/RDLCodeGenerator/src/main/java/ast/ExpressionStatement.java b/RDLCodeGenerator/src/main/java/ast/ExpressionStatement.java
deleted file mode 100644
index 062998f..0000000
--- a/RDLCodeGenerator/src/main/java/ast/ExpressionStatement.java
+++ /dev/null
@@ -1,17 +0,0 @@
-package ast;
-
-public class ExpressionStatement extends Statement{
- private Expression expression;
-
- public ExpressionStatement(Expression expression) {
- this.expression = expression;
- }
-
- public Expression getExpression() { return expression; }
- public void setExpression(Expression expression) { this.expression = expression; }
-
- @Override
- public String toString() {
- return expression + ";";
- }
-}
diff --git a/RDLCodeGenerator/src/main/java/ast/FieldAccess.java b/RDLCodeGenerator/src/main/java/ast/FieldAccess.java
deleted file mode 100644
index ff22302..0000000
--- a/RDLCodeGenerator/src/main/java/ast/FieldAccess.java
+++ /dev/null
@@ -1,50 +0,0 @@
-package ast;
-
-/**
- * Represents field accesses in AST (Abstract Syntax Tree)
- *
- * @author s-yamagiwa
- */
-public class FieldAccess extends Expression {
- private Expression expression;
-
- private String fieldName;
-
- public FieldAccess(String fieldName) {
- this(null, fieldName);
- }
-
- public FieldAccess(Expression expression, String fieldName) {
- this.expression = expression;
- this.fieldName = fieldName;
- }
-
- @Override
- public Expression replace(Variable variable, Expression expression) {
- return new FieldAccess(expression.replace(variable, expression), fieldName);
- }
-
- public Expression getExpression() {
- return expression;
- }
-
- public void setExpression(Expression expression) {
- this.expression = expression;
- }
-
- public String getFieldName() {
- return fieldName;
- }
-
- public void setFieldName(String fieldName) {
- this.fieldName = fieldName;
- }
-
- @Override
- public String toString() {
- if (expression == null) {
- return fieldName;
- }
- return expression + "." + fieldName;
- }
-}
diff --git a/RDLCodeGenerator/src/main/java/ast/FieldDeclaration.java b/RDLCodeGenerator/src/main/java/ast/FieldDeclaration.java
deleted file mode 100644
index e0a3453..0000000
--- a/RDLCodeGenerator/src/main/java/ast/FieldDeclaration.java
+++ /dev/null
@@ -1,88 +0,0 @@
-package ast;
-
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-
-public class FieldDeclaration extends BodyDeclaration implements IAnnotatable {
- private Type type;
- private String fieldName;
- private String initializer = null;
- private String initializationBlock = null;
- private Map annotations = new HashMap<>();
-
- public FieldDeclaration(Type type, String fieldName) {
- this.type = type;
- this.fieldName = fieldName;
- }
-
- public FieldDeclaration(Type type, String fieldName, String initializer) {
- this.type = type;
- this.fieldName = fieldName;
- this.initializer = initializer;
- }
-
- public Type getType() {
- return type;
- }
-
- public void setType(Type type) {
- this.type = type;
- }
-
- public String getName() {
- return fieldName;
- }
-
- public void setName(String fieldName) {
- this.fieldName = fieldName;
- }
-
- public String getInitializer() {
- return initializer;
- }
-
- public void setInitializer(String initializer) {
- this.initializer = initializer;
- }
-
- public String getInitializationBlock() {
- return initializationBlock;
- }
-
- public void setInitializationBlock(String initializationBlock) {
- this.initializationBlock = initializationBlock;
- }
-
- @Override
- public Annotation getAnnotation(String name) {
- return annotations.get(name);
- }
-
- @Override
- public Collection getAnnotations() {
- return annotations.values();
- }
-
- @Override
- public void addAnnotation(Annotation annotation) {
- annotations.put(annotation.getElementName(), annotation);
- }
-
- public String toString() {
- String code = "";
- for (Annotation annotation: getAnnotations()) {
- code += annotation.toString() + "\n";
- }
- if (initializationBlock != null) {
- code += "private " + type.toString() + " " + fieldName + ";\n" + initializationBlock + "\n";
- } else {
- if (initializer == null) {
- code += "private " + type.toString() + " " + fieldName + ";\n";
- } else {
- code += "private " + type.toString() + " " + fieldName + " = " + initializer + ";\n";
- }
- }
- return code;
- }
-}
diff --git a/RDLCodeGenerator/src/main/java/ast/ForStatement.java b/RDLCodeGenerator/src/main/java/ast/ForStatement.java
deleted file mode 100644
index 47c6d1d..0000000
--- a/RDLCodeGenerator/src/main/java/ast/ForStatement.java
+++ /dev/null
@@ -1,70 +0,0 @@
-package ast;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class ForStatement extends Statement {
-
- private List initializers = new ArrayList<>();
- private Expression optionalConditionExpression;
- private List updaters = new ArrayList<>();
- private Statement body;
-
- public List getInitializers() {
- return initializers;
- }
-
- public void setInitializers(List initializers) {
- this.initializers = initializers;
- }
-
- public Expression getExpression() {
- return optionalConditionExpression;
- }
-
- public void setExpression(Expression expression) {
- this.optionalConditionExpression = expression;
- }
-
- public List getUpdaters() {
- return updaters;
- }
-
- public void setUpdaters(List updaters) {
- this.updaters = updaters;
- }
-
- public Statement getBody() {
- return body;
- }
-
- public void setBody(Statement body) {
- this.body = body;
- }
-
- @Override
- public String toString() {
- StringBuilder sb = new StringBuilder();
- sb.append("for (");
-
- for (int i = 0; i < initializers.size(); i++) {
- String init = initializers.get(i).toString();
- sb.append(init.endsWith(";") ? init.substring(0, init.length() - 1) : init);
- if (i < initializers.size() - 1) sb.append(", ");
- }
- sb.append("; ");
-
- if (optionalConditionExpression != null) sb.append(optionalConditionExpression);
- sb.append("; ");
-
- for (int i = 0; i < updaters.size(); i++) {
- String update = updaters.get(i).toString();
- sb.append(update.endsWith(";") ? update.substring(0, update.length() - 1) : update);
- if (i < updaters.size() - 1) sb.append(", ");
- }
- sb.append(") ");
-
- if (body != null) sb.append(body);
- return sb.toString();
- }
-}
\ No newline at end of file
diff --git a/RDLCodeGenerator/src/main/java/ast/IAnnotatable.java b/RDLCodeGenerator/src/main/java/ast/IAnnotatable.java
deleted file mode 100644
index 6d650f7..0000000
--- a/RDLCodeGenerator/src/main/java/ast/IAnnotatable.java
+++ /dev/null
@@ -1,9 +0,0 @@
-package ast;
-
-import java.util.Collection;
-
-public interface IAnnotatable {
- Annotation getAnnotation(String name);
- Collection getAnnotations();
- void addAnnotation(Annotation annotation);
-}
diff --git a/RDLCodeGenerator/src/main/java/ast/IfStatement.java b/RDLCodeGenerator/src/main/java/ast/IfStatement.java
deleted file mode 100644
index 94e3286..0000000
--- a/RDLCodeGenerator/src/main/java/ast/IfStatement.java
+++ /dev/null
@@ -1,43 +0,0 @@
-package ast;
-
-public class IfStatement extends Statement {
-
- private Expression expression;
- private Statement thenStatement;
- private Statement elseStatement;
-
- public Expression getExpression() {
- return expression;
- }
-
- public void setExpression(Expression expression) {
- this.expression = expression;
- }
-
- public Statement getThenStatement() {
- return thenStatement;
- }
-
- public void setThenStatement(Statement thenStatement) {
- this.thenStatement = thenStatement;
- }
-
- public Statement getElseStatement() {
- return elseStatement;
- }
-
- public void setElseStatement(Statement elseStatement) {
- this.elseStatement = elseStatement;
- }
-
- @Override
- public String toString() {
- StringBuilder sb = new StringBuilder();
- sb.append("if ").append(expression);
- sb.append(thenStatement);
- if (elseStatement != null) {
- sb.append(" else ").append(elseStatement);
- }
- return sb.toString();
- }
-}
\ No newline at end of file
diff --git a/RDLCodeGenerator/src/main/java/ast/ImportDeclaration.java b/RDLCodeGenerator/src/main/java/ast/ImportDeclaration.java
deleted file mode 100644
index c9b4b44..0000000
--- a/RDLCodeGenerator/src/main/java/ast/ImportDeclaration.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package ast;
-
-public class ImportDeclaration {
- private String name;
-
- public ImportDeclaration(String name) {
- this.name = name;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String toString() {
- return "import " + name + ";\n";
- }
-}
diff --git a/RDLCodeGenerator/src/main/java/ast/InfixExpression.java b/RDLCodeGenerator/src/main/java/ast/InfixExpression.java
deleted file mode 100644
index 1099e66..0000000
--- a/RDLCodeGenerator/src/main/java/ast/InfixExpression.java
+++ /dev/null
@@ -1,53 +0,0 @@
-package ast;
-
-/**
- * Represents an infix expression in AST (Abstract Syntax Tree)
- *
- * @author s-yamagiwa
- */
-public class InfixExpression extends Expression {
- private String operator;
-
- private Expression leftOperand;
- private Expression rightOperand;
-
- public InfixExpression(String operator, Expression leftOperand, Expression rightOperand) {
- this.operator = operator;
- this.leftOperand = leftOperand;
- this.rightOperand = rightOperand;
- }
-
- @Override
- public Expression replace(Variable variable, Expression expression) {
- return new InfixExpression(operator, leftOperand.replace(variable, expression), rightOperand.replace(variable, expression));
- }
-
- public String getOperator() {
- return this.operator;
- }
-
- public void setOperator(String operator) {
- this.operator = operator;
- }
-
- public Expression getLeftOperand() {
- return leftOperand;
- }
-
- public void setLeftOperand(Expression expression) {
- this.leftOperand = expression;
- }
-
- public Expression getRightOperand() {
- return rightOperand;
- }
-
- public void setRightOperand(Expression expression) {
- this.rightOperand = expression;
- }
-
- @Override
- public String toString() {
- return leftOperand.toString() + " " + operator + " " + rightOperand.toString();
- }
-}
diff --git a/RDLCodeGenerator/src/main/java/ast/InterfaceDeclaration.java b/RDLCodeGenerator/src/main/java/ast/InterfaceDeclaration.java
deleted file mode 100644
index cde4f25..0000000
--- a/RDLCodeGenerator/src/main/java/ast/InterfaceDeclaration.java
+++ /dev/null
@@ -1,67 +0,0 @@
-package ast;
-
-import java.util.*;
-
-
-public class InterfaceDeclaration extends AbstractTypeDeclaration implements IAnnotatable {
- private List methods = new ArrayList<>();
- private Map annotations = new HashMap<>();
-
- public InterfaceDeclaration(String typeName) {
- this.typeName = typeName;
- }
-
- public void addMethod(MethodDeclaration method) {
- methods.add(method);
- }
-
- public void removeMethod(MethodDeclaration method) {
- methods.remove(method);
- }
-
- public List getMethods() {
- return methods;
- }
-
- @Override
- public Annotation getAnnotation(String name) {
- return annotations.get(name);
- }
-
- @Override
- public Collection getAnnotations() {
- return annotations.values();
- }
-
- @Override
- public void addAnnotation(Annotation annotation) {
- annotations.put(annotation.getElementName(), annotation);
- }
-
- public String toString() {
- String code = "";
- for (Annotation annotation : getAnnotations()) {
- code += annotation.toString() + "\n";
- }
- code += "public interface " + typeName + " {\n";
- for (MethodDeclaration m : methods) {
- String signature = "\t";
- if (m.getReturnType() == null) {
- signature += "void ";
- } else {
- signature += m.getReturnType().toString() + " ";
- }
- signature += m.getName() + "(";
- if (m.getParameters() != null) {
- for (int i = 0; i < m.getParameters().size(); i++) {
- signature += m.getParameters().get(i).toString();
- if (i < m.getParameters().size() - 1) signature += ", ";
- }
- }
- signature += ");\n";
- code += signature;
- }
- code += "}";
- return code;
- }
-}
\ No newline at end of file
diff --git a/RDLCodeGenerator/src/main/java/ast/Lexer.java b/RDLCodeGenerator/src/main/java/ast/Lexer.java
deleted file mode 100644
index e07d224..0000000
--- a/RDLCodeGenerator/src/main/java/ast/Lexer.java
+++ /dev/null
@@ -1,55 +0,0 @@
-package ast;
-
-/**
- * The Lexer class provides functionalities for parsing and iterating through
- * a source string of text character by character.
- *
- * @author s-yamagiwa;
- */
-public class Lexer {
- private final String source;
- private int position;
-
- public Lexer(String source) {
- this.source = source;
- this.position = 0;
- }
-
- /**
- * Retrieves the next character without advancing the position.
- *
- * @return The next character.
- */
- public char peek() {
- if (position >= source.length()) {
- return '\0'; // End of line
- }
-
- return source.charAt(position);
- }
-
- /**
- * Retrieves the next character after advancing the position.
- *
- * @return The next character.
- */
- public char peekNext() {
- if (position + 1 >= source.length()) {
- return '\0'; // End of line
- }
-
- return source.charAt(position + 1);
- }
-
- /**
- * Advances the position by one character.
- *
- * @return The character that was previously at the current position.
- */
- public char advance() {
- char current = peek();
- position++;
-
- return current;
- }
-}
diff --git a/RDLCodeGenerator/src/main/java/ast/MethodDeclaration.java b/RDLCodeGenerator/src/main/java/ast/MethodDeclaration.java
deleted file mode 100644
index 778047c..0000000
--- a/RDLCodeGenerator/src/main/java/ast/MethodDeclaration.java
+++ /dev/null
@@ -1,190 +0,0 @@
-package ast;
-
-import java.util.*;
-
-public class MethodDeclaration extends BodyDeclaration implements IAnnotatable {
- private String name = null;
- private boolean isConstructor = false;
- private Type returnType = null;
- private List parameters = null;
- private Block body = null;
- private Map annotations = new HashMap<>();
- private Throws thrws = null;
-
- public MethodDeclaration(String methodName) {
- this(methodName, false);
- }
-
- public MethodDeclaration(String methodName, Type returnType) {
- this(methodName, false);
- this.returnType = returnType;
- }
-
- public MethodDeclaration(String methodName, boolean isConstructor) {
- this.name = methodName;
- this.isConstructor = isConstructor;
- }
-
- public MethodDeclaration(String methodName, boolean isConstructor, Type returnType, List parameters) {
- this(methodName, isConstructor, returnType, parameters, null);
- }
-
- public MethodDeclaration(String methodName, boolean isConstructor, Type returnType, List parameters, Block body) {
- this(methodName, isConstructor);
- this.returnType = returnType;
- this.parameters = parameters;
- this.body = body;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public boolean isConstructor() {
- return isConstructor;
- }
-
- public void setConstructor(boolean isConstructor) {
- this.isConstructor = isConstructor;
- }
-
- public Type getReturnType() {
- return returnType;
- }
-
- public void setReturnType(Type returnType) {
- this.returnType = returnType;
- }
-
- public List getParameters() {
- return parameters;
- }
-
- public void setParameters(List parameters) {
- this.parameters = parameters;
- }
-
- public void addParameter(VariableDeclaration parameter) {
- if (parameters == null) {
- parameters = new ArrayList<>();
- }
- parameters.add(parameter);
- }
-
- public Block getBody() {
- if (body == null) {
- body = new Block();
- }
- return body;
- }
-
- public void setBody(Block body) {
- this.body = body;
- }
-
- public void addUniqueStatement(Statement statement) {
- if (body == null) {
- body = new Block();
- body.addStatement(statement);
- return;
- }
- if (body.contains(List.of(statement))) return;
- body.addStatement(statement);
- }
-
- public void addStatement(Statement statement) {
- if (body == null) {
- body = new Block();
- }
- body.addStatement(statement);
- }
-
- public void addUniqueStatement(String statement) {
- if (body == null) {
- body = new Block();
- body.addStatement(statement);
- return;
- }
- if (body.contains(List.of(new PlainStatement(statement)))) return;
- body.addStatement(statement);
- }
-
- public void addStatement(String statement) {
- if (body == null) {
- body = new Block();
- }
- body.addStatement(statement);
- }
-
- public void addFirstStatement(Statement statement) {
- if (body == null) {
- body = new Block();
- }
- body.addFirstStatement(statement);
- }
-
- public void addFirstStatement(String statement) {
- if (body == null) {
- body = new Block();
- }
- body.addFirstStatement(statement);
- }
-
- public void addThrow(String exception) {
- if (thrws == null) {
- thrws = new Throws();
- }
- thrws.addException(exception);
- }
-
- public Throws getThrows() {
- return thrws;
- }
-
- @Override
- public Annotation getAnnotation(String name) {
- return annotations.get(name);
- }
-
- @Override
- public Collection getAnnotations() {
- return annotations.values();
- }
-
- @Override
- public void addAnnotation(Annotation annotation) {
- annotations.put(annotation.getElementName(), annotation);
- }
-
- public String toString() {
- String code = "";
- for (Annotation annotation: getAnnotations()) {
- code += annotation.toString() + "\n";
- }
- code += "public ";
- if (returnType == null) {
- if(!isConstructor) code += "void ";
- }else {
- code += returnType.toString() + " ";
- }
- code += (name + "(");
- if (parameters != null) {
- for (int i = 0; i < parameters.size(); i++) {
- code += parameters.get(i).toString();
- if (i < parameters.size() - 1) code += ", ";
- }
- }
- code += ") ";
-
- if (body != null) {
- code += body.toString();
- } else {
- code += ";";
- }
- return code;
- }
-}
diff --git a/RDLCodeGenerator/src/main/java/ast/MethodInvocation.java b/RDLCodeGenerator/src/main/java/ast/MethodInvocation.java
deleted file mode 100644
index 40e5235..0000000
--- a/RDLCodeGenerator/src/main/java/ast/MethodInvocation.java
+++ /dev/null
@@ -1,107 +0,0 @@
-package ast;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Represents a method invocation in AST (Abstract Syntax Tree)
- *
- * @author s-yamagiwa
- * @apiNote Type arguments aren't supported because it isn't necessary in DTRAM code generator.
- */
-public class MethodInvocation extends Expression {
- /**
- * The receiver expression of the invocation
- * defaults to {@code null}
- */
- private Expression receiver;
-
- /**
- * The method name to be called by this invocation
- */
- private String methodName;
-
- /**
- * All arguments used in the called method
- */
- private List arguments;
-
- public MethodInvocation(String methodName) {
- this(null, methodName);
- }
-
- public MethodInvocation(Expression receiver, String methodName) {
- this(receiver, methodName, List.of());
- }
-
- public MethodInvocation(Expression receiver, String methodName, List arguments) {
- this.receiver = receiver;
- this.methodName = methodName;
- this.arguments = arguments;
- }
-
- @Override
- public Expression replace(Variable variable, Expression expression) {
- List replacedExpressions = new ArrayList<>();
-
- for (Expression argument : arguments) {
- replacedExpressions.add(argument.replace(variable, expression));
- }
-
- if (receiver == null) {
- return new MethodInvocation(null, methodName, replacedExpressions);
- }
-
- return new MethodInvocation(receiver.replace(variable, expression), methodName, replacedExpressions);
- }
-
- public Expression getReceiver() {
- return receiver;
- }
-
- public void setReceiver(Expression receiver) {
- this.receiver = receiver;
- }
-
- public String getMethodName() {
- return methodName;
- }
-
- public void setMethodName(String methodName) {
- this.methodName = methodName;
- }
-
- public List getArguments() {
- return arguments;
- }
-
- public void setArguments(List arguments) {
- this.arguments = arguments;
- }
-
- @Override
- public String toString() {
- StringBuilder builder = new StringBuilder();
- if (receiver != null) {
- builder.append(receiver.toString()).append(".");
- }
-
- builder.append(methodName).append("(");
-
- if (arguments != null && !arguments.isEmpty()) {
- for (int i = 0; i < arguments.size(); i++) {
- Expression argument = arguments.get(i);
-
- builder.append(argument.toString());
-
- if (i < arguments.size() - 1) {
- builder.append(", ");
- }
- }
- }
-
- builder.append(")");
-
- return builder.toString();
- }
-}
diff --git a/RDLCodeGenerator/src/main/java/ast/Modifier.java b/RDLCodeGenerator/src/main/java/ast/Modifier.java
deleted file mode 100644
index 10ea845..0000000
--- a/RDLCodeGenerator/src/main/java/ast/Modifier.java
+++ /dev/null
@@ -1,29 +0,0 @@
-package ast;
-
-public class Modifier extends ASTNode {
- public static final int ABSTRACT = 0x0400;
- public static final int PRIVATE = 0x0002;
- public static final int PROTECTED = 0x0004;
- public static final int PUBLIC = 0x0001;
- public static final int STATIC = 0x0008;
-
- public static boolean isAbstract(int flags) {
- return (flags & ABSTRACT) != 0;
- }
-
- public static boolean isPrivate(int flags) {
- return (flags & PRIVATE) != 0;
- }
-
- public static boolean isProtected(int flags) {
- return (flags & PROTECTED) != 0;
- }
-
- public static boolean isPublic(int flags) {
- return (flags & PUBLIC) != 0;
- }
-
- public static boolean isStatic(int flags) {
- return (flags & STATIC) != 0;
- }
-}
diff --git a/RDLCodeGenerator/src/main/java/ast/ParameterizedType.java b/RDLCodeGenerator/src/main/java/ast/ParameterizedType.java
deleted file mode 100644
index d0a125d..0000000
--- a/RDLCodeGenerator/src/main/java/ast/ParameterizedType.java
+++ /dev/null
@@ -1,109 +0,0 @@
-package ast;
-
-import java.util.List;
-
-/**
- * Represents a parameterized type in an abstract syntax tree (AST).
- * A parameterized type consists of a base type and a set of type arguments.
- *
- * For example, List<String> is a parameterized type where
- * List is the base type and String is the type argument.
- *
- * @author s-yamagiwa
- */
-public class ParameterizedType extends Type {
- /**
- * The base type of the parameterized type.
- *
- * For example, List in List<String> is a base type.
- */
- private Type type;
-
- /**
- * The type arguments of the parameterized type.
- * Defaults to an empty list.
- *
- * For example, String in List<String> is a type argument.
- */
- private List typeArguments;
-
- public ParameterizedType(Type type, List typeArguments) {
- this.type = type;
- this.typeArguments = typeArguments;
- }
-
- public ParameterizedType(Type type) {
- this(type, List.of());
- }
-
- /**
- * Adds a type argument to the parameterized type.
- *
- * @param type The type argument to add. Only {@link SimpleType}s are allowed for now.
- */
- public void addTypeArgument(Type type) {
- typeArguments.add(type);
- }
-
- public Type getType() {
- return type;
- }
-
- public void setType(Type type) {
- this.type = type;
- }
-
- /**
- * Returns the type arguments of the parameterized type.
- * Only {@link SimpleType}s are allowed for now.
- *
- * It can be empty if it is the type of created instances like in the following example.
- * new List<>() or new HashMap<>()
- *
- * @return The type arguments of the parameterized type.
- */
- public List getTypeArguments() {
- return typeArguments;
- }
-
- public void setTypeArguments(List typeArguments) {
- this.typeArguments = typeArguments;
- }
-
-
- /**
- * Replace all type arguments and their descendant types that match the replacedType with the replacingType.
- * @param replacedType the type to be replaced
- * @param replacingType the type to replace with
- */
- public void replaceSubTypes(Type replacedType, Type replacingType) {
- for (int i = 0; i < typeArguments.size(); i++) {
- Type typeArgment = typeArguments.get(i);
- if (typeArgment.equals(replacedType)) {
- typeArguments.set(i, replacingType);
- } else if (typeArgment instanceof ParameterizedType) {
- ((ParameterizedType) typeArgment).replaceSubTypes(replacedType, replacingType);
- }
- }
- }
-
- @Override
- public String toString() {
- if (typeArguments.isEmpty()) {
- return type.toString();
- }
-
- StringBuilder builder = new StringBuilder();
- builder.append(type.toString());
- builder.append("<");
- for (int i = 0; i < typeArguments.size(); i++) {
- builder.append(typeArguments.get(i).toString());
- if (i < typeArguments.size() - 1) {
- builder.append(", ");
- }
- }
- builder.append(">");
-
- return builder.toString();
- }
-}
diff --git a/RDLCodeGenerator/src/main/java/ast/ParenthesizedExpression.java b/RDLCodeGenerator/src/main/java/ast/ParenthesizedExpression.java
deleted file mode 100644
index 0a5d6f2..0000000
--- a/RDLCodeGenerator/src/main/java/ast/ParenthesizedExpression.java
+++ /dev/null
@@ -1,33 +0,0 @@
-package ast;
-
-/**
- * Represents a parenthesized expression in AST (Abstract Syntax Tree)
- * This class is used to save the priority of each expression
- *
- * @author s-yamagiwa
- */
-public class ParenthesizedExpression extends Expression {
- private Expression expression;
-
- public ParenthesizedExpression(Expression expression) {
- this.expression = expression;
- }
-
- @Override
- public Expression replace(Variable variable, Expression expression) {
- return new ParenthesizedExpression(this.expression.replace(variable, expression));
- }
-
- public Expression getExpression() {
- return expression;
- }
-
- public void setExpression(Expression expression) {
- this.expression = expression;
- }
-
- @Override
- public String toString() {
- return "(" + expression.toString() + ")";
- }
-}
diff --git a/RDLCodeGenerator/src/main/java/ast/PlainExpression.java b/RDLCodeGenerator/src/main/java/ast/PlainExpression.java
deleted file mode 100644
index c5ffcbd..0000000
--- a/RDLCodeGenerator/src/main/java/ast/PlainExpression.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package ast;
-
-//====================================================
-//TODO: CodeGenerator修正後削除
-//====================================================
-
-public class PlainExpression extends Expression {
- private String expression;
-
- public PlainExpression(String expression) {
- this.expression = expression;
- }
-
- @Override
- public Expression replace(Variable variable, Expression newExpression) {
- return new PlainExpression(expression.replace(variable.toString(), newExpression.toString()));
- }
-
- @Override
- public String toString() {
- return expression;
- }
-}
diff --git a/RDLCodeGenerator/src/main/java/ast/PlainStatement.java b/RDLCodeGenerator/src/main/java/ast/PlainStatement.java
deleted file mode 100644
index 9424f1b..0000000
--- a/RDLCodeGenerator/src/main/java/ast/PlainStatement.java
+++ /dev/null
@@ -1,18 +0,0 @@
-package ast;
-
-//====================================================
-//TODO: CodeGenerator修正後削除
-//====================================================
-
-public class PlainStatement extends Statement {
- private String code;
-
- public PlainStatement(String code) {
- this.code = code;
- }
-
- @Override
- public String toString() {
- return code;
- }
-}
\ No newline at end of file
diff --git a/RDLCodeGenerator/src/main/java/ast/PostfixExpression.java b/RDLCodeGenerator/src/main/java/ast/PostfixExpression.java
deleted file mode 100644
index 8205bc0..0000000
--- a/RDLCodeGenerator/src/main/java/ast/PostfixExpression.java
+++ /dev/null
@@ -1,58 +0,0 @@
-package ast;
-
-/**
- * Represents a postfix expression in AST (Abstract Syntax Tree)
- *
- * @author s-yamagiwa
- */
-public class PostfixExpression extends Expression {
- public enum Operator {
- INCREMENT("++"), DECREMENT("--");
-
- Operator(String symbol) {
- this.symbol = symbol;
- }
-
- private final String symbol;
-
- @Override
- public String toString() {
- return symbol;
- }
- }
-
- private Expression operand;
-
- private Operator operator;
-
- public PostfixExpression(Expression operand, Operator operator) {
- this.operand = operand;
- this.operator = operator;
- }
-
- @Override
- public Expression replace(Variable variable, Expression expression) {
- return new PostfixExpression(operand.replace(variable, expression), operator);
- }
-
- public Expression getOperand() {
- return operand;
- }
-
- public void setOperand(Expression operand) {
- this.operand = operand;
- }
-
- public Operator getOperator() {
- return operator;
- }
-
- public void setOperator(Operator operator) {
- this.operator = operator;
- }
-
- @Override
- public String toString() {
- return operand.toString() + operator.toString();
- }
-}
diff --git a/RDLCodeGenerator/src/main/java/ast/PrefixExpression.java b/RDLCodeGenerator/src/main/java/ast/PrefixExpression.java
deleted file mode 100644
index d1444e3..0000000
--- a/RDLCodeGenerator/src/main/java/ast/PrefixExpression.java
+++ /dev/null
@@ -1,58 +0,0 @@
-package ast;
-
-/**
- * Represents a prefix expression in AST (Abstract Syntax Tree)
- *
- * @author s-yamagiwa
- */
-public class PrefixExpression extends Expression {
- public enum Operator {
- INCREMENT("++"), DECREMENT("--"), PLUS("+"), MINUS("-"), NOT("!");
-
- Operator(String symbol) {
- this.symbol = symbol;
- }
-
- private final String symbol;
-
- @Override
- public String toString() {
- return symbol;
- }
- }
-
- private Expression operand;
-
- private Operator operator;
-
- public PrefixExpression(Expression operand, Operator operator) {
- this.operand = operand;
- this.operator = operator;
- }
-
- @Override
- public Expression replace(Variable variable, Expression expression) {
- return new PrefixExpression(operand.replace(variable, expression), operator);
- }
-
- public Expression getOperand() {
- return operand;
- }
-
- public void setOperand(Expression operand) {
- this.operand = operand;
- }
-
- public Operator getOperator() {
- return operator;
- }
-
- public void setOperator(Operator operator) {
- this.operator = operator;
- }
-
- @Override
- public String toString() {
- return operator.toString() + operand.toString();
- }
-}
diff --git a/RDLCodeGenerator/src/main/java/ast/PrimitiveType.java b/RDLCodeGenerator/src/main/java/ast/PrimitiveType.java
deleted file mode 100644
index dfebba5..0000000
--- a/RDLCodeGenerator/src/main/java/ast/PrimitiveType.java
+++ /dev/null
@@ -1,34 +0,0 @@
-package ast;
-
-/**
- * Represents a primitive type in the abstract syntax tree (AST).
- * This class extends the {@code AnnotatableType}, allowing annotations
- * to be attached to primitive types.
- *
- * Primitive types are: {@code boolean}, {@code byte}, {@code char}, {@code short}, {@code int}, {@code long}, {@code float}, {@code double} and {@code void}
- *
- * @author s-yamagiwa
- */
-public class PrimitiveType extends AnnotatableType {
- private String typeName;
-
- public PrimitiveType(String typeName) {
- this.typeName = typeName;
- }
-
- @Override
- public String toString() {
- if (getAnnotations().isEmpty()) {
- return typeName;
- }
-
- StringBuilder builder = new StringBuilder();
- for (Annotation annotation : getAnnotations()) {
- builder.append(annotation.toString());
- builder.append(" ");
- }
- builder.append(typeName);
-
- return builder.toString();
- }
-}
\ No newline at end of file
diff --git a/RDLCodeGenerator/src/main/java/ast/ReturnStatement.java b/RDLCodeGenerator/src/main/java/ast/ReturnStatement.java
deleted file mode 100644
index 4d6cbbe..0000000
--- a/RDLCodeGenerator/src/main/java/ast/ReturnStatement.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package ast;
-
-public class ReturnStatement extends Statement{
- private Expression expression;
-
- public Expression getExpression() {
- return expression;
- }
-
- public void setExpression(Expression expression) {
- this.expression = expression;
- }
-
- @Override
- public String toString() {
- if (expression != null) {
- return "return " + expression + ";";
- }
- return "return;";
- }
-}
diff --git a/RDLCodeGenerator/src/main/java/ast/SimpleType.java b/RDLCodeGenerator/src/main/java/ast/SimpleType.java
deleted file mode 100644
index 0eb0d6a..0000000
--- a/RDLCodeGenerator/src/main/java/ast/SimpleType.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package ast;
-
-/**
- * Represents a simple type in the AST, which is a type with a single identifier.
- * For example, String, List, Map or MyClass.
- *
- * @author s-yamagiwa
- */
-public class SimpleType extends AnnotatableType {
- private String name;
-
- public SimpleType(String name) {
- this.name = name;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- @Override
- public String toString() {
- if (getAnnotations().isEmpty()) {
- return name;
- }
-
- StringBuilder builder = new StringBuilder();
- for (Annotation annotation : getAnnotations()) {
- builder.append(annotation.toString());
- builder.append(" ");
- }
- builder.append(name);
-
- return builder.toString();
- }
-}
diff --git a/RDLCodeGenerator/src/main/java/ast/Statement.java b/RDLCodeGenerator/src/main/java/ast/Statement.java
deleted file mode 100644
index 9da4841..0000000
--- a/RDLCodeGenerator/src/main/java/ast/Statement.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package ast;
-
-public abstract class Statement extends ASTNode {
-
- @Override
- public abstract String toString();
-
- @Override
- public boolean equals(Object another) {
- if (!(another instanceof Statement)) {
- return false;
- }
- return toString().equals(another.toString());
- }
-}
diff --git a/RDLCodeGenerator/src/main/java/ast/SuperMethodInvocation.java b/RDLCodeGenerator/src/main/java/ast/SuperMethodInvocation.java
deleted file mode 100644
index 421a0dc..0000000
--- a/RDLCodeGenerator/src/main/java/ast/SuperMethodInvocation.java
+++ /dev/null
@@ -1,74 +0,0 @@
-package ast;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Represents a super method invocation in AST (Abstract Syntax Tree)
- *
- * @author s-yamagiwa
- * @apiNote Type arguments aren't supported because it isn't necessary in DTRAM code generator.
- */
-public class SuperMethodInvocation extends Expression {
- private String methodName;
- private List arguments;
-
- public SuperMethodInvocation(String methodName) {
- this(methodName, List.of());
- }
-
- public SuperMethodInvocation(String methodName, List arguments) {
- this.methodName = methodName;
- this.arguments = arguments;
- }
-
- @Override
- public Expression replace(Variable variable, Expression expression) {
- List replacedExpressions = new ArrayList<>();
-
- for (Expression argument : arguments) {
- replacedExpressions.add(argument.replace(variable, expression));
- }
-
- return new SuperMethodInvocation(methodName, replacedExpressions);
- }
-
- public String getMethodName() {
- return methodName;
- }
-
- public void setMethodName(String methodName) {
- this.methodName = methodName;
- }
-
- public List getArguments() {
- return arguments;
- }
-
- public void setArguments(List arguments) {
- this.arguments = arguments;
- }
-
- @Override
- public String toString() {
- StringBuilder builder = new StringBuilder();
-
- builder.append("super.").append(methodName).append("(");
-
- if (!arguments.isEmpty()) {
- for (int i = 0; i < arguments.size(); i++) {
- Expression argument = arguments.get(i);
-
- builder.append(argument.toString());
-
- if (i < arguments.size() - 1) {
- builder.append(", ");
- }
- }
- }
-
- builder.append(");");
-
- return builder.toString();
- }
-}
diff --git a/RDLCodeGenerator/src/main/java/ast/ThisExpression.java b/RDLCodeGenerator/src/main/java/ast/ThisExpression.java
deleted file mode 100644
index 11f0cea..0000000
--- a/RDLCodeGenerator/src/main/java/ast/ThisExpression.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package ast;
-
-public class ThisExpression extends Expression {
- @Override
- public Expression replace(Variable variable, Expression expression) {
- return this;
- }
-
- @Override
- public String toString() {
- return "this";
- }
-}
diff --git a/RDLCodeGenerator/src/main/java/ast/Throws.java b/RDLCodeGenerator/src/main/java/ast/Throws.java
deleted file mode 100644
index 583b73c..0000000
--- a/RDLCodeGenerator/src/main/java/ast/Throws.java
+++ /dev/null
@@ -1,29 +0,0 @@
-package ast;
-
-import java.util.HashSet;
-import java.util.Set;
-
-public class Throws extends ASTNode {
- private Set exceptions = new HashSet<>();
-
- public Throws() {
- }
-
- public void addException(String exception) {
- exceptions.add(exception);
- }
-
- public Set getExceptions() {
- return exceptions;
- }
-
- public String toString() {
- String code = "throws ";
- String delimiter = "";
- for (String exception: exceptions) {
- code += delimiter + exception;
- delimiter = ", ";
- }
- return code;
- }
-}
diff --git a/RDLCodeGenerator/src/main/java/ast/Type.java b/RDLCodeGenerator/src/main/java/ast/Type.java
deleted file mode 100644
index 41961d4..0000000
--- a/RDLCodeGenerator/src/main/java/ast/Type.java
+++ /dev/null
@@ -1,37 +0,0 @@
-package ast;
-
-/**
- * Represents an abstract base class for all types in an abstract syntax tree (AST).
- * A type can represent various forms such as primitive types, simple types,
- * parameterized types, or others as defined by subclasses.
- *
- * @author s-yamagiwa
- */
-public abstract class Type extends ASTNode {
- /**
- * Returns whether this type is a primitive type or not.
- *
- * @return true if this type is a primitive type, false otherwise.
- */
- public final boolean isPrimitiveType() {
- return (this instanceof PrimitiveType);
- }
-
- /**
- * Returns whether this type is a simple type or not.
- *
- * @return true if this type is a simple type, false otherwise.
- */
- public final boolean isSimpleType() {
- return (this instanceof SimpleType);
- }
-
- /**
- * Returns whether this type is a parameterized type or not.
- *
- * @return true if this type is a parameterized type, false otherwise.
- */
- public final boolean isParameterizedType() {
- return (this instanceof ParameterizedType);
- }
-}
\ No newline at end of file
diff --git a/RDLCodeGenerator/src/main/java/ast/TypeDeclaration.java b/RDLCodeGenerator/src/main/java/ast/TypeDeclaration.java
deleted file mode 100644
index 873d9f6..0000000
--- a/RDLCodeGenerator/src/main/java/ast/TypeDeclaration.java
+++ /dev/null
@@ -1,98 +0,0 @@
-package ast;
-
-import java.util.*;
-
-public class TypeDeclaration extends AbstractTypeDeclaration implements IAnnotatable {
- private List fields = new ArrayList<>();
- private List methods = new ArrayList<>();
- private Map annotations = new HashMap<>();
- private List implementsInterfaces = new ArrayList<>();
-
- public TypeDeclaration(String typeName) {
- this.typeName = typeName;
- }
-
- public TypeDeclaration(String typeName, List fields) {
- this.typeName = typeName;
- this.fields = fields;
- }
-
- public TypeDeclaration(String typeName, List fields, List methods) {
- this.typeName = typeName;
- this.fields = fields;
- this.methods = methods;
- }
-
- public void addImplementsInterface(String interfaceName) {
- implementsInterfaces.add(interfaceName);
- }
-
- public List getImplementsInterfaces() {
- return implementsInterfaces;
- }
-
- public void addField(FieldDeclaration field) {
- fields.add(field);
- }
-
- public void addMethod(MethodDeclaration method) {
- methods.add(method);
- }
-
- public void removeMethod(MethodDeclaration method) {
- methods.remove(method);
- }
-
- public void removeField(FieldDeclaration field) {
- fields.remove(field);
- }
-
- public List getFields() {
- return fields;
- }
-
- public List getMethods() {
- return methods;
- }
-
- public MethodDeclaration createConstructor() {
- MethodDeclaration constructor = new MethodDeclaration(typeName, true);
- addMethod(constructor);
- return constructor;
- }
-
- @Override
- public Annotation getAnnotation(String name) {
- return annotations.get(name);
- }
-
- @Override
- public Collection getAnnotations() {
- return annotations.values();
- }
-
- @Override
- public void addAnnotation(Annotation annotation) {
- annotations.put(annotation.getElementName(), annotation);
- }
-
- public String toString() {
- String code = "";
- for (Annotation annotation: getAnnotations()) {
- code += annotation.toString() + "\n";
- }
- code += "public class " + typeName;
- if (!implementsInterfaces.isEmpty()) {
- code += " implements " + String.join(", ", implementsInterfaces);
- }
- code += " {\n";
- for (FieldDeclaration f: fields) {
- code += "\t" + f.toString();
- }
- for (MethodDeclaration m: methods) {
- code += CodeUtil.insertTab(m.toString());
- }
- code += "}";
- return code;
- }
-}
diff --git a/RDLCodeGenerator/src/main/java/ast/TypeLiteral.java b/RDLCodeGenerator/src/main/java/ast/TypeLiteral.java
deleted file mode 100644
index bc67baa..0000000
--- a/RDLCodeGenerator/src/main/java/ast/TypeLiteral.java
+++ /dev/null
@@ -1,32 +0,0 @@
-package ast;
-
-/**
- * Represents a type literal expression in the AST.
- *
- * @author s-yamagiwa
- */
-public class TypeLiteral extends Expression {
- private Type type;
-
- public TypeLiteral(Type type) {
- this.type = type;
- }
-
- @Override
- public Expression replace(Variable variable, Expression expression) {
- return this;
- }
-
- public Type getType() {
- return type;
- }
-
- public void setType(Type type) {
- this.type = type;
- }
-
- @Override
- public String toString() {
- return type.toString();
- }
-}
diff --git a/RDLCodeGenerator/src/main/java/ast/Variable.java b/RDLCodeGenerator/src/main/java/ast/Variable.java
deleted file mode 100644
index 983870c..0000000
--- a/RDLCodeGenerator/src/main/java/ast/Variable.java
+++ /dev/null
@@ -1,35 +0,0 @@
-package ast;
-
-/**
- * Represents a variable in the AST (Abstract Syntax Tree)
- *
- * @author s-yamagiwa
- */
-public class Variable extends Expression {
- private String name;
-
- public Variable(String name) {
- this.name = name;
- }
-
- @Override
- public Expression replace(Variable variable, Expression expression) {
- if (this == variable) {
- return expression;
- }
- return this;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- @Override
- public String toString() {
- return name;
- }
-}
diff --git a/RDLCodeGenerator/src/main/java/ast/VariableDeclaration.java b/RDLCodeGenerator/src/main/java/ast/VariableDeclaration.java
deleted file mode 100644
index 66029e4..0000000
--- a/RDLCodeGenerator/src/main/java/ast/VariableDeclaration.java
+++ /dev/null
@@ -1,66 +0,0 @@
-package ast;
-
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-
-public class VariableDeclaration extends ASTNode implements IAnnotatable {
- private Type type;
- private String variableName;
- private Expression optionalInitializer;
- private Map annotations = new HashMap<>();
-
- public VariableDeclaration(Type type, String variableName) {
- this.type = type;
- this.variableName = variableName;
- }
-
- public VariableDeclaration(Type type, String variableName, Expression initializer) {
- this(type, variableName);
- this.optionalInitializer = initializer;
- }
-
- public Type getType() {
- return type;
- }
-
- public void setType(Type type) {
- this.type = type;
- }
-
- public String getName() {
- return variableName;
- }
-
- public void setName(String variableName) {
- this.variableName = variableName;
- }
-
- public Expression getInitializer() { return optionalInitializer; }
-
- public void setInitializer(Expression initializer) { this.optionalInitializer = initializer; }
-
- @Override
- public Annotation getAnnotation(String name) {
- return annotations.get(name);
- }
-
- @Override
- public Collection getAnnotations() {
- return annotations.values();
- }
-
- @Override
- public void addAnnotation(Annotation annotation) {
- annotations.put(annotation.getElementName(), annotation);
- }
-
- public String toString() {
- String code = "";
- code += type.toString() + " " + variableName;
- if (optionalInitializer != null) {
- code += " = " + optionalInitializer;
- }
- return code;
- }
-}
diff --git a/RDLCodeGenerator/src/main/java/ast/VariableDeclarationStatement.java b/RDLCodeGenerator/src/main/java/ast/VariableDeclarationStatement.java
deleted file mode 100644
index 898042c..0000000
--- a/RDLCodeGenerator/src/main/java/ast/VariableDeclarationStatement.java
+++ /dev/null
@@ -1,80 +0,0 @@
-package ast;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class VariableDeclarationStatement extends Statement {
-
- private List modifiers = new ArrayList<>();
- private Type type = null;
- private List fragments = new ArrayList<>();
-
- public List getModifiers() {
- return modifiers;
- }
-
- public void setModifiers(List modifiers) {
- this.modifiers = modifiers;
- }
-
- public Type getType() {
- return type;
- }
-
- public void setType(Type type) {
- this.type = type;
- }
-
- public List getFragments() {
- return fragments;
- }
-
- public void addFragment(VariableDeclaration fragment) {
- if (fragment == null) return;
-
- if (this.type == null) {
- this.type = fragment.getType();
- this.fragments.add(fragment);
- } else {
- if (this.type.equals(fragment.getType())) {
- this.fragments.add(fragment);
- } else {
- System.err.println("Type mismatch: " + fragment);
- }
- }
- }
-
- public void setFragments(List fragments) {
- this.fragments = fragments;
-
- if (fragments != null && !fragments.isEmpty()) {
- this.type = fragments.get(0).getType();
- } else {
- this.type = null;
- }
- }
-
- @Override
- public String toString() {
- StringBuilder sb = new StringBuilder();
-
- for (Integer mod : modifiers) {
- if (mod == Modifier.PRIVATE) sb.append("private ");
- else if (mod == Modifier.PUBLIC) sb.append("public ");
- else if (mod == Modifier.PROTECTED) sb.append("protected ");
- else if (mod == Modifier.STATIC) sb.append("static ");
- }
-
- if (this.type != null) {
- sb.append(this.type.toString()).append(" ");
- }
-
- for (int i = 0; i < fragments.size(); i++) {
- sb.append(fragments.get(i).toString());
- if (i < fragments.size() - 1) sb.append(", ");
- }
-
- sb.append(";");
- return sb.toString();
- }
-}
\ No newline at end of file
diff --git a/RDLCodeGenerator/src/main/java/ast/WhileStatement.java b/RDLCodeGenerator/src/main/java/ast/WhileStatement.java
deleted file mode 100644
index 2cd2aee..0000000
--- a/RDLCodeGenerator/src/main/java/ast/WhileStatement.java
+++ /dev/null
@@ -1,33 +0,0 @@
-package ast;
-
-public class WhileStatement extends Statement {
-
- private Expression expression;
- private Statement body;
-
- public Expression getExpression() {
- return expression;
- }
-
- public void setExpression(Expression expression) {
- this.expression = expression;
- }
-
- public Statement getBody() {
- return body;
- }
-
- public void setBody(Statement body) {
- this.body = body;
- }
-
- @Override
- public String toString() {
- StringBuilder sb = new StringBuilder();
- sb.append("while (").append(expression).append(") ");
- if (body != null) {
- sb.append(body);
- }
- return sb.toString();
- }
-}
\ No newline at end of file
diff --git a/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/ASTNode.java b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/ASTNode.java
new file mode 100644
index 0000000..4b0e430
--- /dev/null
+++ b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/ASTNode.java
@@ -0,0 +1,13 @@
+package org.ntlab.rdlcodegenerator.ast;
+
+public abstract class ASTNode {
+ private ASTNode parent;
+
+ public ASTNode getParent() {
+ return parent;
+ }
+
+ public void setParent(ASTNode parent) {
+ this.parent = parent;
+ }
+}
diff --git a/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/AbstractTypeDeclaration.java b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/AbstractTypeDeclaration.java
new file mode 100644
index 0000000..164485e
--- /dev/null
+++ b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/AbstractTypeDeclaration.java
@@ -0,0 +1,13 @@
+package org.ntlab.rdlcodegenerator.ast;
+
+public class AbstractTypeDeclaration extends BodyDeclaration {
+ protected String typeName = null;
+
+ public String getTypeName() {
+ return typeName;
+ }
+
+ public void setTypeName(String typeName) {
+ this.typeName = typeName;
+ }
+}
diff --git a/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/AnnotatableType.java b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/AnnotatableType.java
new file mode 100644
index 0000000..88479fc
--- /dev/null
+++ b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/AnnotatableType.java
@@ -0,0 +1,26 @@
+package org.ntlab.rdlcodegenerator.ast;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Represents an abstract base class for AST types that can have annotations.
+ * This class extends the functionality of {@link Type} by introducing support
+ * for attaching annotations to the type.
+ *
+ * Subclasses of this class represent specific kinds of types in the AST that
+ * allow annotations, such as primitive types or other specialized types.
+ *
+ * @author s-yamagiwa
+ */
+public abstract class AnnotatableType extends Type {
+ private final List annotations = new ArrayList<>();
+
+ public void addAnnotation(Annotation annotation) {
+ annotations.add(annotation);
+ }
+
+ public List getAnnotations() {
+ return annotations;
+ }
+}
diff --git a/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/Annotation.java b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/Annotation.java
new file mode 100644
index 0000000..ec7ae84
--- /dev/null
+++ b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/Annotation.java
@@ -0,0 +1,57 @@
+package org.ntlab.rdlcodegenerator.ast;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+public class Annotation extends ASTNode {
+ private String name = null;
+ private Map keyValueMap = null;
+
+ public Annotation(String name) {
+ this.name = name;
+ keyValueMap = new HashMap<>();
+ }
+
+ public Annotation(String name, String value) {
+ this.name = name;
+ keyValueMap = new HashMap<>();
+ keyValueMap.put("value", value);
+ }
+
+ public String getElementName() {
+ return name;
+ }
+
+ public Map getParams() {
+ return keyValueMap;
+ }
+
+ public Object getValue(String key) {
+ return keyValueMap.get(key);
+ }
+
+ public void addParam(String key, Object value) {
+ keyValueMap.put(key, value);
+ }
+
+ public String toString() {
+ String code = "@" + name;
+ Set keySet = keyValueMap.keySet();
+ if (keySet.size() == 0) {
+ return code;
+ } else if (keySet.size() == 1 && keySet.iterator().next().equals("value")) {
+ code += "(" + keyValueMap.get("value").toString() + ")";
+ } else {
+ code += "(";
+ String delimitar = "";
+ for (String key: keySet) {
+ Object value = keyValueMap.get(key);
+ code += delimitar + key + " = \"" + value.toString() + "\"";
+ delimitar = ", ";
+ }
+ code += ")";
+ }
+ return code;
+ }
+}
diff --git a/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/Assignment.java b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/Assignment.java
new file mode 100644
index 0000000..55f89cd
--- /dev/null
+++ b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/Assignment.java
@@ -0,0 +1,42 @@
+package org.ntlab.rdlcodegenerator.ast;
+
+/**
+ * Represents an assignment expression node in AST (Abstract Syntax Tree)
+ *
+ * @author s-yamagiwa
+ */
+public class Assignment extends Expression {
+ private Expression left;
+ private Expression right;
+
+ public Assignment(Expression left, Expression right) {
+ this.left = left;
+ this.right = right;
+ }
+
+ @Override
+ public Expression replace(Variable variable, Expression expression) {
+ return new Assignment(left.replace(variable, expression), right.replace(variable, expression));
+ }
+
+ public Expression getLeft() {
+ return left;
+ }
+
+ public void setLeft(Expression left) {
+ this.left = left;
+ }
+
+ public Expression getRight() {
+ return right;
+ }
+
+ public void setRight(Expression right) {
+ this.right = right;
+ }
+
+ @Override
+ public String toString() {
+ return left.toString() + " " + "=" + " " + right.toString();
+ }
+}
diff --git a/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/Block.java b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/Block.java
new file mode 100644
index 0000000..c20bd97
--- /dev/null
+++ b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/Block.java
@@ -0,0 +1,107 @@
+package org.ntlab.rdlcodegenerator.ast;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class Block extends Statement {
+ private List statements = new ArrayList<>();
+
+ public List getStatements2() {
+ return statements;
+ }
+
+ public void setStatements(List statements) {
+ this.statements = statements;
+ }
+
+ public void addFirstStatement(Statement statement) {
+ statements.add(0, statement);
+ }
+
+ public void addStatement(Statement statement) {
+ statements.add(statement);
+ }
+
+ public void addFirstStatements(List statements) {
+ this.statements.addAll(0, statements);
+ }
+
+ public void addStatements(List statements) {
+ this.statements.addAll(statements);
+ }
+
+ public boolean contains(List statements) {
+ if (statements.size() == 0) return true;
+ for (int i = 0; i < this.statements.size(); i++) {
+ Statement st = this.statements.get(i);
+ if (st.equals(statements.get(0))) {
+ if (statements.size() == 1) return true;
+ int j = 1;
+ for (int k = i + 1; k < this.statements.size(); k++) {
+ Statement st2 = this.statements.get(k);
+ if (st2.equals(statements.get(j))) {
+ j++;
+ if (j == statements.size()) return true;
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+ //====================================================
+ //TODO: CodeGenerator修正後削除
+
+ public List getStatements() {
+ List strings = new ArrayList<>();
+ for (Statement stmt : statements) {
+ if (stmt != null) {
+ strings.add(stmt.toString());
+ }
+ }
+ return strings;
+ }
+
+ public void addFirstStatement(String statement) {
+ if (statement != null) {
+ this.addFirstStatement(new Statement() {
+ @Override
+ public String toString() {
+ return statement;
+ }
+ });
+ }
+ }
+
+ public void addStatement(String statement) {
+ if (statement != null) {
+ this.addStatement(new PlainStatement(statement));
+ }
+ }
+
+ //====================================================
+
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append("{\n");
+
+ for (Statement statement : statements) {
+ if (statement != null) {
+ String content = statement.toString();
+
+ // split statement
+ String[] lines = content.split("\n");
+
+ // Tab
+ for (String line : lines) {
+ sb.append("\t").append(line).append("\n");
+ }
+ }
+ }
+
+ sb.append("}");
+ return sb.toString();
+ }
+}
diff --git a/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/BodyDeclaration.java b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/BodyDeclaration.java
new file mode 100644
index 0000000..da78ee6
--- /dev/null
+++ b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/BodyDeclaration.java
@@ -0,0 +1,13 @@
+package org.ntlab.rdlcodegenerator.ast;
+
+public abstract class BodyDeclaration extends ASTNode {
+ private int modifiers = 0;
+
+ public int getModifiers() {
+ return modifiers;
+ }
+
+ public void setModifiers(int modifiers) {
+ this.modifiers = modifiers;
+ }
+}
diff --git a/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/ClassInstanceCreation.java b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/ClassInstanceCreation.java
new file mode 100644
index 0000000..f23f49d
--- /dev/null
+++ b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/ClassInstanceCreation.java
@@ -0,0 +1,71 @@
+package org.ntlab.rdlcodegenerator.ast;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class ClassInstanceCreation extends Expression {
+ private Type type;
+
+ private List arguments;
+
+ public ClassInstanceCreation(Type type) {
+ this(type, List.of());
+ }
+
+ public ClassInstanceCreation(Type type, List arguments) {
+ this.type = type;
+ this.arguments = arguments;
+ }
+
+ @Override
+ public Expression replace(Variable variable, Expression expression) {
+ List replacedExpressions = new ArrayList<>();
+
+ for (Expression argument : arguments) {
+ replacedExpressions.add(argument.replace(variable, expression));
+ }
+
+ return new ClassInstanceCreation(type, replacedExpressions);
+ }
+
+ public Type getType() {
+ return type;
+ }
+
+ public void setType(Type type) {
+ this.type = type;
+ }
+
+ public List getArguments() {
+ return arguments;
+ }
+
+ public void setArguments(List arguments) {
+ this.arguments = arguments;
+ }
+
+ public void addArgument(Expression expression) {
+ arguments.add(expression);
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+
+ builder.append("new ");
+ builder.append(type.toString());
+ builder.append("(");
+ for (int i = 0; i < arguments.size(); i++) {
+ Expression argument = arguments.get(i);
+
+ builder.append(argument.toString());
+
+ if (i < arguments.size() - 1) {
+ builder.append(", ");
+ }
+ }
+ builder.append(")");
+
+ return builder.toString();
+ }
+}
diff --git a/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/CodeUtil.java b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/CodeUtil.java
new file mode 100644
index 0000000..a2ecea3
--- /dev/null
+++ b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/CodeUtil.java
@@ -0,0 +1,13 @@
+package org.ntlab.rdlcodegenerator.ast;
+
+public class CodeUtil {
+
+ public static String insertTab(String code) {
+ String newString = "";
+ String[] lines = code.split("\n");
+ for (String line: lines) {
+ newString = newString + "\t" + line + "\n";
+ }
+ return newString;
+ }
+}
diff --git a/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/CompilationUnit.java b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/CompilationUnit.java
new file mode 100644
index 0000000..a601dc3
--- /dev/null
+++ b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/CompilationUnit.java
@@ -0,0 +1,67 @@
+package org.ntlab.rdlcodegenerator.ast;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class CompilationUnit extends ASTNode {
+ private String fileName = null;
+ private List imports = new ArrayList<>();
+ private List types = new ArrayList<>();
+ private List interfaces = new ArrayList<>();
+
+ public CompilationUnit(TypeDeclaration type) {
+ types.add(type);
+ if(type.getTypeName().contains("<"))
+ fileName = type.getTypeName().split("<")[0] + ".java";
+ else
+ fileName = type.getTypeName() + ".java";
+ }
+
+ public CompilationUnit(InterfaceDeclaration interfaceDeclaration) {
+ interfaces.add(interfaceDeclaration);
+ fileName = interfaceDeclaration.getTypeName() + ".java";
+ }
+
+ public List imports() {
+ return imports;
+ }
+
+ public List types() {
+ return types;
+ }
+
+ public void addImport(ImportDeclaration imp) {
+ imports.add(imp);
+ }
+
+ public void addType(TypeDeclaration type) {
+ types.add(type);
+ }
+
+ public List interfaces() {
+ return interfaces;
+ }
+
+ public void addInterface(InterfaceDeclaration interfaceDeclaration) {
+ interfaces.add(interfaceDeclaration);
+ }
+
+ public String getFileName() {
+ return fileName;
+ }
+
+ public String toString() {
+ String result = "";
+ for (ImportDeclaration imp: imports) {
+ result += imp.toString();
+ }
+ result +="\n";
+ for (TypeDeclaration type: types) {
+ result += type.toString();
+ }
+ for (InterfaceDeclaration iDec: interfaces) {
+ result += iDec.toString();
+ }
+ return result;
+ }
+}
\ No newline at end of file
diff --git a/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/Constant.java b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/Constant.java
new file mode 100644
index 0000000..b3756f0
--- /dev/null
+++ b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/Constant.java
@@ -0,0 +1,32 @@
+package org.ntlab.rdlcodegenerator.ast;
+
+/**
+ * Represents a constant in the AST (Abstract Syntax Tree)
+ *
+ * @author s-yamagiwa
+ */
+public class Constant extends Expression {
+ private String value;
+
+ public Constant(String value) {
+ this.value = value;
+ }
+
+ @Override
+ public Expression replace(Variable variable, Expression expression) {
+ return this;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ @Override
+ public String toString() {
+ return value;
+ }
+}
diff --git a/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/EnhancedForStatement.java b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/EnhancedForStatement.java
new file mode 100644
index 0000000..0368bcb
--- /dev/null
+++ b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/EnhancedForStatement.java
@@ -0,0 +1,23 @@
+package org.ntlab.rdlcodegenerator.ast;
+
+public class EnhancedForStatement extends Statement {
+
+ private VariableDeclaration singleVariableDeclaration;
+ private Expression expression;
+ private Statement body;
+
+ public VariableDeclaration getParameter() { return singleVariableDeclaration; }
+ public void setParameter(VariableDeclaration parameter) { this.singleVariableDeclaration = parameter; }
+
+ public Expression getExpression() { return expression; }
+ public void setExpression(Expression expression) { this.expression = expression; }
+
+ public Statement getBody() { return body; }
+ public void setBody(Statement body) { this.body = body; }
+
+ @Override
+ public String toString() {
+ String typeName = singleVariableDeclaration.getType().toString();
+ return "for (" + typeName + " " + singleVariableDeclaration.getName() + " : " + expression + ") " + body;
+ }
+}
diff --git a/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/Expression.java b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/Expression.java
new file mode 100644
index 0000000..994343a
--- /dev/null
+++ b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/Expression.java
@@ -0,0 +1,19 @@
+package org.ntlab.rdlcodegenerator.ast;
+
+/**
+ * Abstract base class for all expression nodes in the abstract syntax tree (AST).
+ *
+ * @author s-yamagiwa
+ */
+public abstract class Expression extends ASTNode {
+ /**
+ * Replace {@code variable} with {@code expression} in AST.
+ *
+ * @param variable The variable to be replaced
+ * @param expression The expression that {@code variable} is replaced to
+ * @return A duplicated expression that is replaced with a given {@code expression}
+ * @implNote The instance of any member must be immutable
+ * @apiNote All variables match to the given one will be replaced with the given {@code expression}
+ */
+ public abstract Expression replace(Variable variable, Expression expression);
+}
diff --git a/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/ExpressionStatement.java b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/ExpressionStatement.java
new file mode 100644
index 0000000..88aa9ca
--- /dev/null
+++ b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/ExpressionStatement.java
@@ -0,0 +1,17 @@
+package org.ntlab.rdlcodegenerator.ast;
+
+public class ExpressionStatement extends Statement{
+ private Expression expression;
+
+ public ExpressionStatement(Expression expression) {
+ this.expression = expression;
+ }
+
+ public Expression getExpression() { return expression; }
+ public void setExpression(Expression expression) { this.expression = expression; }
+
+ @Override
+ public String toString() {
+ return expression + ";";
+ }
+}
diff --git a/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/FieldAccess.java b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/FieldAccess.java
new file mode 100644
index 0000000..4ffa0c3
--- /dev/null
+++ b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/FieldAccess.java
@@ -0,0 +1,50 @@
+package org.ntlab.rdlcodegenerator.ast;
+
+/**
+ * Represents field accesses in AST (Abstract Syntax Tree)
+ *
+ * @author s-yamagiwa
+ */
+public class FieldAccess extends Expression {
+ private Expression expression;
+
+ private String fieldName;
+
+ public FieldAccess(String fieldName) {
+ this(null, fieldName);
+ }
+
+ public FieldAccess(Expression expression, String fieldName) {
+ this.expression = expression;
+ this.fieldName = fieldName;
+ }
+
+ @Override
+ public Expression replace(Variable variable, Expression expression) {
+ return new FieldAccess(expression.replace(variable, expression), fieldName);
+ }
+
+ public Expression getExpression() {
+ return expression;
+ }
+
+ public void setExpression(Expression expression) {
+ this.expression = expression;
+ }
+
+ public String getFieldName() {
+ return fieldName;
+ }
+
+ public void setFieldName(String fieldName) {
+ this.fieldName = fieldName;
+ }
+
+ @Override
+ public String toString() {
+ if (expression == null) {
+ return fieldName;
+ }
+ return expression + "." + fieldName;
+ }
+}
diff --git a/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/FieldDeclaration.java b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/FieldDeclaration.java
new file mode 100644
index 0000000..da68b2b
--- /dev/null
+++ b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/FieldDeclaration.java
@@ -0,0 +1,88 @@
+package org.ntlab.rdlcodegenerator.ast;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+public class FieldDeclaration extends BodyDeclaration implements IAnnotatable {
+ private Type type;
+ private String fieldName;
+ private String initializer = null;
+ private String initializationBlock = null;
+ private Map annotations = new HashMap<>();
+
+ public FieldDeclaration(Type type, String fieldName) {
+ this.type = type;
+ this.fieldName = fieldName;
+ }
+
+ public FieldDeclaration(Type type, String fieldName, String initializer) {
+ this.type = type;
+ this.fieldName = fieldName;
+ this.initializer = initializer;
+ }
+
+ public Type getType() {
+ return type;
+ }
+
+ public void setType(Type type) {
+ this.type = type;
+ }
+
+ public String getName() {
+ return fieldName;
+ }
+
+ public void setName(String fieldName) {
+ this.fieldName = fieldName;
+ }
+
+ public String getInitializer() {
+ return initializer;
+ }
+
+ public void setInitializer(String initializer) {
+ this.initializer = initializer;
+ }
+
+ public String getInitializationBlock() {
+ return initializationBlock;
+ }
+
+ public void setInitializationBlock(String initializationBlock) {
+ this.initializationBlock = initializationBlock;
+ }
+
+ @Override
+ public Annotation getAnnotation(String name) {
+ return annotations.get(name);
+ }
+
+ @Override
+ public Collection getAnnotations() {
+ return annotations.values();
+ }
+
+ @Override
+ public void addAnnotation(Annotation annotation) {
+ annotations.put(annotation.getElementName(), annotation);
+ }
+
+ public String toString() {
+ String code = "";
+ for (Annotation annotation: getAnnotations()) {
+ code += annotation.toString() + "\n";
+ }
+ if (initializationBlock != null) {
+ code += "private " + type.toString() + " " + fieldName + ";\n" + initializationBlock + "\n";
+ } else {
+ if (initializer == null) {
+ code += "private " + type.toString() + " " + fieldName + ";\n";
+ } else {
+ code += "private " + type.toString() + " " + fieldName + " = " + initializer + ";\n";
+ }
+ }
+ return code;
+ }
+}
diff --git a/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/ForStatement.java b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/ForStatement.java
new file mode 100644
index 0000000..5badd52
--- /dev/null
+++ b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/ForStatement.java
@@ -0,0 +1,70 @@
+package org.ntlab.rdlcodegenerator.ast;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class ForStatement extends Statement {
+
+ private List initializers = new ArrayList<>();
+ private Expression optionalConditionExpression;
+ private List updaters = new ArrayList<>();
+ private Statement body;
+
+ public List getInitializers() {
+ return initializers;
+ }
+
+ public void setInitializers(List initializers) {
+ this.initializers = initializers;
+ }
+
+ public Expression getExpression() {
+ return optionalConditionExpression;
+ }
+
+ public void setExpression(Expression expression) {
+ this.optionalConditionExpression = expression;
+ }
+
+ public List getUpdaters() {
+ return updaters;
+ }
+
+ public void setUpdaters(List updaters) {
+ this.updaters = updaters;
+ }
+
+ public Statement getBody() {
+ return body;
+ }
+
+ public void setBody(Statement body) {
+ this.body = body;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append("for (");
+
+ for (int i = 0; i < initializers.size(); i++) {
+ String init = initializers.get(i).toString();
+ sb.append(init.endsWith(";") ? init.substring(0, init.length() - 1) : init);
+ if (i < initializers.size() - 1) sb.append(", ");
+ }
+ sb.append("; ");
+
+ if (optionalConditionExpression != null) sb.append(optionalConditionExpression);
+ sb.append("; ");
+
+ for (int i = 0; i < updaters.size(); i++) {
+ String update = updaters.get(i).toString();
+ sb.append(update.endsWith(";") ? update.substring(0, update.length() - 1) : update);
+ if (i < updaters.size() - 1) sb.append(", ");
+ }
+ sb.append(") ");
+
+ if (body != null) sb.append(body);
+ return sb.toString();
+ }
+}
\ No newline at end of file
diff --git a/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/IAnnotatable.java b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/IAnnotatable.java
new file mode 100644
index 0000000..7430ede
--- /dev/null
+++ b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/IAnnotatable.java
@@ -0,0 +1,9 @@
+package org.ntlab.rdlcodegenerator.ast;
+
+import java.util.Collection;
+
+public interface IAnnotatable {
+ Annotation getAnnotation(String name);
+ Collection getAnnotations();
+ void addAnnotation(Annotation annotation);
+}
diff --git a/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/IfStatement.java b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/IfStatement.java
new file mode 100644
index 0000000..13ffc2f
--- /dev/null
+++ b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/IfStatement.java
@@ -0,0 +1,43 @@
+package org.ntlab.rdlcodegenerator.ast;
+
+public class IfStatement extends Statement {
+
+ private Expression expression;
+ private Statement thenStatement;
+ private Statement elseStatement;
+
+ public Expression getExpression() {
+ return expression;
+ }
+
+ public void setExpression(Expression expression) {
+ this.expression = expression;
+ }
+
+ public Statement getThenStatement() {
+ return thenStatement;
+ }
+
+ public void setThenStatement(Statement thenStatement) {
+ this.thenStatement = thenStatement;
+ }
+
+ public Statement getElseStatement() {
+ return elseStatement;
+ }
+
+ public void setElseStatement(Statement elseStatement) {
+ this.elseStatement = elseStatement;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append("if ").append(expression);
+ sb.append(thenStatement);
+ if (elseStatement != null) {
+ sb.append(" else ").append(elseStatement);
+ }
+ return sb.toString();
+ }
+}
\ No newline at end of file
diff --git a/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/ImportDeclaration.java b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/ImportDeclaration.java
new file mode 100644
index 0000000..44c775b
--- /dev/null
+++ b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/ImportDeclaration.java
@@ -0,0 +1,21 @@
+package org.ntlab.rdlcodegenerator.ast;
+
+public class ImportDeclaration {
+ private String name;
+
+ public ImportDeclaration(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String toString() {
+ return "import " + name + ";\n";
+ }
+}
diff --git a/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/InfixExpression.java b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/InfixExpression.java
new file mode 100644
index 0000000..b7133fe
--- /dev/null
+++ b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/InfixExpression.java
@@ -0,0 +1,53 @@
+package org.ntlab.rdlcodegenerator.ast;
+
+/**
+ * Represents an infix expression in AST (Abstract Syntax Tree)
+ *
+ * @author s-yamagiwa
+ */
+public class InfixExpression extends Expression {
+ private String operator;
+
+ private Expression leftOperand;
+ private Expression rightOperand;
+
+ public InfixExpression(String operator, Expression leftOperand, Expression rightOperand) {
+ this.operator = operator;
+ this.leftOperand = leftOperand;
+ this.rightOperand = rightOperand;
+ }
+
+ @Override
+ public Expression replace(Variable variable, Expression expression) {
+ return new InfixExpression(operator, leftOperand.replace(variable, expression), rightOperand.replace(variable, expression));
+ }
+
+ public String getOperator() {
+ return this.operator;
+ }
+
+ public void setOperator(String operator) {
+ this.operator = operator;
+ }
+
+ public Expression getLeftOperand() {
+ return leftOperand;
+ }
+
+ public void setLeftOperand(Expression expression) {
+ this.leftOperand = expression;
+ }
+
+ public Expression getRightOperand() {
+ return rightOperand;
+ }
+
+ public void setRightOperand(Expression expression) {
+ this.rightOperand = expression;
+ }
+
+ @Override
+ public String toString() {
+ return leftOperand.toString() + " " + operator + " " + rightOperand.toString();
+ }
+}
diff --git a/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/InterfaceDeclaration.java b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/InterfaceDeclaration.java
new file mode 100644
index 0000000..562e731
--- /dev/null
+++ b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/InterfaceDeclaration.java
@@ -0,0 +1,67 @@
+package org.ntlab.rdlcodegenerator.ast;
+
+import java.util.*;
+
+
+public class InterfaceDeclaration extends AbstractTypeDeclaration implements IAnnotatable {
+ private List methods = new ArrayList<>();
+ private Map annotations = new HashMap<>();
+
+ public InterfaceDeclaration(String typeName) {
+ this.typeName = typeName;
+ }
+
+ public void addMethod(MethodDeclaration method) {
+ methods.add(method);
+ }
+
+ public void removeMethod(MethodDeclaration method) {
+ methods.remove(method);
+ }
+
+ public List getMethods() {
+ return methods;
+ }
+
+ @Override
+ public Annotation getAnnotation(String name) {
+ return annotations.get(name);
+ }
+
+ @Override
+ public Collection getAnnotations() {
+ return annotations.values();
+ }
+
+ @Override
+ public void addAnnotation(Annotation annotation) {
+ annotations.put(annotation.getElementName(), annotation);
+ }
+
+ public String toString() {
+ String code = "";
+ for (Annotation annotation : getAnnotations()) {
+ code += annotation.toString() + "\n";
+ }
+ code += "public interface " + typeName + " {\n";
+ for (MethodDeclaration m : methods) {
+ String signature = "\t";
+ if (m.getReturnType() == null) {
+ signature += "void ";
+ } else {
+ signature += m.getReturnType().toString() + " ";
+ }
+ signature += m.getName() + "(";
+ if (m.getParameters() != null) {
+ for (int i = 0; i < m.getParameters().size(); i++) {
+ signature += m.getParameters().get(i).toString();
+ if (i < m.getParameters().size() - 1) signature += ", ";
+ }
+ }
+ signature += ");\n";
+ code += signature;
+ }
+ code += "}";
+ return code;
+ }
+}
\ No newline at end of file
diff --git a/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/Lexer.java b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/Lexer.java
new file mode 100644
index 0000000..cf3cdaa
--- /dev/null
+++ b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/Lexer.java
@@ -0,0 +1,55 @@
+package org.ntlab.rdlcodegenerator.ast;
+
+/**
+ * The Lexer class provides functionalities for parsing and iterating through
+ * a source string of text character by character.
+ *
+ * @author s-yamagiwa;
+ */
+public class Lexer {
+ private final String source;
+ private int position;
+
+ public Lexer(String source) {
+ this.source = source;
+ this.position = 0;
+ }
+
+ /**
+ * Retrieves the next character without advancing the position.
+ *
+ * @return The next character.
+ */
+ public char peek() {
+ if (position >= source.length()) {
+ return '\0'; // End of line
+ }
+
+ return source.charAt(position);
+ }
+
+ /**
+ * Retrieves the next character after advancing the position.
+ *
+ * @return The next character.
+ */
+ public char peekNext() {
+ if (position + 1 >= source.length()) {
+ return '\0'; // End of line
+ }
+
+ return source.charAt(position + 1);
+ }
+
+ /**
+ * Advances the position by one character.
+ *
+ * @return The character that was previously at the current position.
+ */
+ public char advance() {
+ char current = peek();
+ position++;
+
+ return current;
+ }
+}
diff --git a/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/MethodDeclaration.java b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/MethodDeclaration.java
new file mode 100644
index 0000000..961509a
--- /dev/null
+++ b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/MethodDeclaration.java
@@ -0,0 +1,190 @@
+package org.ntlab.rdlcodegenerator.ast;
+
+import java.util.*;
+
+public class MethodDeclaration extends BodyDeclaration implements IAnnotatable {
+ private String name = null;
+ private boolean isConstructor = false;
+ private Type returnType = null;
+ private List parameters = null;
+ private Block body = null;
+ private Map annotations = new HashMap<>();
+ private Throws thrws = null;
+
+ public MethodDeclaration(String methodName) {
+ this(methodName, false);
+ }
+
+ public MethodDeclaration(String methodName, Type returnType) {
+ this(methodName, false);
+ this.returnType = returnType;
+ }
+
+ public MethodDeclaration(String methodName, boolean isConstructor) {
+ this.name = methodName;
+ this.isConstructor = isConstructor;
+ }
+
+ public MethodDeclaration(String methodName, boolean isConstructor, Type returnType, List parameters) {
+ this(methodName, isConstructor, returnType, parameters, null);
+ }
+
+ public MethodDeclaration(String methodName, boolean isConstructor, Type returnType, List parameters, Block body) {
+ this(methodName, isConstructor);
+ this.returnType = returnType;
+ this.parameters = parameters;
+ this.body = body;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public boolean isConstructor() {
+ return isConstructor;
+ }
+
+ public void setConstructor(boolean isConstructor) {
+ this.isConstructor = isConstructor;
+ }
+
+ public Type getReturnType() {
+ return returnType;
+ }
+
+ public void setReturnType(Type returnType) {
+ this.returnType = returnType;
+ }
+
+ public List getParameters() {
+ return parameters;
+ }
+
+ public void setParameters(List parameters) {
+ this.parameters = parameters;
+ }
+
+ public void addParameter(VariableDeclaration parameter) {
+ if (parameters == null) {
+ parameters = new ArrayList<>();
+ }
+ parameters.add(parameter);
+ }
+
+ public Block getBody() {
+ if (body == null) {
+ body = new Block();
+ }
+ return body;
+ }
+
+ public void setBody(Block body) {
+ this.body = body;
+ }
+
+ public void addUniqueStatement(Statement statement) {
+ if (body == null) {
+ body = new Block();
+ body.addStatement(statement);
+ return;
+ }
+ if (body.contains(List.of(statement))) return;
+ body.addStatement(statement);
+ }
+
+ public void addStatement(Statement statement) {
+ if (body == null) {
+ body = new Block();
+ }
+ body.addStatement(statement);
+ }
+
+ public void addUniqueStatement(String statement) {
+ if (body == null) {
+ body = new Block();
+ body.addStatement(statement);
+ return;
+ }
+ if (body.contains(List.of(new PlainStatement(statement)))) return;
+ body.addStatement(statement);
+ }
+
+ public void addStatement(String statement) {
+ if (body == null) {
+ body = new Block();
+ }
+ body.addStatement(statement);
+ }
+
+ public void addFirstStatement(Statement statement) {
+ if (body == null) {
+ body = new Block();
+ }
+ body.addFirstStatement(statement);
+ }
+
+ public void addFirstStatement(String statement) {
+ if (body == null) {
+ body = new Block();
+ }
+ body.addFirstStatement(statement);
+ }
+
+ public void addThrow(String exception) {
+ if (thrws == null) {
+ thrws = new Throws();
+ }
+ thrws.addException(exception);
+ }
+
+ public Throws getThrows() {
+ return thrws;
+ }
+
+ @Override
+ public Annotation getAnnotation(String name) {
+ return annotations.get(name);
+ }
+
+ @Override
+ public Collection getAnnotations() {
+ return annotations.values();
+ }
+
+ @Override
+ public void addAnnotation(Annotation annotation) {
+ annotations.put(annotation.getElementName(), annotation);
+ }
+
+ public String toString() {
+ String code = "";
+ for (Annotation annotation: getAnnotations()) {
+ code += annotation.toString() + "\n";
+ }
+ code += "public ";
+ if (returnType == null) {
+ if(!isConstructor) code += "void ";
+ }else {
+ code += returnType.toString() + " ";
+ }
+ code += (name + "(");
+ if (parameters != null) {
+ for (int i = 0; i < parameters.size(); i++) {
+ code += parameters.get(i).toString();
+ if (i < parameters.size() - 1) code += ", ";
+ }
+ }
+ code += ") ";
+
+ if (body != null) {
+ code += body.toString();
+ } else {
+ code += ";";
+ }
+ return code;
+ }
+}
diff --git a/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/MethodInvocation.java b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/MethodInvocation.java
new file mode 100644
index 0000000..08905de
--- /dev/null
+++ b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/MethodInvocation.java
@@ -0,0 +1,107 @@
+package org.ntlab.rdlcodegenerator.ast;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Represents a method invocation in AST (Abstract Syntax Tree)
+ *
+ * @author s-yamagiwa
+ * @apiNote Type arguments aren't supported because it isn't necessary in DTRAM code generator.
+ */
+public class MethodInvocation extends Expression {
+ /**
+ * The receiver expression of the invocation
+ * defaults to {@code null}
+ */
+ private Expression receiver;
+
+ /**
+ * The method name to be called by this invocation
+ */
+ private String methodName;
+
+ /**
+ * All arguments used in the called method
+ */
+ private List arguments;
+
+ public MethodInvocation(String methodName) {
+ this(null, methodName);
+ }
+
+ public MethodInvocation(Expression receiver, String methodName) {
+ this(receiver, methodName, List.of());
+ }
+
+ public MethodInvocation(Expression receiver, String methodName, List arguments) {
+ this.receiver = receiver;
+ this.methodName = methodName;
+ this.arguments = arguments;
+ }
+
+ @Override
+ public Expression replace(Variable variable, Expression expression) {
+ List replacedExpressions = new ArrayList<>();
+
+ for (Expression argument : arguments) {
+ replacedExpressions.add(argument.replace(variable, expression));
+ }
+
+ if (receiver == null) {
+ return new MethodInvocation(null, methodName, replacedExpressions);
+ }
+
+ return new MethodInvocation(receiver.replace(variable, expression), methodName, replacedExpressions);
+ }
+
+ public Expression getReceiver() {
+ return receiver;
+ }
+
+ public void setReceiver(Expression receiver) {
+ this.receiver = receiver;
+ }
+
+ public String getMethodName() {
+ return methodName;
+ }
+
+ public void setMethodName(String methodName) {
+ this.methodName = methodName;
+ }
+
+ public List getArguments() {
+ return arguments;
+ }
+
+ public void setArguments(List arguments) {
+ this.arguments = arguments;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ if (receiver != null) {
+ builder.append(receiver.toString()).append(".");
+ }
+
+ builder.append(methodName).append("(");
+
+ if (arguments != null && !arguments.isEmpty()) {
+ for (int i = 0; i < arguments.size(); i++) {
+ Expression argument = arguments.get(i);
+
+ builder.append(argument.toString());
+
+ if (i < arguments.size() - 1) {
+ builder.append(", ");
+ }
+ }
+ }
+
+ builder.append(")");
+
+ return builder.toString();
+ }
+}
diff --git a/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/Modifier.java b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/Modifier.java
new file mode 100644
index 0000000..9ad4468
--- /dev/null
+++ b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/Modifier.java
@@ -0,0 +1,29 @@
+package org.ntlab.rdlcodegenerator.ast;
+
+public class Modifier extends ASTNode {
+ public static final int ABSTRACT = 0x0400;
+ public static final int PRIVATE = 0x0002;
+ public static final int PROTECTED = 0x0004;
+ public static final int PUBLIC = 0x0001;
+ public static final int STATIC = 0x0008;
+
+ public static boolean isAbstract(int flags) {
+ return (flags & ABSTRACT) != 0;
+ }
+
+ public static boolean isPrivate(int flags) {
+ return (flags & PRIVATE) != 0;
+ }
+
+ public static boolean isProtected(int flags) {
+ return (flags & PROTECTED) != 0;
+ }
+
+ public static boolean isPublic(int flags) {
+ return (flags & PUBLIC) != 0;
+ }
+
+ public static boolean isStatic(int flags) {
+ return (flags & STATIC) != 0;
+ }
+}
diff --git a/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/ParameterizedType.java b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/ParameterizedType.java
new file mode 100644
index 0000000..3c9ff9d
--- /dev/null
+++ b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/ParameterizedType.java
@@ -0,0 +1,109 @@
+package org.ntlab.rdlcodegenerator.ast;
+
+import java.util.List;
+
+/**
+ * Represents a parameterized type in an abstract syntax tree (AST).
+ * A parameterized type consists of a base type and a set of type arguments.
+ *
+ * For example, List<String> is a parameterized type where
+ * List is the base type and String is the type argument.
+ *
+ * @author s-yamagiwa
+ */
+public class ParameterizedType extends Type {
+ /**
+ * The base type of the parameterized type.
+ *
+ * For example, List in List<String> is a base type.
+ */
+ private Type type;
+
+ /**
+ * The type arguments of the parameterized type.
+ * Defaults to an empty list.
+ *
+ * For example, String in List<String> is a type argument.
+ */
+ private List typeArguments;
+
+ public ParameterizedType(Type type, List typeArguments) {
+ this.type = type;
+ this.typeArguments = typeArguments;
+ }
+
+ public ParameterizedType(Type type) {
+ this(type, List.of());
+ }
+
+ /**
+ * Adds a type argument to the parameterized type.
+ *
+ * @param type The type argument to add. Only {@link SimpleType}s are allowed for now.
+ */
+ public void addTypeArgument(Type type) {
+ typeArguments.add(type);
+ }
+
+ public Type getType() {
+ return type;
+ }
+
+ public void setType(Type type) {
+ this.type = type;
+ }
+
+ /**
+ * Returns the type arguments of the parameterized type.
+ * Only {@link SimpleType}s are allowed for now.
+ *
+ * It can be empty if it is the type of created instances like in the following example.
+ * new List<>() or new HashMap<>()
+ *
+ * @return The type arguments of the parameterized type.
+ */
+ public List getTypeArguments() {
+ return typeArguments;
+ }
+
+ public void setTypeArguments(List typeArguments) {
+ this.typeArguments = typeArguments;
+ }
+
+
+ /**
+ * Replace all type arguments and their descendant types that match the replacedType with the replacingType.
+ * @param replacedType the type to be replaced
+ * @param replacingType the type to replace with
+ */
+ public void replaceSubTypes(Type replacedType, Type replacingType) {
+ for (int i = 0; i < typeArguments.size(); i++) {
+ Type typeArgment = typeArguments.get(i);
+ if (typeArgment.equals(replacedType)) {
+ typeArguments.set(i, replacingType);
+ } else if (typeArgment instanceof ParameterizedType) {
+ ((ParameterizedType) typeArgment).replaceSubTypes(replacedType, replacingType);
+ }
+ }
+ }
+
+ @Override
+ public String toString() {
+ if (typeArguments.isEmpty()) {
+ return type.toString();
+ }
+
+ StringBuilder builder = new StringBuilder();
+ builder.append(type.toString());
+ builder.append("<");
+ for (int i = 0; i < typeArguments.size(); i++) {
+ builder.append(typeArguments.get(i).toString());
+ if (i < typeArguments.size() - 1) {
+ builder.append(", ");
+ }
+ }
+ builder.append(">");
+
+ return builder.toString();
+ }
+}
diff --git a/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/ParenthesizedExpression.java b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/ParenthesizedExpression.java
new file mode 100644
index 0000000..a9c544b
--- /dev/null
+++ b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/ParenthesizedExpression.java
@@ -0,0 +1,33 @@
+package org.ntlab.rdlcodegenerator.ast;
+
+/**
+ * Represents a parenthesized expression in AST (Abstract Syntax Tree)
+ * This class is used to save the priority of each expression
+ *
+ * @author s-yamagiwa
+ */
+public class ParenthesizedExpression extends Expression {
+ private Expression expression;
+
+ public ParenthesizedExpression(Expression expression) {
+ this.expression = expression;
+ }
+
+ @Override
+ public Expression replace(Variable variable, Expression expression) {
+ return new ParenthesizedExpression(this.expression.replace(variable, expression));
+ }
+
+ public Expression getExpression() {
+ return expression;
+ }
+
+ public void setExpression(Expression expression) {
+ this.expression = expression;
+ }
+
+ @Override
+ public String toString() {
+ return "(" + expression.toString() + ")";
+ }
+}
diff --git a/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/PlainExpression.java b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/PlainExpression.java
new file mode 100644
index 0000000..c2f2567
--- /dev/null
+++ b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/PlainExpression.java
@@ -0,0 +1,23 @@
+package org.ntlab.rdlcodegenerator.ast;
+
+//====================================================
+//TODO: CodeGenerator修正後削除
+//====================================================
+
+public class PlainExpression extends Expression {
+ private String expression;
+
+ public PlainExpression(String expression) {
+ this.expression = expression;
+ }
+
+ @Override
+ public Expression replace(Variable variable, Expression newExpression) {
+ return new PlainExpression(expression.replace(variable.toString(), newExpression.toString()));
+ }
+
+ @Override
+ public String toString() {
+ return expression;
+ }
+}
diff --git a/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/PlainStatement.java b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/PlainStatement.java
new file mode 100644
index 0000000..c747a38
--- /dev/null
+++ b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/PlainStatement.java
@@ -0,0 +1,18 @@
+package org.ntlab.rdlcodegenerator.ast;
+
+//====================================================
+//TODO: CodeGenerator修正後削除
+//====================================================
+
+public class PlainStatement extends Statement {
+ private String code;
+
+ public PlainStatement(String code) {
+ this.code = code;
+ }
+
+ @Override
+ public String toString() {
+ return code;
+ }
+}
\ No newline at end of file
diff --git a/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/PostfixExpression.java b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/PostfixExpression.java
new file mode 100644
index 0000000..6250d41
--- /dev/null
+++ b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/PostfixExpression.java
@@ -0,0 +1,58 @@
+package org.ntlab.rdlcodegenerator.ast;
+
+/**
+ * Represents a postfix expression in AST (Abstract Syntax Tree)
+ *
+ * @author s-yamagiwa
+ */
+public class PostfixExpression extends Expression {
+ public enum Operator {
+ INCREMENT("++"), DECREMENT("--");
+
+ Operator(String symbol) {
+ this.symbol = symbol;
+ }
+
+ private final String symbol;
+
+ @Override
+ public String toString() {
+ return symbol;
+ }
+ }
+
+ private Expression operand;
+
+ private Operator operator;
+
+ public PostfixExpression(Expression operand, Operator operator) {
+ this.operand = operand;
+ this.operator = operator;
+ }
+
+ @Override
+ public Expression replace(Variable variable, Expression expression) {
+ return new PostfixExpression(operand.replace(variable, expression), operator);
+ }
+
+ public Expression getOperand() {
+ return operand;
+ }
+
+ public void setOperand(Expression operand) {
+ this.operand = operand;
+ }
+
+ public Operator getOperator() {
+ return operator;
+ }
+
+ public void setOperator(Operator operator) {
+ this.operator = operator;
+ }
+
+ @Override
+ public String toString() {
+ return operand.toString() + operator.toString();
+ }
+}
diff --git a/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/PrefixExpression.java b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/PrefixExpression.java
new file mode 100644
index 0000000..660bcb0
--- /dev/null
+++ b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/PrefixExpression.java
@@ -0,0 +1,58 @@
+package org.ntlab.rdlcodegenerator.ast;
+
+/**
+ * Represents a prefix expression in AST (Abstract Syntax Tree)
+ *
+ * @author s-yamagiwa
+ */
+public class PrefixExpression extends Expression {
+ public enum Operator {
+ INCREMENT("++"), DECREMENT("--"), PLUS("+"), MINUS("-"), NOT("!");
+
+ Operator(String symbol) {
+ this.symbol = symbol;
+ }
+
+ private final String symbol;
+
+ @Override
+ public String toString() {
+ return symbol;
+ }
+ }
+
+ private Expression operand;
+
+ private Operator operator;
+
+ public PrefixExpression(Expression operand, Operator operator) {
+ this.operand = operand;
+ this.operator = operator;
+ }
+
+ @Override
+ public Expression replace(Variable variable, Expression expression) {
+ return new PrefixExpression(operand.replace(variable, expression), operator);
+ }
+
+ public Expression getOperand() {
+ return operand;
+ }
+
+ public void setOperand(Expression operand) {
+ this.operand = operand;
+ }
+
+ public Operator getOperator() {
+ return operator;
+ }
+
+ public void setOperator(Operator operator) {
+ this.operator = operator;
+ }
+
+ @Override
+ public String toString() {
+ return operator.toString() + operand.toString();
+ }
+}
diff --git a/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/PrimitiveType.java b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/PrimitiveType.java
new file mode 100644
index 0000000..eb269e2
--- /dev/null
+++ b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/PrimitiveType.java
@@ -0,0 +1,34 @@
+package org.ntlab.rdlcodegenerator.ast;
+
+/**
+ * Represents a primitive type in the abstract syntax tree (AST).
+ * This class extends the {@code AnnotatableType}, allowing annotations
+ * to be attached to primitive types.
+ *
+ * Primitive types are: {@code boolean}, {@code byte}, {@code char}, {@code short}, {@code int}, {@code long}, {@code float}, {@code double} and {@code void}
+ *
+ * @author s-yamagiwa
+ */
+public class PrimitiveType extends AnnotatableType {
+ private String typeName;
+
+ public PrimitiveType(String typeName) {
+ this.typeName = typeName;
+ }
+
+ @Override
+ public String toString() {
+ if (getAnnotations().isEmpty()) {
+ return typeName;
+ }
+
+ StringBuilder builder = new StringBuilder();
+ for (Annotation annotation : getAnnotations()) {
+ builder.append(annotation.toString());
+ builder.append(" ");
+ }
+ builder.append(typeName);
+
+ return builder.toString();
+ }
+}
\ No newline at end of file
diff --git a/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/ReturnStatement.java b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/ReturnStatement.java
new file mode 100644
index 0000000..31de516
--- /dev/null
+++ b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/ReturnStatement.java
@@ -0,0 +1,21 @@
+package org.ntlab.rdlcodegenerator.ast;
+
+public class ReturnStatement extends Statement{
+ private Expression expression;
+
+ public Expression getExpression() {
+ return expression;
+ }
+
+ public void setExpression(Expression expression) {
+ this.expression = expression;
+ }
+
+ @Override
+ public String toString() {
+ if (expression != null) {
+ return "return " + expression + ";";
+ }
+ return "return;";
+ }
+}
diff --git a/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/SimpleType.java b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/SimpleType.java
new file mode 100644
index 0000000..4956e08
--- /dev/null
+++ b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/SimpleType.java
@@ -0,0 +1,39 @@
+package org.ntlab.rdlcodegenerator.ast;
+
+/**
+ * Represents a simple type in the AST, which is a type with a single identifier.
+ * For example, String, List, Map or MyClass.
+ *
+ * @author s-yamagiwa
+ */
+public class SimpleType extends AnnotatableType {
+ private String name;
+
+ public SimpleType(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public String toString() {
+ if (getAnnotations().isEmpty()) {
+ return name;
+ }
+
+ StringBuilder builder = new StringBuilder();
+ for (Annotation annotation : getAnnotations()) {
+ builder.append(annotation.toString());
+ builder.append(" ");
+ }
+ builder.append(name);
+
+ return builder.toString();
+ }
+}
diff --git a/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/Statement.java b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/Statement.java
new file mode 100644
index 0000000..233db06
--- /dev/null
+++ b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/Statement.java
@@ -0,0 +1,15 @@
+package org.ntlab.rdlcodegenerator.ast;
+
+public abstract class Statement extends ASTNode {
+
+ @Override
+ public abstract String toString();
+
+ @Override
+ public boolean equals(Object another) {
+ if (!(another instanceof Statement)) {
+ return false;
+ }
+ return toString().equals(another.toString());
+ }
+}
diff --git a/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/SuperMethodInvocation.java b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/SuperMethodInvocation.java
new file mode 100644
index 0000000..524e7a7
--- /dev/null
+++ b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/SuperMethodInvocation.java
@@ -0,0 +1,74 @@
+package org.ntlab.rdlcodegenerator.ast;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Represents a super method invocation in AST (Abstract Syntax Tree)
+ *
+ * @author s-yamagiwa
+ * @apiNote Type arguments aren't supported because it isn't necessary in DTRAM code generator.
+ */
+public class SuperMethodInvocation extends Expression {
+ private String methodName;
+ private List arguments;
+
+ public SuperMethodInvocation(String methodName) {
+ this(methodName, List.of());
+ }
+
+ public SuperMethodInvocation(String methodName, List arguments) {
+ this.methodName = methodName;
+ this.arguments = arguments;
+ }
+
+ @Override
+ public Expression replace(Variable variable, Expression expression) {
+ List replacedExpressions = new ArrayList<>();
+
+ for (Expression argument : arguments) {
+ replacedExpressions.add(argument.replace(variable, expression));
+ }
+
+ return new SuperMethodInvocation(methodName, replacedExpressions);
+ }
+
+ public String getMethodName() {
+ return methodName;
+ }
+
+ public void setMethodName(String methodName) {
+ this.methodName = methodName;
+ }
+
+ public List getArguments() {
+ return arguments;
+ }
+
+ public void setArguments(List arguments) {
+ this.arguments = arguments;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+
+ builder.append("super.").append(methodName).append("(");
+
+ if (!arguments.isEmpty()) {
+ for (int i = 0; i < arguments.size(); i++) {
+ Expression argument = arguments.get(i);
+
+ builder.append(argument.toString());
+
+ if (i < arguments.size() - 1) {
+ builder.append(", ");
+ }
+ }
+ }
+
+ builder.append(");");
+
+ return builder.toString();
+ }
+}
diff --git a/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/ThisExpression.java b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/ThisExpression.java
new file mode 100644
index 0000000..ab5f6b2
--- /dev/null
+++ b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/ThisExpression.java
@@ -0,0 +1,13 @@
+package org.ntlab.rdlcodegenerator.ast;
+
+public class ThisExpression extends Expression {
+ @Override
+ public Expression replace(Variable variable, Expression expression) {
+ return this;
+ }
+
+ @Override
+ public String toString() {
+ return "this";
+ }
+}
diff --git a/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/Throws.java b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/Throws.java
new file mode 100644
index 0000000..6a148bc
--- /dev/null
+++ b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/Throws.java
@@ -0,0 +1,29 @@
+package org.ntlab.rdlcodegenerator.ast;
+
+import java.util.HashSet;
+import java.util.Set;
+
+public class Throws extends ASTNode {
+ private Set exceptions = new HashSet<>();
+
+ public Throws() {
+ }
+
+ public void addException(String exception) {
+ exceptions.add(exception);
+ }
+
+ public Set getExceptions() {
+ return exceptions;
+ }
+
+ public String toString() {
+ String code = "throws ";
+ String delimiter = "";
+ for (String exception: exceptions) {
+ code += delimiter + exception;
+ delimiter = ", ";
+ }
+ return code;
+ }
+}
diff --git a/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/Type.java b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/Type.java
new file mode 100644
index 0000000..18ea88b
--- /dev/null
+++ b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/Type.java
@@ -0,0 +1,37 @@
+package org.ntlab.rdlcodegenerator.ast;
+
+/**
+ * Represents an abstract base class for all types in an abstract syntax tree (AST).
+ * A type can represent various forms such as primitive types, simple types,
+ * parameterized types, or others as defined by subclasses.
+ *
+ * @author s-yamagiwa
+ */
+public abstract class Type extends ASTNode {
+ /**
+ * Returns whether this type is a primitive type or not.
+ *
+ * @return true if this type is a primitive type, false otherwise.
+ */
+ public final boolean isPrimitiveType() {
+ return (this instanceof PrimitiveType);
+ }
+
+ /**
+ * Returns whether this type is a simple type or not.
+ *
+ * @return true if this type is a simple type, false otherwise.
+ */
+ public final boolean isSimpleType() {
+ return (this instanceof SimpleType);
+ }
+
+ /**
+ * Returns whether this type is a parameterized type or not.
+ *
+ * @return true if this type is a parameterized type, false otherwise.
+ */
+ public final boolean isParameterizedType() {
+ return (this instanceof ParameterizedType);
+ }
+}
\ No newline at end of file
diff --git a/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/TypeDeclaration.java b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/TypeDeclaration.java
new file mode 100644
index 0000000..758ed43
--- /dev/null
+++ b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/TypeDeclaration.java
@@ -0,0 +1,98 @@
+package org.ntlab.rdlcodegenerator.ast;
+
+import java.util.*;
+
+public class TypeDeclaration extends AbstractTypeDeclaration implements IAnnotatable {
+ private List fields = new ArrayList<>();
+ private List methods = new ArrayList<>();
+ private Map annotations = new HashMap<>();
+ private List implementsInterfaces = new ArrayList<>();
+
+ public TypeDeclaration(String typeName) {
+ this.typeName = typeName;
+ }
+
+ public TypeDeclaration(String typeName, List fields) {
+ this.typeName = typeName;
+ this.fields = fields;
+ }
+
+ public TypeDeclaration(String typeName, List fields, List methods) {
+ this.typeName = typeName;
+ this.fields = fields;
+ this.methods = methods;
+ }
+
+ public void addImplementsInterface(String interfaceName) {
+ implementsInterfaces.add(interfaceName);
+ }
+
+ public List getImplementsInterfaces() {
+ return implementsInterfaces;
+ }
+
+ public void addField(FieldDeclaration field) {
+ fields.add(field);
+ }
+
+ public void addMethod(MethodDeclaration method) {
+ methods.add(method);
+ }
+
+ public void removeMethod(MethodDeclaration method) {
+ methods.remove(method);
+ }
+
+ public void removeField(FieldDeclaration field) {
+ fields.remove(field);
+ }
+
+ public List getFields() {
+ return fields;
+ }
+
+ public List getMethods() {
+ return methods;
+ }
+
+ public MethodDeclaration createConstructor() {
+ MethodDeclaration constructor = new MethodDeclaration(typeName, true);
+ addMethod(constructor);
+ return constructor;
+ }
+
+ @Override
+ public Annotation getAnnotation(String name) {
+ return annotations.get(name);
+ }
+
+ @Override
+ public Collection getAnnotations() {
+ return annotations.values();
+ }
+
+ @Override
+ public void addAnnotation(Annotation annotation) {
+ annotations.put(annotation.getElementName(), annotation);
+ }
+
+ public String toString() {
+ String code = "";
+ for (Annotation annotation: getAnnotations()) {
+ code += annotation.toString() + "\n";
+ }
+ code += "public class " + typeName;
+ if (!implementsInterfaces.isEmpty()) {
+ code += " implements " + String.join(", ", implementsInterfaces);
+ }
+ code += " {\n";
+ for (FieldDeclaration f: fields) {
+ code += "\t" + f.toString();
+ }
+ for (MethodDeclaration m: methods) {
+ code += CodeUtil.insertTab(m.toString());
+ }
+ code += "}";
+ return code;
+ }
+}
diff --git a/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/TypeLiteral.java b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/TypeLiteral.java
new file mode 100644
index 0000000..0fc23a0
--- /dev/null
+++ b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/TypeLiteral.java
@@ -0,0 +1,32 @@
+package org.ntlab.rdlcodegenerator.ast;
+
+/**
+ * Represents a type literal expression in the AST.
+ *
+ * @author s-yamagiwa
+ */
+public class TypeLiteral extends Expression {
+ private Type type;
+
+ public TypeLiteral(Type type) {
+ this.type = type;
+ }
+
+ @Override
+ public Expression replace(Variable variable, Expression expression) {
+ return this;
+ }
+
+ public Type getType() {
+ return type;
+ }
+
+ public void setType(Type type) {
+ this.type = type;
+ }
+
+ @Override
+ public String toString() {
+ return type.toString();
+ }
+}
diff --git a/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/Variable.java b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/Variable.java
new file mode 100644
index 0000000..2f24d96
--- /dev/null
+++ b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/Variable.java
@@ -0,0 +1,35 @@
+package org.ntlab.rdlcodegenerator.ast;
+
+/**
+ * Represents a variable in the AST (Abstract Syntax Tree)
+ *
+ * @author s-yamagiwa
+ */
+public class Variable extends Expression {
+ private String name;
+
+ public Variable(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public Expression replace(Variable variable, Expression expression) {
+ if (this == variable) {
+ return expression;
+ }
+ return this;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public String toString() {
+ return name;
+ }
+}
diff --git a/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/VariableDeclaration.java b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/VariableDeclaration.java
new file mode 100644
index 0000000..8c38d51
--- /dev/null
+++ b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/VariableDeclaration.java
@@ -0,0 +1,66 @@
+package org.ntlab.rdlcodegenerator.ast;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+public class VariableDeclaration extends ASTNode implements IAnnotatable {
+ private Type type;
+ private String variableName;
+ private Expression optionalInitializer;
+ private Map annotations = new HashMap<>();
+
+ public VariableDeclaration(Type type, String variableName) {
+ this.type = type;
+ this.variableName = variableName;
+ }
+
+ public VariableDeclaration(Type type, String variableName, Expression initializer) {
+ this(type, variableName);
+ this.optionalInitializer = initializer;
+ }
+
+ public Type getType() {
+ return type;
+ }
+
+ public void setType(Type type) {
+ this.type = type;
+ }
+
+ public String getName() {
+ return variableName;
+ }
+
+ public void setName(String variableName) {
+ this.variableName = variableName;
+ }
+
+ public Expression getInitializer() { return optionalInitializer; }
+
+ public void setInitializer(Expression initializer) { this.optionalInitializer = initializer; }
+
+ @Override
+ public Annotation getAnnotation(String name) {
+ return annotations.get(name);
+ }
+
+ @Override
+ public Collection getAnnotations() {
+ return annotations.values();
+ }
+
+ @Override
+ public void addAnnotation(Annotation annotation) {
+ annotations.put(annotation.getElementName(), annotation);
+ }
+
+ public String toString() {
+ String code = "";
+ code += type.toString() + " " + variableName;
+ if (optionalInitializer != null) {
+ code += " = " + optionalInitializer;
+ }
+ return code;
+ }
+}
diff --git a/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/VariableDeclarationStatement.java b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/VariableDeclarationStatement.java
new file mode 100644
index 0000000..189aced
--- /dev/null
+++ b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/VariableDeclarationStatement.java
@@ -0,0 +1,80 @@
+package org.ntlab.rdlcodegenerator.ast;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class VariableDeclarationStatement extends Statement {
+
+ private List modifiers = new ArrayList<>();
+ private Type type = null;
+ private List fragments = new ArrayList<>();
+
+ public List getModifiers() {
+ return modifiers;
+ }
+
+ public void setModifiers(List modifiers) {
+ this.modifiers = modifiers;
+ }
+
+ public Type getType() {
+ return type;
+ }
+
+ public void setType(Type type) {
+ this.type = type;
+ }
+
+ public List getFragments() {
+ return fragments;
+ }
+
+ public void addFragment(VariableDeclaration fragment) {
+ if (fragment == null) return;
+
+ if (this.type == null) {
+ this.type = fragment.getType();
+ this.fragments.add(fragment);
+ } else {
+ if (this.type.equals(fragment.getType())) {
+ this.fragments.add(fragment);
+ } else {
+ System.err.println("Type mismatch: " + fragment);
+ }
+ }
+ }
+
+ public void setFragments(List fragments) {
+ this.fragments = fragments;
+
+ if (fragments != null && !fragments.isEmpty()) {
+ this.type = fragments.get(0).getType();
+ } else {
+ this.type = null;
+ }
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+
+ for (Integer mod : modifiers) {
+ if (mod == Modifier.PRIVATE) sb.append("private ");
+ else if (mod == Modifier.PUBLIC) sb.append("public ");
+ else if (mod == Modifier.PROTECTED) sb.append("protected ");
+ else if (mod == Modifier.STATIC) sb.append("static ");
+ }
+
+ if (this.type != null) {
+ sb.append(this.type.toString()).append(" ");
+ }
+
+ for (int i = 0; i < fragments.size(); i++) {
+ sb.append(fragments.get(i).toString());
+ if (i < fragments.size() - 1) sb.append(", ");
+ }
+
+ sb.append(";");
+ return sb.toString();
+ }
+}
\ No newline at end of file
diff --git a/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/WhileStatement.java b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/WhileStatement.java
new file mode 100644
index 0000000..e662abe
--- /dev/null
+++ b/RDLCodeGenerator/src/main/java/org/ntlab/rdlcodegenerator/ast/WhileStatement.java
@@ -0,0 +1,33 @@
+package org.ntlab.rdlcodegenerator.ast;
+
+public class WhileStatement extends Statement {
+
+ private Expression expression;
+ private Statement body;
+
+ public Expression getExpression() {
+ return expression;
+ }
+
+ public void setExpression(Expression expression) {
+ this.expression = expression;
+ }
+
+ public Statement getBody() {
+ return body;
+ }
+
+ public void setBody(Statement body) {
+ this.body = body;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append("while (").append(expression).append(") ");
+ if (body != null) {
+ sb.append(body);
+ }
+ return sb.toString();
+ }
+}
\ No newline at end of file