Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
mcculls committed Feb 18, 2018
2 parents 2799d00 + 904a477 commit 00e0259
Show file tree
Hide file tree
Showing 110 changed files with 1,712 additions and 1,184 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -6,8 +6,8 @@ cache:
- $HOME/.m2

jdk:
- oraclejdk9
- oraclejdk8
- oraclejdk7
- openjdk7

env:
Expand Down
8 changes: 4 additions & 4 deletions build.xml
Expand Up @@ -120,7 +120,7 @@
<pathelement location="lib/build/guava-testlib-19.0.jar"/>
<pathelement location="lib/build/junit.jar"/>
<pathelement location="lib/build/servlet-api-2.5.jar"/>
<pathelement location="lib/build/truth-0.29.jar"/>
<pathelement location="lib/build/truth-0.36.jar"/>
<pathelement location="lib/build/easymock.jar"/>
<pathelement location="lib/build/javax.inject-tck.jar"/>
<pathelement location="lib/build/bnd-0.0.384.jar"/>
Expand Down Expand Up @@ -279,13 +279,13 @@
<arg value="-DNO_AOP" />
</munge>
<replace file="build/no_aop/common.xml" value="">
<replacetoken><![CDATA[<zipfileset src="${common.basedir}/lib/build/asm-5.0.3.jar"/>]]></replacetoken>
<replacetoken><![CDATA[<zipfileset src="${common.basedir}/lib/build/asm-6.0.jar"/>]]></replacetoken>
</replace>
<replace file="build/no_aop/common.xml" value="">
<replacetoken><![CDATA[<zipfileset src="${common.basedir}/lib/build/cglib-3.2.jar"/>]]></replacetoken>
<replacetoken><![CDATA[<zipfileset src="${common.basedir}/lib/build/cglib-3.2.6.jar"/>]]></replacetoken>
</replace>
<replace file="build/no_aop/common.xml" value="">
<replacetoken><![CDATA[<zipfileset src="${common.basedir}/lib/build/cglib-3.2.jar"><include name="LICENSE"/><include name="NOTICE"/></zipfileset>]]></replacetoken>
<replacetoken><![CDATA[<zipfileset src="${common.basedir}/lib/build/cglib-3.2.6.jar"><include name="LICENSE"/><include name="NOTICE"/></zipfileset>]]></replacetoken>
</replace>
<replace file="build/no_aop/common.xml" value='Bundle-Name" value="$${ant.project.name} (no_aop)'>
<replacetoken><![CDATA[Bundle-Name" value="${ant.project.name}]]></replacetoken>
Expand Down
4 changes: 2 additions & 2 deletions common.xml
Expand Up @@ -148,8 +148,8 @@
classpath="${common.basedir}/lib/build/jarjar-1.1.jar"/>
<jarjar jarfile="${build.dir}/${ant.project.name}-with-deps.jar">
<fileset dir="${build.dir}/classes"/>
<zipfileset src="${common.basedir}/lib/build/cglib-3.2.jar"/>
<zipfileset src="${common.basedir}/lib/build/asm-5.0.3.jar"/>
<zipfileset src="${common.basedir}/lib/build/cglib-3.2.6.jar"/>
<zipfileset src="${common.basedir}/lib/build/asm-6.0.jar"/>
<rule pattern="net.sf.cglib.*" result="com.google.inject.internal.cglib.$@1"/>
<rule pattern="net.sf.cglib.**.*" result="com.google.inject.internal.cglib.@1.$@2"/>
<rule pattern="org.objectweb.asm.*" result="com.google.inject.internal.asm.$@1"/>
Expand Down
10 changes: 10 additions & 0 deletions core/pom.xml
Expand Up @@ -79,6 +79,11 @@
<version>3.0.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.truth</groupId>
<artifactId>truth</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -142,6 +147,11 @@
<exclude>LICENSE</exclude>
<exclude>NOTICE</exclude>
</excludes>
<archive>
<manifestEntries>
<Automatic-Module-Name>com.google.guice</Automatic-Module-Name>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
Expand Down
25 changes: 13 additions & 12 deletions core/src/com/google/inject/ConfigurationException.java
Expand Up @@ -18,10 +18,8 @@

import static com.google.common.base.Preconditions.checkState;

import com.google.common.collect.ImmutableSet;
import com.google.inject.internal.Errors;
import com.google.inject.internal.Messages;
import com.google.inject.spi.Message;

import java.util.Collection;

/**
Expand All @@ -33,13 +31,13 @@
*/
public final class ConfigurationException extends RuntimeException {

private final ImmutableSet<Message> messages;
private final com.google.common.collect.ImmutableSet<Message> messages;
private Object partialValue = null;

/** Creates a ConfigurationException containing {@code messages}. */
public ConfigurationException(Iterable<Message> messages) {
this.messages = ImmutableSet.copyOf(messages);
initCause(Errors.getOnlyCause(this.messages));
this.messages = com.google.common.collect.ImmutableSet.copyOf(messages);
initCause(Messages.getOnlyCause(this.messages));
}

/** Returns a copy of this configuration exception with the specified partial value. */
Expand All @@ -57,20 +55,23 @@ public Collection<Message> getErrorMessages() {
}

/**
* Returns a value that was only partially computed due to this exception. The caller can use
* this while collecting additional configuration problems.
* Returns a value that was only partially computed due to this exception. The caller can use this
* while collecting additional configuration problems.
*
* @return the partial value, or {@code null} if none was set. The type of the partial value is
* specified by the throwing method.
* specified by the throwing method.
*/
@SuppressWarnings("unchecked") // this is *extremely* unsafe. We trust the caller here.
@SuppressWarnings({
"unchecked",
"TypeParameterUnusedInFormals"
}) // this is *extremely* unsafe. We trust the caller here.
public <E> E getPartialValue() {
return (E) partialValue;
}

@Override public String getMessage() {
return Errors.format("Guice configuration errors", messages);
return Messages.formatMessages("Guice configuration errors", messages);
}

private static final long serialVersionUID = 0;
}
}
6 changes: 3 additions & 3 deletions core/src/com/google/inject/CreationException.java
Expand Up @@ -19,7 +19,7 @@
import static com.google.common.base.Preconditions.checkArgument;

import com.google.common.collect.ImmutableSet;
import com.google.inject.internal.Errors;
import com.google.inject.internal.Messages;
import com.google.inject.spi.Message;
import java.util.Collection;

Expand All @@ -37,7 +37,7 @@ public class CreationException extends RuntimeException {
public CreationException(Collection<Message> messages) {
this.messages = ImmutableSet.copyOf(messages);
checkArgument(!this.messages.isEmpty());
initCause(Errors.getOnlyCause(this.messages));
initCause(Messages.getOnlyCause(this.messages));
}

/** Returns messages for the errors that caused this exception. */
Expand All @@ -47,7 +47,7 @@ public Collection<Message> getErrorMessages() {

@Override
public String getMessage() {
return Errors.format("Unable to create injector, see the following errors", messages);
return Messages.formatMessages("Unable to create injector, see the following errors", messages);
}

private static final long serialVersionUID = 0;
Expand Down
5 changes: 3 additions & 2 deletions core/src/com/google/inject/Injector.java
Expand Up @@ -105,8 +105,9 @@ public interface Injector {
/**
* Returns a snapshot of this injector's bindings, <strong>both explicit and
* just-in-time</strong>. The returned map is immutable; it contains only the bindings that were
* present when {@code getAllBindings()} was invoked. Subsequent calls may return a map with
* additional just-in-time bindings.
* present when {@code getAllBindings()} was invoked. Just-in-time bindings are only present if
* they have been requested at least once. Subsequent calls may return a map with additional
* just-in-time bindings.
*
* <p>The returned map does not include bindings inherited from a {@link #getParent() parent
* injector}, should one exist.
Expand Down
6 changes: 3 additions & 3 deletions core/src/com/google/inject/ProvisionException.java
Expand Up @@ -19,7 +19,7 @@
import static com.google.common.base.Preconditions.checkArgument;

import com.google.common.collect.ImmutableSet;
import com.google.inject.internal.Errors;
import com.google.inject.internal.Messages;
import com.google.inject.spi.Message;
import java.util.Collection;

Expand All @@ -39,7 +39,7 @@ public final class ProvisionException extends RuntimeException {
public ProvisionException(Iterable<Message> messages) {
this.messages = ImmutableSet.copyOf(messages);
checkArgument(!this.messages.isEmpty());
initCause(Errors.getOnlyCause(this.messages));
initCause(Messages.getOnlyCause(this.messages));
}

public ProvisionException(String message, Throwable cause) {
Expand All @@ -58,7 +58,7 @@ public Collection<Message> getErrorMessages() {

@Override
public String getMessage() {
return Errors.format("Unable to provision, see the following errors", messages);
return Messages.formatMessages("Unable to provision, see the following errors", messages);
}

private static final long serialVersionUID = 0;
Expand Down
34 changes: 34 additions & 0 deletions core/src/com/google/inject/internal/Annotations.java
Expand Up @@ -16,6 +16,8 @@

package com.google.inject.internal;

import static java.lang.annotation.RetentionPolicy.RUNTIME;

import com.google.common.base.Function;
import com.google.common.base.Joiner;
import com.google.common.base.Joiner.MapJoiner;
Expand Down Expand Up @@ -212,6 +214,35 @@ static boolean containsComponentAnnotation(Annotation[] annotations) {
return false;
}

private static final boolean QUOTE_MEMBER_VALUES = determineWhetherToQuote();

/**
* Returns {@code value}, quoted if annotation implementations quote their member values. In Java
* 9, annotations quote their string members.
*/
public static String memberValueString(String value) {
return QUOTE_MEMBER_VALUES ? "\"" + value + "\"" : value;
}

@Retention(RUNTIME)
private @interface TestAnnotation {
String value();
}

@TestAnnotation("determineWhetherToQuote")
private static boolean determineWhetherToQuote() {
try {
String annotation =
Annotations.class
.getDeclaredMethod("determineWhetherToQuote")
.getAnnotation(TestAnnotation.class)
.toString();
return annotation.contains("\"determineWhetherToQuote\"");
} catch (NoSuchMethodException e) {
throw new AssertionError(e);
}
}

/** Checks for the presence of annotations. Caches results because Android doesn't. */
static class AnnotationChecker {
private final Collection<Class<? extends Annotation>> annotationTypes;
Expand Down Expand Up @@ -269,6 +300,9 @@ public static void checkForMisplacedScopeAnnotations(
}
}

// NOTE: getKey/findBindingAnnotation are used by Gin which is abandoned. So changing this API
// will prevent Gin users from upgrading Guice version.

/** Gets a key for the given type, member and annotations. */
public static Key<?> getKey(
TypeLiteral<?> type, Member member, Annotation[] annotations, Errors errors)
Expand Down
24 changes: 12 additions & 12 deletions core/src/com/google/inject/internal/BoundProviderFactory.java
Expand Up @@ -52,31 +52,31 @@ public void notify(Errors errors) {
}

@Override
public T get(Errors errors, InternalContext context, Dependency<?> dependency, boolean linked)
throws ErrorsException {
public T get(InternalContext context, Dependency<?> dependency, boolean linked)
throws InternalProvisionException {
context.pushState(providerKey, source);

try {
javax.inject.Provider<? extends T> provider = providerFactory.get(context, dependency, true);
return circularGet(provider, context, dependency, provisionCallback);
} catch (InternalProvisionException ipe) {
throw ipe.addSource(providerKey);
} finally {
context.popState();

errors = errors.withSource(providerKey);
javax.inject.Provider<? extends T> provider =
providerFactory.get(errors, context, dependency, true);
return circularGet(provider, errors, context, dependency, provisionCallback);
} finally {
context.popState();
}
}

@Override
protected T provision(
Provider<? extends T> provider,
Errors errors,
Dependency<?> dependency,
ConstructionContext<T> constructionContext)
throws ErrorsException {
throws InternalProvisionException {
try {
return super.provision(provider, errors, dependency, constructionContext);
return super.provision(provider, dependency, constructionContext);
} catch (RuntimeException userException) {
throw errors.errorInProvider(userException).toException();
throw InternalProvisionException.errorInProvider(userException);
}
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/com/google/inject/internal/BytecodeGen.java
Expand Up @@ -395,7 +395,7 @@ private static class BridgeClassLoader extends ClassLoader {
@Override
protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {

if (name.startsWith("sun.reflect")) {
if (name.startsWith("sun.reflect") || name.startsWith("jdk.internal.reflect")) {
// these reflection classes must be loaded from bootstrap class loader
return SystemBridgeHolder.SYSTEM_BRIDGE.classicLoadClass(name, resolve);
}
Expand Down
6 changes: 3 additions & 3 deletions core/src/com/google/inject/internal/ConstantFactory.java
Expand Up @@ -29,9 +29,9 @@ public ConstantFactory(Initializable<T> initializable) {
}

@Override
public T get(Errors errors, InternalContext context, Dependency dependency, boolean linked)
throws ErrorsException {
return initializable.get(errors);
public T get(InternalContext context, Dependency<?> dependency, boolean linked)
throws InternalProvisionException {
return initializable.get();
}

@Override
Expand Down
8 changes: 4 additions & 4 deletions core/src/com/google/inject/internal/ConstructionContext.java
Expand Up @@ -58,13 +58,13 @@ public void finishConstruction() {
invocationHandlers = null;
}

public Object createProxy(Errors errors, InjectorOptions injectorOptions, Class<?> expectedType)
throws ErrorsException {
public Object createProxy(InjectorOptions injectorOptions, Class<?> expectedType)
throws InternalProvisionException {
if (injectorOptions.disableCircularProxies) {
throw errors.circularDependenciesDisabled(expectedType).toException();
throw InternalProvisionException.circularDependenciesDisabled(expectedType);
}
if (!expectedType.isInterface()) {
throw errors.cannotProxyClass(expectedType).toException();
throw InternalProvisionException.cannotProxyClass(expectedType);
}

if (invocationHandlers == null) {
Expand Down
Expand Up @@ -290,20 +290,20 @@ private static class Factory<T> implements InternalFactory<T> {

@Override
@SuppressWarnings("unchecked")
public T get(Errors errors, InternalContext context, Dependency<?> dependency, boolean linked)
throws ErrorsException {
public T get(InternalContext context, Dependency<?> dependency, boolean linked)
throws InternalProvisionException {
ConstructorInjector<T> localInjector = constructorInjector;
if (localInjector == null) {
throw new IllegalStateException("Constructor not ready");
}

if (!linked && failIfNotLinked) {
throw errors.jitDisabled(key).toException();
throw InternalProvisionException.jitDisabled(key);
}

// This may not actually be safe because it could return a super type of T (if that's all the
// client needs), but it should be OK in practice thanks to the wonders of erasure.
return (T) localInjector.construct(errors, context, dependency, provisionCallback);
return (T) localInjector.construct(context, dependency, provisionCallback);
}
}
}

0 comments on commit 00e0259

Please sign in to comment.