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


Java JMod类代码示例

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


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

示例1: createFromMap

import com.helger.jcodemodel.JMod; //导入依赖的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: setOnRequestPermissionsResultMethod

import com.helger.jcodemodel.JMod; //导入依赖的package包/类
private void setOnRequestPermissionsResultMethod() {
    onRequestPermissionsResultMethod = holder().getGeneratedClass().method(JMod.PUBLIC, getCodeModel().VOID, "onRequestPermissionsResult");
    onRequestPermissionsResultMethod.annotate(Override.class);

    onRequestPermissionsResultRequestCodeParam = onRequestPermissionsResultMethod.param(getCodeModel().INT, "requestCode");
    JVar permissionsParam = onRequestPermissionsResultMethod.param(getJClass("java.lang.String").array(), "permissions");
    onRequestPermissionsResultGrantResultsParam = onRequestPermissionsResultMethod.param(getCodeModel().INT.array(), "grantResults");

    JBlock onRequestPermissionsResultMethodBody = onRequestPermissionsResultMethod.body();

    onRequestPermissionsResultMethodBody.invoke(JExpr._super(), "onRequestPermissionsResult")
            .arg(onRequestPermissionsResultRequestCodeParam)
            .arg(permissionsParam)
            .arg(onRequestPermissionsResultGrantResultsParam);

    onRequestPermissionsResultMethodDelegateBlock = onRequestPermissionsResultMethodBody.blockVirtual();

    onRequestPermissionsResultMethodBody.assign(getPermissionDispatcherCalledField(), JExpr.FALSE);
}
 
开发者ID:permissions-dispatcher,项目名称:AndroidAnnotationsPermissionsDispatcherPlugin,代码行数:20,代码来源:PermissionDispatcherHolder.java

示例3: buildFactory

import com.helger.jcodemodel.JMod; //导入依赖的package包/类
JMethod buildFactory(Map<String, JMethod> constructorMethods) throws JClassAlreadyExistsException {
    JDefinedClass factory = buildFactoryClass(constructorMethods);

    JFieldVar factoryField = environment.buildValueClassField(JMod.PRIVATE | JMod.STATIC | JMod.FINAL, factory, "FACTORY");
    JAnnotationUse fieldAnnotationUse = factoryField.annotate(SuppressWarnings.class);
    JAnnotationArrayMember paramArray = fieldAnnotationUse.paramArray("value");
    paramArray.param("unchecked");
    paramArray.param("rawtypes");

    factoryField.init(JExpr._new(factory));
    JMethod factoryMethod = environment.buildValueClassMethod(Source.toJMod(environment.factoryMethodAccessLevel()) | JMod.STATIC, "factory");
    Source.annotateNonnull(factoryMethod);
    JAnnotationUse methodAnnotationUse = factoryMethod.annotate(SuppressWarnings.class);
    methodAnnotationUse.param("value", "unchecked");
    for (JTypeVar visitorTypeParameter: environment.getValueTypeParameters()) {
        JTypeVar typeParameter = factoryMethod.generify(visitorTypeParameter.name());
        typeParameter.boundLike(visitorTypeParameter);
    }
    AbstractJClass usedValueClassType = environment.wrappedValueClassType(factoryMethod.typeParams());
    factoryMethod.type(environment.visitor(usedValueClassType, usedValueClassType, types._RuntimeException).getVisitorType());
    factoryMethod.body()._return(factoryField);
    return factoryMethod;
}
 
开发者ID:sviperll,项目名称:adt4j,代码行数:24,代码来源:FinalValueClassModel.java

示例4: declareAcceptMethod

import com.helger.jcodemodel.JMod; //导入依赖的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

示例5: buildHashCodeCachedValueField

import com.helger.jcodemodel.JMod; //导入依赖的package包/类
private JFieldVar buildHashCodeCachedValueField(Serialization serialization) {
    if (!environment.hashCodeCaching().enabled())
        throw new IllegalStateException("Unsupported method evaluation to cache hash code: " + environment.hashCodeCaching());
    else {
        boolean isSerializable = serialization.isSerializable();
        boolean precomputes = environment.hashCodeCaching() == Caching.PRECOMPUTE;
        int mods = JMod.PRIVATE;
        mods = !isSerializable ? mods : mods | JMod.TRANSIENT;
        if (!precomputes)
            return environment.buildValueClassField(mods, types._int, "hashCodeCachedValue", JExpr.lit(0));
        else {
            mods = isSerializable ? mods : mods | JMod.FINAL;
            return environment.buildValueClassField(mods, types._int, "hashCodeCachedValue");
        }
    }
}
 
开发者ID:sviperll,项目名称:adt4j,代码行数:17,代码来源:FinalValueClassModel.java

示例6: buildProtectedConstructor

import com.helger.jcodemodel.JMod; //导入依赖的package包/类
void buildProtectedConstructor(Serialization serialization) {
    JMethod constructor = environment.buildValueClassConstructor(JMod.PROTECTED);
    JAnnotationUse annotation = constructor.annotate(SuppressWarnings.class);
    annotation.paramArray("value", "null");
    AbstractJClass unwrappedUsedValueClassType = environment.unwrappedValueClassTypeInsideValueClass();
    JVar param = constructor.param(unwrappedUsedValueClassType, "implementation");
    Source.annotateNonnull(param);
    if (isError) {
        constructor.body()._throw(JExpr._new(types._UnsupportedOperationException));
    } else {
        JConditional nullCheck = constructor.body()._if(JExpr.ref("implementation").eq(JExpr._null()));
        JInvocation nullPointerExceptionConstruction = JExpr._new(types._NullPointerException);
        nullPointerExceptionConstruction.arg(JExpr.lit("Argument shouldn't be null: 'implementation' argument in class constructor invocation: " + environment.valueClassQualifiedName()));
        nullCheck._then()._throw(nullPointerExceptionConstruction);

        if (environment.hashCodeCaching().enabled())
            constructor.body().assign(JExpr.refthis(hashCodeCachedValueField), param.ref(hashCodeCachedValueField));
        constructor.body().assign(JExpr.refthis(acceptorField), param.ref(acceptorField));
    }
}
 
开发者ID:sviperll,项目名称:adt4j,代码行数:21,代码来源:FinalValueClassModel.java

示例7: generatePredicate

import com.helger.jcodemodel.JMod; //导入依赖的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

示例8: visitConstant_def

import com.helger.jcodemodel.JMod; //导入依赖的package包/类
@Override
public Void visitConstant_def(Constant_defContext ctx) {
    String constName = ctx.constant_name().IDENTIFIER().getText();
    String constType = ctx.constant_type().TYPE_LITERAL().getText();
    Literal_valueContext lit = ctx.literal_value();
    ProtoTypes type = ProtoTypes.valueOf( constType.toUpperCase() );

    ProtoContext pkgCtx = (ProtoContext) ctx.getParent();
    String pkg = pkgCtx.package_def().package_name().QUALIFIED_IDENTIFIER().getText();
    JDefinedClass container = codeModel._package( pkg )._getClass( containerName );

    int modifier = JMod.PUBLIC | JMod.STATIC | JMod.FINAL;
    AbstractJType jtype = primitiveType( type ).unboxify();

    JFieldVar f = container.field( modifier, jtype, constName.toUpperCase(), parse( type, container, lit ) );
    logger.info( "\t +-> {} {} = {}", f.type().name(), f.name(), lit.getText() );

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

示例9: visitEnum_def

import com.helger.jcodemodel.JMod; //导入依赖的package包/类
@Override
public Void visitEnum_def(Enum_defContext ctx) {
    try {
        String name = ctx.enum_name().IDENTIFIER().getText();
        ProtoContext pkgCtx = (ProtoContext) ctx.getParent();
        String pkg = pkgCtx.package_def().package_name().QUALIFIED_IDENTIFIER().getText();
        JPackage jPackage = codeModel._package( pkg );
        JDefinedClass m = codeModel._package( pkg )._enum( name );
        JDefinedClass container = jPackage._getClass( containerName );

        String tag = "tag";
        m.field( JMod.PUBLIC | JMod.FINAL, codeModel.INT, tag );

        JMethod constructor = m.constructor( JMod.PRIVATE );
        constructor.param( codeModel.INT, tag );
        constructor.body().assign( JExpr._this().ref( tag ), JExpr.ref( tag ) );

        addDenifition( container, m );

        logger.info( "Enum({}.{})", m._package().name(), m.name() );
        return super.visitEnum_def( ctx );
    }
    catch ( JClassAlreadyExistsException err ) {
        throw new RuntimeException( err );
    }
}
 
开发者ID:turbospaces,项目名称:protoc,代码行数:27,代码来源:Antlr4ProtoVisitor.java

示例10: createToMap

import com.helger.jcodemodel.JMod; //导入依赖的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

示例11: createSaveMethod

import com.helger.jcodemodel.JMod; //导入依赖的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

示例12: makeCall

import com.helger.jcodemodel.JMod; //导入依赖的package包/类
@Override
protected void makeCall(JBlock listenerMethodBody, JInvocation call, TypeMirror returnType) {
    JVar currentClickTime = listenerMethodBody.decl(JMod.NONE, JPrimitiveType.LONG, "currentClickMilliseconds", getCodeModel().directClass("android.os.SystemClock").staticInvoke("uptimeMillis"));
    JVar elapsedTime = listenerMethodBody.decl(JMod.NONE, JPrimitiveType.LONG, "elapsedMilliseconds", JOp.minus(currentClickTime, lastClickMilliseconds));
    listenerMethodBody._if(JOp.lte(elapsedTime, intervalTime))._then()._return();
    listenerMethodBody.assign(lastClickMilliseconds, currentClickTime);
    listenerMethodBody.add(call);
}
 
开发者ID:m0er,项目名称:androidannotations-interval-click-plugin,代码行数:9,代码来源:IntervalClickHandler.java

示例13: createAcceptingInterface

import com.helger.jcodemodel.JMod; //导入依赖的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

示例14: buildPrivateConstructor

import com.helger.jcodemodel.JMod; //导入依赖的package包/类
void buildPrivateConstructor() {
    if (!isError) {
        JMethod constructor = environment.buildValueClassConstructor(JMod.PRIVATE);
        JVar acceptorParam = constructor.param(acceptorField.type(), acceptorField.name());
        if (environment.hashCodeCaching() == Caching.PRECOMPUTE) {
            JInvocation invocation = acceptorParam.invoke(hashCodeAcceptorMethodName());
            constructor.body().assign(JExpr.refthis(hashCodeCachedValueField), invocation);
        }
        constructor.body().assign(JExpr.refthis(acceptorField.name()), acceptorParam);
    }
}
 
开发者ID:sviperll,项目名称:adt4j,代码行数:12,代码来源:FinalValueClassModel.java

示例15: buildAcceptMethod

import com.helger.jcodemodel.JMod; //导入依赖的package包/类
void buildAcceptMethod() {
    JMethod acceptMethod = environment.buildValueClassMethod(Source.toJMod(environment.acceptMethodAccessLevel()) | JMod.FINAL, environment.acceptMethodName());

    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 exceptionTypeVar = acceptMethod.generify(visitorExceptionTypeParameter.name());
        exceptionTypeVar.boundLike(visitorExceptionTypeParameter);
        exceptionType = exceptionTypeVar;
        acceptMethod._throws(exceptionType);
    }

    AbstractJClass usedValueClassType = environment.wrappedValueClassTypeInsideValueClass();
    VisitorDefinition.VisitorUsage usedVisitorType = environment.visitor(usedValueClassType, resultType, exceptionType);
    acceptMethod.param(usedVisitorType.getVisitorType(), "visitor");
    if (isError) {
        acceptMethod.body()._throw(JExpr._new(types._UnsupportedOperationException));
    } else {
        JInvocation invocation = acceptorField.invoke(environment.acceptMethodName());
        invocation.arg(JExpr.ref("visitor"));
        acceptMethod.body()._return(invocation);
    }
}
 
开发者ID:sviperll,项目名称:adt4j,代码行数:35,代码来源:FinalValueClassModel.java


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