Skip to content

Commit

Permalink
Adopt java 11 in guice builds
Browse files Browse the repository at this point in the history
Use `var` in a few places to prove it out.

PiperOrigin-RevId: 715002121
  • Loading branch information
lukesandberg authored and Guice Team committed Jan 13, 2025
1 parent 1152193 commit 6a3557e
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 21 deletions.
2 changes: 1 addition & 1 deletion BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ javadoc_library(
],
doctitle = "Guice Dependency Injection API",
external_javadoc_links = [
"https://docs.oracle.com/javase/8/docs/api/",
"https://docs.oracle.com/javase/11/docs/api/",
"https://guava.dev/releases/snapshot-jre/api/docs/",
"https://google.github.io/truth/api/latest/",
"http://errorprone.info/api/latest/",
Expand Down
4 changes: 2 additions & 2 deletions build_defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
JAVAC_OPTS = [
"-Xdoclint:html,syntax",
"-source",
"1.8",
"11",
"-target",
"1.8",
"11",
]

POM_VERSION = "${project.version}"
17 changes: 8 additions & 9 deletions core/src/com/google/inject/internal/InjectorImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ enum JitLimitation {
@Override
public <T> List<Binding<T>> findBindingsByType(TypeLiteral<T> type) {
@SuppressWarnings("unchecked") // safe because we only put matching entries into the map
List<Binding<T>> list =
var list =
(List<Binding<T>>)
(List) bindingData.getIndexedExplicitBindings().get(checkNotNull(type, "type"));
return Collections.unmodifiableList(list);
Expand All @@ -161,7 +161,7 @@ public <T> List<Binding<T>> findBindingsByType(TypeLiteral<T> type) {
public <T> BindingImpl<T> getBinding(Key<T> key) {
Errors errors = new Errors(checkNotNull(key, "key"));
try {
BindingImpl<T> result = getBindingOrThrow(key, errors, JitLimitation.EXISTING_JIT);
var result = getBindingOrThrow(key, errors, JitLimitation.EXISTING_JIT);
errors.throwConfigurationExceptionIfErrorsExist();
return result;
} catch (ErrorsException e) {
Expand All @@ -175,15 +175,14 @@ public <T> BindingImpl<T> getBinding(Key<T> key) {
@Override
public <T> BindingImpl<T> getExistingBinding(Key<T> key) {
// Check explicit bindings, i.e. bindings created by modules.
BindingImpl<T> explicitBinding = bindingData.getExplicitBinding(checkNotNull(key, "key"));
var explicitBinding = bindingData.getExplicitBinding(checkNotNull(key, "key"));
if (explicitBinding != null) {
return explicitBinding;
}
synchronized (jitBindingData.lock()) {
// See if any jit bindings have been created for this key.
for (InjectorImpl injector = this; injector != null; injector = injector.parent) {
@SuppressWarnings("unchecked")
BindingImpl<T> jitBinding = (BindingImpl<T>) injector.jitBindingData.getJitBinding(key);
var jitBinding = injector.jitBindingData.getJitBinding(key);
if (jitBinding != null) {
return jitBinding;
}
Expand All @@ -196,7 +195,7 @@ public <T> BindingImpl<T> getExistingBinding(Key<T> key) {
try {
// This is safe because isProvider above ensures that T is a Provider<?>
@SuppressWarnings("unchecked")
Key<?> providedKey = (Key<?>) getProvidedKey((Key) key, new Errors());
var providedKey = (Key<?>) getProvidedKey((Key) key, new Errors());
if (getExistingBinding(providedKey) != null) {
return getBinding(key);
}
Expand Down Expand Up @@ -268,8 +267,8 @@ private <T> BindingImpl<T> getJustInTimeBinding(Key<T> key, Errors errors, JitLi
synchronized (jitBindingData.lock()) {
// first try to find a JIT binding that we've already created
for (InjectorImpl injector = this; injector != null; injector = injector.parent) {
@SuppressWarnings("unchecked") // we only store bindings that match their key
BindingImpl<T> binding = (BindingImpl<T>) injector.jitBindingData.getJitBinding(key);

var binding = injector.jitBindingData.getJitBinding(key);

if (binding != null) {
// If we found a JIT binding and we don't allow them,
Expand Down Expand Up @@ -634,7 +633,7 @@ private boolean cleanup(BindingImpl<?> binding, Set<Key<?>> encountered) {
Key<?> depKey = dep.getKey();
InjectionPoint ip = dep.getInjectionPoint();
if (encountered.add(depKey)) { // only check if we haven't looked at this key yet
BindingImpl<?> depBinding = jitBindingData.getJitBinding(depKey);
var depBinding = jitBindingData.getJitBinding(depKey);
if (depBinding != null) { // if the binding still exists, validate
boolean failed = cleanup(depBinding, encountered); // if children fail, we fail
if (depBinding instanceof ConstructorBindingImpl) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,13 @@ Map<Key<?>, BindingImpl<?>> getJitBindings() {
return Collections.unmodifiableMap(jitBindings);
}

BindingImpl<?> getJitBinding(Key<?> key) {
return jitBindings.get(key);
<T> BindingImpl<T> getJitBinding(Key<T> key) {
@SuppressWarnings("unchecked") // safe because putJitBinding maintains this relationship
BindingImpl<T> binding = (BindingImpl<T>) jitBindings.get(key);
return binding;
}

void putJitBinding(Key<?> key, BindingImpl<?> binding) {
<T> void putJitBinding(Key<T> key, BindingImpl<T> binding) {
jitBindings.put(key, binding);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,11 @@ private static Function<String, BiFunction<Object, Object[], Object>> bindSignat
return signature -> {
try {
// pass this signature's index into the table function to retrieve the invoker
return (BiFunction<Object, Object[], Object>)
invokerTable.invokeExact(signatureTable.applyAsInt(signature));
@SuppressWarnings("unchecked")
var invoker =
(BiFunction<Object, Object[], Object>)
invokerTable.invokeExact(signatureTable.applyAsInt(signature));
return invoker;
} catch (Throwable e) {
throw asIfUnchecked(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*
* @author [email protected] (Stuart McCulloch)
*/
@SuppressWarnings("SunApi")
final class AnonymousClassDefiner implements ClassDefiner {

private static final sun.misc.Unsafe THE_UNSAFE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
*
* @author [email protected] (Stuart McCulloch)
*/
@SuppressWarnings("SunApi")
final class HiddenClassDefiner implements ClassDefiner {

private static final sun.misc.Unsafe THE_UNSAFE;
Expand Down
1 change: 1 addition & 0 deletions core/src/com/google/inject/internal/aop/UnsafeGetter.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.google.inject.internal.aop;

@SuppressWarnings("SunApi")
final class UnsafeGetter {

private UnsafeGetter() {}
Expand Down
4 changes: 2 additions & 2 deletions examples/guice-demo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
<properties>
<guice.version>5.1.0</guice.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>

<dependencies>
Expand Down
2 changes: 1 addition & 1 deletion pom-template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ See the Apache License Version 2.0 for the specific language governing permissio


<description>
Guice is a lightweight dependency injection framework for Java 8 and above
Guice is a lightweight dependency injection framework for Java 11 and above
</description>

<url>https://github.com/google/guice</url>
Expand Down
2 changes: 1 addition & 1 deletion tools/OsgiWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public final class OsgiWrapper implements Callable<Integer> {
.collect(Collectors.joining(","));

private static final String DESCRIPTION =
"Guice is a lightweight dependency injection framework for Java 8 and above";
"Guice is a lightweight dependency injection framework for Java 11 and above";

private static final String COPYRIGHT = "Copyright (C) 2022 Google Inc.";

Expand Down

0 comments on commit 6a3557e

Please sign in to comment.