Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A lightweight annotated class for resolving
git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@1605 1c488680-804c-0410-94cd-c6b725194a0e
- Loading branch information
Showing
3 changed files
with
100 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
webbeans-ri/src/main/java/org/jboss/webbeans/injection/ResolvableAnnotatedClass.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package org.jboss.webbeans.injection; | ||
|
||
import java.lang.annotation.Annotation; | ||
import java.lang.reflect.ParameterizedType; | ||
import java.lang.reflect.Type; | ||
import java.util.Arrays; | ||
|
||
import javax.inject.TypeLiteral; | ||
|
||
import org.jboss.webbeans.introspector.AnnotationStore; | ||
import org.jboss.webbeans.introspector.jlr.AbstractAnnotatedItem; | ||
|
||
/** | ||
* Extension of an element which bases equality not only on type, but also on | ||
* binding type | ||
*/ | ||
public class ResolvableAnnotatedClass<T> extends AbstractAnnotatedItem<T, Class<T>> | ||
{ | ||
|
||
private static final Annotation[] EMPTY_ANNOTATION_ARRAY = new Annotation[0]; | ||
private final Class<T> rawType; | ||
private final Type[] actualTypeArguments; | ||
|
||
private final String _string; | ||
|
||
public static <T> ResolvableAnnotatedClass<T> of(TypeLiteral<T> typeLiteral, Annotation[] annotations) | ||
{ | ||
return new ResolvableAnnotatedClass<T>(typeLiteral.getRawType(), typeLiteral.getType(), annotations); | ||
} | ||
|
||
public static <T> ResolvableAnnotatedClass<T> of(Class<T> clazz, Annotation[] annotations) | ||
{ | ||
return new ResolvableAnnotatedClass<T>(clazz, clazz, annotations); | ||
} | ||
|
||
private ResolvableAnnotatedClass(Class<T> rawType, Type type, Annotation[] annotations) | ||
{ | ||
super(AnnotationStore.of(annotations, EMPTY_ANNOTATION_ARRAY)); | ||
this.rawType = rawType; | ||
if (type instanceof ParameterizedType) | ||
{ | ||
this.actualTypeArguments = ((ParameterizedType) type).getActualTypeArguments(); | ||
this._string = rawType.toString() + "<" + Arrays.asList(actualTypeArguments).toString() + ">"; | ||
} | ||
else | ||
{ | ||
this.actualTypeArguments = new Type[0]; | ||
this._string = rawType.toString(); | ||
} | ||
} | ||
|
||
@Override | ||
public String toString() | ||
{ | ||
return _string; | ||
} | ||
|
||
@Override | ||
public Class<T> getDelegate() | ||
{ | ||
return rawType; | ||
} | ||
|
||
public Type[] getActualTypeArguments() | ||
{ | ||
return actualTypeArguments; | ||
} | ||
|
||
public String getName() | ||
{ | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
public Class<T> getType() | ||
{ | ||
return rawType; | ||
} | ||
|
||
public boolean isFinal() | ||
{ | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
public boolean isPublic() | ||
{ | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
public boolean isStatic() | ||
{ | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters