Skip to content

Commit 6a3557e

Browse files
lukesandbergGuice Team
authored andcommitted
Adopt java 11 in guice builds
Use `var` in a few places to prove it out. PiperOrigin-RevId: 715002121
1 parent 1152193 commit 6a3557e

11 files changed

Lines changed: 28 additions & 21 deletions

File tree

‎BUILD‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ javadoc_library(
3333
],
3434
doctitle = "Guice Dependency Injection API",
3535
external_javadoc_links = [
36-
"https://docs.oracle.com/javase/8/docs/api/",
36+
"https://docs.oracle.com/javase/11/docs/api/",
3737
"https://guava.dev/releases/snapshot-jre/api/docs/",
3838
"https://google.github.io/truth/api/latest/",
3939
"http://errorprone.info/api/latest/",

‎build_defs.bzl‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
JAVAC_OPTS = [
1717
"-Xdoclint:html,syntax",
1818
"-source",
19-
"1.8",
19+
"11",
2020
"-target",
21-
"1.8",
21+
"11",
2222
]
2323

2424
POM_VERSION = "${project.version}"

‎core/src/com/google/inject/internal/InjectorImpl.java‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ enum JitLimitation {
150150
@Override
151151
public <T> List<Binding<T>> findBindingsByType(TypeLiteral<T> type) {
152152
@SuppressWarnings("unchecked") // safe because we only put matching entries into the map
153-
List<Binding<T>> list =
153+
var list =
154154
(List<Binding<T>>)
155155
(List) bindingData.getIndexedExplicitBindings().get(checkNotNull(type, "type"));
156156
return Collections.unmodifiableList(list);
@@ -161,7 +161,7 @@ public <T> List<Binding<T>> findBindingsByType(TypeLiteral<T> type) {
161161
public <T> BindingImpl<T> getBinding(Key<T> key) {
162162
Errors errors = new Errors(checkNotNull(key, "key"));
163163
try {
164-
BindingImpl<T> result = getBindingOrThrow(key, errors, JitLimitation.EXISTING_JIT);
164+
var result = getBindingOrThrow(key, errors, JitLimitation.EXISTING_JIT);
165165
errors.throwConfigurationExceptionIfErrorsExist();
166166
return result;
167167
} catch (ErrorsException e) {
@@ -175,15 +175,14 @@ public <T> BindingImpl<T> getBinding(Key<T> key) {
175175
@Override
176176
public <T> BindingImpl<T> getExistingBinding(Key<T> key) {
177177
// Check explicit bindings, i.e. bindings created by modules.
178-
BindingImpl<T> explicitBinding = bindingData.getExplicitBinding(checkNotNull(key, "key"));
178+
var explicitBinding = bindingData.getExplicitBinding(checkNotNull(key, "key"));
179179
if (explicitBinding != null) {
180180
return explicitBinding;
181181
}
182182
synchronized (jitBindingData.lock()) {
183183
// See if any jit bindings have been created for this key.
184184
for (InjectorImpl injector = this; injector != null; injector = injector.parent) {
185-
@SuppressWarnings("unchecked")
186-
BindingImpl<T> jitBinding = (BindingImpl<T>) injector.jitBindingData.getJitBinding(key);
185+
var jitBinding = injector.jitBindingData.getJitBinding(key);
187186
if (jitBinding != null) {
188187
return jitBinding;
189188
}
@@ -196,7 +195,7 @@ public <T> BindingImpl<T> getExistingBinding(Key<T> key) {
196195
try {
197196
// This is safe because isProvider above ensures that T is a Provider<?>
198197
@SuppressWarnings("unchecked")
199-
Key<?> providedKey = (Key<?>) getProvidedKey((Key) key, new Errors());
198+
var providedKey = (Key<?>) getProvidedKey((Key) key, new Errors());
200199
if (getExistingBinding(providedKey) != null) {
201200
return getBinding(key);
202201
}
@@ -268,8 +267,8 @@ private <T> BindingImpl<T> getJustInTimeBinding(Key<T> key, Errors errors, JitLi
268267
synchronized (jitBindingData.lock()) {
269268
// first try to find a JIT binding that we've already created
270269
for (InjectorImpl injector = this; injector != null; injector = injector.parent) {
271-
@SuppressWarnings("unchecked") // we only store bindings that match their key
272-
BindingImpl<T> binding = (BindingImpl<T>) injector.jitBindingData.getJitBinding(key);
270+
271+
var binding = injector.jitBindingData.getJitBinding(key);
273272

274273
if (binding != null) {
275274
// If we found a JIT binding and we don't allow them,
@@ -634,7 +633,7 @@ private boolean cleanup(BindingImpl<?> binding, Set<Key<?>> encountered) {
634633
Key<?> depKey = dep.getKey();
635634
InjectionPoint ip = dep.getInjectionPoint();
636635
if (encountered.add(depKey)) { // only check if we haven't looked at this key yet
637-
BindingImpl<?> depBinding = jitBindingData.getJitBinding(depKey);
636+
var depBinding = jitBindingData.getJitBinding(depKey);
638637
if (depBinding != null) { // if the binding still exists, validate
639638
boolean failed = cleanup(depBinding, encountered); // if children fail, we fail
640639
if (depBinding instanceof ConstructorBindingImpl) {

‎core/src/com/google/inject/internal/InjectorJitBindingData.java‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,13 @@ Map<Key<?>, BindingImpl<?>> getJitBindings() {
4545
return Collections.unmodifiableMap(jitBindings);
4646
}
4747

48-
BindingImpl<?> getJitBinding(Key<?> key) {
49-
return jitBindings.get(key);
48+
<T> BindingImpl<T> getJitBinding(Key<T> key) {
49+
@SuppressWarnings("unchecked") // safe because putJitBinding maintains this relationship
50+
BindingImpl<T> binding = (BindingImpl<T>) jitBindings.get(key);
51+
return binding;
5052
}
5153

52-
void putJitBinding(Key<?> key, BindingImpl<?> binding) {
54+
<T> void putJitBinding(Key<T> key, BindingImpl<T> binding) {
5355
jitBindings.put(key, binding);
5456
}
5557

‎core/src/com/google/inject/internal/aop/AbstractGlueGenerator.java‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,11 @@ private static Function<String, BiFunction<Object, Object[], Object>> bindSignat
142142
return signature -> {
143143
try {
144144
// pass this signature's index into the table function to retrieve the invoker
145-
return (BiFunction<Object, Object[], Object>)
146-
invokerTable.invokeExact(signatureTable.applyAsInt(signature));
145+
@SuppressWarnings("unchecked")
146+
var invoker =
147+
(BiFunction<Object, Object[], Object>)
148+
invokerTable.invokeExact(signatureTable.applyAsInt(signature));
149+
return invoker;
147150
} catch (Throwable e) {
148151
throw asIfUnchecked(e);
149152
}

‎core/src/com/google/inject/internal/aop/AnonymousClassDefiner.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
*
2424
* @author mcculls@gmail.com (Stuart McCulloch)
2525
*/
26+
@SuppressWarnings("SunApi")
2627
final class AnonymousClassDefiner implements ClassDefiner {
2728

2829
private static final sun.misc.Unsafe THE_UNSAFE;

‎core/src/com/google/inject/internal/aop/HiddenClassDefiner.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
*
2727
* @author mcculls@gmail.com (Stuart McCulloch)
2828
*/
29+
@SuppressWarnings("SunApi")
2930
final class HiddenClassDefiner implements ClassDefiner {
3031

3132
private static final sun.misc.Unsafe THE_UNSAFE;

‎core/src/com/google/inject/internal/aop/UnsafeGetter.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.google.inject.internal.aop;
1818

19+
@SuppressWarnings("SunApi")
1920
final class UnsafeGetter {
2021

2122
private UnsafeGetter() {}

‎examples/guice-demo/pom.xml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
<properties>
1515
<guice.version>5.1.0</guice.version>
1616
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
17-
<maven.compiler.source>1.8</maven.compiler.source>
18-
<maven.compiler.target>1.8</maven.compiler.target>
17+
<maven.compiler.source>11</maven.compiler.source>
18+
<maven.compiler.target>11</maven.compiler.target>
1919
</properties>
2020

2121
<dependencies>

‎pom-template.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ See the Apache License Version 2.0 for the specific language governing permissio
3030

3131

3232
<description>
33-
Guice is a lightweight dependency injection framework for Java 8 and above
33+
Guice is a lightweight dependency injection framework for Java 11 and above
3434
</description>
3535

3636
<url>https://github.com/google/guice</url>

0 commit comments

Comments
 (0)
⌂ 换网址