You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@onami.apache.org by si...@apache.org on 2013/01/20 21:33:48 UTC
svn commit: r1435946 -
/incubator/onami/trunk/logging/core/src/main/java/org/apache/onami/logging/core/AbstractLoggingModule.java
Author: simonetripodi
Date: Sun Jan 20 20:33:48 2013
New Revision: 1435946
URL: http://svn.apache.org/viewvc?rev=1435946&view=rev
Log:
[ONAMI-28] Do not use code from com.google.inject.internal
Modified:
incubator/onami/trunk/logging/core/src/main/java/org/apache/onami/logging/core/AbstractLoggingModule.java
Modified: incubator/onami/trunk/logging/core/src/main/java/org/apache/onami/logging/core/AbstractLoggingModule.java
URL: http://svn.apache.org/viewvc/incubator/onami/trunk/logging/core/src/main/java/org/apache/onami/logging/core/AbstractLoggingModule.java?rev=1435946&r1=1435945&r2=1435946&view=diff
==============================================================================
--- incubator/onami/trunk/logging/core/src/main/java/org/apache/onami/logging/core/AbstractLoggingModule.java (original)
+++ incubator/onami/trunk/logging/core/src/main/java/org/apache/onami/logging/core/AbstractLoggingModule.java Sun Jan 20 20:33:48 2013
@@ -21,15 +21,19 @@ package org.apache.onami.logging.core;
import static java.lang.String.format;
+import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
+import java.lang.reflect.GenericArrayType;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.lang.reflect.TypeVariable;
import com.google.inject.Binder;
import com.google.inject.MembersInjector;
import com.google.inject.Module;
import com.google.inject.ProvisionException;
import com.google.inject.TypeLiteral;
-import com.google.inject.internal.MoreTypes;
import com.google.inject.matcher.Matcher;
import com.google.inject.spi.TypeEncounter;
import com.google.inject.spi.TypeListener;
@@ -85,7 +89,7 @@ public class AbstractLoggingModule<L>
}
this.matcher = matcher;
- loggerClass = MoreTypes.getRawType( getType() );
+ loggerClass = getRawType( getType() );
try
{
logInjectorConstructor = loggerInjectorClass.getConstructor( Field.class );
@@ -146,4 +150,46 @@ public class AbstractLoggingModule<L>
hear( klass.getSuperclass(), encounter );
}
+ private static Class<?> getRawType( Type type )
+ {
+ if ( type instanceof Class<?> )
+ {
+ // type is a normal class.
+ return (Class<?>) type;
+ }
+ else if ( type instanceof ParameterizedType )
+ {
+ ParameterizedType parameterizedType = (ParameterizedType) type;
+
+ // I'm not exactly sure why getRawType() returns Type instead of Class.
+ // Neal isn't either but suspects some pathological case related
+ // to nested classes exists.
+ Type rawType = parameterizedType.getRawType();
+ if ( !(rawType instanceof Class) )
+ {
+ throw new IllegalArgumentException( format( "Expected a Class, but <%s> is of type %s",
+ type,
+ type.getClass().getName() ) );
+ }
+ return (Class<?>) rawType;
+ }
+ else if ( type instanceof GenericArrayType )
+ {
+ Type componentType = ( (GenericArrayType) type ).getGenericComponentType();
+ return Array.newInstance( getRawType( componentType ), 0 ).getClass();
+ }
+ else if ( type instanceof TypeVariable )
+ {
+ // we could use the variable's bounds, but that'll won't work if there are multiple.
+ // having a raw type that's more general than necessary is okay
+ return Object.class;
+ }
+ else
+ {
+ throw new IllegalArgumentException( format( "Expected a Class, ParameterizedType, or GenericArrayType, but <%s> is of type %s",
+ type,
+ type.getClass().getName() ) );
+ }
+ }
+
}