Examples of JConstructor


Examples of com.google.gwt.dev.jjs.ast.JConstructor

      String lastProvidedNamespace = "";
      boolean createdClinit = false;

      // export 1 constructor
      JConstructor ctor = null;
      for (JMethod m : x.getMethods()) {
        if (m instanceof JConstructor) {
          if (!((JConstructor) m).isDefaultConstructor()
              && typeOracle.isExportedMethod(m)) {
            ctor = (JConstructor) m;
View Full Code Here

Examples of com.google.gwt.dev.jjs.ast.JConstructor

  }

  @Override
  public boolean visit(JNewInstance x, Context ctx) {
    print(CHARS_NEW);
    JConstructor target = x.getTarget();
    printName(target);
    lparen();
    visitCollectionWithCommas(x.getArgs().iterator());
    rparen();
    return false;
View Full Code Here

Examples of com.google.gwt.dev.jjs.ast.JConstructor

    @Override
    public void endVisit(JExpressionStatement x, Context ctx) {
      if (x.getExpr() instanceof JMethodCall && !(x.getExpr() instanceof JNewInstance)) {
        JMethodCall call = (JMethodCall) x.getExpr();
        if (call.getTarget() instanceof JConstructor) {
          JConstructor ctor = (JConstructor) call.getTarget();
          if (program.isJsTypePrototype(ctor.getEnclosingType())) {
            // don't remove calls to JsType super-constructors;
            return;
          }
          if (ctor.isEmpty()) {
            // TODO: move this 3-way into Simplifier.
            if (call.getArgs().isEmpty()) {
              ctx.removeMe();
            } else if (call.getArgs().size() == 1) {
              ctx.replaceMe(call.getArgs().get(0).makeStatement());
View Full Code Here

Examples of com.google.gwt.dev.jjs.ast.JConstructor

  }

  private JConstructor processConstructor(MethodBinding b,
      ConstructorDeclaration decl, SourceInfo info) {
    JClassType enclosingType = (JClassType) getType(b.declaringClass);
    JConstructor newCtor = program.createConstructor(info, enclosingType);

    // Enums have hidden arguments for name and value
    if (enclosingType.isEnumOrSubclass() != null) {
      JProgram.createParameter(info, "enum$name",
          program.getTypeJavaLangString(), true, false, newCtor);
      JProgram.createParameter(info, "enum$ordinal",
          program.getTypePrimitiveInt(), true, false, newCtor);
    }

    ReferenceBinding declaringClass = b.declaringClass;
    Set<String> alreadyNamedVariables = new HashSet<String>();
    if (declaringClass.isNestedType() && !declaringClass.isStatic()) {
      // TODO(tobyr) Do we have to do the equivalent for binary types here
      // or will this just fall out correctly?

      // add synthetic args for outer this
      NestedTypeBinding nestedBinding = (NestedTypeBinding) declaringClass;
      if (nestedBinding.enclosingInstances != null) {
        for (int i = 0; i < nestedBinding.enclosingInstances.length; ++i) {
          SyntheticArgumentBinding arg = nestedBinding.enclosingInstances[i];
          String argName = String.valueOf(arg.name);
          if (alreadyNamedVariables.contains(argName)) {
            argName += "_" + i;
          }
          createParameter(arg, argName, newCtor);
          alreadyNamedVariables.add(argName);
        }
      }
    }

    // user args
    if (decl == null) {
      mapParameters(newCtor, b, info);
    } else {
      mapParameters(newCtor, decl, info);
    }
    // original params are now frozen

    addThrownExceptions(b, newCtor);

    info.addCorrelation(info.getCorrelator().by(newCtor));

    if (declaringClass.isNestedType() && !declaringClass.isStatic()) {
      // add synthetic args for locals
      NestedTypeBinding nestedBinding = (NestedTypeBinding) declaringClass;
      // add synthetic args for outer this and locals
      if (nestedBinding.outerLocalVariables != null) {
        for (int i = 0; i < nestedBinding.outerLocalVariables.length; ++i) {
          SyntheticArgumentBinding arg = nestedBinding.outerLocalVariables[i];
          String argName = String.valueOf(arg.name);
          if (alreadyNamedVariables.contains(argName)) {
            argName += "_" + i;
          }
          createParameter(arg, argName, newCtor);
          alreadyNamedVariables.add(argName);
        }
      }
    }

    if (enclosingType.isExternal()) {
      newCtor.setBody(null);
    }

    typeMap.put(b, newCtor);
    return newCtor;
  }
View Full Code Here

Examples of com.google.gwt.dev.jjs.ast.JConstructor

    @Override
    public void endVisit(ExplicitConstructorCall x, BlockScope scope) {
      try {
        SourceInfo info = makeSourceInfo(x);
        JConstructor ctor = (JConstructor) typeMap.get(x.binding);
        JExpression trueQualifier = makeThisRef(info);
        JMethodCall call = new JMethodCall(info, trueQualifier, ctor);
        List<JExpression> callArgs = popCallArgs(x.arguments, x.binding);

        if (curClass.classType.isEnumOrSubclass() != null) {
View Full Code Here

Examples of com.google.gwt.dev.jjs.ast.JConstructor

    }

    @Override
    public boolean visit(ConstructorDeclaration x, ClassScope scope) {
      try {
        JConstructor method = (JConstructor) typeMap.get(x.binding);
        assert !method.getEnclosingType().isExternal();
        JMethodBody body = new JMethodBody(method.getSourceInfo());
        method.setBody(body);
        pushMethodInfo(new MethodInfo(method, body, x.scope));

        // Map all arguments.
        Iterator<JParameter> it = method.getParams().iterator();

        // Enum arguments have no mapping.
        if (curClass.classType.isEnumOrSubclass() != null) {
          // Skip past name and ordinal.
          it.next();
View Full Code Here

Examples of com.google.gwt.dev.jjs.ast.JConstructor

      assert typeBinding.isClass() || typeBinding.isEnum();

      SourceInfo info = makeSourceInfo(x);
      MethodBinding b = x.binding;
      assert b.isConstructor();
      JConstructor ctor = (JConstructor) typeMap.get(b);
      JMethodCall call = new JNewInstance(info, ctor, curClass.type);
      JExpression qualExpr = pop(qualifier);

      // Enums: hidden arguments for the name and id.
      if (x.enumConstant != null) {
        call.addArgs(getStringLiteral(info, x.enumConstant.name), JIntLiteral
            .get(x.enumConstant.binding.original().id));
      }

      // Synthetic args for inner classes
      ReferenceBinding targetBinding = (ReferenceBinding) b.declaringClass.erasure();
      NestedTypeBinding nestedBinding = null;
      if (targetBinding.isNestedType() && !targetBinding.isStatic()) {
        nestedBinding = (NestedTypeBinding) targetBinding;
      }
      if (nestedBinding != null) {
        // Synthetic this args for inner classes
        if (nestedBinding.enclosingInstances != null) {
          ReferenceBinding checkedTargetType =
              targetBinding.isAnonymousType() ? (ReferenceBinding) targetBinding.superclass()
                  .erasure() : targetBinding;
          ReferenceBinding targetEnclosingType = checkedTargetType.enclosingType();
          for (SyntheticArgumentBinding arg : nestedBinding.enclosingInstances) {
            TypeBinding argType = arg.type.erasure();
            if (qualifier != null && argType == targetEnclosingType) {
              call.addArg(qualExpr);
            } else {
              JExpression thisRef =
                  makeThisReference(info, (ReferenceBinding) argType, false, scope);
              call.addArg(thisRef);
            }
          }
        }
      }

      // Plain old regular user arguments
      call.addArgs(arguments);

      // Synthetic args for inner classes
      if (nestedBinding != null) {
        // Synthetic locals for local classes
        if (nestedBinding.outerLocalVariables != null) {
          for (SyntheticArgumentBinding arg : nestedBinding.outerLocalVariables) {
            LocalVariableBinding targetVariable = arg.actualOuterLocalVariable;
            VariableBinding[] path = scope.getEmulationPath(targetVariable);
            assert path.length == 1;
            if (curMethod.scope.isInsideInitializer()
                && path[0] instanceof SyntheticArgumentBinding) {
              SyntheticArgumentBinding sb = (SyntheticArgumentBinding) path[0];
              JField field = curClass.syntheticFields.get(sb);
              assert field != null;
              call.addArg(makeInstanceFieldRef(info, field));
            } else if (path[0] instanceof LocalVariableBinding) {
              JExpression localRef = makeLocalRef(info, (LocalVariableBinding) path[0]);
              call.addArg(localRef);
            } else if (path[0] instanceof FieldBinding) {
              JField field = typeMap.get((FieldBinding) path[0]);
              assert field != null;
              call.addArg(makeInstanceFieldRef(info, field));
            } else {
              throw new InternalCompilerException("Unknown emulation path.");
            }
          }
        }
      }

      if (ctor.getEnclosingType() == javaLangString) {
        /*
         * MAGIC: java.lang.String is implemented as a JavaScript String
         * primitive with a modified prototype. This requires funky handling of
         * constructor calls. We find a method named _String() whose signature
         * matches the requested constructor
View Full Code Here

Examples of com.google.gwt.dev.jjs.ast.JConstructor

    Set<String> alreadyNamedVariables = new HashSet<String>();
    JDeclaredType enclosingType = (JDeclaredType) typeMap.get(declaringClass);
    assert !enclosingType.isExternal();
    JMethod method;
    if (x.isConstructor()) {
      method = new JConstructor(info, (JClassType) enclosingType);
      if (x.binding.declaringClass.isEnum()) {
        // Enums have hidden arguments for name and value
        method.addParam(new JParameter(info, "enum$name", typeMap.get(x.scope.getJavaLangString()),
            true, false, method));
        method.addParam(new JParameter(info, "enum$ordinal", JPrimitiveType.INT, true, false,
View Full Code Here

Examples of com.google.gwt.dev.jjs.ast.JConstructor

          assert "_".equals(lhs.getIdent());
        } else {
          // A constructor function is being assigned to.
          assert "prototype".equals(lhs.getIdent());
          JsNameRef ctorRef = (JsNameRef) lhs.getQualifier();
          JConstructor ctor = (JConstructor) map.nameToMethod(ctorRef.getName());
          assert ctor != null;
          if (livenessPredicate.isLive(ctor)
              && !alreadyLoadedPredicate.isLive(ctor)) {
            anyLiveCode[0] = true;
          } else {
View Full Code Here

Examples of com.google.gwt.dev.jjs.ast.JConstructor

        rescue(param);
      }
      // JsniMethodRef rescues as a JMethodCall
      if (x.getTarget() instanceof JConstructor) {
        // But if a constructor is targeted, there is an implicit 'new' op.
        JConstructor ctor = (JConstructor) x.getTarget();
        rescueAndInstantiate(ctor.getEnclosingType());
      }
      return visit((JMethodCall) x, ctx);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.