本文整理汇总了Java中com.sun.codemodel.JInvocation.arg方法的典型用法代码示例。如果您正苦于以下问题:Java JInvocation.arg方法的具体用法?Java JInvocation.arg怎么用?Java JInvocation.arg使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.codemodel.JInvocation
的用法示例。
在下文中一共展示了JInvocation.arg方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addFactoryMethod
import com.sun.codemodel.JInvocation; //导入方法依赖的package包/类
private void addFactoryMethod(JDefinedClass _enum, JType backingType) {
JFieldVar quickLookupMap = addQuickLookupMap(_enum, backingType);
JMethod fromValue = _enum.method(JMod.PUBLIC | JMod.STATIC, _enum, "fromValue");
JVar valueParam = fromValue.param(backingType, "value");
JBlock body = fromValue.body();
JVar constant = body.decl(_enum, "constant");
constant.init(quickLookupMap.invoke("get").arg(valueParam));
JConditional _if = body._if(constant.eq(JExpr._null()));
JInvocation illegalArgumentException = JExpr._new(_enum.owner().ref(IllegalArgumentException.class));
JExpression expr = valueParam;
// if string no need to add ""
if(!isString(backingType)){
expr = expr.plus(JExpr.lit(""));
}
illegalArgumentException.arg(expr);
_if._then()._throw(illegalArgumentException);
_if._else()._return(constant);
ruleFactory.getAnnotator().enumCreatorMethod(fromValue);
}
示例2: getDefaultSet
import com.sun.codemodel.JInvocation; //导入方法依赖的package包/类
/**
* Creates a default value for a set property by:
* <ol>
* <li>Creating a new {@link LinkedHashSet} with the correct generic type
* <li>Using {@link Arrays#asList(Object...)} to initialize the set with the
* correct default values
* </ol>
*
* @param fieldType
* the java type that applies for this field ({@link Set} with
* some generic type argument)
* @param node
* the node containing default values for this set
* @return an expression that creates a default value that can be assigned
* to this field
*/
private JExpression getDefaultSet(JType fieldType, JsonNode node) {
JClass setGenericType = ((JClass) fieldType).getTypeParameters().get(0);
JClass setImplClass = fieldType.owner().ref(LinkedHashSet.class);
setImplClass = setImplClass.narrow(setGenericType);
JInvocation newSetImpl = JExpr._new(setImplClass);
if (node instanceof ArrayNode && node.size() > 0) {
JInvocation invokeAsList = fieldType.owner().ref(Arrays.class).staticInvoke("asList");
for (JsonNode defaultValue : node) {
invokeAsList.arg(getDefaultValue(setGenericType, defaultValue));
}
newSetImpl.arg(invokeAsList);
} else if (!ruleFactory.getGenerationConfig().isInitializeCollections()) {
return JExpr._null();
}
return newSetImpl;
}
示例3: getDefaultList
import com.sun.codemodel.JInvocation; //导入方法依赖的package包/类
/**
* Creates a default value for a list property by:
* <ol>
* <li>Creating a new {@link ArrayList} with the correct generic type
* <li>Using {@link Arrays#asList(Object...)} to initialize the list with
* the correct default values
* </ol>
*
* @param fieldType
* the java type that applies for this field ({@link List} with
* some generic type argument)
* @param node
* the node containing default values for this list
* @return an expression that creates a default value that can be assigned
* to this field
*/
private JExpression getDefaultList(JType fieldType, JsonNode node) {
JClass listGenericType = ((JClass) fieldType).getTypeParameters().get(0);
JClass listImplClass = fieldType.owner().ref(ArrayList.class);
listImplClass = listImplClass.narrow(listGenericType);
JInvocation newListImpl = JExpr._new(listImplClass);
if (node instanceof ArrayNode && node.size() > 0) {
JInvocation invokeAsList = fieldType.owner().ref(Arrays.class).staticInvoke("asList");
for (JsonNode defaultValue : node) {
invokeAsList.arg(getDefaultValue(listGenericType, defaultValue));
}
newListImpl.arg(invokeAsList);
} else if (!ruleFactory.getGenerationConfig().isInitializeCollections()) {
return JExpr._null();
}
return newListImpl;
}
示例4: declareVectorValueSetupAndMember
import com.sun.codemodel.JInvocation; //导入方法依赖的package包/类
public JVar declareVectorValueSetupAndMember(DirectExpression batchName, TypedFieldId fieldId) {
final ValueVectorSetup setup = new ValueVectorSetup(batchName, fieldId);
final Class<?> valueVectorClass = fieldId.getIntermediateClass();
final JClass vvClass = model.ref(valueVectorClass);
final JClass retClass = fieldId.isHyperReader() ? vvClass.array() : vvClass;
final JVar vv = declareClassField("vv", retClass);
final JBlock b = getSetupBlock();
int[] fieldIndices = fieldId.getFieldIds();
JInvocation invoke = model.ref(VectorResolver.class).staticInvoke(fieldId.isHyperReader() ? "hyper" : "simple")
.arg(batchName)
.arg(vvClass.dotclass());
for(int i = 0; i < fieldIndices.length; i++){
invoke.arg(JExpr.lit(fieldIndices[i]));
}
// we have to cast here since Janino doesn't handle generic inference well.
JExpression casted = JExpr.cast(retClass, invoke);
b.assign(vv, casted);
vvDeclaration.put(setup, vv);
return vv;
}
示例5: addCtor
import com.sun.codemodel.JInvocation; //导入方法依赖的package包/类
/**
* The code generator creates a method called __DRILL_INIT__ which takes the
* place of the constructor when the code goes though the byte code merge.
* For Plain-old Java, we call the method from a constructor created for
* that purpose. (Generated code, fortunately, never includes a constructor,
* so we can create one.) Since the init block throws an exception (which
* should never occur), the generated constructor converts the checked
* exception into an unchecked one so as to not require changes to the
* various places that create instances of the generated classes.
*
* Example:<code><pre>
* public StreamingAggregatorGen1() {
* try {
* __DRILL_INIT__();
* } catch (SchemaChangeException e) {
* throw new UnsupportedOperationException(e);
* }
* }</pre></code>
*
* Note: in Java 8 we'd use the <tt>Parameter</tt> class defined in Java's
* introspection package. But, Drill prefers Java 7 which only provides
* parameter types.
*/
private void addCtor(Class<?>[] parameters) {
JMethod ctor = clazz.constructor(JMod.PUBLIC);
JBlock body = ctor.body();
// If there are parameters, need to pass them to the super class.
if (parameters.length > 0) {
JInvocation superCall = JExpr.invoke("super");
// This case only occurs for nested classes, and all nested classes
// in Drill are inner classes. Don't pass along the (hidden)
// this$0 field.
for (int i = 1; i < parameters.length; i++) {
Class<?> p = parameters[i];
superCall.arg(ctor.param(model._ref(p), "arg" + i));
}
body.add(superCall);
}
JTryBlock tryBlock = body._try();
tryBlock.body().invoke(SignatureHolder.DRILL_INIT_METHOD);
JCatchBlock catchBlock = tryBlock._catch(model.ref(SchemaChangeException.class));
catchBlock.body()._throw(JExpr._new(model.ref(UnsupportedOperationException.class)).arg(catchBlock.param("e")));
}
示例6: caseAClassInitializerArrayCreationExpression
import com.sun.codemodel.JInvocation; //导入方法依赖的package包/类
@Override
public void caseAClassInitializerArrayCreationExpression(AClassInitializerArrayCreationExpression node) {
TypeAdapter ta = new TypeAdapter(context);
node.getClassOrInterfaceType().apply(ta);
int dim = node.getDim().size();
JType type = ta.type;
for (int i = 0; i < dim; i++) {
type = type.array();
}
JInvocation inv = JExpr._new(type);
AArrayInitializer inits = (AArrayInitializer) node.getArrayInitializer();
for (PVariableInitializer init : inits.getVariableInitializer()) {
VarInitAdapter via = new VarInitAdapter(context);
init.apply(via);
inv.arg(via.expr);
}
expr = inv;
}
示例7: caseAPrimitiveInitializerArrayCreationExpression
import com.sun.codemodel.JInvocation; //导入方法依赖的package包/类
@Override
public void caseAPrimitiveInitializerArrayCreationExpression(APrimitiveInitializerArrayCreationExpression node) {
TypeAdapter ta = new TypeAdapter(context);
node.getPrimitiveType().apply(ta);
int dim = node.getDim().size();
JType type = ta.type;
for (int i = 0; i < dim; i++) {
type = type.array();
}
JInvocation inv = JExpr._new(type);
AArrayInitializer inits = (AArrayInitializer) node.getArrayInitializer();
for (PVariableInitializer init : inits.getVariableInitializer()) {
VarInitAdapter via = new VarInitAdapter(context);
init.apply(via);
inv.arg(via.expr);
}
expr = inv;
}
示例8: defineReduceAction
import com.sun.codemodel.JInvocation; //导入方法依赖的package包/类
private void defineReduceAction(Action a, JBlock body) {
Rule r = a.production();
JDefinedClass nodeClass = nodes.getConcreteNode(r);
String[] rhs = r.rightHandSide();
JVar[] fields = new JVar[rhs.length];
for( int i = fields.length - 1 ; i >= 0 ; --i ){
JDefinedClass type = nodes.getAbstractNode(rhs[i]);
if(type == null){
throw new NullPointerException("Node for: "+rhs[i]+" is null.");
}
fields[i] = body.decl(type, "field"+i, JExpr.cast(type, JExpr.invoke(stack, "pop")));
}
JInvocation newNodeClass = JExpr._new(nodeClass);
for(JVar field : fields){
newNodeClass = newNodeClass.arg(field);
}
JVar node = body.decl(nodes.getNodeInterface(), "reduced", JExpr.invoke(newNodeClass, "replace"));
body.invoke(JExpr._this(), advance)
.arg(stack).arg(node);
body._return(JExpr.invoke(JExpr._this(), advance)
.arg(stack).arg(lookahead));
}
示例9: createSuperInvocation
import com.sun.codemodel.JInvocation; //导入方法依赖的package包/类
static
private JInvocation createSuperInvocation(JDefinedClass clazz, JMethod method){
JInvocation invocation;
if(method.type() != null){
invocation = JExpr._super().invoke(method.name());
} else
{
invocation = JExpr.invoke("super");
}
List<JVar> parameters = method.params();
for(JVar parameter : parameters){
invocation.arg(parameter);
}
return invocation;
}
示例10: addFactoryMethod
import com.sun.codemodel.JInvocation; //导入方法依赖的package包/类
private void addFactoryMethod(JsonNode node, JDefinedClass _enum) {
JFieldVar quickLookupMap = addQuickLookupMap(_enum);
JMethod fromValue = _enum.method(JMod.PUBLIC | JMod.STATIC, _enum, "fromValue");
JVar valueParam = fromValue.param(String.class, "value");
JBlock body = fromValue.body();
JVar constant = body.decl(_enum, "constant");
constant.init(quickLookupMap.invoke("get").arg(valueParam));
JConditional _if = body._if(constant.eq(JExpr._null()));
JInvocation illegalArgumentException = JExpr._new(_enum.owner().ref(IllegalArgumentException.class));
illegalArgumentException.arg(valueParam);
_if._then()._throw(illegalArgumentException);
_if._else()._return(constant);
ruleFactory.getAnnotator().enumCreatorMethod(fromValue);
}
示例11: getDefaultList
import com.sun.codemodel.JInvocation; //导入方法依赖的package包/类
/**
* Creates a default value for a list property by:
* <ol>
* <li>Creating a new {@link ArrayList} with the correct generic type
* <li>Using {@link Arrays#asList(Object...)} to initialize the list with
* the correct default values
* </ol>
*
* @param fieldType
* the java type that applies for this field ({@link List} with
* some generic type argument)
* @param node
* the node containing default values for this list
* @return an expression that creates a default value that can be assigned
* to this field
*/
private JExpression getDefaultList(JType fieldType, JsonNode node) {
JClass listGenericType = ((JClass) fieldType).getTypeParameters().get(0);
JClass listImplClass = fieldType.owner().ref(ArrayList.class);
listImplClass = listImplClass.narrow(listGenericType);
JInvocation newListImpl = JExpr._new(listImplClass);
if (node instanceof ArrayNode && node.size() > 0) {
JInvocation invokeAsList = fieldType.owner().ref(Arrays.class).staticInvoke("asList");
for (JsonNode defaultValue : node) {
invokeAsList.arg(getDefaultValue(listGenericType, defaultValue));
}
newListImpl.arg(invokeAsList);
}
return newListImpl;
}
示例12: getDefaultSet
import com.sun.codemodel.JInvocation; //导入方法依赖的package包/类
/**
* Creates a default value for a set property by:
* <ol>
* <li>Creating a new {@link HashSet} with the correct generic type
* <li>Using {@link Arrays#asList(Object...)} to initialize the set with the
* correct default values
* </ol>
*
* @param fieldType
* the java type that applies for this field ({@link Set} with
* some generic type argument)
* @param node
* the node containing default values for this set
* @return an expression that creates a default value that can be assigned
* to this field
*/
private JExpression getDefaultSet(JType fieldType, JsonNode node) {
JClass setGenericType = ((JClass) fieldType).getTypeParameters().get(0);
JClass setImplClass = fieldType.owner().ref(HashSet.class);
setImplClass = setImplClass.narrow(setGenericType);
JInvocation newSetImpl = JExpr._new(setImplClass);
if (node instanceof ArrayNode) {
JInvocation invokeAsList = fieldType.owner().ref(Arrays.class).staticInvoke("asList");
for (JsonNode defaultValue : node) {
invokeAsList.arg(getDefaultValue(setGenericType, defaultValue));
}
newSetImpl.arg(invokeAsList);
}
return newSetImpl;
}
示例13: addQuickLookupMap
import com.sun.codemodel.JInvocation; //导入方法依赖的package包/类
private JFieldVar addQuickLookupMap(JDefinedClass _enum, JType backingType) {
JClass lookupType = _enum.owner().ref(Map.class).narrow(backingType.boxify(), _enum);
JFieldVar lookupMap = _enum.field(JMod.PRIVATE | JMod.STATIC | JMod.FINAL, lookupType, "CONSTANTS");
JClass lookupImplType = _enum.owner().ref(HashMap.class).narrow(backingType.boxify(), _enum);
lookupMap.init(JExpr._new(lookupImplType));
JForEach forEach = _enum.init().forEach(_enum, "c", JExpr.invoke("values"));
JInvocation put = forEach.body().invoke(lookupMap, "put");
put.arg(forEach.var().ref("value"));
put.arg(forEach.var());
return lookupMap;
}
示例14: getDefaultEnum
import com.sun.codemodel.JInvocation; //导入方法依赖的package包/类
/**
* @see EnumRule
*/
private static JExpression getDefaultEnum(JType fieldType, JsonNode node) {
JDefinedClass enumClass = (JDefinedClass) fieldType;
JType backingType = enumClass.fields().get("value").type();
JInvocation invokeFromValue = enumClass.staticInvoke("fromValue");
invokeFromValue.arg(getDefaultValue(backingType, node));
return invokeFromValue;
}
示例15: addSetter
import com.sun.codemodel.JInvocation; //导入方法依赖的package包/类
private void addSetter(JDefinedClass jclass, JType propertyType, JFieldVar field) {
JMethod setter = jclass.method(JMod.PUBLIC, void.class, "setAdditionalProperty");
ruleFactory.getAnnotator().anySetter(setter);
JVar nameParam = setter.param(String.class, "name");
JVar valueParam = setter.param(propertyType, "value");
JInvocation mapInvocation = setter.body().invoke(JExpr._this().ref(field), "put");
mapInvocation.arg(nameParam);
mapInvocation.arg(valueParam);
}