Update open-source Guice to use DirectStackWalkerFinder, now that the base level is JDK11.

PiperOrigin-RevId: 620889085
This commit is contained in:
Sam Berlin
2024-04-01 10:39:21 -07:00
committed by Guice Team
parent 2d4a3952ee
commit cc5511b94f
3 changed files with 35 additions and 2 deletions
+17 -1
View File
@@ -35,6 +35,15 @@ IMPLEMENTED_BY_SRCS = [
"ImplementedBy.java",
]
CALLER_FINDER_STACK_WALKER_SRCS = ["internal/util/DirectStackWalkerFinder.java"]
java_library(
name = "caller_finder_impl",
srcs = CALLER_FINDER_STACK_WALKER_SRCS,
javacopts = JAVAC_OPTS,
deps = [":caller_finder_common"],
)
java_library(
name = "caller_finder_common",
srcs = CALLER_FINDER_COMMON_SRCS,
@@ -65,19 +74,25 @@ java_library(
name = "inject",
srcs = glob(
["**/*.java"],
exclude = IMPLEMENTED_BY_SRCS + PROVIDED_BY_SRCS + ANNOTATION_SRCS + CALLER_FINDER_COMMON_SRCS,
exclude = IMPLEMENTED_BY_SRCS +
PROVIDED_BY_SRCS +
ANNOTATION_SRCS +
CALLER_FINDER_COMMON_SRCS +
CALLER_FINDER_STACK_WALKER_SRCS,
),
javacopts = JAVAC_OPTS,
tags = ["maven_coordinates=com.google.inject:guice:" + POM_VERSION],
exports = [
":annotations",
":caller_finder_common",
":caller_finder_impl",
":implemented_by",
":provided_by",
],
deps = [
":annotations",
":caller_finder_common",
":caller_finder_impl",
":implemented_by",
":provided_by",
"//third_party/java/aopalliance",
@@ -120,6 +135,7 @@ gen_maven_artifact(
":annotations",
":implemented_by",
":caller_finder_common",
":caller_finder_impl",
":provided_by",
],
javadoc_srcs = [":javadoc-srcs"],
@@ -0,0 +1,17 @@
package com.google.inject.internal.util;
import java.util.function.Predicate;
/** A CallerFinder directly compiled against StackWalker. Requires compiling against jdk11+. */
final class DirectStackWalkerFinder implements CallerFinder {
private static final StackWalker WALKER =
StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE);
@Override
public StackTraceElement findCaller(Predicate<String> shouldBeSkipped) {
return WALKER
.walk(s -> s.skip(2).filter(f -> !shouldBeSkipped.test(f.getClassName())).findFirst())
.map(StackWalker.StackFrame::toStackTraceElement)
.orElseThrow(AssertionError::new);
}
}
@@ -96,6 +96,6 @@ public final class SourceProvider {
}
private static CallerFinder loadCallerFinder() {
return new NewThrowableFinder();
return new DirectStackWalkerFinder();
}
}