예제 #1
0
  static void objectArgument(final Tree.ObjectArgument that, final GenerateJsVisitor gen) {
    final Class c = (Class) that.getDeclarationModel().getTypeDeclaration();

    gen.out("(function()");
    gen.beginBlock();
    gen.out("//ObjectArgument ", that.getIdentifier().getText());
    gen.location(that);
    gen.endLine();
    gen.out(GenerateJsVisitor.function, gen.getNames().name(c), "()");
    gen.beginBlock();
    gen.instantiateSelf(c);
    gen.referenceOuter(c);
    Tree.ExtendedType xt = that.getExtendedType();
    final Tree.ClassBody body = that.getClassBody();
    final Tree.SatisfiedTypes sts = that.getSatisfiedTypes();

    final List<Declaration> superDecs = new ArrayList<Declaration>(3);
    if (!gen.opts.isOptimize()) {
      new GenerateJsVisitor.SuperVisitor(superDecs).visit(that.getClassBody());
    }
    TypeGenerator.callSupertypes(
        sts == null ? null : TypeUtils.getTypes(sts.getTypes()),
        xt == null ? null : xt.getType(),
        c,
        that,
        superDecs,
        xt == null ? null : xt.getInvocationExpression(),
        xt == null ? null : c.getParameterList(),
        gen);

    body.visit(gen);
    gen.out("return ", gen.getNames().self(c), ";");
    gen.endBlock(false, true);
    // Add reference to metamodel
    gen.out(gen.getNames().name(c), ".$crtmm$=");
    TypeUtils.encodeForRuntime(that, c, gen);
    gen.endLine(true);

    TypeGenerator.typeInitialization(
        xt,
        sts,
        c,
        new GenerateJsVisitor.PrototypeInitCallback() {
          @Override
          public void addToPrototypeCallback() {
            gen.addToPrototype(that, c, body.getStatements());
          }
        },
        gen,
        null,
        null);
    gen.out("return ", gen.getNames().name(c), "(new ", gen.getNames().name(c), ".$$);");
    gen.endBlock();
    gen.out("())");
  }
예제 #2
0
  @Override
  public void visit(Tree.ClassBody that) {
    if (that.getScope() == declaration.getContainer()) {
      Tree.Statement les = getLastExecutableStatement(that);
      Tree.Declaration lc = getLastConstructor(that);
      declarationSection = les == null;
      lastExecutableStatement = les;
      lastConstructor = lc;
      super.visit(that);
      declarationSection = false;
      lastExecutableStatement = null;
      lastConstructor = null;

      if (!declaration.isAnonymous()) {
        if (isSharedDeclarationUninitialized()) {
          getDeclaration(that)
              .addError(
                  "must be definitely specified by class initializer: "
                      + message(declaration)
                      + " is shared",
                  1401);
        }
      }
    } else {
      super.visit(that);
    }
  }
예제 #3
0
 private Tree.Declaration getDeclaration(Tree.ClassBody that) {
   for (Tree.Statement s : that.getStatements()) {
     if (s instanceof Tree.Declaration) {
       Tree.Declaration d = (Tree.Declaration) s;
       if (d.getDeclarationModel() == declaration) {
         return d;
       }
     }
   }
   return null;
 }