001package daikon.chicory;
002
003import java.util.EnumSet;
004import org.checkerframework.checker.nullness.qual.Nullable;
005
006/**
007 * The ThisObjInfo class is a subtype of DaikonVariableInfo used for variable types which represent
008 * the "this" object.
009 */
010public class ThisObjInfo extends DaikonVariableInfo {
011  public Class<?> type;
012
013  //     public ThisObjInfo(String typeName, String repTypeName)
014  //     {
015  //         super("this");
016  //     }
017
018  public ThisObjInfo(Class<?> type) {
019    this("this", type);
020  }
021
022  /**
023   * thisName is the name to be used to specify the variable. It's "this" except for outer classes,
024   * as in "OuterClass.this".
025   */
026  public ThisObjInfo(String thisName, Class<?> type) {
027    super(thisName, type.getName() + isNonNullParamString, getRepName(type, false));
028    this.type = type;
029  }
030
031  /* (non-Javadoc)
032   * @see daikon.chicory.DaikonVariableInfo#getChildValue(java.lang.Object)
033   */
034  @Override
035  public @Nullable Object getMyValFromParentVal(Object val) {
036    throw new Error("shouldn't be called");
037  }
038
039  /** {@code this} is a top-level variable. */
040  @Override
041  public VarKind get_var_kind() {
042    return VarKind.VARIABLE;
043  }
044
045  /** Add IS_PARAM to list of variable flags, because the receiver "this" is a formal parameter. */
046  @Override
047  public EnumSet<VarFlags> get_var_flags() {
048    // System.out.printf("%s is a parameter%n", this);
049    EnumSet<VarFlags> var_flags = super.get_var_flags();
050    var_flags.add(VarFlags.IS_PARAM);
051    var_flags.add(VarFlags.NON_NULL);
052    return var_flags;
053  }
054}