From 8d3bd936a74d759a686e1a37dea40959729f4577 Mon Sep 17 00:00:00 2001
From: Damien Hunter
Date: Sun, 4 Feb 2024 18:02:51 +0000
Subject: [PATCH 1/4] modified:
src/main/java/org/jsoup/select/StructuralEvaluator.java
---
.../org/jsoup/select/StructuralEvaluator.java | 24 +++++++++----------
1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/src/main/java/org/jsoup/select/StructuralEvaluator.java b/src/main/java/org/jsoup/select/StructuralEvaluator.java
index ca7beacb15..8d186793d2 100644
--- a/src/main/java/org/jsoup/select/StructuralEvaluator.java
+++ b/src/main/java/org/jsoup/select/StructuralEvaluator.java
@@ -12,19 +12,19 @@
/**
* Base structural evaluator.
*/
-abstract class StructuralEvaluator extends Evaluator {
+public abstract class StructuralEvaluator extends Evaluator {
final Evaluator evaluator;
- public StructuralEvaluator(Evaluator evaluator) {
+ StructuralEvaluator(Evaluator evaluator) {
this.evaluator = evaluator;
}
// Memoize inner matches, to save repeated re-evaluations of parent, sibling etc.
// root + element: Boolean matches. ThreadLocal in case the Evaluator is compiled then reused across multi threads
- final ThreadLocal>>
+ public final ThreadLocal>>
threadMemo = ThreadLocal.withInitial(IdentityHashMap::new);
- boolean memoMatches(final Element root, final Element element) {
+ public boolean memoMatches(final Element root, final Element element) {
Map> rootMemo = threadMemo.get();
Map memo = rootMemo.computeIfAbsent(root, Functions.identityMapFunction());
return memo.computeIfAbsent(element, key -> evaluator.matches(root, key));
@@ -35,7 +35,7 @@ boolean memoMatches(final Element root, final Element element) {
super.reset();
}
- static class Root extends Evaluator {
+ public static class Root extends Evaluator {
@Override
public boolean matches(Element root, Element element) {
return root == element;
@@ -50,7 +50,7 @@ public boolean matches(Element root, Element element) {
}
}
- static class Has extends StructuralEvaluator {
+ public static class Has extends StructuralEvaluator {
static final ThreadLocal> ThreadElementIter =
ThreadLocal.withInitial(() -> new NodeIterator<>(new Element("html"), Element.class));
// the element here is just a placeholder so this can be final - gets set in restart()
@@ -84,7 +84,7 @@ public String toString() {
}
/** Implements the :is(sub-query) pseudo-selector */
- static class Is extends StructuralEvaluator {
+ public static class Is extends StructuralEvaluator {
public Is(Evaluator evaluator) {
super(evaluator);
}
@@ -104,7 +104,7 @@ public String toString() {
}
}
- static class Not extends StructuralEvaluator {
+ public static class Not extends StructuralEvaluator {
public Not(Evaluator evaluator) {
super(evaluator);
}
@@ -124,7 +124,7 @@ public String toString() {
}
}
- static class Parent extends StructuralEvaluator {
+ public static class Parent extends StructuralEvaluator {
public Parent(Evaluator evaluator) {
super(evaluator);
}
@@ -159,7 +159,7 @@ public String toString() {
Holds a list of evaluators for one > two > three immediate parent matches, and the final direct evaluator under
test. To match, these are effectively ANDed together, starting from the last, matching up to the first.
*/
- static class ImmediateParentRun extends Evaluator {
+ public static class ImmediateParentRun extends Evaluator {
final ArrayList evaluators = new ArrayList<>();
int cost = 2;
@@ -199,7 +199,7 @@ public String toString() {
}
}
- static class PreviousSibling extends StructuralEvaluator {
+ public static class PreviousSibling extends StructuralEvaluator {
public PreviousSibling(Evaluator evaluator) {
super(evaluator);
}
@@ -228,7 +228,7 @@ public String toString() {
}
}
- static class ImmediatePreviousSibling extends StructuralEvaluator {
+ public static class ImmediatePreviousSibling extends StructuralEvaluator {
public ImmediatePreviousSibling(Evaluator evaluator) {
super(evaluator);
}
From 895ca0be0d8225695a10f7854a2f3dba23f63d2f Mon Sep 17 00:00:00 2001
From: Damien Hunter
Date: Sun, 4 Feb 2024 18:21:21 +0000
Subject: [PATCH 2/4] modified:
src/main/java/org/jsoup/parser/StreamParser.java
---
src/main/java/org/jsoup/parser/StreamParser.java | 13 +++++--------
1 file changed, 5 insertions(+), 8 deletions(-)
diff --git a/src/main/java/org/jsoup/parser/StreamParser.java b/src/main/java/org/jsoup/parser/StreamParser.java
index ba0078f8ad..6d4d5f3a25 100644
--- a/src/main/java/org/jsoup/parser/StreamParser.java
+++ b/src/main/java/org/jsoup/parser/StreamParser.java
@@ -51,9 +51,9 @@ interface to the document and its elements.
@since 1.18.1
*/
public class StreamParser implements Closeable {
- final private Parser parser;
- final private TreeBuilder treeBuilder;
- final private ElementIterator it = new ElementIterator();
+ private final Parser parser;
+ private final TreeBuilder treeBuilder;
+ private final ElementIterator it = new ElementIterator();
@Nullable private Document document;
private boolean stopped = false;
@@ -294,7 +294,7 @@ public Element expectNext(String query) throws IOException {
final class ElementIterator implements Iterator, NodeVisitor {
// listeners add to a next emit queue, as a single token read step may yield multiple elements
- final private Queue emitQueue = new LinkedList<>();
+ private final Queue emitQueue = new LinkedList<>();
private @Nullable Element current; // most recently emitted
private @Nullable Element next; // element waiting to be picked up
private @Nullable Element tail; // The last tailed element (