Sfoglia il codice sorgente

fix: ObjectWalker ignored "visited mark" when visited collections
fix: ObjectWalker doesn't scan some built-ins
new: ObjectWalker.ObjectContext#hash

Ranides Atterwim 2 anni fa
parent
commit
28be5505a5

+ 10 - 0
assira.core/src/main/java/net/ranides/assira/reflection/walker/ObjectWalker.java

@@ -272,6 +272,11 @@ public class ObjectWalker {
             return ValueUtils.or(visited.get(value), id);
         }
 
+        @Override
+        public long hash() {
+            return System.identityHashCode(value);
+        }
+
         @Override
         public String typePath() {
             return typePath.apply(() -> WalkerUtils.typePath(this));
@@ -370,6 +375,7 @@ public class ObjectWalker {
                 }
 
                 if (!isNull() && !isPrimitive()) {
+                    mark(this);
                     actual()
                         .fields()
                         .require(IAttribute.ANY)
@@ -426,6 +432,7 @@ public class ObjectWalker {
                     return;
                 }
                 if (!isNull()) {
+                    mark(this);
                     IClass<?> cmp = component();
                     for (int index = 0, n = size(); index < n; index++) {
                         context("[" + index + "]", cmp, at(index)).accept(visitor);
@@ -499,6 +506,7 @@ public class ObjectWalker {
                     return;
                 }
                 if (!isNull()) {
+                    mark(this);
                     IClass<?> cmp = component();
                     for (int index = 0, n = size(); index < n; index++) {
                         context("[" + index + "]", cmp, at(index)).accept(visitor);
@@ -562,6 +570,7 @@ public class ObjectWalker {
                     return;
                 }
                 if (!isNull()) {
+                    mark(this);
                     IClass<?> cmp = component();
                     for (Object item : value()) {
                         context("[?]", cmp, item).accept(listener);
@@ -639,6 +648,7 @@ public class ObjectWalker {
                     return;
                 }
                 if (!isNull()) {
+                    mark(this);
                     if(value() instanceof SortedMap || value() instanceof LinkedHashMap) {
                         exactIterate(listener);
                     } else {

+ 2 - 0
assira.core/src/main/java/net/ranides/assira/reflection/walker/WalkerContexts.java

@@ -111,6 +111,8 @@ public class WalkerContexts {
          */
         long ref();
 
+        long hash();
+
         /**
          * Returns depth of recursive scan
          *

+ 11 - 2
assira.core/src/main/java/net/ranides/assira/reflection/walker/WalkerRules.java

@@ -9,6 +9,7 @@ import net.ranides.assira.reflection.walker.rules.PrintRules;
 import net.ranides.assira.text.FormatHex;
 
 import javax.xml.datatype.XMLGregorianCalendar;
+import java.net.URL;
 import java.time.temporal.Temporal;
 import java.util.*;
 
@@ -30,7 +31,7 @@ public class WalkerRules {
             .match(ObjectContext::isVisited)
             .term("{PATH} <ref> = #{ref}")
         .rule()
-            .match(ctx -> ctx.depth() > 32)
+            .match(ctx -> ctx.depth() > 128)
             .term("{PATH} ...")
         .rule()
             .match(ObjectContext::isNull)
@@ -60,6 +61,10 @@ public class WalkerRules {
             .match(XMLGregorianCalendar.class)
             .match(Temporal.class)
             .match(Number.class)
+            .match(Enum.class)
+            .match(BitSet.class)
+            .match(URL.class)
+            .match(StackTraceElement.class)
             .match(ObjectContext::isPrimitive)
             .term("{PATH} {actual.shortName} = {value}")
         .rule()
@@ -75,7 +80,7 @@ public class WalkerRules {
                 .match(ObjectContext::isVisited)
                 .skip()
             .rule()
-                .match(ctx -> ctx.depth() > 32)
+                .match(ctx -> ctx.depth() > 128)
                 .skip()
             .rule()
                 .match(ObjectContext::isNull)
@@ -93,6 +98,10 @@ public class WalkerRules {
                 .match(XMLGregorianCalendar.class)
                 .match(Temporal.class)
                 .match(Number.class)
+                .match(Enum.class)
+                .match(BitSet.class)
+                .match(URL.class)
+                .match(StackTraceElement.class)
                 .match(ObjectContext::isPrimitive)
                 .term(WalkerEntry::new)
             .rule()