Skip to content

Commit

Permalink
Changed type visitor to accept a generic type description even for no…
Browse files Browse the repository at this point in the history
…n-generic types as these types might be represented as a raw type projection (or a non-resolved lazy projection).
  • Loading branch information
Rafael Winterhalter committed Jul 23, 2015
1 parent de751fe commit 5fdcdd8
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 33 deletions.
Expand Up @@ -1213,12 +1213,12 @@ public GenericTypeDescription onParameterizedType(GenericTypeDescription paramet
}

@Override
public GenericTypeDescription onNonGenericType(TypeDescription typeDescription) {
public GenericTypeDescription onNonGenericType(GenericTypeDescription typeDescription) {
return visitor.onNonGenericType(typeDescription);
}

@Override
protected TypeDescription onSimpleType(TypeDescription typeDescription) {
protected GenericTypeDescription onSimpleType(GenericTypeDescription typeDescription) {
throw new UnsupportedOperationException();
}

Expand Down
Expand Up @@ -144,13 +144,6 @@ public interface TypeDescription extends GenericTypeDescription, TypeVariableSou
*/
boolean represents(Class<?> type);

/**
* Checks if the type described by this entity is an array.
*
* @return {@code true} if this type description represents an array.
*/
boolean isArray();

@Override
TypeDescription getComponentType();

Expand All @@ -160,13 +153,6 @@ public interface TypeDescription extends GenericTypeDescription, TypeVariableSou
@Override
TypeDescription getDeclaringType();

/**
* Checks if the type described by this entity is a primitive type.
*
* @return {@code true} if this type description represents a primitive type.
*/
boolean isPrimitive();

/**
* Returns a description of the enclosing method of this type.
*
Expand Down
Expand Up @@ -205,6 +205,20 @@ public interface GenericTypeDescription extends NamedElement {
*/
StackSize getStackSize();

/**
* Checks if the type described by this entity is an array.
*
* @return {@code true} if this type description represents an array.
*/
boolean isArray();

/**
* Checks if the type described by this entity is a primitive type.
*
* @return {@code true} if this type description represents a primitive type.
*/
boolean isPrimitive();

/**
* Applies a visitor to this generic type description.
*
Expand Down Expand Up @@ -392,7 +406,7 @@ interface Visitor<T> {
* @param typeDescription The non-generic type.
* @return The visitor's return value.
*/
T onNonGenericType(TypeDescription typeDescription);
T onNonGenericType(GenericTypeDescription typeDescription);

/**
* A non-operational generic type visitor. Any visited type is returned in its existing form.
Expand Down Expand Up @@ -425,7 +439,7 @@ public GenericTypeDescription onTypeVariable(GenericTypeDescription typeVariable
}

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

Expand Down Expand Up @@ -490,8 +504,8 @@ public GenericTypeDescription onTypeVariable(GenericTypeDescription typeVariable
}

@Override
public GenericTypeDescription onNonGenericType(TypeDescription typeDescription) {
return new ForParameterizedType.Raw(typeDescription);
public GenericTypeDescription onNonGenericType(GenericTypeDescription typeDescription) {
return new ForParameterizedType.Raw(typeDescription.asRawType());
}

@Override
Expand All @@ -505,6 +519,7 @@ public String toString() {
* parameters.
*/
protected enum PartialErasureReviser implements Visitor<Boolean> {

/**
* The singleton instance.
*/
Expand Down Expand Up @@ -534,7 +549,7 @@ public Boolean onTypeVariable(GenericTypeDescription typeVariable) {
}

@Override
public Boolean onNonGenericType(TypeDescription typeDescription) {
public Boolean onNonGenericType(GenericTypeDescription typeDescription) {
return false;
}

Expand Down Expand Up @@ -612,13 +627,13 @@ public SignatureVisitor onTypeVariable(GenericTypeDescription typeVariable) {
}

@Override
public SignatureVisitor onNonGenericType(TypeDescription typeDescription) {
public SignatureVisitor onNonGenericType(GenericTypeDescription typeDescription) {
if(typeDescription.isArray()) {
typeDescription.getComponentType().accept(new ForSignatureVisitor(signatureVisitor.visitArrayType()));
} else if (typeDescription.isPrimitive()) {
signatureVisitor.visitBaseType(typeDescription.getDescriptor().charAt(ONLY_CHARACTER));
signatureVisitor.visitBaseType(typeDescription.asRawType().getDescriptor().charAt(ONLY_CHARACTER));
} else {
signatureVisitor.visitClassType(typeDescription.getInternalName());
signatureVisitor.visitClassType(typeDescription.asRawType().getInternalName());
signatureVisitor.visitEnd();
}
return signatureVisitor;
Expand Down Expand Up @@ -689,7 +704,7 @@ public SignatureVisitor onTypeVariable(GenericTypeDescription typeVariable) {
}

@Override
public SignatureVisitor onNonGenericType(TypeDescription typeDescription) {
public SignatureVisitor onNonGenericType(GenericTypeDescription typeDescription) {
typeDescription.accept(new ForSignatureVisitor(signatureVisitor.visitTypeArgument(SignatureVisitor.INSTANCEOF)));
return signatureVisitor;
}
Expand Down Expand Up @@ -735,13 +750,13 @@ public GenericTypeDescription onWildcardType(GenericTypeDescription wildcardType
}

@Override
public GenericTypeDescription onNonGenericType(TypeDescription typeDescription) {
public GenericTypeDescription onNonGenericType(GenericTypeDescription typeDescription) {
int arity = 0;
while (typeDescription.isArray()) {
typeDescription = typeDescription.getComponentType();
arity++;
}
return TypeDescription.ArrayProjection.of(onSimpleType(typeDescription), arity);
return ForGenericArray.Latent.of(onSimpleType(typeDescription), arity);
}

/**
Expand All @@ -750,7 +765,7 @@ public GenericTypeDescription onNonGenericType(TypeDescription typeDescription)
* @param typeDescription The type that is visited.
* @return The substituted type.
*/
protected abstract TypeDescription onSimpleType(TypeDescription typeDescription);
protected abstract GenericTypeDescription onSimpleType(GenericTypeDescription typeDescription);

/**
* A substitutor that attaches type variables to a type variable source and replaces representations of
Expand Down Expand Up @@ -828,7 +843,7 @@ public GenericTypeDescription onTypeVariable(GenericTypeDescription genericTypeD
}

@Override
protected TypeDescription onSimpleType(TypeDescription typeDescription) {
protected GenericTypeDescription onSimpleType(GenericTypeDescription typeDescription) {
return typeDescription.equals(TargetType.DESCRIPTION)
? declaringType
: typeDescription;
Expand Down Expand Up @@ -895,8 +910,8 @@ public GenericTypeDescription onTypeVariable(GenericTypeDescription genericTypeD
}

@Override
protected TypeDescription onSimpleType(TypeDescription typeDescription) {
return typeMatcher.matches(typeDescription)
protected GenericTypeDescription onSimpleType(GenericTypeDescription typeDescription) {
return typeMatcher.matches(typeDescription.asRawType())
? TargetType.DESCRIPTION
: typeDescription;
}
Expand Down Expand Up @@ -1015,12 +1030,12 @@ public GenericTypeDescription onTypeVariable(GenericTypeDescription typeVariable
}

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

@Override
protected TypeDescription onSimpleType(TypeDescription typeDescription) {
protected GenericTypeDescription onSimpleType(GenericTypeDescription typeDescription) {
throw new UnsupportedOperationException();
}

Expand Down Expand Up @@ -1128,6 +1143,16 @@ public String getSourceCodeName() {
: toString();
}

@Override
public boolean isArray() {
return true;
}

@Override
public boolean isPrimitive() {
return false;
}

@Override
public <T> T accept(Visitor<T> visitor) {
return getSort().isNonGeneric()
Expand Down Expand Up @@ -1319,6 +1344,16 @@ public String getSourceCodeName() {
return toString();
}

@Override
public boolean isPrimitive() {
return false;
}

@Override
public boolean isArray() {
return false;
}

@Override
public <T> T accept(Visitor<T> visitor) {
return visitor.onWildcardType(this);
Expand Down Expand Up @@ -1528,6 +1563,16 @@ public String getSourceCodeName() {
return toString();
}

@Override
public boolean isPrimitive() {
return false;
}

@Override
public boolean isArray() {
return false;
}

@Override
public <T> T accept(Visitor<T> visitor) {
return visitor.onParameterizedType(this);
Expand Down Expand Up @@ -1813,6 +1858,16 @@ public String getSourceCodeName() {
return typeDescription.getSourceCodeName();
}

@Override
public boolean isArray() {
return typeDescription.isArray();
}

@Override
public boolean isPrimitive() {
return typeDescription.isPrimitive();
}

@Override
public int hashCode() {
return typeDescription.hashCode();
Expand Down Expand Up @@ -1908,6 +1963,16 @@ public StackSize getStackSize() {
return StackSize.SINGLE;
}

@Override
public boolean isArray() {
return false;
}

@Override
public boolean isPrimitive() {
return false;
}

@Override
public int hashCode() {
return getVariableSource().hashCode() ^ getSymbol().hashCode();
Expand Down Expand Up @@ -2096,6 +2161,16 @@ public StackSize getStackSize() {
return asRawType().getStackSize();
}

@Override
public boolean isArray() {
return asRawType().isArray();
}

@Override
public boolean isPrimitive() {
return asRawType().isPrimitive();
}

@Override
public int hashCode() {
return resolve().hashCode();
Expand Down

0 comments on commit 5fdcdd8

Please sign in to comment.