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


Java JMethod.annotate方法代码示例

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


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

示例1: buildFactory

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

示例2: declareAcceptMethod

import com.helger.jcodemodel.JMethod; //导入方法依赖的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: buildProtectedConstructor

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

示例4: generatePredicate

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


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