本文整理汇总了Java中com.helger.jcodemodel.JMethod.generify方法的典型用法代码示例。如果您正苦于以下问题:Java JMethod.generify方法的具体用法?Java JMethod.generify怎么用?Java JMethod.generify使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.helger.jcodemodel.JMethod
的用法示例。
在下文中一共展示了JMethod.generify方法的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;
}
示例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;
}
示例3: 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;
}
示例4: 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);
}
}