Esempio n. 1
0
  ClassElement makeListElement() {
    final TypeVariable typeVar = typeVar("E", itype(object));
    final ClassElement element = element("List", itype(object), typeVar);
    DartTypeNode returnTypeNode =
        new DartTypeNode(
            new DartIdentifier("Iterator"),
            Arrays.asList(new DartTypeNode(new DartIdentifier("E"))));

    DartMethodDefinition iteratorMethod =
        DartMethodDefinition.create(
            new DartIdentifier("iterator"),
            new DartFunction(
                Collections.<DartParameter>emptyList(),
                new DartBlock(Collections.<DartStatement>emptyList()),
                returnTypeNode),
            Modifiers.NONE,
            Collections.<DartInitializer>emptyList());
    MethodNodeElement iteratorMethodElement =
        Elements.methodFromMethodNode(iteratorMethod, element);
    Type returnType = Types.interfaceType(iterElement, Arrays.<Type>asList(typeVar));
    FunctionType functionType =
        ftype(function, returnType, Collections.<String, Type>emptyMap(), null);
    Elements.setType(iteratorMethodElement, functionType);
    Elements.addMethod(element, iteratorMethodElement);
    return element;
  }
Esempio n. 2
0
  /** Add runtime type information to a "new" expression, if necessary. */
  void mayAddRuntimeTypeToConstrutorOrFactoryCall(
      ClassElement enclosingClass, DartNewExpression x, JsInvocation invoke) {
    // TODO(johnlenz):in optimized mode, only add this where it is needed.

    InterfaceType instanceType = Types.constructorType(x);
    if (instanceType == null) {
      // TODO(johnlenz): HackHack. Currently the "new FallThroughError" injected by the
      // Normalizer does not have the instance type attached. But in this
      // case we know it does not have any type parameters.
      // reportError(x.getParent().getParent(), new AssertionError("missing type information"));
      assert typeProvider
          .getFallThroughError()
          .getElement()
          .lookupConstructor("")
          .equals(x.getSymbol());
    } else if (constructorHasTypeParameters(x)) {
      ConstructorElement constructor = x.getSymbol();
      ClassElement containingClassElement = enclosingClass;
      if (constructor.getModifiers().isFactory()) {
        // We are calling a factory, this is either in a class
        FunctionType functionType = (FunctionType) constructor.getType();
        JsExpression typeArgs =
            generateTypeArgsArrayForFactory(functionType, instanceType, containingClassElement);
        assert typeArgs != null;
        invoke.getArguments().add(0, typeArgs);
      } else {
        ClassElement constructorClassElement = constructor.getConstructorType();
        invoke
            .getArguments()
            .add(
                0,
                generateRTTLookup(constructorClassElement, instanceType, containingClassElement));
      }
    }
  }
Esempio n. 3
0
 private boolean constructorHasTypeParameters(DartNewExpression x) {
   ConstructorElement element = x.getSymbol();
   if (element.getModifiers().isFactory()) {
     return isParameterizedFactoryMethod((DartMethodDefinition) element.getNode());
   } else {
     InterfaceType instanceType = Types.constructorType(x);
     return hasTypeParameters(instanceType.getElement());
   }
 }