Skip to content

Commit

Permalink
Further improved handling of generic types.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafael Winterhalter committed May 22, 2015
1 parent 52d8784 commit f9272d1
Show file tree
Hide file tree
Showing 11 changed files with 829 additions and 526 deletions.
Expand Up @@ -107,7 +107,7 @@ public TypeDescription getFieldType() {

@Override
public GenericType getFieldTypeGen() {
return new GenericType.LazyProjection.OfFieldType(field);
return new GenericType.LazyProjection.OfLoadedFieldType(field);
}

@Override
Expand Down
Expand Up @@ -11,10 +11,18 @@
*/
public interface FieldList extends FilterableList<FieldDescription, FieldList> {

abstract class AbstractBase extends FilterableList.AbstractBase<FieldDescription, FieldList> implements FieldList {

@Override
protected FieldList wrap(List<FieldDescription> values) {
return new Explicit(values);
}
}

/**
* An implementation of a field list for an array of loaded fields.
*/
class ForLoadedField extends AbstractBase<FieldDescription, FieldList> implements FieldList {
class ForLoadedField extends AbstractBase {

/**
* The loaded fields this field list represents.
Expand Down Expand Up @@ -48,17 +56,12 @@ public FieldDescription get(int index) {
public int size() {
return fields.size();
}

@Override
protected FieldList wrap(List<FieldDescription> values) {
return new Explicit(values);
}
}

/**
* A wrapper implementation of a field list for a given list of field descriptions.
*/
class Explicit extends AbstractBase<FieldDescription, FieldList> implements FieldList {
class Explicit extends AbstractBase {

/**
* The list of field descriptions this list represents.
Expand All @@ -83,17 +86,12 @@ public FieldDescription get(int index) {
public int size() {
return fieldDescriptions.size();
}

@Override
protected FieldList wrap(List<FieldDescription> values) {
return new Explicit(values);
}
}

/**
* An implementation of an empty field list.
*/
class Empty extends FilterableList.Empty<FieldDescription, FieldList> implements FieldList {

/* empty */
}
}
Expand Up @@ -465,6 +465,11 @@ public boolean isDefaultValue(Object value) {
|| (returnType.represents(Class.class) && value instanceof TypeDescription);
}

@Override
public TypeVariableSource getEnclosingSource() {
return getDeclaringType();
}

@Override
public boolean equals(Object other) {
return other == this || other instanceof MethodDescription
Expand Down Expand Up @@ -662,7 +667,7 @@ public TypeDescription getReturnType() {

@Override
public GenericType getReturnTypeGen() {
return new GenericType.LazyProjection.OfReturnType(method);
return new GenericType.LazyProjection.OfLoadedReturnType(method);
}

@Override
Expand Down
Expand Up @@ -13,11 +13,19 @@
*/
public interface MethodList extends FilterableList<MethodDescription, MethodList> {

abstract class AbstractBase extends FilterableList.AbstractBase<MethodDescription, MethodList> implements MethodList {

@Override
protected MethodList wrap(List<MethodDescription> values) {
return new Explicit(values);
}
}

/**
* A method list implementation that returns all loaded byte code methods (methods and constructors) that
* are declared for a given type.
*/
class ForLoadedType extends AbstractBase<MethodDescription, MethodList> implements MethodList {
class ForLoadedType extends AbstractBase {

/**
* The loaded methods that are represented by this method list.
Expand Down Expand Up @@ -73,17 +81,12 @@ public MethodDescription get(int index) {
public int size() {
return constructors.size() + methods.size();
}

@Override
protected MethodList wrap(List<MethodDescription> values) {
return new Explicit(values);
}
}

/**
* A method list that is a wrapper for a given list of method descriptions.
*/
class Explicit extends AbstractBase<MethodDescription, MethodList> implements MethodList {
class Explicit extends AbstractBase {

/**
* The list of methods that is represented by this method list.
Expand All @@ -108,17 +111,12 @@ public MethodDescription get(int index) {
public int size() {
return methodDescriptions.size();
}

@Override
protected MethodList wrap(List<MethodDescription> values) {
return new Explicit(values);
}
}

/**
* An implementation of an empty method list.
*/
class Empty extends FilterableList.Empty<MethodDescription, MethodList> implements MethodList {

/* empty */
}
}
Expand Up @@ -235,7 +235,7 @@ public TypeDescription getTypeDescription() {

@Override
public GenericType getTypeGen() {
return new TypeDescription.LazyProjection.OfParameter(parameter);
return new GenericType.LazyProjection.OfLoadedParameter(parameter);
}

@Override
Expand Down
Expand Up @@ -586,6 +586,14 @@ public GenericType getOwnerType() {
return null;
}

@Override
public TypeVariableSource getEnclosingSource() {
MethodDescription enclosingMethod = getEnclosingMethod();
return enclosingMethod == null
? getEnclosingType()
: enclosingMethod;
}

@Override
public boolean equals(Object other) {
return other == this || other instanceof TypeDescription
Expand Down Expand Up @@ -836,7 +844,7 @@ public TypeDescription getSupertype() {

@Override
public GenericType getSuperTypeGen() {
return new LazyProjection.OfSuperType(type);
return new LazyProjection.OfLoadedSuperType(type);
}

@Override
Expand Down
Expand Up @@ -26,10 +26,18 @@ public interface TypeList extends FilterableList<TypeDescription, TypeList> {
*/
int getStackSize();

abstract class AbstractBase extends FilterableList.AbstractBase<TypeDescription, TypeList> implements TypeList {

@Override
protected TypeList wrap(List<TypeDescription> values) {
return new Explicit(values);
}
}

/**
* Implementation of a type list for an array of loaded types.
*/
class ForLoadedType extends AbstractBase<TypeDescription, TypeList> implements TypeList {
class ForLoadedType extends AbstractBase {

/**
* The loaded types this type list represents.
Expand Down Expand Up @@ -78,17 +86,12 @@ public String[] toInternalNames() {
public int getStackSize() {
return StackSize.sizeOf(types);
}

@Override
protected TypeList wrap(List<TypeDescription> values) {
return new Explicit(values);
}
}

/**
* A wrapper implementation of an explicit list of types.
*/
class Explicit extends AbstractBase<TypeDescription, TypeList> implements TypeList {
class Explicit extends AbstractBase {

/**
* The list of type descriptions this list represents.
Expand Down Expand Up @@ -132,11 +135,6 @@ public int getStackSize() {
}
return stackSize;
}

@Override
protected TypeList wrap(List<TypeDescription> values) {
return new Explicit(values);
}
}

/**
Expand Down
Expand Up @@ -692,11 +692,11 @@ public String toString() {
return resolve().toString();
}

public static class OfSuperType extends LazyProjection {
public static class OfLoadedSuperType extends LazyProjection {

private final Class<?> type;

public OfSuperType(Class<?> type) {
public OfLoadedSuperType(Class<?> type) {
this.type = type;
}

Expand All @@ -711,11 +711,11 @@ public TypeDescription asRawType() {
}
}

public static class OfReturnType extends LazyProjection {
public static class OfLoadedReturnType extends LazyProjection {

private final Method method;

public OfReturnType(Method method) {
public OfLoadedReturnType(Method method) {
this.method = method;
}

Expand All @@ -730,11 +730,11 @@ public TypeDescription asRawType() {
}
}

public static class OfFieldType extends LazyProjection {
public static class OfLoadedFieldType extends LazyProjection {

private final Field field;

public OfFieldType(Field field) {
public OfLoadedFieldType(Field field) {
this.field = field;
}

Expand All @@ -749,7 +749,7 @@ public TypeDescription asRawType() {
}
}

public static class OfParameter extends LazyProjection {
public static class OfLoadedParameter extends LazyProjection {

protected static final JavaMethod GET_TYPE;

Expand All @@ -772,7 +772,7 @@ public static class OfParameter extends LazyProjection {

private final Object parameter;

public OfParameter(Object parameter) {
public OfLoadedParameter(Object parameter) {
this.parameter = parameter;
}

Expand Down
Expand Up @@ -22,7 +22,12 @@ abstract class AbstractBase extends FilterableList.AbstractBase<GenericType, Gen

@Override
public String toSignature() {
return null;
return null; // TODO: implement, remove?
}

@Override
protected GenericTypeList wrap(List<GenericType> values) {
return new Explicit(values);
}
}

Expand All @@ -34,11 +39,6 @@ public Explicit(List<? extends GenericType> genericTypes) {
this.genericTypes = genericTypes;
}

@Override
protected GenericTypeList wrap(List<GenericType> values) {
return new Explicit(values);
}

@Override
public GenericType get(int index) {
return genericTypes.get(index);
Expand Down Expand Up @@ -71,11 +71,6 @@ public ForLoadedType(List<? extends Type> types) {
this.types = types;
}

@Override
protected GenericTypeList wrap(List<GenericType> values) {
return new Explicit(values);
}

@Override
public GenericType get(int index) {
return GenericType.Sort.describe(types.get(index));
Expand Down Expand Up @@ -135,11 +130,6 @@ public TypeList asRawTypes() {
}
}

@Override
protected GenericTypeList wrap(List<GenericType> values) {
return new Explicit(values);
}

public static class OfConstructorExceptionTypes extends LazyProjection {

private final Constructor<?> constructor;
Expand Down
Expand Up @@ -5,4 +5,6 @@
public interface TypeVariableSource extends ByteCodeElement {

GenericTypeList getTypeVariables();

TypeVariableSource getEnclosingSource();
}

0 comments on commit f9272d1

Please sign in to comment.