Improve to SC generation

This commit is contained in:
Till Schnell 2021-08-30 18:37:14 +02:00
parent 2e1e69df9a
commit 26ae463e96

View File

@ -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<ResultSet> typeInference = typeInference();
if (typeInference.isEmpty())
return;
ResultSet resultSet = typeInference.get(0); // Use the first available result sets
for (Map.Entry<File, SourceFile> 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.