You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by ma...@apache.org on 2021/11/03 17:34:57 UTC
[netbeans] branch master updated: VaniallaPartialReparser reports
incorrectly reparsed files
This is an automated email from the ASF dual-hosted git repository.
matthiasblaesing pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans.git
The following commit(s) were added to refs/heads/master by this push:
new 2ffea86 VaniallaPartialReparser reports incorrectly reparsed files
new b66d00e Merge pull request #3286 from matthiasblaesing/vanilla_reparser
2ffea86 is described below
commit 2ffea8698bc9c572a502e1354485ddc04e503f41
Author: Matthias Bläsing <mb...@doppel-helix.eu>
AuthorDate: Fri Oct 29 20:05:53 2021 +0200
VaniallaPartialReparser reports incorrectly reparsed files
The verification step of the VanillaPartialReparser serialises the
reparsed tree to a string and comparse these. The issue is, that the
toString result of a CapturedType contains the sequence
"capture#NUMBER". Number is the hashCode of the mirror. As hashCode
is not overwriten, this is more or less a random number and thus
meaningless for the tree comparisson leading to invalid incorrect
partial reparsing reports
This normalises it to a plain capture.
---
.../java/source/parsing/VanillaPartialReparser.java | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/java/java.source.base/src/org/netbeans/modules/java/source/parsing/VanillaPartialReparser.java b/java/java.source.base/src/org/netbeans/modules/java/source/parsing/VanillaPartialReparser.java
index 41532f3..e4f7c0f 100644
--- a/java/java.source.base/src/org/netbeans/modules/java/source/parsing/VanillaPartialReparser.java
+++ b/java/java.source.base/src/org/netbeans/modules/java/source/parsing/VanillaPartialReparser.java
@@ -75,6 +75,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
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;
@@ -530,7 +531,7 @@ public class VanillaPartialReparser implements PartialReparser {
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());
@@ -581,7 +582,7 @@ public class VanillaPartialReparser implements PartialReparser {
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);
@@ -590,6 +591,18 @@ public class VanillaPartialReparser implements PartialReparser {
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 {
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists