diff --git a/LanguageServer/src/main/java/de/dhbw/helper/TypeFinder.java b/LanguageServer/src/main/java/de/dhbw/helper/TypeFinder.java
index 30dcbe1..9ac605e 100644
--- a/LanguageServer/src/main/java/de/dhbw/helper/TypeFinder.java
+++ b/LanguageServer/src/main/java/de/dhbw/helper/TypeFinder.java
@@ -4,35 +4,76 @@ import de.dhbw.compiler.languageServerInterface.LanguageServerInterface;
import java.awt.desktop.SystemSleepEvent;
import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Stack;
+import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
/**
* Helper-Class for finding the Type of a selected Word
- *
- * */
+ */
public class TypeFinder {
LanguageServerInterface languageServer;
- public TypeFinder(){
+ public TypeFinder() {
languageServer = new LanguageServerInterface();
}
+
/**
* find the Type of a specific Word, given by its line and character. The character must be any Part of the Word.
- *
+ *
* DOES NOT WORK RIGHT NOW
*
- * @param line the line of the character
- * @param character the character of the character or the char-Number of the String
+ * @param line the line of the character
+ * @param character the character of the character or the char-Number of the String
* @param currentTextDocument the String of the Content of the current Document.
- * */
+ */
public String findAvailableTypes(int line, int character, String currentTextDocument) throws IOException, ClassNotFoundException {
+ HashMap> typePlaceholderTypes = new HashMap<>();
+
var resultSet = languageServer.getResultSetAndAbstractSyntax(currentTextDocument);
+ resultSet.getResultSets().forEach(conSet -> {
+ for (var constraint : conSet.results) {
+
+ var typeNameString = constraint.getLeft().toString();
+ System.out.println(typeNameString);
+
+ ArrayList finalTypes = new ArrayList<>();
+ Queue queue = new LinkedList<>();
+
+ if (typeNameString.contains("TPH")) {
+ queue.add(typeNameString);
+ } else {
+ finalTypes.add(typeNameString);
+ }
+
+
+ while (!queue.isEmpty()) {
+ var nextType = queue.remove();
+ resultSet.getResultSets().forEach(el -> el.results.forEach(el2 -> {
+
+ if (el2.getLeft().toString().equals(nextType)) {
+ if (el2.getRight().toString().toLowerCase().contains("TPH")) {
+ queue.add(el2.getRight().toString());
+ } else {
+ finalTypes.add(el2.getRight().toString());
+ }
+ }
+ }));
+
+ }
+
+ typePlaceholderTypes.put(typeNameString, finalTypes);
+ }
+ }
+ );
+
+ typePlaceholderTypes.forEach((k, v) -> {
+ System.out.println(k + " : ");
+ v.forEach(System.out::println);
+ System.out.println("-----------");
+ });
return "";
}
}
\ No newline at end of file
diff --git a/LanguageServer/src/main/java/de/dhbw/model/MethodNameWithType.java b/LanguageServer/src/main/java/de/dhbw/model/MethodNameWithType.java
new file mode 100644
index 0000000..46dbd11
--- /dev/null
+++ b/LanguageServer/src/main/java/de/dhbw/model/MethodNameWithType.java
@@ -0,0 +1,27 @@
+package de.dhbw.model;
+
+public class MethodNameWithType {
+ String name;
+ String type;
+
+ public MethodNameWithType(String name, String type) {
+ this.name = name;
+ this.type = type;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+}
diff --git a/LanguageServer/src/test/java/CompilerInterfaceTest.java b/LanguageServer/src/test/java/CompilerInterfaceTest.java
index b9d3ce3..dc02c76 100644
--- a/LanguageServer/src/test/java/CompilerInterfaceTest.java
+++ b/LanguageServer/src/test/java/CompilerInterfaceTest.java
@@ -19,6 +19,21 @@ public class CompilerInterfaceTest {
System.out.println("TEST OUTPUT:");
System.out.println(res.getResultSets().toString());
+
+
+ System.out.println("\n\n\nPRINTED AST:");
System.out.println(res.getPrintedAst());
}
+
+ @Test
+ public void testTypeFinder() throws IOException, ClassNotFoundException {
+ TypeFinder typeFinder = new TypeFinder();
+ typeFinder.findAvailableTypes(0,0, "import java.lang.Integer; public class test{\n" +
+ " \n" +
+ " public main( test){\n" +
+ " Integer i = test; " +
+ " return i;\n" +
+ " }\n" +
+ "}");
+ }
}