Exemple #1
0
  @Override
  public int getTypeMatch(IType type) {
    if (this.field == null) {
      return 0;
    }

    IType type1 = this.getType();
    if (type.equals(type1)) {
      return 3;
    }
    if (type.isSuperTypeOf(type1)) {
      return 2;
    }
    return 0;
  }
Exemple #2
0
  public static IValue autoBox(IValue value, IType valueType, IType targetType) {
    if (!targetType.isSuperTypeOf(valueType)) {
      return null;
    }

    boolean primitive = valueType.isPrimitive();
    if (primitive != targetType.isPrimitive()) {
      // Box Primitive -> Object
      if (primitive) {
        return new BoxedValue(value, valueType.getBoxMethod());
      }
      // Unbox Object -> Primitive
      return new BoxedValue(value, targetType.getUnboxMethod());
    }
    return value;
  }
Exemple #3
0
 @Override
 public IValue withType(
     IType type, ITypeContext typeContext, MarkerList markers, IContext context) {
   if (type == Types.BOOLEAN) {
     return this;
   }
   return type.isSuperTypeOf(Types.BOOLEAN) ? new BoxedValue(this, Types.BOOLEAN.boxMethod) : null;
 }
  private void checkMethod(IMethod m) {
    Name name = m.getName();
    if (name == Name.equals) {
      if (m.parameterCount() == 1 && m.getParameter(0).getType().equals(Types.OBJECT)) {
        this.methods |= EQUALS;
      }
      return;
    }
    if (name == Name.hashCode) {
      if (m.parameterCount() == 0) {
        this.methods |= HASHCODE;
      }
      return;
    }
    if (name == Name.toString) {
      if (m.parameterCount() == 0) {
        this.methods |= TOSTRING;
      }
      return;
    }
    if (name == Name.apply) {
      if (m.parameterCount() == this.theClass.parameterCount()) {
        int len = this.theClass.parameterCount();
        for (int i = 0; i < len; i++) {
          IType t1 = m.getParameter(i).getType();
          IType t2 = m.getParameter(i).getType();
          if (!t1.equals(t2)) {
            return;
          }
        }

        this.methods |= APPLY;
      }
      return;
    }
  }
Exemple #5
0
 public void writeLocal(MethodWriter writer, Label start, Label end) {
   IType type = this.refType != null ? this.refType : this.type;
   writer.writeLocal(
       this.index, this.name.qualified, type.getExtendedName(), type.getSignature(), start, end);
 }
Exemple #6
0
 @Override
 public boolean isType(IType type) {
   return type == Types.BOOLEAN || type.isSuperTypeOf(Types.BOOLEAN);
 }
Exemple #7
0
 @Override
 public boolean isType(IType type) {
   return this.field == null ? false : type.isSuperTypeOf(this.getType());
 }