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


Java JMethod.type方法代码示例

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


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

示例4: createAcceptingInterface

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

示例5: buildAcceptMethod

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

示例6: createMethodMap

import com.helger.jcodemodel.JMethod; //导入方法依赖的package包/类
private static GenerationResult<Map<String, JMethod>> createMethodMap(JDefinedClass jVisitorModel,
                                                    SpecialTypeVariables specialTypeVariables) {
    GenerationProcess generation = new GenerationProcess();
    Map<String, JMethod> methods = new TreeMap<>();
    for (JMethod method: jVisitorModel.methods()) {
        AbstractJType methodType = method.type();
        if (methodType == null)
            generation.reportError(MessageFormat.format("Visitor method result type is missing: {0}", method.name()));
        else if (methodType.isError()) {
            generation.reportError(MessageFormat.format("Visitor method result type is erroneous: {0}", method.name()));
        } else if (!specialTypeVariables.isResult(method.type())) {
            generation.reportError(MessageFormat.format("Visitor method is only allowed to return type declared as a result type of visitor: {0}: expecting {1}, found: {2}",
                    method.name(), specialTypeVariables.resultTypeParameter().name(), methodType.fullName()));
        }
        for (JTypeVar typeVariable: method.typeParamList()) {
            for (AbstractJClass bound: typeVariable.bounds()) {
                if (bound.containsTypeVar(specialTypeVariables.resultTypeParameter())) {
                    generation.reportError(MessageFormat.format("Visitor method type-parameters shouldn''t depend on result type: {0}: {1} type-variable",
                            method.name(), typeVariable.name()));
                }
            }
        }
        for (JVar parameter: method.listParams()) {
            if (parameter.type().containsTypeVar(specialTypeVariables.resultTypeParameter())) {
                generation.reportError(MessageFormat.format("Visitor method shouldn''t have result type as a parameter: {0}: result type-parameter: {1}",
                        method.name(), specialTypeVariables.resultTypeParameter().name()));
            }
        }

        Collection<AbstractJClass> exceptions = method.getThrows();
        if (exceptions.size() > 1)
            generation.reportError(MessageFormat.format("Visitor method is allowed to throw no exceptions or throw single exception, declared as type-variable: {0}",
                    method.name()));
        else if (exceptions.size() == 1) {
            AbstractJClass exception = exceptions.iterator().next();
            if (exception.isError())
                generation.reportError(MessageFormat.format("Visitor method exception type is erroneous: {0}", method.name()));
            else if (!specialTypeVariables.isException(exception))
                generation.reportError(MessageFormat.format("Visitor method throws exception, not declared as type-variable: {0}: {1}",
                    method.name(), exception.fullName()));
        }

        JMethod exitingValue = methods.put(method.name(), method);
        if (exitingValue != null) {
            generation.reportError(MessageFormat.format("Method overloading is not supported for visitor interfaces: two methods with the same name: {0}",
                                                method.name()));
        }
        for (JVar param: method.params()) {
            generation.processGenerationResult(Source.getNullability(param));
        }
    }
    return generation.createGenerationResult(methods);
}
 
开发者ID:sviperll,项目名称:adt4j,代码行数:54,代码来源:VisitorDefinition.java


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