当前位置: 首页>>代码示例>>Java>>正文


Java JDefinedClass.method方法代码示例

本文整理汇总了Java中com.helger.jcodemodel.JDefinedClass.method方法的典型用法代码示例。如果您正苦于以下问题:Java JDefinedClass.method方法的具体用法?Java JDefinedClass.method怎么用?Java JDefinedClass.method使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.helger.jcodemodel.JDefinedClass的用法示例。


在下文中一共展示了JDefinedClass.method方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createFromMap

import com.helger.jcodemodel.JDefinedClass; //导入方法依赖的package包/类
private void createFromMap(JCodeModel codeModel, JDefinedClass genClazz) {
    JMethod fromMap = genClazz.method(JMod.PUBLIC | JMod.STATIC, genClazz, "fromMap");
    fromMap.param(codeModel.directClass(Map.class.getCanonicalName()).narrow(String.class).narrow(Object.class), "obj");
    fromMap.body().directStatement("return obj != null ? new " + genClazz.name() + "(obj) : null;");

    JMethod fromMapList = genClazz.method(JMod.PUBLIC | JMod.STATIC, codeModel.directClass(List.class.getCanonicalName()).narrow(genClazz), "fromMap");
    fromMapList.param(codeModel.directClass(List.class.getCanonicalName()).narrow(codeModel.directClass(Map.class.getCanonicalName()).narrow(String.class).narrow(Object.class)), "obj");

    StringBuilder mBuilder = new StringBuilder()
            .append("if(obj != null) { \n")
            .append("java.util.List<" + genClazz.name() + "> result = new java.util.ArrayList<" + genClazz.name() + ">(); \n")
            .append("for(java.util.Map<String, Object> entry : obj) { \n")
            .append("result.add(new " + genClazz.name() + "(entry)); \n")
            .append("} \n")
            .append("return result; \n")
            .append("} \n")
            .append("return null; \n");


    fromMapList.body().directStatement(mBuilder.toString());
}
 
开发者ID:Kaufland,项目名称:andcouchbaseentity,代码行数:22,代码来源:EntityGeneration.java

示例2: declareAcceptMethod

import com.helger.jcodemodel.JDefinedClass; //导入方法依赖的package包/类
private JMethod declareAcceptMethod(JDefinedClass caseClass, AbstractJClass usedValueClassType) {
    JMethod acceptMethod = caseClass.method(JMod.PUBLIC, types._void, environment.acceptMethodName());
    acceptMethod.annotate(Override.class);
    JTypeVar visitorResultTypeParameter = environment.visitorDefinition().getResultTypeParameter();
    AbstractJClass resultType;
    if (visitorResultTypeParameter == null)
        resultType = types._Object;
    else {
        JTypeVar resultTypeVar = acceptMethod.generify(visitorResultTypeParameter.name());
        resultTypeVar.boundLike(visitorResultTypeParameter);
        resultType = resultTypeVar;
    }
    acceptMethod.type(resultType);
    JTypeVar visitorExceptionTypeParameter = environment.visitorDefinition().getExceptionTypeParameter();
    JTypeVar exceptionType = null;
    if (visitorExceptionTypeParameter != null) {
        JTypeVar exceptionTypeParameter = acceptMethod.generify(visitorExceptionTypeParameter.name());
        exceptionTypeParameter.boundLike(visitorExceptionTypeParameter);
        exceptionType = exceptionTypeParameter;
        acceptMethod._throws(exceptionType);
    }
    VisitorDefinition.VisitorUsage usedVisitorType = environment.visitor(usedValueClassType, resultType, exceptionType);
    acceptMethod.param(usedVisitorType.getVisitorType(), "visitor");
    return acceptMethod;
}
 
开发者ID:sviperll,项目名称:adt4j,代码行数:26,代码来源:FinalValueClassModel.java

示例3: generatePredicate

import com.helger.jcodemodel.JDefinedClass; //导入方法依赖的package包/类
void generatePredicate(String name, PredicateConfigutation predicate) {
    JMethod predicateMethod = environment.buildValueClassMethod(Source.toJMod(predicate.accessLevel()) | JMod.FINAL, name);
    predicateMethod.type(types._boolean);
    if (isError) {
        predicateMethod.body()._throw(JExpr._new(types._UnsupportedOperationException));
    } else {
        JMethod implementation = environment.buildAcceptingInterfaceMethod(JMod.PUBLIC, name);
        implementation.type(types._boolean);

        predicateMethod.body()._return(JExpr.refthis(acceptorField).invoke(implementation));

        for (JMethod interfaceMethod1: environment.visitorDefinition().methodDefinitions()) {
            JDefinedClass caseClass = caseClasses.get(interfaceMethod1.name());
            predicateMethod = caseClass.method(JMod.PUBLIC | JMod.FINAL, types._boolean, name);
            predicateMethod.annotate(Override.class);

            boolean result = predicate.isTrueFor(interfaceMethod1);
            predicateMethod.body()._return(JExpr.lit(result));
        }
    }
}
 
开发者ID:sviperll,项目名称:adt4j,代码行数:22,代码来源:FinalValueClassModel.java

示例4: createToMap

import com.helger.jcodemodel.JDefinedClass; //导入方法依赖的package包/类
private void createToMap(JCodeModel codeModel, JDefinedClass genClazz) {

        JMethod toMap = genClazz.method(JMod.PUBLIC | JMod.STATIC, codeModel.directClass(HashMap.class.getCanonicalName()).narrow(String.class).narrow(Object.class), "toMap");
        toMap.param(genClazz, "obj");

        StringBuilder builderSingle = new StringBuilder();
        builderSingle.append("if(obj == null){ \n");
        builderSingle.append("return null; \n");
        builderSingle.append("} \n");
        builderSingle.append("java.util.HashMap<String, Object> result = new java.util.HashMap<String, Object>(); \n");
        builderSingle.append("result.putAll(obj.mDoc); \n");
        builderSingle.append("result.putAll(obj.mDocChanges);\n");
        builderSingle.append("return result;\n");
        toMap.body().directStatement(builderSingle.toString());

        JMethod toMapList = genClazz.method(JMod.PUBLIC | JMod.STATIC, codeModel.directClass(List.class.getCanonicalName()).narrow(codeModel.directClass(HashMap.class.getCanonicalName()).narrow(String.class).narrow(Object.class)), "toMap");
        toMapList.param(codeModel.directClass(List.class.getCanonicalName()).narrow(genClazz), "obj");

        StringBuilder builderMulti = new StringBuilder();
        builderMulti.append("if(obj == null) return null; \n");
        builderMulti.append("java.util.List<java.util.HashMap<String, Object>> result = new java.util.ArrayList<java.util.HashMap<String, Object>>(); \n");
        builderMulti.append("for(" + genClazz.name() + " entry : obj) {\n");
        builderMulti.append("result.add(((" + genClazz.name() + ")entry).toMap(entry));\n");
        builderMulti.append("}\n");
        builderMulti.append("return result;\n");
        toMapList.body().directStatement(builderMulti.toString());
    }
 
开发者ID:Kaufland,项目名称:andcouchbaseentity,代码行数:28,代码来源:EntityGeneration.java

示例5: createSaveMethod

import com.helger.jcodemodel.JDefinedClass; //导入方法依赖的package包/类
private void createSaveMethod(JCodeModel codeModel, JDefinedClass genClazz, List<CblFieldHolder> attachments, List<CblConstantHolder> constantFields) {
    JMethod mSave = genClazz.method(JMod.PUBLIC, codeModel.VOID, "save");
    mSave._throws(CouchbaseLiteException.class);

    StringBuilder builder = new StringBuilder();
    builder.append("com.couchbase.lite.Document doc = kaufland.com.coachbasebinderapi.PersistenceConfig.getInstance().createOrGet(getId()); \n");

    for (CblConstantHolder constant : constantFields) {
        builder.append("mDocChanges.put(\"" + constant.getDbField() + "\",\"" + constant.getConstantValue() + "\"); \n");
    }

    builder.append("java.util.HashMap<String, Object> temp = new java.util.HashMap<String, Object>(); \n");
    builder.append("if(doc.getProperties() != null){ \n");
    builder.append("temp.putAll(doc.getProperties()); \n");
    builder.append("} \n");
    builder.append("if(mDocChanges != null){ \n");
    builder.append("temp.putAll(mDocChanges); \n");
    builder.append("} \n");
    builder.append("doc.putProperties(temp); \n");

    if (attachments.size() > 0) {

        builder.append("com.couchbase.lite.UnsavedRevision rev = doc.createRevision(); \n");
        for (CblFieldHolder attachment : attachments) {

            builder.append("if(" + attachment.getDbField() + " != null){ \n");
            builder.append("rev.setAttachment(\"" + attachment.getDbField() + "\", \"" + attachment.getAttachmentType() + "\", " + attachment.getDbField() + "); \n");
            builder.append("} \n");
        }
        builder.append("rev.save(); \n");
    }
    builder.append("rebind(doc.getProperties()); \n");

    mSave.body().directStatement(builder.toString());
}
 
开发者ID:Kaufland,项目名称:andcouchbaseentity,代码行数:36,代码来源:EntityGeneration.java

示例6: createAcceptingInterface

import com.helger.jcodemodel.JDefinedClass; //导入方法依赖的package包/类
private JDefinedClass createAcceptingInterface() throws JClassAlreadyExistsException {
    JDefinedClass acceptingInterface = valueClass._class(JMod.PUBLIC, valueClass.name() + "Acceptor", EClassType.INTERFACE);

    // Hack to overcome bug in codeModel. We want private interface!!! Not public.
    acceptingInterface.mods().setPrivate();

    for (JTypeVar visitorTypeParameter: configuration.getValueTypeParameters()) {
        JTypeVar typeParameter = acceptingInterface.generify(visitorTypeParameter.name());
        typeParameter.boundLike(visitorTypeParameter);
    }

    JMethod acceptMethod = acceptingInterface.method(JMod.PUBLIC, types._void, configuration.acceptMethodName());

    JTypeVar visitorResultType = configuration.visitorDefinition().getResultTypeParameter();
    AbstractJClass resultType;
    if (visitorResultType == null)
        resultType = types._Object;
    else {
        JTypeVar resultTypeVar = acceptMethod.generify(visitorResultType.name());
        resultTypeVar.boundLike(visitorResultType);
        resultType = resultTypeVar;
    }
    acceptMethod.type(resultType);

    JTypeVar visitorExceptionType = configuration.visitorDefinition().getExceptionTypeParameter();
    JTypeVar exceptionType = null;
    if (visitorExceptionType != null) {
        JTypeVar exceptionTypeParameter = acceptMethod.generify(visitorExceptionType.name());
        exceptionTypeParameter.boundLike(visitorExceptionType);
        exceptionType = exceptionTypeParameter;
        acceptMethod._throws(exceptionType);
    }

    AbstractJClass usedValueClassType = Source.narrowType(valueClass, valueClass.typeParams());
    VisitorDefinition.VisitorUsage usedVisitorType = configuration.visitorDefinition().narrowed(usedValueClassType, resultType, exceptionType);
    acceptMethod.param(usedVisitorType.getVisitorType(), "visitor");

    return acceptingInterface;
}
 
开发者ID:sviperll,项目名称:adt4j,代码行数:40,代码来源:Stage1ValueClassModel.java

示例7: visitService_method_def

import com.helger.jcodemodel.JDefinedClass; //导入方法依赖的package包/类
@Override
public Void visitService_method_def(Service_method_defContext ctx) {
    String methodName = ctx.service_method_name().IDENTIFIER().getText();
    ProtoContext pkgCtx = (ProtoContext) ctx.getParent().getParent();
    String pkg = pkgCtx.package_def().package_name().QUALIFIED_IDENTIFIER().getText();
    JPackage jPackage = codeModel._package( pkg );
    JDefinedClass container = jPackage._getClass( containerName );

    Service_defContext sCtx = (Service_defContext) ctx.getParent();
    String serviceName = sCtx.service_name().IDENTIFIER().getText();
    JDefinedClass service = jPackage._getClass( serviceName );

    Collection_map_valueContext reqCtx = ctx.service_method_req().collection_map_value();
    AbstractJClass respType = resolveType( container, ctx.service_method_resp().collection_map_value() );
    AbstractJClass reqType = null;

    JMethod m = service.method( JMod.PUBLIC, respType, methodName );
    if ( reqCtx != null ) {
        reqType = resolveType( container, reqCtx );
        m.param( reqType, "var" );
    }

    List<Service_method_excpContext> excpCtxs = ctx.service_method_throws().service_method_excp();
    for ( Service_method_excpContext excpCtx : excpCtxs ) {
        AbstractJClass exception = resolveType( container, excpCtx.all_identifiers() );
        m._throws( exception );
    }

    logger.info( "\t +-> {}({}) -> {}", m.name(), ( reqType != null ? reqType.name() : "" ), respType.name() );

    return super.visitService_method_def( ctx );
}
 
开发者ID:turbospaces,项目名称:protoc,代码行数:33,代码来源:Antlr4ProtoVisitor.java

示例8: createDeleteMethod

import com.helger.jcodemodel.JDefinedClass; //导入方法依赖的package包/类
private void createDeleteMethod(JCodeModel codeModel, JDefinedClass genClazz) {
    JMethod delete = genClazz.method(JMod.PUBLIC, codeModel.VOID, "delete");
    delete._throws(CouchbaseLiteException.class);
    delete.body().directStatement("kaufland.com.coachbasebinderapi.PersistenceConfig.getInstance().createOrGet(getId()).delete();");
}
 
开发者ID:Kaufland,项目名称:andcouchbaseentity,代码行数:6,代码来源:EntityGeneration.java

示例9: createListenerMethod

import com.helger.jcodemodel.JDefinedClass; //导入方法依赖的package包/类
@Override
protected JMethod createListenerMethod(JDefinedClass listenerAnonymousClass) {
    intervalTime = listenerAnonymousClass.field(JMod.PRIVATE | JMod.FINAL | JMod.FINAL, Long.class, "MIN_CLICK_INTERVAL_MILLISECONDS", JExpr.lit(intervalMilliseconds));
    lastClickMilliseconds = listenerAnonymousClass.field(JMod.PRIVATE, JPrimitiveType.LONG, "lastClickMilliseconds", JExpr.lit(0L));
    return listenerAnonymousClass.method(JMod.PUBLIC, getCodeModel().VOID, "onClick");
}
 
开发者ID:m0er,项目名称:androidannotations-interval-click-plugin,代码行数:7,代码来源:IntervalClickHandler.java


注:本文中的com.helger.jcodemodel.JDefinedClass.method方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。