From 26ae463e96c4f3a9e5d1e3f8e201d982591eb4e3 Mon Sep 17 00:00:00 2001 From: Till Schnell Date: Mon, 30 Aug 2021 18:37:14 +0200 Subject: [PATCH] Improve to SC generation --- .../JavaTXCompilerWildcards.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/main/java/de/dhbwstuttgart/inferWildcards/JavaTXCompilerWildcards.java b/src/main/java/de/dhbwstuttgart/inferWildcards/JavaTXCompilerWildcards.java index dd0f5481..a346dbce 100644 --- a/src/main/java/de/dhbwstuttgart/inferWildcards/JavaTXCompilerWildcards.java +++ b/src/main/java/de/dhbwstuttgart/inferWildcards/JavaTXCompilerWildcards.java @@ -10,6 +10,8 @@ import java.nio.file.Files; import java.util.Arrays; import java.util.List; import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import java.util.stream.Collectors; import org.antlr.v4.runtime.Token; @@ -101,6 +103,10 @@ public class JavaTXCompilerWildcards } List typeInference = typeInference(); + + if (typeInference.isEmpty()) + return; + ResultSet resultSet = typeInference.get(0); // Use the first available result sets for (Map.Entry e : sourceFiles.entrySet()) { @@ -155,6 +161,37 @@ public class JavaTXCompilerWildcards int length = token.getStopIndex() - token.getStartIndex() + 1; reader.read(new char[length]); readIdx += length; + + // Read the replaced nested type if the result was a nested type + Pattern pattern = Pattern.compile("<.*>"); + Matcher matcher = pattern.matcher(string); + if (matcher.find()) { + + // Read the first and check if it will be a Java Generic Expression starting + // with < + char c = (char) reader.read(); + readIdx++; + + if (c != '<') + throw new IllegalStateException("At this position is a < expected, found " + c); + + // Read and forget all content until a > on the same level + int opens = 1; + while (opens > 0) { + c = (char) reader.read(); + readIdx++; + + switch (c) + { + case '<': + opens++; + break; + case '>': + opens--; + break; + } + } + } } // Read the rest of the file.