From 43ca14194b74c1dbdef667ac9292575cd6aaee39 Mon Sep 17 00:00:00 2001 From: Ruben Date: Thu, 12 Dec 2024 22:03:27 +0100 Subject: [PATCH] feat: display all alternative Types --- .../src/main/java/de/dhbw/helper/TypeFinder.java | 10 +++++++++- .../src/test/java/CompilerInterfaceTest.java | 7 +++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/LanguageServer/src/main/java/de/dhbw/helper/TypeFinder.java b/LanguageServer/src/main/java/de/dhbw/helper/TypeFinder.java index ed4f454..6105aa7 100644 --- a/LanguageServer/src/main/java/de/dhbw/helper/TypeFinder.java +++ b/LanguageServer/src/main/java/de/dhbw/helper/TypeFinder.java @@ -8,6 +8,7 @@ import java.io.IOException; import java.io.OutputStream; import java.io.PrintStream; import java.util.*; +import java.util.concurrent.atomic.AtomicReference; /** @@ -74,7 +75,14 @@ public class TypeFinder { for (var method : transferObj.getAst().getAllMethods()) { if (method.name.equals(methodName)) { if (method.getReturnType().toString().contains("TPH ")) { - return typeHashMap.get(method.getReturnType().toString()).getFirst(); + StringBuilder possibleTypes = new StringBuilder(); + + for(var type : typeHashMap.get(method.getReturnType().toString())){ + possibleTypes.append(" | ").append(type); + } + + + return possibleTypes.toString().substring(3); }else{ return method.getReturnType().toString(); } diff --git a/LanguageServer/src/test/java/CompilerInterfaceTest.java b/LanguageServer/src/test/java/CompilerInterfaceTest.java index f0a2793..4a8cce6 100644 --- a/LanguageServer/src/test/java/CompilerInterfaceTest.java +++ b/LanguageServer/src/test/java/CompilerInterfaceTest.java @@ -28,9 +28,12 @@ public class CompilerInterfaceTest { @Test public void testTypeFinder() throws IOException, ClassNotFoundException { TypeFinder typeFinder = new TypeFinder(); - var inferedMethods = typeFinder.infereMethodType("import java.lang.Integer;" + + var inferedMethods = typeFinder.infereMethodType("import java.lang.Integer; import java.lang.String;" + "public class test{"+ - "public main(test){"+ + "public main(test){" + + "if(0>1){" + + "return \"w\";" + + "}"+ "Integer i = 0;"+ "return i;"+ "}"+