Skip to content

Commit

Permalink
Added missing test coverage and documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
raphw committed Jul 10, 2015
1 parent 89e483a commit 0e7e43f
Show file tree
Hide file tree
Showing 5 changed files with 320 additions and 29 deletions.
Expand Up @@ -166,7 +166,7 @@ public String getName() {
}

@Override
public TypeDescription getDeclaringType() {
public GenericTypeDescription getDeclaringType() {
return new TypeDescription.ForLoadedType(field.getDeclaringClass());
}

Expand All @@ -187,37 +187,55 @@ public boolean isSynthetic() {
*/
class Latent extends AbstractFieldDescription {

/**
* The type for which this field is defined.
*/
private final GenericTypeDescription declaringType;

/**
* The name of the field.
*/
private final String fieldName;

/**
* The type for which this field is defined.
* The field's modifiers.
*/
private final TypeDescription declaringType;
private final int modifiers;

/**
* The type of the field.
*/
private final GenericTypeDescription fieldType;

/**
* The field's modifiers.
* The annotations of this field.
*/
private final int modifiers;

private final List<? extends AnnotationDescription> declaredAnnotations;

public Latent(TypeDescription declaringType, FieldDescription.Token token) {
/**
* Creates a new latent field description. All provided types are attached to this instance before they are returned.
*
* @param declaringType The declaring type of the field.
* @param token A token representing the field's shape.
*/
public Latent(GenericTypeDescription declaringType, FieldDescription.Token token) {
this(declaringType,
token.getName(),
token.getType(),
token.getModifiers(),
token.getAnnotations());
}

public Latent(TypeDescription declaringType,
/**
* Creates a new latent field description. All provided types are attached to this instance before they are returned.
*
* @param declaringType The declaring type of the field.
* @param fieldName The name of the field.
* @param fieldType The field's modifiers.
* @param modifiers The type of the field.
* @param declaredAnnotations The annotations of this field.
*/
public Latent(GenericTypeDescription declaringType,
String fieldName,
GenericTypeDescription fieldType,
int modifiers,
Expand Down Expand Up @@ -245,7 +263,7 @@ public String getName() {
}

@Override
public TypeDescription getDeclaringType() {
public GenericTypeDescription getDeclaringType() {
return declaringType;
}

Expand Down Expand Up @@ -275,7 +293,7 @@ class TypeSubstituting extends AbstractFieldDescription {
/**
* Creates a field description with a substituted field type.
*
* @param declaringType
* @param declaringType The declaring type of the field.
* @param fieldDescription The represented field.
* @param visitor A visitor that is applied to the field type.
*/
Expand Down
Expand Up @@ -754,7 +754,7 @@ public ForLoadedMethod(Method method) {
}

@Override
public TypeDescription getDeclaringType() {
public GenericTypeDescription getDeclaringType() {
return new TypeDescription.ForLoadedType(method.getDeclaringClass());
}

Expand Down Expand Up @@ -860,10 +860,10 @@ class Latent extends AbstractMethodDescription {
/**
* The type that is declaring this method.
*/
private final TypeDescription declaringType;
private final GenericTypeDescription declaringType;

/**
* the internal name of this method.
* The internal name of this method.
*/
private final String internalName;

Expand All @@ -872,25 +872,43 @@ class Latent extends AbstractMethodDescription {
*/
private final int modifiers;

/**
* The type variables of the described method.
*/
private final List<? extends GenericTypeDescription> typeVariables;

/**
* The return type of this method.
*/
private final GenericTypeDescription returnType;

/**
* The parameter tokens describing this method.
*/
private final List<? extends ParameterDescription.Token> parameterTokens;

/**
* This method's exception types.
*/
private final List<? extends GenericTypeDescription> exceptionTypes;

/**
* The annotations of this method.
*/
private final List<? extends AnnotationDescription> declaredAnnotations;

/**
* The default value of this method or {@code null} if no default annotation value is defined.
*/
private final Object defaultValue;

public Latent(TypeDescription declaringType, Token token) {
/**
* Creates a new latent method description. All provided types are attached to this instance before they are returned.
*
* @param declaringType The declaring type of the method.
* @param token A token representing the method's shape.
*/
public Latent(GenericTypeDescription declaringType, Token token) {
this(declaringType,
token.getInternalName(),
token.getModifiers(),
Expand All @@ -902,7 +920,20 @@ public Latent(TypeDescription declaringType, Token token) {
token.getDefaultValue());
}

public Latent(TypeDescription declaringType,
/**
* Creates a new latent method description. All provided types are attached to this instance before they are returned.
*
* @param declaringType The type that is declaring this method.
* @param internalName The internal name of this method.
* @param modifiers The modifiers of this method.
* @param typeVariables The type variables of the described method.
* @param returnType The return type of this method.
* @param parameterTokens The parameter tokens describing this method.
* @param exceptionTypes This method's exception types.
* @param declaredAnnotations The annotations of this method.
* @param defaultValue The default value of this method or {@code null} if no default annotation value is defined.
*/
public Latent(GenericTypeDescription declaringType,
String internalName,
int modifiers,
List<? extends GenericTypeDescription> typeVariables,
Expand Down Expand Up @@ -953,7 +984,7 @@ public String getInternalName() {
}

@Override
public TypeDescription getDeclaringType() {
public GenericTypeDescription getDeclaringType() {
return declaringType;
}

Expand All @@ -967,11 +998,22 @@ public Object getDefaultValue() {
return defaultValue;
}

/**
* A method description that represents the type initializer.
*/
public static class TypeInitializer extends MethodDescription.AbstractMethodDescription {

private final TypeDescription typeDescription;
/**
* The type for which the type initializer should be represented.
*/
private final GenericTypeDescription typeDescription;

public TypeInitializer(TypeDescription typeDescription) {
/**
* Creates a new method description representing the type initializer.
*
* @param typeDescription The type for which the type initializer should be represented.
*/
public TypeInitializer(GenericTypeDescription typeDescription) {
this.typeDescription = typeDescription;
}

Expand Down Expand Up @@ -1006,7 +1048,7 @@ public AnnotationList getDeclaredAnnotations() {
}

@Override
public TypeDescription getDeclaringType() {
public GenericTypeDescription getDeclaringType() {
return typeDescription;
}

Expand Down Expand Up @@ -1045,6 +1087,7 @@ class TypeSubstituting extends AbstractMethodDescription {
/**
* Creates a method description with substituted method types.
*
* @param declaringType The type that is declaring the substituted method.
* @param methodDescription The represented method description.
* @param visitor A visitor that is applied to the method type.
*/
Expand Down Expand Up @@ -1376,20 +1419,21 @@ public boolean equals(Object other) {
if (this == other) return true;
if (!(other instanceof Token)) return false;
Token token = (Token) other;
if (!internalName.equals(token.internalName)) return false;
if (!returnType.asRawType().equals(token.returnType.asRawType())) return false;
if (parameterTokens.size() != token.parameterTokens.size()) return false;
for (int index = 0; index < parameterTokens.size(); index++) {
if (!parameterTokens.get(index).getType().asRawType().equals(token.parameterTokens.get(index).getType().asRawType())) return false;
if (!getInternalName().equals(token.getInternalName())) return false;
if (!getReturnType().asRawType().equals(token.getReturnType().asRawType())) return false;
List<ParameterDescription.Token> tokens = getParameterTokens(), otherTokens = getParameterTokens();
if (tokens.size() != otherTokens.size()) return false;
for (int index = 0; index < tokens.size(); index++) {
if (!tokens.get(index).getType().asRawType().equals(otherTokens.get(index).getType().asRawType())) return false;
}
return true;
}

@Override
public int hashCode() {
int result = internalName.hashCode();
result = 31 * result + returnType.asRawType().hashCode();
for (ParameterDescription.Token parameterToken : parameterTokens) {
int result = getInternalName().hashCode();
result = 31 * result + getReturnType().asRawType().hashCode();
for (ParameterDescription.Token parameterToken : getParameterTokens()) {
result = 31 * result + parameterToken.getType().asRawType().hashCode();
}
return result;
Expand Down

0 comments on commit 0e7e43f

Please sign in to comment.