feat: add Method to get Type for all TPHs in ResultSet in V1
This commit is contained in:
parent
3a9468a174
commit
2f25c64dc6
@ -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.
|
||||
*
|
||||
* <p>
|
||||
* 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<String, ArrayList<String>> 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<String> finalTypes = new ArrayList<>();
|
||||
Queue<String> 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 "";
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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" +
|
||||
"}");
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user