Skip to content

Commit

Permalink
Merge pull request #3286 from matthiasblaesing/vanilla_reparser
Browse files Browse the repository at this point in the history
VaniallaPartialReparser reports incorrectly reparsed files
  • Loading branch information
matthiasblaesing committed Nov 3, 2021
2 parents c260af8 + 2ffea86 commit b66d00e
Showing 1 changed file with 15 additions and 2 deletions.
Expand Up @@ -75,6 +75,7 @@
import java.util.concurrent.atomic.AtomicReference;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import javax.lang.model.SourceVersion;
import javax.tools.Diagnostic;
Expand Down Expand Up @@ -530,7 +531,7 @@ private void verifyCompilationInfos(CompilationInfoImpl reparsed, CompilationInf
String verifyTree = treeToString(verifyInfo, verifyInfo.getCompilationUnit());
if (cancel.get()) return ;
if (!Objects.equals(reparsedTree, verifyTree)) {
failInfo += "Expected tree: " + reparsedTree + ", actual tree: " + verifyTree;
failInfo += "Expected tree: " + reparsedTree + "\n" + " actual tree: " + verifyTree;
}
if (!failInfo.isEmpty() && !cancel.get()) {
Utilities.revalidate(reparsed.getFileObject());
Expand Down Expand Up @@ -581,7 +582,7 @@ public Void scan(Tree tree, Void p) {
dump.append(Trees.instance(info.getJavacTask()).getSourcePositions().getStartPosition(tp.getCompilationUnit(), tree)).append(":");
dump.append(Trees.instance(info.getJavacTask()).getSourcePositions().getEndPosition(tp.getCompilationUnit(), tree)).append(":");
dump.append(String.valueOf(Trees.instance(info.getJavacTask()).getElement(tp))).append(":");
dump.append(String.valueOf(Trees.instance(info.getJavacTask()).getTypeMirror(tp))).append(":");
dump.append(normalizeCapture(String.valueOf(Trees.instance(info.getJavacTask()).getTypeMirror(tp)))).append(":");
dump.append(",");
}
return super.scan(tree, p);
Expand All @@ -590,6 +591,18 @@ public Void scan(Tree tree, Void p) {
return dump.toString();
}

private static final Pattern MIRROR_PATTERN = Pattern.compile("capture#(\\d+)");
private static String normalizeCapture(String s) {
// the toString result of a CapturedType contains the sequence
// "capture#NUMBER" where number is the hashCode of the mirror
// as hashCode is not overwriten, this is more or less a random
// number and thus meaning less for the tree comparisson leading to
// invalid incorrect partial reparsing reports
//
// This normalises it to a plain capture.
return MIRROR_PATTERN.matcher(s).replaceAll("capture");
}

@MimeRegistration(service=TaskFactory.class, mimeType="text/x-java")
public static final class FactoryImpl extends TaskFactory {

Expand Down

0 comments on commit b66d00e

Please sign in to comment.