From f457e7e4d0e97b95ef2b339db57a313240a7b48b Mon Sep 17 00:00:00 2001 From: Etienne Zink Date: Fri, 18 Mar 2022 09:09:33 +0100 Subject: [PATCH] =?UTF-8?q?Erste=20Implementierung=20des=20IntermediateTyp?= =?UTF-8?q?e=20und=20unvollst=C3=A4ndige=20Implementierung=20von=20Interme?= =?UTF-8?q?diateRefType.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../convert/ASTToIntermediate.java | 5 ++ .../types/IntermediateExtendsWildcard.java | 11 +++- .../types/IntermediateGenericType.java | 11 +++- .../types/IntermediateRefType.java | 66 ++++++++++++++++++- .../types/IntermediateSuperWildcard.java | 11 +++- .../intermediate/types/IntermediateType.java | 35 +++++++++- 6 files changed, 133 insertions(+), 6 deletions(-) create mode 100644 src/main/java/de/dhbwstuttgart/intermediate/convert/ASTToIntermediate.java diff --git a/src/main/java/de/dhbwstuttgart/intermediate/convert/ASTToIntermediate.java b/src/main/java/de/dhbwstuttgart/intermediate/convert/ASTToIntermediate.java new file mode 100644 index 00000000..0673cbe2 --- /dev/null +++ b/src/main/java/de/dhbwstuttgart/intermediate/convert/ASTToIntermediate.java @@ -0,0 +1,5 @@ +package de.dhbwstuttgart.intermediate.convert; + +public class ASTToIntermediate { + //ToDo +} diff --git a/src/main/java/de/dhbwstuttgart/intermediate/types/IntermediateExtendsWildcard.java b/src/main/java/de/dhbwstuttgart/intermediate/types/IntermediateExtendsWildcard.java index 20190127..b4f57597 100644 --- a/src/main/java/de/dhbwstuttgart/intermediate/types/IntermediateExtendsWildcard.java +++ b/src/main/java/de/dhbwstuttgart/intermediate/types/IntermediateExtendsWildcard.java @@ -1,4 +1,13 @@ package de.dhbwstuttgart.intermediate.types; -public class IntermediateExtendsWildcard { +import de.dhbwstuttgart.parser.scope.JavaClassName; + +/** + * //ToDo Beschreiben + * + * @since Studienarbeit Type Erasure + * @author etiennezink + */ +public final class IntermediateExtendsWildcard { + //ToDo } diff --git a/src/main/java/de/dhbwstuttgart/intermediate/types/IntermediateGenericType.java b/src/main/java/de/dhbwstuttgart/intermediate/types/IntermediateGenericType.java index 7f4df842..8e176a49 100644 --- a/src/main/java/de/dhbwstuttgart/intermediate/types/IntermediateGenericType.java +++ b/src/main/java/de/dhbwstuttgart/intermediate/types/IntermediateGenericType.java @@ -1,4 +1,13 @@ package de.dhbwstuttgart.intermediate.types; -public class IntermediateGenericType { +import de.dhbwstuttgart.parser.scope.JavaClassName; + +/** + * //ToDo Beschreiben + * + * @since Studienarbeit Type Erasure + * @author etiennezink + */ +public final class IntermediateGenericType { + //ToDo } diff --git a/src/main/java/de/dhbwstuttgart/intermediate/types/IntermediateRefType.java b/src/main/java/de/dhbwstuttgart/intermediate/types/IntermediateRefType.java index af3f9d05..84d66b1e 100644 --- a/src/main/java/de/dhbwstuttgart/intermediate/types/IntermediateRefType.java +++ b/src/main/java/de/dhbwstuttgart/intermediate/types/IntermediateRefType.java @@ -1,4 +1,68 @@ package de.dhbwstuttgart.intermediate.types; -public class IntermediateRefType { +import de.dhbwstuttgart.parser.scope.JavaClassName; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * Represents a Java reference type. + * + * @since Studienarbeit Type Erasure + * @author etiennezink + */ +public final class IntermediateRefType extends IntermediateType{ + + private final List typParameters; + + public IntermediateRefType(JavaClassName className) { + this(className, new ArrayList<>()); + } + + public IntermediateRefType(JavaClassName className, List typParameters){ + super(className); + this.typParameters = Collections.unmodifiableList(typParameters); + } + + @Override + public String getClassSignature() { + //ToDo + return null; + } + + @Override + public String getClassDescriptor() { + //ToDo + return null; + } + + @Override + public boolean equals(Object o) { + if (!(o instanceof IntermediateRefType)) return false; + + IntermediateRefType intermediateRefType = (IntermediateRefType) o; + if(!getFullyQualifiedName().equals(intermediateRefType.getFullyQualifiedName())) return false; + + for(int index = 0; index < typParameters.size(); index++){ + if(!typParameters.get(index).equals(intermediateRefType.typParameters.get(index))) return false; + } + return true; + } + + @Override + public int hashCode() { + //ToDo korrekte Definition auf Basis von equals + return 0; + } + + public int getTypParameterSize(){ return typParameters.size(); } + + /** + * @param index + * @return the typ parameter at {@code index} or {@code null}, iff {@code |typ parameters| < index} + */ + public IntermediateType getTypParameter(int index) { + if(getTypParameterSize() < index) return null; + return typParameters.get(index); + } } diff --git a/src/main/java/de/dhbwstuttgart/intermediate/types/IntermediateSuperWildcard.java b/src/main/java/de/dhbwstuttgart/intermediate/types/IntermediateSuperWildcard.java index d3cb6f8c..1fe48ace 100644 --- a/src/main/java/de/dhbwstuttgart/intermediate/types/IntermediateSuperWildcard.java +++ b/src/main/java/de/dhbwstuttgart/intermediate/types/IntermediateSuperWildcard.java @@ -1,4 +1,13 @@ package de.dhbwstuttgart.intermediate.types; -public class IntermediateSuperWildcard { +import de.dhbwstuttgart.parser.scope.JavaClassName; + +/** + * //ToDo Beschreiben + * + * @since Studienarbeit Type Erasure + * @author etiennezink + */ +public final class IntermediateSuperWildcard { + //ToDo } diff --git a/src/main/java/de/dhbwstuttgart/intermediate/types/IntermediateType.java b/src/main/java/de/dhbwstuttgart/intermediate/types/IntermediateType.java index 42df3d5d..3e0725bc 100644 --- a/src/main/java/de/dhbwstuttgart/intermediate/types/IntermediateType.java +++ b/src/main/java/de/dhbwstuttgart/intermediate/types/IntermediateType.java @@ -1,5 +1,36 @@ package de.dhbwstuttgart.intermediate.types; -public interface IntermediateType { - +import de.dhbwstuttgart.core.IItemWithOffset; +import de.dhbwstuttgart.parser.scope.JavaClassName; +import org.antlr.v4.runtime.Token; + +/** + * //ToDo Beschreiben + * + * @since Studienarbeit Type Erasure + * @author etiennezink + */ +public abstract class IntermediateType { + + private final JavaClassName className; + + public IntermediateType(JavaClassName className){ this.className = className; } + + @Override + public abstract boolean equals(Object o); + + @Override + public abstract int hashCode(); + + public abstract String getClassSignature(); + public abstract String getClassDescriptor(); + + @Override + public String toString() { return getFullyQualifiedName(); } + + public String getClassName() { + return className.getClassName(); + } + public String getPackageName() { return className.getPackageName(); } + public String getFullyQualifiedName() { return className.toString(); } }