You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ChocoPy/src/main/java/chocopy/common/analysis/types/ListValueType.java

58 lines
1.4 KiB

3 years ago
package chocopy.common.analysis.types;
import chocopy.common.astnodes.ListType;
import com.fasterxml.jackson.annotation.JsonCreator;
import java.util.Objects;
/** Represents a semantic value of a list type denotation. */
public class ListValueType extends ValueType {
/** This ListValueType represents [ELEMENTTYPE]. */
public final ValueType elementType;
/** Represents [ELEMENTTYPE]. */
@JsonCreator
public ListValueType(Type elementType) {
this.elementType = (ValueType) elementType;
}
/** Represents [<type>], where <type> is that denoted in TYPEANNOTATION. */
public ListValueType(ListType typeAnnotation) {
elementType = ValueType.annotationToValueType(typeAnnotation.elementType);
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
ListValueType listType = (ListValueType) o;
return Objects.equals(elementType, listType.elementType);
}
@Override
public int hashCode() {
return Objects.hash(elementType);
}
@Override
public String toString() {
return "[" + elementType.toString() + "]";
}
/** Returns true iff I represent [T]. */
@Override
public boolean isListType() {
return true;
}
@Override
public ValueType elementType() {
return elementType;
}
}