Examples of JNewInstance


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

            throw new UnableToCompleteException();
          }

          // Construct a new instance of the class to qualify the non-static
          // call
          JNewInstance newInstance = new JNewInstance(program, null, mainClass);
          qualifier = new JMethodCall(program, null, newInstance, noArgCtor);
        }
      }

      // qualifier will be null if onModuleLoad is static
View Full Code Here

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

      // Define the method
      JMethod synthetic = program.createMethod(null, "new".toCharArray(), type,
          type, false, true, true, false, false);

      // new Foo() : Create the instance
      JNewInstance newInstance = new JNewInstance(program, null, type);

      // (new Foo()).Foo() : Invoke the constructor method on the instance
      JMethodCall call = new JMethodCall(program, null, newInstance,
          constructor);
      List<JExpression> args = call.getArgs();
View Full Code Here

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

          throw new InternalCompilerException(
              "String constructor error; no matching implementation.");
        }
        call = new JMethodCall(program, makeSourceInfo(x), null, targetMethod);
      } else {
        JNewInstance newInstance = new JNewInstance(program, info, newType);
        call = new JMethodCall(program, info, newInstance, ctor);
      }

      // Enums: hidden arguments for the name and id.
      if (x.enumConstant != null) {
View Full Code Here

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

      SourceInfo info = makeSourceInfo(x);
      MethodBinding b = x.binding;
      JMethod ctor = (JMethod) typeMap.get(b);
      JClassType enclosingType = (JClassType) ctor.getEnclosingType();
      JNewInstance newInstance = new JNewInstance(program, info, enclosingType);
      JMethodCall call = new JMethodCall(program, info, newInstance, ctor);
      JExpression qualifier = dispProcessExpression(x.enclosingInstance);
      List<JExpression> qualList = new ArrayList<JExpression>();
      qualList.add(qualifier);
View Full Code Here

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

            }
          }
        }
        assert (noArgCtor != null);
        // Call it, using a new expression as a qualifier
        JNewInstance newInstance = new JNewInstance(program, x.getSourceInfo(),
            classType);
        JMethodCall call = new JMethodCall(program, x.getSourceInfo(),
            newInstance, noArgCtor);
        ctx.replaceMe(call);
      }
View Full Code Here

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

    return false;
  }

  @Override
  public boolean visit(JNewInstance x, Context ctx) {
    expression = new JNewInstance(program, x.getSourceInfo(), x.getClassType());
    return false;
  }
View Full Code Here

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

    return false;
  }

  @Override
  public boolean visit(JNewInstance x, Context ctx) {
    JNewInstance newInstance = new JNewInstance(x);
    newInstance.addArgs(cloneExpressions(x.getArgs()));
    expression = newInstance;
    return false;
  }
View Full Code Here

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

    return false;
  }

  @Override
  public boolean visit(JNewInstance x, Context ctx) {
    expression = new JNewInstance(program, x.getSourceInfo(), x.getClassType());
    return false;
  }
View Full Code Here

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

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

      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();
      boolean isNested = JdtUtil.isInnerClass(targetBinding);
      if (isNested) {
        // Synthetic this args for inner classes
        if (targetBinding.syntheticEnclosingInstanceTypes() != null) {
          ReferenceBinding checkedTargetType =
              targetBinding.isAnonymousType() ? (ReferenceBinding) targetBinding.superclass()
                  .erasure() : targetBinding;
          ReferenceBinding targetEnclosingType = checkedTargetType.enclosingType();
          for (ReferenceBinding argType : targetBinding.syntheticEnclosingInstanceTypes()) {
            argType = (ReferenceBinding) argType.erasure();
            if (qualifier != null && argType == targetEnclosingType) {
              call.addArg(qualExpr);
            } else {
              JExpression thisRef = makeThisReference(info, argType, false, scope);
              call.addArg(thisRef);
            }
          }
        }
      }

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

      // Synthetic args for inner classes
      if (isNested) {
        // Synthetic locals for local classes
        if (targetBinding.syntheticOuterLocalVariables() != null) {
          for (SyntheticArgumentBinding arg : targetBinding.syntheticOuterLocalVariables()) {
            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
         *
         * TODO(scottb): consider moving this to a later pass.
         */
        MethodBinding staticBinding =
            targetBinding.getExactMethod(_STRING, b.parameters, curCud.scope);
        assert staticBinding.isStatic();
        JMethod staticMethod = typeMap.get(staticBinding);
        JMethodCall newCall = new JMethodCall(info, null, staticMethod);
        newCall.addArgs(call.getArgs());
        call = newCall;
      }

      push(call);
    }
View Full Code Here

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

    @Override public void endVisit(JNewInstance x, Context ctx) {
      JConstructor target = x.getTarget();
      JClassType enclosingType = target.getEnclosingType();
      if (enclosingType.isEnumOrSubclass() != null) {
        if (!typeInBlacklist(blacklistedEnums, enclosingType)) {
          JNewInstance newEnum = new JNewInstance(x);
          // replace first argument with null
          List<JExpression> args = new ArrayList<JExpression>(x.getArgs());
          if (closureMode) {
            JMethodCall makeEnum = new JMethodCall(x.getSourceInfo(), null, makeEnumName, args.get(0));
            args.set(0, makeEnum);
          } else {
            args.set(0, JNullLiteral.INSTANCE);
          }
          newEnum.addArgs(args);
          ctx.replaceMe(newEnum);
        }
      }
    }
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.