Package com.sun.codemodel

Examples of com.sun.codemodel.JInvocation


          ifOut._else().assign(outputContainer.getValue(), JExpr.lit(0));
          return outputContainer;
        }
      } else {

        final JInvocation setMeth = GetSetVectorHelper.write(e.getChild().getMajorType(), vv, inputContainer, outIndex, e.isSafe() ? "setSafe" : "set");
        final String isSafeMethod = "isSafe";

        if (e.isSafe()) {
          HoldingContainer outputContainer = generator.declare(Types.REQUIRED_BIT);
          block.assign(outputContainer.getValue(), JExpr.lit(1));
          if (inputContainer.isOptional()) {
            // block._if(vv.invoke("getMutator").invoke(setMethod).arg(outIndex).not())._then().assign(outputContainer.getValue(),
            // JExpr.lit(0));
            JConditional jc = block._if(inputContainer.getIsSet().eq(JExpr.lit(0)).not());
            block = jc._then();
            jc._else()._if(vv.invoke("getMutator").invoke(isSafeMethod).arg(outIndex).not())._then()
                .assign(outputContainer.getValue(), JExpr.lit(0));
          }
          block._if(setMeth.not())._then().assign(outputContainer.getValue(), JExpr.lit(0));
          return outputContainer;
        } else {
          if (inputContainer.isOptional()) {
            // block.add(vv.invoke("getMutator").invoke(setMethod).arg(outIndex));
            JConditional jc = block._if(inputContainer.getIsSet().eq(JExpr.lit(0)).not());
View Full Code Here


  // eval.add(getValueAccessor.arg(indexVariable).arg(out.getHolder()));

  public static void read(MajorType type, JExpression vector, JBlock eval, HoldingContainer out, JCodeModel model,
      JExpression indexVariable) {

    JInvocation getValueAccessor = vector.invoke("getAccessor");

    switch(type.getMode()){
    case OPTIONAL:
      eval.assign(out.getIsSet(), getValueAccessor.invoke("isSet").arg(indexVariable));
      eval = eval._if(out.getIsSet().eq(JExpr.lit(1)))._then();

    // fall through
    case REQUIRED:
      switch (type.getMinorType()) {
      case BIGINT:
      case FLOAT4:
      case FLOAT8:
      case INT:
      case MONEY:
      case SMALLINT:
      case TINYINT:
      case UINT1:
      case UINT2:
      case UINT4:
      case UINT8:
      case INTERVALYEAR:
      case DATE:
      case TIME:
      case TIMESTAMP:
      case BIT:
        eval.assign(out.getValue(), getValueAccessor.invoke("get").arg(indexVariable));
        return;
      case DECIMAL9:
      case DECIMAL18:
        eval.assign(out.getHolder().ref("scale"), vector.invoke("getField").invoke("getScale"));
        eval.assign(out.getHolder().ref("precision"), vector.invoke("getField").invoke("getPrecision"));
        eval.assign(out.getValue(), getValueAccessor.invoke("get").arg(indexVariable));
        return;
      case DECIMAL28DENSE:
      case DECIMAL28SPARSE:
      case DECIMAL38DENSE:
      case DECIMAL38SPARSE:
        eval.assign(out.getHolder().ref("scale"), vector.invoke("getField").invoke("getScale"));
        eval.assign(out.getHolder().ref("precision"), vector.invoke("getField").invoke("getPrecision"));
        eval.assign(out.getHolder().ref("start"), JExpr.lit(TypeHelper.getSize(type)).mul(indexVariable));
        eval.assign(out.getHolder().ref("buffer"), vector.invoke("getData"));
        return;
      case INTERVAL:{
        JVar start = eval.decl(model.INT, "start", JExpr.lit(TypeHelper.getSize(type)).mul(indexVariable));
        JVar data = eval.decl(model.ref(DrillBuf.class), "data", vector.invoke("getData"));
        eval.assign(out.getHolder().ref("months"), data.invoke("getInt").arg(start));
        eval.assign(out.getHolder().ref("days"), data.invoke("getInt").arg(start.plus(JExpr.lit(4))));
        eval.assign(out.getHolder().ref("milliseconds"), data.invoke("getInt").arg(start.plus(JExpr.lit(8))));
        return;
      }
      case INTERVALDAY: {
        JVar start = eval.decl(model.INT, "start", JExpr.lit(TypeHelper.getSize(type)).mul(indexVariable));
        eval.assign(out.getHolder().ref("days"), vector.invoke("getData").invoke("getInt").arg(start));
        eval.assign(out.getHolder().ref("milliseconds"), vector.invoke("getData").invoke("getInt").arg(start.plus(JExpr.lit(4))));
        return;
      }
      case VAR16CHAR:
      case VARBINARY:
      case VARCHAR:
         eval.assign(out.getHolder().ref("buffer"), vector.invoke("getData"));
         JVar se = eval.decl(model.LONG, "startEnd", getValueAccessor.invoke("getStartEnd").arg(indexVariable));
         eval.assign(out.getHolder().ref("start"), JExpr.cast(model._ref(int.class), se));
         eval.assign(out.getHolder().ref("end"), JExpr.cast(model._ref(int.class), se.shr(JExpr.lit(32))));
        return;

      }
    }

    // fallback.
    eval.add(getValueAccessor.invoke("get").arg(indexVariable).arg(out.getHolder()));
  }
View Full Code Here

    eval.add(getValueAccessor.invoke("get").arg(indexVariable).arg(out.getHolder()));
  }

  public static JInvocation write(MajorType type, JVar vector, HoldingContainer in, JExpression indexVariable, String setMethodName) {

    JInvocation setMethod = vector.invoke("getMutator").invoke(setMethodName).arg(indexVariable);

    switch(type.getMode()){
    case OPTIONAL:
      setMethod = setMethod.arg(in.f("isSet"));
    case REQUIRED:
      switch (type.getMinorType()) {
      case BIGINT:
      case FLOAT4:
      case FLOAT8:
      case INT:
      case MONEY:
      case SMALLINT:
      case TINYINT:
      case UINT1:
      case UINT2:
      case UINT4:
      case UINT8:
      case INTERVALYEAR:
      case DATE:
      case TIME:
      case TIMESTAMP:
      case BIT:
      case DECIMAL9:
      case DECIMAL18:
        return setMethod //
            .arg(in.getValue());
      case DECIMAL28DENSE:
      case DECIMAL28SPARSE:
      case DECIMAL38DENSE:
      case DECIMAL38SPARSE:
        return setMethod //
            .arg(in.f("start")) //
            .arg(in.f("buffer"));
      case INTERVAL:{
        return setMethod //
            .arg(in.f("months")) //
            .arg(in.f("days")) //
            .arg(in.f("milliseconds"));
      }
      case INTERVALDAY: {
        return setMethod //
            .arg(in.f("days")) //
            .arg(in.f("milliseconds"));
      }
      case VAR16CHAR:
      case VARBINARY:
      case VARCHAR:
        return setMethod //
            .arg(in.f("start")) //
            .arg(in.f("end")) //
            .arg(in.f("buffer"));
      }
    }


    return setMethod.arg(in.getHolder());

  }
View Full Code Here

        String serviceName = serviceFieldName + "_QNAME";
        cls.field(JMod.PRIVATE | JMod.STATIC | JMod.FINAL, QName.class, serviceName,
            JExpr._new(cm.ref(QName.class)).arg(service.getName().getNamespaceURI()).arg(service.getName().getLocalPart()));

        JClass qNameCls = cm.ref(QName.class);
        JInvocation inv;
        inv = JExpr._new(qNameCls);
        inv.arg("namespace");
        inv.arg("localpart");

        if (wsdlLocation.startsWith("http://") || wsdlLocation.startsWith("file:/")) {
            writeAbsWSDLLocation(cls, urlField, exField);
        } else {
            writeResourceWSDLLocation(className, cls, urlField, exField);
View Full Code Here

      method.annotate(xmlElementDeclModelClass).param("namespace", info.namespace).param("name", info.name)
                  .param("scope", targetClass);

      // FIXME: Make a try to load constants and (a) rename it appropriately (b) use it?
      JInvocation qname = JExpr._new(codeModel.ref(QName.class)).arg(info.namespace).arg(info.name);

      method.body()._return(
                  JExpr._new(wrapperType).arg(qname).arg(info.type.boxify().dotclass())
                              .arg(targetClass.dotclass()).arg(method.param(info.type, "value")));
View Full Code Here

  public JInvocation createAddToSerializeToExpression( @NotNull AbstractGenerator<?> generator, @NotNull JDefinedClass serializerClass, @NotNull JExpression serializeTo, @NotNull FieldDeclarationInfo fieldInfo, @NotNull JVar object, JVar formatVersion ) {
    generator.addDelegatingSerializerToConstructor( serializerClass, codeGenerator.ref( TypeUtils.getErasure( fieldInfo.getCollectionParam() ).toString() ) );

    JFieldVar constant = getConstant( serializerClass, fieldInfo );

    JInvocation getterInvocation = codeGenerator.createGetterInvocation( object, fieldInfo );

    return JExpr.invoke( METHOD_NAME_SERIALIZE_COLLECTION )
      .arg( getterInvocation )
      .arg( JExpr.dotclass( codeGenerator.ref( fieldInfo.getCollectionParam().toString() ) ) )
      .arg( constant )
View Full Code Here

  @Override
  @NotNull
  public Expressions createReadFromDeserializeFromExpression( @NotNull AbstractGenerator<?> generator, @NotNull JDefinedClass serializerClass, @NotNull JExpression deserializeFrom, @NotNull JVar formatVersion, @NotNull FieldDeclarationInfo fieldInfo ) {
    JClass collectionParamType = codeGenerator.ref( fieldInfo.getCollectionParam().toString() );

    JInvocation nextTagExpression = createNextTagInvocation( serializerClass, deserializeFrom, fieldInfo );

    JInvocation expression = JExpr.invoke( METHOD_NAME_DESERIALIZE_COLLECTION ).arg( deserializeFrom ).arg( JExpr.dotclass( collectionParamType ) ).arg( formatVersion );
    return new Expressions( expression, nextTagExpression );
  }
View Full Code Here

  }

  @NotNull
  @Override
  public Expressions createReadFromDeserializeFromExpression( @NotNull AbstractGenerator<?> generator, @NotNull JDefinedClass serializerClass, @NotNull JExpression deserializeFrom, @NotNull JVar formatVersion, @NotNull FieldDeclarationInfo fieldInfo ) {
    JInvocation nextTagExpression = createNextTagInvocation( serializerClass, deserializeFrom, fieldInfo );

    JClass type = codeGenerator.ref( TypeUtils.getErasure( fieldInfo.getType() ).toString() );
    JInvocation expression = JExpr.invoke( METHOD_NAME_DESERIALIZE ).arg( JExpr.dotclass( type ) ).arg( formatVersion ).arg( deserializeFrom );
    return new Expressions( expression, nextTagExpression );
  }
View Full Code Here

        try {
            JDefinedClass jc = codeModel.rootPackage()._class("JAXBDebug");
            JMethod m = jc.method(JMod.PUBLIC|JMod.STATIC,JAXBContext.class,"createContext");
            JVar $classLoader = m.param(ClassLoader.class,"classLoader");
            m._throws(JAXBException.class);
            JInvocation inv = codeModel.ref(JAXBContext.class).staticInvoke("newInstance");
            m.body()._return(inv);

            switch(model.strategy) {
            case INTF_AND_IMPL:
                {
                    StringBuilder buf = new StringBuilder();
                    for( PackageOutlineImpl po : packageContexts.values() ) {
                        if(buf.length()>0buf.append(':');
                        buf.append(po._package().name());
                    }
                    inv.arg(buf.toString()).arg($classLoader);
                    break;
                }
            case BEAN_ONLY:
                for( ClassOutlineImpl cc : getClasses() )
                    inv.arg(cc.implRef.dotclass());
                for( PackageOutlineImpl po : packageContexts.values() )
                    inv.arg(po.objectFactory().dotclass());
                break;
            default:
                throw new IllegalStateException();
            }
        } catch (JClassAlreadyExistsException e) {
View Full Code Here

                else
                    eq = fe.var().ref($value).invoke("equals").arg($v);

                fe.body()._if(eq)._then()._return(fe.var());

                JInvocation ex = JExpr._new(codeModel.ref(IllegalArgumentException.class));

                JExpression strForm;
                if(baseExposedType.isPrimitive()) {
                    strForm = codeModel.ref(String.class).staticInvoke("valueOf").arg($v);
                } else
                if(baseExposedType==codeModel.ref(String.class)){
                    strForm = $v;
                } else {
                    strForm = $v.invoke("toString");
                }
                m.body()._throw(ex.arg(strForm));
            }
        } else {
            // [RESULT]
            // public String value() { return name(); }
            type.method(JMod.PUBLIC, String.class, "value" ).body()._return(JExpr.invoke("name"));
View Full Code Here

TOP

Related Classes of com.sun.codemodel.JInvocation

Copyright © 2018 www.massapicom. 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.