Ejemplo n.º 1
0
  /** Flatten complex expressions within the AST */
  public Node leave(Node old, Node n, NodeVisitor v) {
    if (n == noFlatten) {
      noFlatten = null;
      return n;
    }

    if (n instanceof Block) {
      List l = (List) stack.removeFirst();
      return ((Block) n).statements(l);
    } else if (n instanceof Stmt && !(n instanceof LocalDecl)) {
      List l = (List) stack.getFirst();
      l.add(n);
      return n;
    } else if (n instanceof Expr
        && !(n instanceof Lit)
        && !(n instanceof Special)
        && !(n instanceof Local)) {

      Expr e = (Expr) n;

      if (e instanceof Assign) {
        return n;
      }

      // create a local temp, initialized to the value of the complex
      // expression

      String name = newID();
      LocalDecl def =
          nf.LocalDecl(
              e.position(), Flags.FINAL, nf.CanonicalTypeNode(e.position(), e.type()), name, e);
      def = def.localInstance(ts.localInstance(e.position(), Flags.FINAL, e.type(), name));

      List l = (List) stack.getFirst();
      l.add(def);

      // return the local temp instead of the complex expression
      Local use = nf.Local(e.position(), name);
      use = (Local) use.type(e.type());
      use = use.localInstance(ts.localInstance(e.position(), Flags.FINAL, e.type(), name));
      return use;
    }

    return n;
  }
Ejemplo n.º 2
0
 public Type convertToInferred(List typeVars, List inferredTypes) {
   List newBounds = new ArrayList();
   for (Iterator it = typeArguments().iterator(); it.hasNext(); ) {
     Type next = (Type) it.next();
     if (next instanceof IntersectionType) {
       newBounds.add(inferredTypes.get(typeVars.indexOf(next)));
     } else if (next instanceof ParameterizedType) {
       newBounds.add(((ParameterizedType) next).convertToInferred(typeVars, inferredTypes));
     }
     /*else if (next instanceof AnySubType){
         newBounds.add(((AnySubType)next).convertToInferred(typeVars, inferredTypes));
     }*/
     else {
       newBounds.add(next);
     }
   }
   ParameterizedType converted = ((JL5TypeSystem) typeSystem()).parameterizedType(this.baseType());
   converted.typeArguments(newBounds);
   return converted;
 }