diff --git a/AlgebraicDataflowArchitectureModel/src/code/ast/AnnotatableType.java b/AlgebraicDataflowArchitectureModel/src/code/ast/AnnotatableType.java new file mode 100644 index 0000000..6e87c83 --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/src/code/ast/AnnotatableType.java @@ -0,0 +1,26 @@ +package code.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
+ * For example,
+ * For example,
+ * For example,
+ * It can be empty if it is the type of created instances like in the following example.
+ *
+ * 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 SimpleName name;
+
+ public PrimitiveType(SimpleName name) {
+ this.name = name;
+ }
+
+ public SimpleName getName() {
+ return name;
+ }
+
+ public void setName(SimpleName name) {
+ this.name = name;
+ }
+
+ @Override
+ public String toString() {
+ if (getAnnotations().isEmpty()) {
+ return name.getIdentifier();
+ }
+
+ StringBuilder builder = new StringBuilder();
+ for (Annotation annotation : getAnnotations()) {
+ builder.append(annotation.toString());
+ builder.append(" ");
+ }
+ builder.append(name.getIdentifier());
+
+ return builder.toString();
+ }
+}
\ No newline at end of file
diff --git a/AlgebraicDataflowArchitectureModel/src/code/ast/SimpleName.java b/AlgebraicDataflowArchitectureModel/src/code/ast/SimpleName.java
new file mode 100644
index 0000000..e8de874
--- /dev/null
+++ b/AlgebraicDataflowArchitectureModel/src/code/ast/SimpleName.java
@@ -0,0 +1,45 @@
+package code.ast;
+
+/**
+ * AST Node for identifiers such as types, variables, and methods.
+ *
+ * @author s-yamagiwa
+ */
+public class SimpleName extends Expression {
+ private String identifier;
+
+ /**
+ * Indicates whether this name represents a variable or not, default to false.
+ */
+ private boolean isVar = false;
+
+ public SimpleName(String identifier) {
+ this.identifier = identifier;
+ }
+
+ public SimpleName(String identifier, boolean isVar) {
+ this(identifier);
+ this.isVar = isVar;
+ }
+
+ public String getIdentifier() {
+ return identifier;
+ }
+
+ public void setIdentifier(String identifier) {
+ this.identifier = identifier;
+ }
+
+ public boolean isVar() {
+ return isVar;
+ }
+
+ public void setVar(boolean isVar) {
+ this.isVar = isVar;
+ }
+
+ @Override
+ public String toString() {
+ return identifier;
+ }
+}
diff --git a/AlgebraicDataflowArchitectureModel/src/code/ast/SimpleType.java b/AlgebraicDataflowArchitectureModel/src/code/ast/SimpleType.java
new file mode 100644
index 0000000..7e66ae4
--- /dev/null
+++ b/AlgebraicDataflowArchitectureModel/src/code/ast/SimpleType.java
@@ -0,0 +1,39 @@
+package code.ast;
+
+/**
+ * Represents a simple type in the AST, which is a type with a single identifier.
+ * 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.
+ * List in List<String> is a base type.
+ */
+ private Type type;
+
+ /**
+ * The type arguments of the parameterized type.
+ * Defaults to an empty list.
+ * String in List<String> is a type argument.
+ */
+ private Listnew List<>() or new HashMap<>()
+ *
+ * @return The type arguments of the parameterized type.
+ */
+ public ListString, List, Map or MyClass.
+ *
+ * @author s-yamagiwa
+ */
+public class SimpleType extends AnnotatableType {
+ private SimpleName name;
+
+ public SimpleType(SimpleName name) {
+ this.name = name;
+ }
+
+ public SimpleName getName() {
+ return name;
+ }
+
+ public void setName(SimpleName name) {
+ this.name = name;
+ }
+
+ @Override
+ public String toString() {
+ if (getAnnotations().isEmpty()) {
+ return name.getIdentifier();
+ }
+
+ StringBuilder builder = new StringBuilder();
+ for (Annotation annotation : getAnnotations()) {
+ builder.append(annotation.toString());
+ builder.append(" ");
+ }
+ builder.append(name.getIdentifier());
+
+ return builder.toString();
+ }
+}
diff --git a/AlgebraicDataflowArchitectureModel/src/code/ast/Type.java b/AlgebraicDataflowArchitectureModel/src/code/ast/Type.java
new file mode 100644
index 0000000..bdf304b
--- /dev/null
+++ b/AlgebraicDataflowArchitectureModel/src/code/ast/Type.java
@@ -0,0 +1,44 @@
+package code.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);
+ }
+
+ /**
+ * Returns whether this type is a var or not.
+ */
+ public boolean isVar() {
+ return false;
+ }
+}
\ No newline at end of file