Examples of JConstructor


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

    sourceTypes.put(key, type);
  }

  JMethod createConstructor(SourceInfo info, MethodBinding b) {
    JDeclaredType enclosingType = (JDeclaredType) get(b.declaringClass);
    JMethod method = new JConstructor(info, (JClassType) enclosingType);
    enclosingType.addMethod(method);

    /*
     * Don't need to synthesize enum intrinsic args because enum ctors can only
     * be called locally.
     */

    int argPosition = 0;

    ReferenceBinding declaringClass = b.declaringClass;
    if (declaringClass.isNestedType() && !declaringClass.isStatic()) {
      // add synthetic args for outer this
      if (declaringClass.syntheticEnclosingInstanceTypes() != null) {
        for (ReferenceBinding argType : declaringClass.syntheticEnclosingInstanceTypes()) {
          createParameter(info, argType, method, argPosition++);
        }
      }
    }

    // User args.
    argPosition = mapParameters(info, method, b, argPosition);

    if (declaringClass.isNestedType() && !declaringClass.isStatic()) {
      // add synthetic args for locals
      if (declaringClass.syntheticOuterLocalVariables() != null) {
        for (SyntheticArgumentBinding arg : declaringClass.syntheticOuterLocalVariables()) {
          createParameter(info, arg.type, method, argPosition++);
        }
      }
    }

    mapExceptions(method, b);
    if (b.isSynthetic()) {
      method.setSynthetic();
    }
    return method;
  }
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

     * The order of emulation is: - assign all synthetic fields from synthetic
     * args - call our super constructor emulation method - call our instance
     * initializer emulation method - run user code
     */
    void processConstructor(ConstructorDeclaration x) {
      JConstructor ctor = (JConstructor) typeMap.get(x.binding);
      try {
        processHasAnnotations(ctor, x.annotations);
        SourceInfo info = ctor.getSourceInfo();

        currentMethod = ctor;
        currentMethodBody = ctor.getBody();
        currentMethodScope = x.scope;

        /*
         * Determine if we have an explicit this call. The presence of an
         * explicit this call indicates we can skip certain initialization steps
         * (as the callee will perform those steps for us). These skippable
         * steps are 1) assigning synthetic args to fields and 2) running
         * initializers.
         */
        boolean hasExplicitThis = (x.constructorCall != null)
            && !x.constructorCall.isSuperAccess();

        JClassType enclosingType = ctor.getEnclosingType();
        JBlock block = currentMethodBody.getBlock();
        currentOuterThisRefParams = Maps.create();

        /*
         * All synthetic fields must be assigned, unless we have an explicit
         * this constructor call, in which case the callee will assign them for
         * us.
         */
        ReferenceBinding declaringClass = x.binding.declaringClass;
        if (declaringClass instanceof NestedTypeBinding) {
          Iterator<JParameter> paramIt = currentMethod.getParams().iterator();
          NestedTypeBinding nestedBinding = (NestedTypeBinding) declaringClass;
          if (nestedBinding.enclosingInstances != null) {
            for (SyntheticArgumentBinding arg : nestedBinding.enclosingInstances) {
              JParameter param = paramIt.next();
              JField field = (JField) typeMap.get(arg);
              if (!hasExplicitThis) {
                block.addStmt(JProgram.createAssignmentStmt(info,
                    createVariableRef(info, field),
                    createVariableRef(info, param)));
              }
              currentOuterThisRefParams = Maps.put(currentOuterThisRefParams,
                  field, param);
            }
          }

          if (!hasExplicitThis) {
            paramIt = getSyntheticLocalsIterator();
            if (nestedBinding.outerLocalVariables != null) {
              for (SyntheticArgumentBinding arg : nestedBinding.outerLocalVariables) {
                JParameter param = paramIt.next();
                JField field = (JField) typeMap.get(arg);
                block.addStmt(JProgram.createAssignmentStmt(info,
                    createVariableRef(info, field),
                    createVariableRef(info, param)));
              }
            }
          }
        }

        // optional this or super constructor call
        if (x.constructorCall != null) {
          JMethodCall superOrThisCall = (JMethodCall) dispatch(
              "processExpression", x.constructorCall);
          // Enums: wire up synthetic name/ordinal params to the super method.
          if (enclosingType.isEnumOrSubclass() != null) {
            JVariableRef enumNameRef = createVariableRef(
                superOrThisCall.getSourceInfo(), ctor.getParams().get(0));
            superOrThisCall.addArg(0, enumNameRef);
            JVariableRef enumOrdinalRef = createVariableRef(
                superOrThisCall.getSourceInfo(), ctor.getParams().get(1));
            superOrThisCall.addArg(1, enumOrdinalRef);
          }

          superOrThisCall.setStaticDispatchOnly();
          block.addStmt(superOrThisCall.makeStatement());
View Full Code Here

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

         */
        return program.getLiteralNull();
      }
      JClassType newType = (JClassType) typeMap.get(typeBinding);
      MethodBinding b = x.binding;
      JConstructor ctor = (JConstructor) typeMap.get(b);
      JMethodCall call;
      JClassType javaLangString = program.getTypeJavaLangString();
      if (newType == javaLangString && !newType.isExternal()) {
        /*
         * 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
         */
        int ctorArgc = ctor.getParams().size();
        JMethod targetMethod = null;
        outer : for (JMethod method : javaLangString.getMethods()) {
          if (method.getName().equals("_String")
              && method.getParams().size() == ctorArgc) {
            for (int i = 0; i < ctorArgc; ++i) {
              JParameter mparam = method.getParams().get(i);
              JParameter cparam = ctor.getParams().get(i);
              if (mparam.getType() != cparam.getType()) {
                continue outer;
              }
            }
            targetMethod = method;
View Full Code Here

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

        return processExpression((AllocationExpression) x);
      }

      SourceInfo info = makeSourceInfo(x);
      MethodBinding b = x.binding;
      JConstructor ctor = (JConstructor) typeMap.get(b);
      JNewInstance newInstance = new JNewInstance(info, ctor, currentClass);
      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.JConstructor

              if (x == dontReplaceCtor) {
                // Do nothing, parent will handle.
              } else {
                // Replace with a local closure function.
                // function(a,b,c){return new Obj(a,b,c);}
                JConstructor ctor = (JConstructor) node;
                JsName jsName = names.get(ctor);
                assert (jsName != null);
                x.resolve(jsName);
                SourceInfo info = x.getSourceInfo();
                JsFunction closureFunc = new JsFunction(info, jsFunc.getScope());
                for (JParameter p : ctor.getParams()) {
                  JsName name = closureFunc.getScope().declareName(p.getName());
                  closureFunc.getParameters().add(new JsParameter(info, name));
                }
                JsNew jsNew = new JsNew(info, x);
                for (JsParameter p : closureFunc.getParameters()) {
View Full Code Here

Examples of org.codehaus.modello.plugin.java.javasource.JConstructor

      instance.getModifiers().setFinal(true);
      instance.getModifiers().setStatic(true);
      instance.getModifiers().makePublic();
      instance.setInitString("new "+libraryClass.getName(true) +"()");
      libraryClass.addField(instance);
      JConstructor constructor = libraryClass.createConstructor();
      constructor.getSourceCode().add("super(NAMESPACE);");

      for (InterfaceDeclaration decl : getCollectedInterfaceDeclarations()) {
        if (decl.getPackage().equals(packageDeclaration)) {
          appendComponent(constructor, decl, tagSet);
        }
View Full Code Here

Examples of org.codehaus.modello.plugin.java.javasource.JConstructor

      instance.getModifiers().setFinal(true);
      instance.getModifiers().setStatic(true);
      instance.getModifiers().makePublic();
      instance.setInitString("new "+libraryClass.getName(true) +"()");
      libraryClass.addField(instance);
      JConstructor constructor = libraryClass.createConstructor();
      constructor.getSourceCode().add("super(NAMESPACE);");

      for (InterfaceDeclaration decl : getCollectedInterfaceDeclarations()) {
        if (decl.getPackage().equals(packageDeclaration)) {
          appendComponent(constructor, decl, tagSet);
        }
View Full Code Here

Examples of org.exolab.javasource.JConstructor

        String descriptorClassName = getQualifiedDescriptorClassName(jClass.getName());
        DescriptorJClass classDesc = new DescriptorJClass(_config, descriptorClassName, jClass);

        //-- get handle to default constuctor
        JConstructor cons = classDesc.getConstructor(0);
        JSourceCode jsc   = cons.getSourceCode();
        XMLInfoNature xmlNature = new XMLInfoNature(classInfo);

        //-- Set namespace prefix
        String nsPrefix = xmlNature.getNamespacePrefix();
        if ((nsPrefix != null) && (nsPrefix.length() > 0)) {
View Full Code Here

Examples of org.exolab.javasource.JConstructor

     * Adds our default constructor.
     * @param extended true if we extend another class and thus need to call super()
     */
    private void addDefaultConstructor(final boolean extended) {
        addConstructor(createConstructor());
        JConstructor cons = getConstructor(0);
        JSourceCode jsc = cons.getSourceCode();
        jsc.add("super();");

        if (extended) {
            //-- add base class (for validation)
            jsc.add("setExtendsWithoutFlatten(");
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.