本文整理匯總了Java中com.sun.codemodel.JDefinedClass.fields方法的典型用法代碼示例。如果您正苦於以下問題:Java JDefinedClass.fields方法的具體用法?Java JDefinedClass.fields怎麽用?Java JDefinedClass.fields使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.sun.codemodel.JDefinedClass
的用法示例。
在下文中一共展示了JDefinedClass.fields方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: addToString
import com.sun.codemodel.JDefinedClass; //導入方法依賴的package包/類
private void addToString(JDefinedClass jclass) {
Map<String, JFieldVar> fields = jclass.fields();
JMethod toString = jclass.method(JMod.PUBLIC, String.class, "toString");
Set<String> excludes = new HashSet<String>(Arrays.asList(ruleFactory.getGenerationConfig().getToStringExcludes()));
JBlock body = toString.body();
Class<?> toStringBuilder = ruleFactory.getGenerationConfig().isUseCommonsLang3() ? org.apache.commons.lang3.builder.ToStringBuilder.class : org.apache.commons.lang.builder.ToStringBuilder.class;
JClass toStringBuilderClass = jclass.owner().ref(toStringBuilder);
JInvocation toStringBuilderInvocation = JExpr._new(toStringBuilderClass).arg(JExpr._this());
if (!jclass._extends().fullName().equals(Object.class.getName())) {
toStringBuilderInvocation = toStringBuilderInvocation.invoke("appendSuper").arg(JExpr._super().invoke("toString"));
}
for (JFieldVar fieldVar : fields.values()) {
if (excludes.contains(fieldVar.name()) || (fieldVar.mods().getValue() & JMod.STATIC) == JMod.STATIC) {
continue;
}
toStringBuilderInvocation = toStringBuilderInvocation.invoke("append").arg(fieldVar.name()).arg(fieldVar);
}
body._return(toStringBuilderInvocation.invoke("toString"));
toString.annotate(Override.class);
}
示例2: searchClassAndSuperClassesForField
import com.sun.codemodel.JDefinedClass; //導入方法依賴的package包/類
private JFieldVar searchClassAndSuperClassesForField(String property, JDefinedClass jclass) {
Map<String, JFieldVar> fields = jclass.fields();
JFieldVar field = fields.get(property);
if (field == null) {
return searchSuperClassesForField(property, jclass);
}
return field;
}