本文整理汇总了Java中com.sun.codemodel.JStatement类的典型用法代码示例。如果您正苦于以下问题:Java JStatement类的具体用法?Java JStatement怎么用?Java JStatement使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JStatement类属于com.sun.codemodel包,在下文中一共展示了JStatement类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: generateWriter
import com.sun.codemodel.JStatement; //导入依赖的package包/类
protected JBlock generateWriter(AcScheme scheme, JavaWriter writer) {
JBlock bl=new JBlock();
for (AbstractType tp:scheme.getSchemes().keySet()){
String name = getName(tp, writer);
String ge="value.get"+Character.toUpperCase(name.charAt(0))+name.substring(1)+"()";
JBlock th=bl._if(JExpr.direct(ge+"!=null"))._then();
th.add(new JStatement() {
@Override
public void state(JFormatter f) {
f.p("gson.toJson("+ge+","+ge+".getClass(), out);");
f.nl();
}
});
}
return bl;
}
开发者ID:OnPositive,项目名称:aml,代码行数:18,代码来源:GenericAcAdapterWriter.java
示例2: generateWriter
import com.sun.codemodel.JStatement; //导入依赖的package包/类
protected JBlock generateWriter(AcScheme scheme, JavaWriter writer) {
JBlock bl=new JBlock();
for (AbstractType tp:scheme.getSchemes().keySet()){
String name = getName(tp, writer);
String ge="value.get"+Character.toUpperCase(name.charAt(0))+name.substring(1)+"()";
JBlock th=bl._if(JExpr.direct(ge+"!=null"))._then();
th.add(new JStatement() {
@Override
public void state(JFormatter f) {
f.p("gen.writeObject("+ge+");");
f.nl();
}
});
}
return bl;
}
开发者ID:OnPositive,项目名称:aml,代码行数:18,代码来源:JacksonSerializerWriter.java
示例3: customize
import com.sun.codemodel.JStatement; //导入依赖的package包/类
@Override
public void customize(ClassCustomizerParameters parameters) {
parameters.clazz._implements(Cloneable.class);
parameters.clazz.method(JMod.PUBLIC, parameters.clazz, "clone").body().add(new JStatement() {
@Override
public void state(JFormatter f) {
f.p("try {");
f.nl();
f.p("return ("+parameters.clazz.name()+")super.clone();");
f.nl();
f.p("} catch (CloneNotSupportedException e){ throw new IllegalStateException(e);}");
f.nl();
}
});
}
开发者ID:OnPositive,项目名称:aml,代码行数:18,代码来源:ClonableCustomizer.java
示例4: split
import com.sun.codemodel.JStatement; //导入依赖的package包/类
public static JStatement split(JDefinedClass theClass,
JStatement[] statements, String prefix, int start, int length,
int threshold) {
final JMethod method = theClass.method(JMod.PRIVATE + JMod.STATIC,
theClass.owner().VOID, prefix);
if (length < threshold) {
for (int index = start; (index - start) < length; index++) {
final JStatement statement = statements[index];
method.body().add(statement);
}
} else {
method.body().add(
split(theClass, statements, prefix + "_0", start,
length / 2, threshold));
method.body().add(
split(theClass, statements, prefix + "_1", start + length
/ 2, length - (length / 2), threshold));
}
return JExpr.invoke(method);
}
开发者ID:highsource,项目名称:jaxb2-basics,代码行数:21,代码来源:CodeModelUtils.java
示例5: caseAIfThenStatement
import com.sun.codemodel.JStatement; //导入依赖的package包/类
@Override
public void caseAIfThenStatement(AIfThenStatement node) {
ExpressionAdapter ea = new ExpressionAdapter(new JExprParent(), context);
node.getCond().apply(ea);
JConditional cond = parent._if(ea.expr);
JBlock tmpBlock = new JBlock();
StatementAdapter sa = new StatementAdapter(new JBlockParent(tmpBlock, context), context);
node.getThen().apply(sa);
JStatement stmt = (JStatement) tmpBlock.getContents().get(0);
if (stmt instanceof JBlock) {
JBlock stmtBlock = (JBlock) stmt;
stmtBlock.setNewlineRequired(false);
}
cond.setThen(stmt);
}
开发者ID:kompics,项目名称:kola,代码行数:16,代码来源:StatementAdapter.java
示例6: caseAWhileStatement
import com.sun.codemodel.JStatement; //导入依赖的package包/类
@Override
public void caseAWhileStatement(AWhileStatement node) {
ExpressionAdapter ea = new ExpressionAdapter(new JExprParent(), context);
node.getCond().apply(ea);
JWhileLoop wl = parent._while(ea.expr);
JBlock tmpBlock = new JBlock();
StatementAdapter sa = new StatementAdapter(new JBlockParent(tmpBlock, context), context);
node.getDo().apply(sa);
JStatement stmt = (JStatement) tmpBlock.getContents().get(0);
wl.setBody(stmt);
}
开发者ID:kompics,项目名称:kola,代码行数:12,代码来源:StatementAdapter.java
示例7: caseADoStatement
import com.sun.codemodel.JStatement; //导入依赖的package包/类
@Override
public void caseADoStatement(ADoStatement node) {
ExpressionAdapter ea = new ExpressionAdapter(new JExprParent(), context);
node.getCond().apply(ea);
JDoLoop wl = parent._do(ea.expr);
JBlock tmpBlock = new JBlock();
StatementAdapter sa = new StatementAdapter(new JBlockParent(tmpBlock, context), context);
node.getDo().apply(sa);
JStatement stmt = (JStatement) tmpBlock.getContents().get(0);
if (stmt instanceof JBlock) {
JBlock stmtBlock = (JBlock) stmt;
stmtBlock.setNewlineRequired(false);
}
wl.setBody(stmt);
}
开发者ID:kompics,项目名称:kola,代码行数:16,代码来源:StatementAdapter.java
示例8: basicForStatement
import com.sun.codemodel.JStatement; //导入依赖的package包/类
private void basicForStatement(PForInit init, Node cond, PForUpdate update, PStatement _do) {
context.pushStatementScope();
try {
JForLoop loop = parent._for();
if (init != null) {
ForInitAdapter fia = new ForInitAdapter(loop, context);
init.apply(fia);
}
if (update != null) {
ForUpdateAdapter fua = new ForUpdateAdapter(loop, context);
update.apply(fua);
}
if (cond != null) {
ExpressionAdapter ea = new ExpressionAdapter(new JExprParent(), context);
cond.apply(ea);
loop.test(ea.expr);
}
JBlock tmpBlock = new JBlock();
StatementAdapter sa = new StatementAdapter(new JBlockParent(tmpBlock, context), context);
_do.apply(sa);
JStatement stmt = (JStatement) tmpBlock.getContents().get(0);
if (stmt instanceof JBlock) {
JBlock stmtBlock = (JBlock) stmt;
stmtBlock.setNewlineRequired(false);
}
loop.setBody(stmt);
} finally {
context.popScope();
}
}
开发者ID:kompics,项目名称:kola,代码行数:31,代码来源:StatementAdapter.java
示例9: caseAEnhancedForStatement
import com.sun.codemodel.JStatement; //导入依赖的package包/类
@Override
public void caseAEnhancedForStatement(AEnhancedForStatement node) {
context.pushStatementScope();
try {
// Formal Parameter
AFormalParameter paramNode = (AFormalParameter) node.getVariable();
FormalParameter param = new FormalParameter();
FieldModifierAdapter fma = new FieldModifierAdapter(context);
paramNode.apply(fma);
param.mods = fma.getMods();
TypeAdapter ta = new TypeAdapter(context);
paramNode.getType().apply(ta);
param.type = ta.type;
AVariableDeclaratorId avdid = (AVariableDeclaratorId) paramNode.getVariableDeclaratorId();
param.id = avdid.getIdentifier().getText();
param.dim = avdid.getDim().size();
// Iterable
ExpressionAdapter ea = new ExpressionAdapter(new JExprParent(), context);
node.getIterable().apply(ea);
JForEach loop = parent.forEach(param.type, param.id, ea.expr);
context.addField(param.id, loop.var(), Field.Type.NORMAL);
// Do
JBlock tmpBlock = new JBlock();
StatementAdapter sa = new StatementAdapter(new JBlockParent(tmpBlock, context), context);
node.getDo().apply(sa);
JStatement stmt = (JStatement) tmpBlock.getContents().get(0);
// if (stmt instanceof JBlock) {
// JBlock stmtBlock = (JBlock) stmt;
// stmtBlock.setNewlineRequired(false);
// }
loop.setBody(stmt);
} finally {
context.popScope();
}
}
开发者ID:kompics,项目名称:kola,代码行数:40,代码来源:StatementAdapter.java
示例10: logMethodEntry
import com.sun.codemodel.JStatement; //导入依赖的package包/类
protected JStatement logMethodEntry(JMethod method) {
assert JavaClassGen.this.log_var != null;
final String msg = format("%%s.%s()", method.name());
return this.log_var
.invoke("debug").arg(msg).arg(JExpr._this());
}
开发者ID:BrainTech,项目名称:jsignalml,代码行数:8,代码来源:JavaClassGen.java
示例11: closeClass
import com.sun.codemodel.JStatement; //导入依赖的package包/类
private void closeClass(final JDefinedClass _class) {
final GenData data = generationData.get(_class.fullName());
final JMethod construct = _class.constructor(JMod.PUBLIC);
for (final JStatement expr : data.constructorList) {
construct.body().add(expr);
}
}
开发者ID:nhrdl,项目名称:javacash,代码行数:10,代码来源:CashGenerator.java
示例12: ensureArgumentNotNull
import com.sun.codemodel.JStatement; //导入依赖的package包/类
public JStatement ensureArgumentNotNull(final JVar param) {
ensureThatArgument(param, notNull());
return this.ensureClass
.staticInvoke("requireNonNull") //$NON-NLS-1$
.arg(param);
}
开发者ID:AndreasWBartels,项目名称:libraries,代码行数:7,代码来源:EnsurePredicateFactory.java
示例13: contribute
import com.sun.codemodel.JStatement; //导入依赖的package包/类
protected void contribute(CompositeAcElement ac,JBlock block,AbstractType target,JavaWriter writer){
JExpression expression=null;
switch (ac.getFamily()) {
case BOOLEAN:
expression=JExpr.direct("vl.isJsonPrimitive()&&vl.getAsJsonPrimitive().isBoolean()");
break;
case ARRAY:
expression=JExpr.direct("vl.isJsonArray()");
break;
case NUMBER:
expression=JExpr.direct("vl.isJsonPrimitive()&&vl.getAsJsonPrimitive().isNumber()");
break;
case STRING:
expression=JExpr.direct("vl.isJsonPrimitive()&&vl.getAsJsonPrimitive().isString()");
break;
case OBJECT:
expression=JExpr.direct("vl.isJsonObject()");
break;
default:
break;
}
JBlock _then = block._if(expression)._then();
for (AcElement x:ac.getChildren()){
if (x.kind()==AcElementKind.PROPERTY_EXISTANCE){
_then=_then._if(JExpr.direct("vl.getAsJsonObject().has(\""+x.getProperty()+"\")"))._then();
}
if (x.kind()==AcElementKind.PROPERTY_VALUE){
TestPropertyValueAcElement pv=(TestPropertyValueAcElement) x;
_then=_then._if(JExpr.direct("vl.getAsJsonObject().has(\""+x.getProperty()+"\")&&vl.getAsJsonObject().get(\""+x.getProperty()+"\").getAsString()!=null&&vl.getAsJsonObject().get(\""+x.getProperty()+"\").getAsString().equals(\""+pv.getValue()+"\")"))._then();
}
};
_then.add(new JStatement() {
@Override
public void state(JFormatter f) {
String name = getName(target, writer);
if (ac.getFamily()==TypeFamily.ARRAY&&writer.getConfig().containerStrategyCollection){
JType type = writer.getType(target);
if (type.erasure()!=type){
String elementName=((JClass) type).getTypeParameters().get(0).fullName();
String vv="new SimpleParameterizedType("+type.erasure().fullName()+".class,"+elementName+".class)";
f.p("union.set"+Character.toUpperCase(name.charAt(0))+name.substring(1)+"(gson.fromJson(vl, "+vv+"));");
}
else{
f.p("union.set"+Character.toUpperCase(name.charAt(0))+name.substring(1)+"(gson.fromJson(vl,"+getJavaTypeName(target, writer)+".class));");
}
}
else{
f.p("union.set"+Character.toUpperCase(name.charAt(0))+name.substring(1)+"(gson.fromJson(vl,"+getJavaTypeName(target, writer)+".class));");
}
f.nl();
f.p("return union;");
f.nl();
}
});
}
开发者ID:OnPositive,项目名称:aml,代码行数:58,代码来源:GsonAcElementWriter.java
示例14: contribute
import com.sun.codemodel.JStatement; //导入依赖的package包/类
protected void contribute(CompositeAcElement ac,JBlock block,AbstractType target,JavaWriter writer){
JExpression expression=null;
switch (ac.getFamily()) {
case BOOLEAN:
expression=JExpr.direct("vl.isValueNode()&&vl.isBoolean()");
break;
case ARRAY:
expression=JExpr.direct("vl.isArray()");
break;
case NUMBER:
expression=JExpr.direct("vl.isValueNode()&&vl.isNumber()");
break;
case STRING:
expression=JExpr.direct("vl.isValueNode()&&vl.isTextual()");
break;
case OBJECT:
expression=JExpr.direct("vl.isObject()");
break;
default:
break;
}
JBlock _then = block._if(expression)._then();
for (AcElement x:ac.getChildren()){
if (x.kind()==AcElementKind.PROPERTY_EXISTANCE){
_then=_then._if(JExpr.direct("vl.has(\""+x.getProperty()+"\")"))._then();
}
if (x.kind()==AcElementKind.PROPERTY_VALUE){
TestPropertyValueAcElement el=(TestPropertyValueAcElement) x;
_then=_then._if(JExpr.direct("vl.has(\""+x.getProperty()+"\")&&vl.get(\""+x.getProperty()+"\").asText().equals(\""+el.getValue()+"\")"))._then();
}
};
_then.add(new JStatement() {
@Override
public void state(JFormatter f) {
String name = getName(target, writer);
if (ac.getFamily()==TypeFamily.ARRAY&&writer.getConfig().containerStrategyCollection){
JType type = writer.getType(target);
if (type.erasure()!=type){
String elementName=((JClass) type).getTypeParameters().get(0).fullName();
String vv="com.fasterxml.jackson.databind.type.CollectionType.construct("+type.erasure().fullName()+".class,com.fasterxml.jackson.databind.type.SimpleType.construct("+elementName+".class))";
f.p("union.set"+Character.toUpperCase(name.charAt(0))+name.substring(1)+"(codec.readValue(vl.traverse(), "+vv+"));");
}
}
else{
f.p("union.set"+Character.toUpperCase(name.charAt(0))+name.substring(1)+"(codec.readValue(vl.traverse(), "+getJavaTypeName(target, writer)+".class));");
}
f.nl();
f.p("return union;");
f.nl();
}
});
}
开发者ID:OnPositive,项目名称:aml,代码行数:56,代码来源:JacksonDeserializerWriter.java
注:本文中的com.sun.codemodel.JStatement类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论