Example #1
0
  public boolean isAssignableTo(Type type) {
    if (resolved != null) return type.isAssignableFrom(resolved);

    if (Type.OBJECT.equals(type)) return true;

    if (potentialClass != null && !type.isAssignableFrom(potentialClass)) potentialClass = null;

    Map map = mergeMultiAndSingle(this, type);

    if (map.size() == 1 && potentialClass == null) {
      // Update previous merge paths to the same resolved type
      resolved = Type.get((CtClass) map.values().iterator().next());
      propogateResolved();

      return true;
    }

    // Keep all previous merge paths up to date
    if (map.size() >= 1) {
      interfaces = map;
      propogateState();

      return true;
    }

    if (potentialClass != null) {
      resolved = potentialClass;
      propogateResolved();

      return true;
    }

    return false;
  }
Example #2
0
  public Type merge(Type type) {
    if (this == type) return this;

    if (type == UNINIT) return this;

    if (type == BOGUS) return BOGUS;

    if (type == null) return this;

    if (resolved != null) return resolved.merge(type);

    if (potentialClass != null) {
      Type mergePotential = potentialClass.merge(type);
      if (!mergePotential.equals(potentialClass) || mergePotential.popChanged()) {
        potentialClass = Type.OBJECT.equals(mergePotential) ? null : mergePotential;
        changed = true;
      }
    }

    Map merged;

    if (type instanceof MultiType) {
      MultiType multi = (MultiType) type;

      if (multi.resolved != null) {
        merged = mergeMultiAndSingle(this, multi.resolved);
      } else {
        merged = mergeMultiInterfaces(multi, this);
        if (!inMergeSource(multi)) mergeSource = multi;
      }
    } else {
      merged = mergeMultiAndSingle(this, type);
    }

    // Keep all previous merge paths up to date
    if (merged.size() > 1 || (merged.size() == 1 && potentialClass != null)) {
      // Check for changes
      if (merged.size() != interfaces.size()) {
        changed = true;
      } else if (changed == false) {
        Iterator iter = merged.keySet().iterator();
        while (iter.hasNext()) if (!interfaces.containsKey(iter.next())) changed = true;
      }

      interfaces = merged;
      propogateState();

      return this;
    }

    if (merged.size() == 1) {
      resolved = Type.get((CtClass) merged.values().iterator().next());
    } else if (potentialClass != null) {
      resolved = potentialClass;
    } else {
      resolved = OBJECT;
    }

    propogateResolved();

    return resolved;
  }