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


Java JForEach类代码示例

本文整理汇总了Java中com.sun.codemodel.JForEach的典型用法代码示例。如果您正苦于以下问题:Java JForEach类的具体用法?Java JForEach怎么用?Java JForEach使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


JForEach类属于com.sun.codemodel包,在下文中一共展示了JForEach类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addQuickLookupMap

import com.sun.codemodel.JForEach; //导入依赖的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;
    }
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:16,代码来源:EnumRule.java

示例2: generateEnumFromStringMethod

import com.sun.codemodel.JForEach; //导入依赖的package包/类
private void generateEnumFromStringMethod(JDefinedClass klass, JFieldVar valueField) {
    JMethod converter = klass.method(JMod.PUBLIC | JMod.STATIC, klass, "fromString");
    JVar param = converter.param(String.class, VALUE);

    JBlock body = converter.body();
    JForEach forEach = body.forEach(klass, "v", klass.staticInvoke("values"));
    JBlock loopBlock = forEach.body();
    loopBlock._if(forEach.var().ref(valueField).invoke("equals").arg(param))._then()
        ._return(forEach.var());
    body._throw(JExpr._new(codeModel._ref(IllegalArgumentException.class)).arg(param));
}
 
开发者ID:ops4j,项目名称:org.ops4j.ramler,代码行数:12,代码来源:EnumGenerator.java

示例3: registerAll

import com.sun.codemodel.JForEach; //导入依赖的package包/类
private void registerAll(EComponentHolder holder, Element element, String methodName, JClass eventOrRequestClass) {
    JMethod method = getMethodForRegistering(holder);
    final JClass moduleProviderClass = refClass(ModuleObjectsShare.class);
    final JInvocation modulesNames = moduleProviderClass.staticInvoke("modulesNames");
    final JConditional isEmpty = method.body()._if(modulesNames.invoke("isEmpty"));
    register(holder, element, methodName, eventOrRequestClass, lit(""), isEmpty._then());
    final JForEach forEach = isEmpty._else().forEach(refClass(String.class), "moduleName", modulesNames);
    forEach.body().directStatement("// we need to store module name in some final variable to use it in the listener");
    final JVar moduleNameToPass = forEach.body().decl(JMod.FINAL, refClass(String.class), "moduleNameToPass", forEach.var());
    register(holder, element, methodName, eventOrRequestClass, moduleNameToPass, forEach.body());
}
 
开发者ID:netimen,项目名称:android-modules,代码行数:12,代码来源:BusHandler.java

示例4: withValueField

import com.sun.codemodel.JForEach; //导入依赖的package包/类
public EnumBuilder withValueField(Class<?> type) {
	pojoCreationCheck();
	if (!this.pojo.fields().containsKey("value")) {
		//Create Field
		valueField = this.pojo.field(JMod.PRIVATE | JMod.FINAL, type, "value");
		
		//Create private Constructor
        JMethod constructor =  this.pojo.constructor(JMod.PRIVATE);
        JVar valueParam = constructor.param(type, "value");
        constructor.body().assign(JExpr._this().ref(valueField), valueParam);
        
        //add values to map
        JClass lookupType = this.pojo.owner().ref(Map.class).narrow(valueField.type().boxify(), this.pojo);
        lookupMap = this.pojo.field(JMod.PRIVATE | JMod.STATIC | JMod.FINAL, lookupType, "VALUE_CACHE");

        JClass lookupImplType = this.pojo.owner().ref(HashMap.class).narrow(valueField.type().boxify(), this.pojo);
        lookupMap.init(JExpr._new(lookupImplType));

        JForEach forEach = this.pojo.init().forEach(this.pojo, "c", JExpr.invoke("values"));
        JInvocation put = forEach.body().invoke(lookupMap, "put");
        put.arg(forEach.var().ref("value"));
        put.arg(forEach.var());
        
        //Add method to retrieve value
        JMethod fromValue = this.pojo.method(JMod.PUBLIC, valueField.type(), "value");
        fromValue.body()._return(JExpr._this().ref(valueField));
        
        addFromValueMethod();
        addToStringMethod();
	}
       return this;
}
 
开发者ID:phoenixnap,项目名称:springmvc-raml-plugin,代码行数:33,代码来源:EnumBuilder.java

示例5: caseAEnhancedForStatement

import com.sun.codemodel.JForEach; //导入依赖的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

示例6: addQuickLookupMap

import com.sun.codemodel.JForEach; //导入依赖的package包/类
private JFieldVar addQuickLookupMap(JDefinedClass _enum) {

        JClass lookupType = _enum.owner().ref(Map.class).narrow(_enum.owner().ref(String.class), _enum);
        JFieldVar lookupMap = _enum.field(JMod.PRIVATE | JMod.STATIC, lookupType, "constants");

        JClass lookupImplType = _enum.owner().ref(HashMap.class).narrow(_enum.owner().ref(String.class), _enum);
        lookupMap.init(JExpr._new(lookupImplType));

        JForEach forEach = _enum.init().forEach(_enum, "c", _enum.staticInvoke("values"));
        JInvocation put = forEach.body().invoke(lookupMap, "put");
        put.arg(forEach.var().ref("value"));
        put.arg(forEach.var());

        return lookupMap;
    }
 
开发者ID:fge,项目名称:jsonschema2pojo,代码行数:16,代码来源:EnumRule.java

示例7: forEach

import com.sun.codemodel.JForEach; //导入依赖的package包/类
@Override
public JForEach forEach(JType type, String id, JExpression iterable) {
    return block.forEach(type, id, iterable);
}
 
开发者ID:kompics,项目名称:kola,代码行数:5,代码来源:JBlockParent.java

示例8: loop

import com.sun.codemodel.JForEach; //导入依赖的package包/类
public JForEach loop(final JBlock block, final JExpression source, final JType sourceElementType, final JAssignmentTarget target, final JType targetElementType) {
	final JConditional ifNull = block._if(source.eq(JExpr._null()));
	ifNull._then().assign(target, JExpr._null());
	ifNull._else().assign(target, JExpr._new(this.arrayListClass.narrow(targetElementType)));
	return ifNull._else().forEach(sourceElementType, "_item", source);
}
 
开发者ID:mklemm,项目名称:jaxb2-rich-contract-plugin,代码行数:7,代码来源:PluginContext.java

示例9: generateAddMethods

import com.sun.codemodel.JForEach; //导入依赖的package包/类
private void generateAddMethods(final PropertyOutline propertyOutline,
                                final QName elementName, final JType jType) {
	final JClass elementType = jType.boxify();
	final JClass iterableType = this.pluginContext.iterableClass.narrow(elementType.wildcard());
	final String fieldName = this.pluginContext.outline.getModel().getNameConverter().toVariableName(elementName.getLocalPart());
	final String propertyName = this.pluginContext.outline.getModel().getNameConverter().toPropertyName(elementName.getLocalPart());
	final JMethod addIterableMethod = this.builderClass.raw.method(JMod.PUBLIC, this.builderClass.type, PluginContext.ADD_METHOD_PREFIX + propertyName);
	final JVar addIterableParam = addIterableMethod.param(JMod.FINAL, iterableType, fieldName + "_");
	generateAddMethodJavadoc(addIterableMethod, addIterableParam);
	final JMethod addVarargsMethod = this.builderClass.raw.method(JMod.PUBLIC, this.builderClass.type, PluginContext.ADD_METHOD_PREFIX + propertyName);
	final JVar addVarargsParam = addVarargsMethod.varParam(elementType, fieldName + "_");
	generateAddMethodJavadoc(addVarargsMethod, addVarargsParam);
	final BuilderOutline childBuilderOutline = getBuilderDeclaration(elementType);
	final JMethod addMethod;
	if (childBuilderOutline != null && !childBuilderOutline.getClassOutline().getImplClass().isAbstract()) {
		final JClass builderWithMethodReturnType = childBuilderOutline.getBuilderClass().narrow(this.builderClass.type.wildcard());
		addMethod = this.builderClass.raw.method(JMod.PUBLIC, builderWithMethodReturnType, PluginContext.ADD_METHOD_PREFIX + propertyName);
		generateBuilderMethodJavadoc(addMethod, "add", fieldName);
	} else {
		addMethod = null;
	}
	if (this.implement) {
		final BuilderOutline choiceChildBuilderOutline = getBuilderDeclaration(propertyOutline.getElementType());
		final JClass childBuilderType = childBuilderOutline == null ? this.pluginContext.buildableInterface : childBuilderOutline.getBuilderClass().narrow(this.builderClass.type);
		final JClass builderFieldElementType = choiceChildBuilderOutline == null ? this.pluginContext.buildableInterface : choiceChildBuilderOutline.getBuilderClass().narrow(this.builderClass.type);
		final JClass builderArrayListClass = this.pluginContext.arrayListClass.narrow(builderFieldElementType);
		final JFieldVar builderField = this.builderClass.raw.fields().get(propertyOutline.getFieldName());
		addVarargsMethod.body()._return(JExpr.invoke(addIterableMethod).arg(this.pluginContext.asList(addVarargsParam)));
		if (addMethod == null) {
			addIterableMethod.body()._return(JExpr.invoke(PluginContext.ADD_METHOD_PREFIX + propertyOutline.getBaseName()).arg(addIterableParam));
		} else {
			final JConditional addIterableIfParamNull = addIterableMethod.body()._if(addIterableParam.ne(JExpr._null()));
			final JConditional addIterableIfNull = addIterableIfParamNull._then()._if(JExpr._this().ref(builderField).eq(JExpr._null()));
			addIterableIfNull._then().assign(JExpr._this().ref(builderField), JExpr._new(builderArrayListClass));
			final JForEach addIterableForEach = addIterableIfParamNull._then().forEach(elementType, BuilderGenerator.ITEM_VAR_NAME, addIterableParam);
			final JExpression builderCreationExpression = JExpr._new(childBuilderType).arg(JExpr._this()).arg(addIterableForEach.var()).arg(this.settings.isCopyAlways() ? JExpr.TRUE : JExpr.FALSE);
			addIterableForEach.body().add(JExpr._this().ref(builderField).invoke("add").arg(builderCreationExpression));
			addIterableMethod.body()._return(JExpr._this());

			final JConditional addIfNull = addMethod.body()._if(JExpr._this().ref(builderField).eq(JExpr._null()));
			addIfNull._then().assign(JExpr._this().ref(builderField), JExpr._new(builderArrayListClass));
			final JVar childBuilderVar = addMethod.body().decl(JMod.FINAL, childBuilderType, fieldName + this.settings.getBuilderFieldSuffix(), JExpr._new(childBuilderType).arg(JExpr._this()).arg(JExpr._null()).arg(JExpr.FALSE));
			addMethod.body().add(JExpr._this().ref(builderField).invoke("add").arg(childBuilderVar));
			addMethod.body()._return(childBuilderVar);
		}
	}
}
 
开发者ID:mklemm,项目名称:jaxb2-rich-contract-plugin,代码行数:48,代码来源:BuilderGenerator.java

示例10: generateCollectionProperty

import com.sun.codemodel.JForEach; //导入依赖的package包/类
private void generateCollectionProperty(final JBlock initBody, final JVar productParam, final PropertyOutline propertyOutline, final JClass elementType) {
	final String fieldName = propertyOutline.getFieldName();
	final String propertyName = propertyOutline.getBaseName();
	final JClass iterableType = this.pluginContext.iterableClass.narrow(elementType.wildcard());
	final JMethod addIterableMethod = this.builderClass.raw.method(JMod.PUBLIC, this.builderClass.type, PluginContext.ADD_METHOD_PREFIX + propertyName);
	final JVar addIterableParam = addIterableMethod.param(JMod.FINAL, iterableType, fieldName);
	generateAddMethodJavadoc(addIterableMethod, addIterableParam);
	final JMethod withIterableMethod = this.builderClass.raw.method(JMod.PUBLIC, this.builderClass.type, PluginContext.WITH_METHOD_PREFIX + propertyName);
	final JVar withIterableParam = withIterableMethod.param(JMod.FINAL, iterableType, fieldName);
	generateWithMethodJavadoc(withIterableMethod, withIterableParam);
	final JMethod addVarargsMethod = this.builderClass.raw.method(JMod.PUBLIC, this.builderClass.type, PluginContext.ADD_METHOD_PREFIX + propertyName);
	final JVar addVarargsParam = addVarargsMethod.varParam(elementType, fieldName);
	generateAddMethodJavadoc(addVarargsMethod, addVarargsParam);
	final JMethod withVarargsMethod = this.builderClass.raw.method(JMod.PUBLIC, this.builderClass.type, PluginContext.WITH_METHOD_PREFIX + propertyName);
	final JVar withVarargsParam = withVarargsMethod.varParam(elementType, fieldName);
	generateWithMethodJavadoc(withVarargsMethod, withVarargsParam);
	final BuilderOutline childBuilderOutline = getBuilderDeclaration(elementType);
	final JMethod addMethod;
	if (childBuilderOutline != null && !childBuilderOutline.getClassOutline().getImplClass().isAbstract()) {
		final JClass builderWithMethodReturnType = childBuilderOutline.getBuilderClass().narrow(this.builderClass.type.wildcard());
		addMethod = this.builderClass.raw.method(JMod.PUBLIC, builderWithMethodReturnType, PluginContext.ADD_METHOD_PREFIX + propertyName);
		generateBuilderMethodJavadoc(addMethod, "add", propertyName);
	} else {
		addMethod = null;
	}
	if (this.implement) {
		final JClass childBuilderType = childBuilderOutline == null ? this.pluginContext.buildableInterface : childBuilderOutline.getBuilderClass().narrow(this.builderClass.type);
		final JClass builderArrayListClass = this.pluginContext.arrayListClass.narrow(childBuilderType);
		final JClass builderListClass = this.pluginContext.listClass.narrow(childBuilderType);
		final JFieldVar builderField = this.builderClass.raw.field(JMod.PRIVATE, builderListClass, fieldName);
		addVarargsMethod.body().invoke(addIterableMethod).arg(this.pluginContext.asList(addVarargsParam));
		addVarargsMethod.body()._return(JExpr._this());
		withVarargsMethod.body().invoke(withIterableMethod).arg(this.pluginContext.asList(withVarargsParam));
		withVarargsMethod.body()._return(JExpr._this());
		final JConditional addIterableIfParamNull = addIterableMethod.body()._if(addIterableParam.ne(JExpr._null()));
		final JConditional addIterableIfNull = addIterableIfParamNull._then()._if(JExpr._this().ref(builderField).eq(JExpr._null()));
		addIterableIfNull._then().assign(JExpr._this().ref(builderField), JExpr._new(builderArrayListClass));
		final JForEach jForEach = addIterableIfParamNull._then().forEach(elementType, BuilderGenerator.ITEM_VAR_NAME, addIterableParam);
		final JExpression builderCreationExpression = childBuilderOutline == null
				? JExpr._new(this.pluginContext.buildableClass).arg(jForEach.var())
				: JExpr._new(childBuilderType).arg(JExpr._this()).arg(jForEach.var()).arg(this.settings.isCopyAlways() ? JExpr.TRUE : JExpr.FALSE);
		jForEach.body().add(JExpr._this().ref(builderField).invoke("add").arg(builderCreationExpression));
		addIterableMethod.body()._return(JExpr._this());
		final JConditional withIterableIfNull = withIterableMethod.body()._if(JExpr._this().ref(builderField).ne(JExpr._null()));
		withIterableIfNull._then().add(JExpr._this().ref(builderField).invoke("clear"));
		withIterableMethod.body()._return(JExpr.invoke(addIterableMethod).arg(withIterableParam));
		final JConditional ifNull = initBody._if(JExpr._this().ref(builderField).ne(JExpr._null()));
		final JVar collectionVar = ifNull._then().decl(JMod.FINAL, this.pluginContext.listClass.narrow(elementType), fieldName, JExpr._new(this.pluginContext.arrayListClass.narrow(elementType)).arg(JExpr._this().ref(builderField).invoke("size")));
		final JForEach initForEach = ifNull._then().forEach(childBuilderType, BuilderGenerator.ITEM_VAR_NAME, JExpr._this().ref(builderField));
		final JInvocation buildMethodInvocation = initForEach.var().invoke(this.settings.getBuildMethodName());
		final JExpression buildExpression = childBuilderOutline == null ? JExpr.cast(elementType, buildMethodInvocation) : buildMethodInvocation;
		initForEach.body().add(collectionVar.invoke("add").arg(buildExpression));
		ifNull._then().assign(productParam.ref(fieldName), collectionVar);
		if (addMethod != null) {
			final JConditional addIfNull = addMethod.body()._if(JExpr._this().ref(builderField).eq(JExpr._null()));
			addIfNull._then().assign(JExpr._this().ref(builderField), JExpr._new(builderArrayListClass));
			final JVar childBuilderVar = addMethod.body().decl(JMod.FINAL, childBuilderType, fieldName + this.settings.getBuilderFieldSuffix(), JExpr._new(childBuilderType).arg(JExpr._this()).arg(JExpr._null()).arg(JExpr.FALSE));
			addMethod.body().add(JExpr._this().ref(builderField).invoke("add").arg(childBuilderVar));
			addMethod.body()._return(childBuilderVar);
		}
		this.pluginContext.generateImmutableFieldInit(initBody, productParam, propertyOutline);
	}
}
 
开发者ID:mklemm,项目名称:jaxb2-rich-contract-plugin,代码行数:64,代码来源:BuilderGenerator.java

示例11: loop

import com.sun.codemodel.JForEach; //导入依赖的package包/类
JForEach loop(final JBlock block, final JExpression source, final JType sourceElementType, final JAssignmentTarget target, final JType targetElementType) {
	final JConditional ifNull = block._if(source.eq(JExpr._null()));
	ifNull._then().assign(target, JExpr._null());
	ifNull._else().assign(target, JExpr._new(this.pluginContext.arrayListClass.narrow(targetElementType)));
	return ifNull._else().forEach(sourceElementType, BuilderGenerator.ITEM_VAR_NAME, source);
}
 
开发者ID:mklemm,项目名称:jaxb2-rich-contract-plugin,代码行数:7,代码来源:BuilderGenerator.java

示例12: getArgumentsType

import com.sun.codemodel.JForEach; //导入依赖的package包/类
private static JType getArgumentsType(JCodeModel cm, JDefinedClass cls, String name, Element[] args, boolean out) throws XPathExpressionException, JClassAlreadyExistsException {
        JDefinedClass returnClass = cls._class(JMod.PUBLIC | JMod.STATIC , name + (out ? "Response" : "Request"));
        returnClass._extends(SOAPSerializable.class);

        // public void parse(SOAPMessage soapmessage) throws SOAPException;
        JMethod parse = returnClass.method(JMod.PUBLIC, cm.VOID, "parse");
        JVar soapMessageParam = parse.param(SOAPMessage.class, "soapMessage");

        // public SOAPMessage format()
        JMethod format = returnClass.method(JMod.PUBLIC, SOAPMessage.class, "format");
        format._throws(SOAPException.class);
        JVar formatRetVal = format.body().decl(cm.ref(SOAPMessage.class), "retVal").init(returnClass.staticInvoke("createMessage"));
        JInvocation formatBodyElementInvocation = formatRetVal.invoke("getSOAPBody").invoke("addBodyElement").arg(JExpr._new(cm.ref(QName.class)).arg(JExpr.ref("URI")).arg(JExpr.lit(returnClass.name())).arg(JExpr.lit("u")));

        JClass xmlUtilClass = cm.ref(XmlUtil.class);
        if (args.length > 0) {
            parse.annotate(SuppressWarnings.class).param("value", "unchecked");
            parse._throws(SOAPException.class);
            
//            for (Element e : XmlUtil.getChildElements(XmlUtil.getChildElements(body).get(0))) {
            
//            for (Element e : XmlUtil.getChildElements(XmlUtil.getChildElements(soapMessage.getSOAPBody()).get(0))) {

            JInvocation collection = xmlUtilClass.staticInvoke("getChildElements").arg(xmlUtilClass.staticInvoke("getChildElements").arg(soapMessageParam.invoke("getSOAPBody")).invoke("get").arg(JExpr.lit(0)));
            
            
            JForEach parseFor = parse.body().forEach(cm._ref(Element.class), "e", collection);
            JVar parseForElement = parseFor.var();
            JVar parseForName = parseFor.body().decl(cm.ref(String.class), "name", parseForElement.invoke("getNodeName"));
            JVar formatElement = format.body().decl(cm.ref(SOAPBodyElement.class), "soapBodyElement",formatBodyElementInvocation);   
            for (Element outArg : args) {

                String relatedStateVariable = XPathUtil.getStringValue(outArg, "relatedStateVariable").trim();
                String elementName = XPathUtil.getStringValue(outArg, "name").trim(); 
                String fieldName = Character.toLowerCase(elementName.charAt(0)) + elementName.substring(1);
                JType fieldType = getStateVariableType(cm, cls, relatedStateVariable, outArg.getOwnerDocument());
                JFieldVar fieldVar = returnClass.field(JMod.PUBLIC, fieldType, fieldName);
                
                // element.addChildElement("Result").setTextContent(resultDidl);
                JInvocation formatSetText = formatElement.invoke("addChildElement").arg(JExpr.lit(elementName)).invoke("setTextContent");
                format.body().add(formatSetText);
                // if ("Result".equals(name)) {
                JBlock ifBody = parseFor.body()._if(JExpr.lit(elementName).invoke("equals").arg(parseForName))._then();
                // String value = e.getTextContent();
                if (fieldType.isPrimitive()) {
                    formatSetText.arg(cm.ref(Integer.class).staticInvoke("toString").arg(fieldVar));
                } else {
                    formatSetText.arg(fieldVar.invoke("toString"));
                }
                
                if (fieldType.equals(cm.ref(String.class))) {
                    // TransferID = e.getTextContent();
                    ifBody.assign(fieldVar, parseForElement.invoke("getTextContent"));
                } else if (fieldType.equals(cm.ref(Integer.class)) || fieldType.equals(cm.INT)) {
                    // TransferID = Integer.valueOf(e.getTextContent());
                    ifBody.assign(fieldVar, cm.ref(Integer.class).staticInvoke("valueOf").arg(parseForElement.invoke("getTextContent")));
                } else if (fieldType.equals(cm.ref(Boolean.class)) || fieldType.equals(cm.BOOLEAN)) {
                    // TransferID = Integer.valueOf(e.getTextContent());
                    ifBody.assign(fieldVar, cm.ref(Boolean.class).staticInvoke("valueOf").arg(parseForElement.invoke("getTextContent")));
                } else if (fieldType instanceof JClass) {
                    JClass fieldCls = (JClass) fieldType;
                    // TransferStatus = org.saintandreas.serket.scpd.TransferStatus.valueOf(e.getTextContent());
                    ifBody.assign(fieldVar, fieldCls.staticInvoke("valueOf").arg(parseForElement.invoke("getTextContent")));
                } else {
                    System.out.println("unparsed type " + fieldType);
                }
                //            JVar value = ifBody.decl(cm.ref(String.class), "value", );
                ifBody._continue();
            }
        } else {
            format.body().add(formatBodyElementInvocation);
        }
        
        format.body()._return(formatRetVal);
        return returnClass;
    }
 
开发者ID:jherico,项目名称:serket,代码行数:77,代码来源:GenerateScpdClasses.java

示例13: generateEnum

import com.sun.codemodel.JForEach; //导入依赖的package包/类
/**
 * Generates an enum for a given field
 * 
 * @param f
 * @param name
 *            of enum in UpperCamelCase
 * @return
 * @throws JClassAlreadyExistsException
 */
public JDefinedClass generateEnum(ApplicationField f, String name) throws JClassAlreadyExistsException {
	JDefinedClass result = jp != null ? jp._enum(name) : jc._package("")._enum(name);
	result._implements(PodioCategory.class);

	// fields:
	JFieldVar podioId = result.field(JMod.PRIVATE, jc.INT, "podioId");
	JFieldVar value = result.field(JMod.PRIVATE, jc.ref(String.class), "value");

	// constructor:
	JMethod constructor = result.constructor(JMod.PRIVATE);
	JVar constructorPodioIdParam = constructor.param(jc.INT, "podioId");
	JVar constructorToStringParam = constructor.param(jc.ref(String.class), "value");
	constructor.body().assign(JExpr._this().ref(podioId), constructorPodioIdParam);
	constructor.body().assign(JExpr._this().ref(value), constructorToStringParam);

	// toString:
	result.method(JMod.PUBLIC, String.class, "toString").body()._return(value);

	// getId:
	result.method(JMod.PUBLIC, jc.INT, "getPodioId").body()._return(podioId);

	// static byId:
	JMethod byId = result.method(JMod.PUBLIC | JMod.STATIC, result, "byId");
	byId.javadoc().addReturn().add("{@code null}, if no element with given {@code id} exists.");
	JVar byIdParam = byId.param(jc.INT, "podioId");
	JForEach forEach = byId.body().forEach(result, "e", result.staticInvoke("values"));
	forEach.body()._if(byIdParam.eq(forEach.var().invoke("getPodioId")))._then()._return(forEach.var());
	byId.body()._return(JExpr._null());

	// literals:
	result.enumConstant("NONE").arg(JExpr.lit(0)).arg(JExpr.lit("--"));
	for (CategoryOption option : f.getConfiguration().getSettings().getOptions()) {
		String constantName = JavaNames.createValidJavaTypeName(option.getText(), name);
		String finalConstantName = CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE,
				constantName);
		JEnumConstant constant = result.enumConstant(finalConstantName);
		constant.arg(JExpr.lit(option.getId())).arg(JExpr.lit(option.getText()));
		if (option.getStatus().equals(CategoryOptionStatus.DELETED)) {
			constant.annotate(Deprecated.class);
		}
	}

	return result;
}
 
开发者ID:daniel-sc,项目名称:podio-java-codegen,代码行数:54,代码来源:EnumGenerator.java

示例14: createFormatMethod

import com.sun.codemodel.JForEach; //导入依赖的package包/类
static
private void createFormatMethod(JDefinedClass clazz, JPrimitiveType type){
	JCodeModel codeModel = clazz.owner();

	JClass numberClazz = codeModel.ref(Number.class);
	JClass stringBuilderClazz = codeModel.ref(StringBuilder.class);

	JType numberListClazz;

	try {
		numberListClazz = codeModel.parseType("java.util.List<? extends java.lang.Number>");
	} catch(ClassNotFoundException cnfe){
		throw new RuntimeException(cnfe);
	}

	JMethod method = clazz.method(JMod.STATIC | JMod.PRIVATE, String.class, "format");

	JVar valuesParameter = method.param(numberListClazz, "values");

	JBlock body = method.body();

	JVar sbVariable = body.decl(stringBuilderClazz, "sb", JExpr._new(stringBuilderClazz).arg(valuesParameter.invoke("size").mul(JExpr.lit(32))));

	JForEach forStatement = body.forEach(numberClazz, "value", valuesParameter);

	JBlock forBody = forStatement.body();

	forBody.add(createReportInvocation(clazz, sbVariable, "${0}", Collections.singletonList(forStatement.var()), type));

	body._return(sbVariable.invoke("toString"));
}
 
开发者ID:jpmml,项目名称:jpmml-evaluator,代码行数:32,代码来源:OperationProcessor.java

示例15: forEach

import com.sun.codemodel.JForEach; //导入依赖的package包/类
public JForEach forEach(JType type, String id, JExpression iterable); 
开发者ID:kompics,项目名称:kola,代码行数:2,代码来源:StatementAdapter.java


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