From e27eb3a3fed2710bb8cf8704b7194587019332a3 Mon Sep 17 00:00:00 2001 From: Daniel Holle Date: Fri, 8 Mar 2024 16:58:00 +0100 Subject: [PATCH] Fix #285 --- .../SyntaxTreeGenerator/StatementGenerator.java | 14 +++++++++++--- .../syntaxtree/statement/StaticClassName.java | 5 +++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java b/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java index 1875a312..f2056e3a 100644 --- a/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java +++ b/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java @@ -8,12 +8,12 @@ import java.util.List; import java.util.Map; import java.util.Objects; import java.util.stream.Collectors; +import java.util.stream.Stream; import de.dhbwstuttgart.core.JavaTXCompiler; import de.dhbwstuttgart.syntaxtree.*; import de.dhbwstuttgart.syntaxtree.statement.*; import de.dhbwstuttgart.syntaxtree.type.Void; -import de.dhbwstuttgart.target.tree.expression.TargetClassName; import org.antlr.v4.runtime.Token; import de.dhbwstuttgart.exceptions.NotImplementedException; @@ -101,6 +101,7 @@ import de.dhbwstuttgart.parser.scope.JavaClassRegistry; import de.dhbwstuttgart.syntaxtree.type.RefType; import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; +import org.stringtemplate.v4.ST; public class StatementGenerator { @@ -756,6 +757,13 @@ public class StatementGenerator { } } + private StaticClassName generateStaticClassName(String name, Token offset) { + var className = reg.getName(name); + var numberOfGenerics = reg.getNumberOfGenerics(name); + var refType = new RefType(className, Stream.generate(() -> (RefTypeOrTPHOrWildcardOrGeneric) TypePlaceholder.fresh(offset)).limit(numberOfGenerics).toList(), offset); + return new StaticClassName(refType, offset); + } + /** * Der Parser kann nicht zwischen einer lokalen Variable, einem Feldzugriff und einer Klassenangabe unterscheiden. * @@ -774,7 +782,7 @@ public class StatementGenerator { var field = fields.get(expression); return new FieldVar(new This(offset), Modifier.isStatic(field.modifiers()), expression, fields.get(expression).type(), offset); } else if (reg.contains(expression)) { - return new StaticClassName(reg.getName(expression), offset); + return generateStaticClassName(expression, offset); } else { // lokale Variable wurde ohne "var"-Keyword deklariert und direkt mit Wert versehen localVars.put(expression, TypePlaceholder.fresh(offset)); @@ -792,7 +800,7 @@ public class StatementGenerator { whole += part; // Check for Classname: if (reg.contains(whole)) { - receiver = new StaticClassName(reg.getName(whole), offset); + receiver = generateStaticClassName(whole, offset); } whole += "."; } diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/statement/StaticClassName.java b/src/main/java/de/dhbwstuttgart/syntaxtree/statement/StaticClassName.java index a7089d8c..75d2a42e 100644 --- a/src/main/java/de/dhbwstuttgart/syntaxtree/statement/StaticClassName.java +++ b/src/main/java/de/dhbwstuttgart/syntaxtree/statement/StaticClassName.java @@ -3,14 +3,15 @@ package de.dhbwstuttgart.syntaxtree.statement; import de.dhbwstuttgart.parser.scope.JavaClassName; import de.dhbwstuttgart.syntaxtree.StatementVisitor; import de.dhbwstuttgart.syntaxtree.type.RefType; +import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation; import de.dhbwstuttgart.typeinference.constraints.ConstraintSet; import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation; import org.antlr.v4.runtime.Token; public class StaticClassName extends Receiver { - public StaticClassName(JavaClassName className, Token offset) { - super(new RefType(className, offset), offset); + public StaticClassName(RefTypeOrTPHOrWildcardOrGeneric type, Token offset) { + super(type, offset); } @Override