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


Java JConditional类代码示例

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


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

示例1: addFactoryMethod

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

示例2: addPublicGetMethod

import com.sun.codemodel.JConditional; //导入依赖的package包/类
private JMethod addPublicGetMethod(JDefinedClass jclass, JMethod internalGetMethod, JFieldRef notFoundValue) {
    JMethod method = jclass.method(PUBLIC, jclass.owner()._ref(Object.class), GETTER_NAME);
    JTypeVar returnType = method.generify("T");
    method.type(returnType);
    Models.suppressWarnings(method, "unchecked");
    JVar nameParam = method.param(String.class, "name");
    JBlock body = method.body();
    JVar valueVar = body.decl(jclass.owner()._ref(Object.class), "value",
            invoke(internalGetMethod).arg(nameParam).arg(notFoundValue));
    JConditional found = method.body()._if(notFoundValue.ne(valueVar));
    found._then()._return(cast(returnType, valueVar));
    JBlock notFound = found._else();

    JMethod getAdditionalProperties = jclass.getMethod("getAdditionalProperties", new JType[] {});
    if (getAdditionalProperties != null) {
        notFound._return(cast(returnType, invoke(getAdditionalProperties).invoke("get").arg(nameParam)));
    } else {
        notFound._throw(illegalArgumentInvocation(jclass, nameParam));
    }

    return method;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:DynamicPropertiesRule.java

示例3: addParameter

import com.sun.codemodel.JConditional; //导入依赖的package包/类
private void addParameter(JBlock methodBody, JVar queryParams, String valueName, Boolean encode, Boolean simple, boolean isList) {
  JBlock b = methodBody;
  if (!simple) {
    JConditional _if = methodBody._if(JExpr.ref(valueName).ne(JExpr._null()));
    b = _if._then();
  }
  b.invoke(queryParams, "append").arg(JExpr.lit(valueName + "="));
  if (encode) {
      JExpression expr = jCodeModel.ref(java.net.URLEncoder.class).staticInvoke("encode").arg(JExpr.ref(valueName)).arg("UTF-8");
      b.invoke(queryParams, "append").arg(expr);
  } else {
    if(isList){
      b.directStatement("if("+valueName+".getClass().isArray())"
          +"{queryParams.append(String.join(\"&"+valueName+"=\"," +valueName+"));}");
    } else{
      b.invoke(queryParams, "append").arg(JExpr.ref(valueName));
    }
  }
  b.invoke(queryParams, "append").arg(JExpr.lit("&"));
}
 
开发者ID:folio-org,项目名称:raml-module-builder,代码行数:21,代码来源:ClientGenerator.java

示例4: createMethodFieldSetFieldValue

import com.sun.codemodel.JConditional; //导入依赖的package包/类
private void createMethodFieldSetFieldValue(JDefinedClass _class, Map<String, JType> fields) {
		JMethod method = _class.method(JMod.PUBLIC, Void.TYPE, "setFieldValue");
		JClass refEnumFields = codeModel.ref(_class.fullName() + DOT_FIELD);
		JVar param = method.param(refEnumFields, "field");
		JVar param2 = method.param(codeModel.ref(Object.class), "value");
		JBlock body = method.body();

		JSwitch _switch = body._switch(param);
		for (Map.Entry<String, JType> entry : fields.entrySet()) {
			JBlock bodyCase = _switch._case(JExpr.ref(entry.getKey().toUpperCase())).body();
			JConditional _if = bodyCase._if(param2.eq(JExpr._null()));
			String capitalizeName = JavaGeneratorUtil.getCapitalizeString(entry.getKey());
			_if._then().invoke("unset" + capitalizeName);
			_if._else().invoke("set" + capitalizeName).arg(JExpr.cast(getTypeGetMethodByName(_class, capitalizeName), param2));
			bodyCase._break();
		}

//		JInvocation _newException = JExpr._new(codeModel.ref(IllegalStateException.class));
//		_switch._default().body()._throw(_newException);

	}
 
开发者ID:l3ug1m,项目名称:thrift-java-compiler,代码行数:22,代码来源:StructCodeGeneratorHelper.java

示例5: ifHasSetValue

import com.sun.codemodel.JConditional; //导入依赖的package包/类
public JBlock ifHasSetValue(JBlock block, boolean isAlwaysSet,
		boolean checkForNullRequired) {
	if (isAlwaysSet || !checkForNullRequired) {
		return block;
	} else {
		final JConditional ifLeftHasSetValue = block._if(leftHasSetValue());
		final JConditional ifLeftHasSetValueAndRightHasSetValue = ifLeftHasSetValue
				._then()._if(rightHasSetValue());
		final JBlock subBlock = ifLeftHasSetValueAndRightHasSetValue
				._then();
		ifLeftHasSetValueAndRightHasSetValue._else()._return(JExpr.FALSE);
		ifLeftHasSetValue._elseif(rightHasSetValue())._then()
				._return(JExpr.FALSE);
		return subBlock;
	}
}
 
开发者ID:highsource,项目名称:jaxb2-basics,代码行数:17,代码来源:EqualsArguments.java

示例6: createSetter

import com.sun.codemodel.JConditional; //导入依赖的package包/类
protected JMethod createSetter() {
	final JMethod setter;

	final MethodWriter writer = outline.createMethodWriter();
	setter = writer.declareMethod(codeModel.VOID, getSetterName());
	final JVar target = writer.addParameter(exposedType, "target");

	final JExpression wrapCondition = wrapCondifiton(target);
	if (wrapCondition == null) {
		setCore(setter.body(), wrap(target));
	} else {
		final JConditional _if = setter.body()._if(wrapCondition);
		setCore(_if._then(), wrap(target));
	}
	return setter;
}
 
开发者ID:highsource,项目名称:hyperjaxb3,代码行数:17,代码来源:AbstractWrappingField.java

示例7: createGetter

import com.sun.codemodel.JConditional; //导入依赖的package包/类
protected JMethod createGetter() {
	final MethodWriter writer = outline.createMethodWriter();
	final JMethod getter = writer.declareMethod(exposedType,
			getGetterName());
	JExpression source = getCore();
	final JExpression unwrapCondition = unwrapCondifiton(source);
	if (unwrapCondition == null) {
		getter.body()._return(unwrap(source));
	} else {
		final JConditional _if = getter.body()._if(unwrapCondition);
		_if._then()._return(unwrap(source));
		_if._else()._return(JExpr._null());
	}
	return getter;
}
 
开发者ID:highsource,项目名称:hyperjaxb3,代码行数:16,代码来源:AbstractWrappingField.java

示例8: generateBuildMethod

import com.sun.codemodel.JConditional; //导入依赖的package包/类
JMethod generateBuildMethod(final JMethod initMethod) {
	final JMethod buildMethod = this.builderClass.raw.method(JMod.PUBLIC, this.definedClass, this.settings.getBuildMethodName());
	if (!(this.builderClass.type._extends() == null || this.builderClass.type._extends().name().equals("java.lang.Object"))) {
		buildMethod.annotate(Override.class);
	}
	if (this.implement) {
		final JExpression buildExpression = JExpr._this().invoke(initMethod).arg(JExpr._new(this.definedClass));
		if (this.settings.isCopyAlways()) {
			buildMethod.body()._return(buildExpression);
		} else if (this.definedClass.isAbstract()) {
			buildMethod.body()._return(JExpr.cast(this.definedClass, this.storedValueField));
		} else {
			final JConditional jConditional = buildMethod.body()._if(this.storedValueField.eq(JExpr._null()));
			jConditional._then()._return(buildExpression);
			jConditional._else()._return(JExpr.cast(this.definedClass, this.storedValueField));
		}
	}
	return buildMethod;
}
 
开发者ID:mklemm,项目名称:jaxb2-rich-contract-plugin,代码行数:20,代码来源:BuilderGenerator.java

示例9: renderBuilderCreateContract

import com.sun.codemodel.JConditional; //导入依赖的package包/类
private void renderBuilderCreateContract(JDefinedClass builderClass, JClass literalBuilderClass, List<FieldModel> fields, Class<?> contractInterface) {
	JMethod createContractMethod = builderClass.method(JMod.PUBLIC | JMod.STATIC, literalBuilderClass, "create");
	JVar contractParam = createContractMethod.param(contractInterface, "contract");
	JBlock body = createContractMethod.body();
	JConditional nullContractCheck = body._if(contractParam.eq(JExpr._null()));
	nullContractCheck._then().directStatement("throw new IllegalArgumentException(\"contract was null\");");
	body.directStatement("// TODO if create() is modified to accept required parameters, this will need to be modified");
	body.directStatement("Builder builder = create();");
	for (FieldModel fieldModel : fields) {
		String fieldName = fieldModel.fieldName;
		body.directStatement("builder." + Util.generateSetter(fieldName, "contract." + Util.generateGetter(fieldName, isBoolean(fieldModel.fieldType))) + ";");
	}
	body.directStatement("return builder;");
}
 
开发者ID:kuali,项目名称:rice,代码行数:15,代码来源:ImmutableJaxbGenerator.java

示例10: replaceCollectionGetter

import com.sun.codemodel.JConditional; //导入依赖的package包/类
private void replaceCollectionGetter(FieldOutline field, final JMethod getter) {
    JDefinedClass clazz = field.parent().implClass;
    // remove the old getter
    clazz.methods().remove(getter);
    // and create a new one
    JMethod newGetter = field.parent().implClass.method(getter.mods().getValue(), getter.type(), getter.name());
    JBlock block = newGetter.body();

    JVar ret = block.decl(getJavaType(field), "ret");
    JCodeModel codeModel = field.parent().implClass.owner();
    JVar param = generateMethodParameter(getter, field);
    JConditional conditional = block._if(param.eq(JExpr._null()));
    conditional._then().assign(ret, getEmptyCollectionExpression(codeModel, param));
    conditional._else().assign(ret, getUnmodifiableWrappedExpression(codeModel, param));
    block._return(ret);

    getter.javadoc().append("Returns unmodifiable collection.");
}
 
开发者ID:sabomichal,项目名称:immutable-xjc,代码行数:19,代码来源:PluginImpl.java

示例11: generatePropertyAssignment

import com.sun.codemodel.JConditional; //导入依赖的package包/类
private void generatePropertyAssignment(final JMethod method, FieldOutline fieldOutline, boolean wrapUnmodifiable) {
    JBlock block = method.body();
    JCodeModel codeModel = fieldOutline.parent().implClass.owner();
    String fieldName = fieldOutline.getPropertyInfo().getName(false);
    JVar param = generateMethodParameter(method, fieldOutline);
    if (fieldOutline.getPropertyInfo().isCollection()) {
        if (wrapUnmodifiable) {
            JConditional conditional = block._if(param.eq(JExpr._null()));
            conditional._then().assign(JExpr.refthis(fieldName), JExpr._null());
            conditional._else().assign(JExpr.refthis(fieldName), getDefensiveCopyExpression(codeModel, getJavaType(fieldOutline), param));
        } else {
            block.assign(JExpr.refthis(fieldName), JExpr.ref(fieldName));
        }

        replaceCollectionGetter(fieldOutline, getGetterProperty(fieldOutline));
    } else {
        block.assign(JExpr.refthis(fieldName), JExpr.ref(fieldName));
    }
}
 
开发者ID:sabomichal,项目名称:immutable-xjc,代码行数:20,代码来源:PluginImpl.java

示例12: addEquals

import com.sun.codemodel.JConditional; //导入依赖的package包/类
/**
 * Adds a equals method, containing all non-static field variables.
 * 
 * @param jclass
 * @param jCodeModel
 * @param includeSuperEquals
 *            if {@code true} super.equals() is incorporated.
 */
public static void addEquals(JDefinedClass jclass, JCodeModel jCodeModel, boolean includeSuperEquals) {
	JMethod equals = jclass.method(JMod.PUBLIC, jCodeModel.BOOLEAN, "equals");
	JVar _obj = equals.param(jCodeModel.ref(Object.class), "obj");
	if (includeSuperEquals) {
		equals.body()._if(JExpr.FALSE.eq(JExpr._super().invoke("equals").arg(_obj)))._then()._return(JExpr.FALSE);
	}
	equals.body().directStatement("\tif (this == obj)\n\t\treturn true;\n\tif (obj == null)\n\t\treturn false;\n\tif (getClass() != obj.getClass())\treturn false;");
	JVar _other = equals.body().decl(jclass, "other", JExpr.cast(jclass, _obj));
	for (JFieldVar jvar : jclass.fields().values()) {
		if ((jvar.mods().getValue() & JMod.STATIC) == JMod.STATIC) {
			continue;
		}
		
		JConditional _outerIf = equals.body()._if(jvar.eq(JExpr._null()));
		_outerIf._then()._if(_other.ref(jvar.name()).ne(JExpr._null()))._then()._return(JExpr.FALSE);
		_outerIf._else()._if((jvar.invoke("equals").arg(_other.ref(jvar.name())).not()))._then()._return(JExpr.FALSE);
	}
	equals.body()._return(JExpr.TRUE);
}
 
开发者ID:daniel-sc,项目名称:podio-java-codegen,代码行数:28,代码来源:CodeGenerator.java

示例13: addFactoryMethod

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

示例14: addInternalGetMethodJava6

import com.sun.codemodel.JConditional; //导入依赖的package包/类
private JMethod addInternalGetMethodJava6(JDefinedClass jclass, JsonNode propertiesNode) {
    JMethod method = jclass.method(PROTECTED, jclass.owner()._ref(Object.class), DEFINED_GETTER_NAME);
    JVar nameParam = method.param(String.class, "name");
    JVar notFoundParam = method.param(jclass.owner()._ref(Object.class), "notFoundValue");
    JBlock body = method.body();
    JConditional propertyConditional = null;

    if (propertiesNode != null) {
        for (Iterator<Map.Entry<String, JsonNode>> properties = propertiesNode.fields(); properties.hasNext();) {
            Map.Entry<String, JsonNode> property = properties.next();
            String propertyName = property.getKey();
            JsonNode node = property.getValue();
            String fieldName = ruleFactory.getNameHelper().getPropertyName(propertyName, node);
            JType propertyType = jclass.fields().get(fieldName).type();

            JExpression condition = lit(propertyName).invoke("equals").arg(nameParam);
            if (propertyConditional == null) {
                propertyConditional = body._if(condition);
            } else {
                propertyConditional = propertyConditional._elseif(condition);
            }
            JMethod propertyGetter = jclass.getMethod(getGetterName(propertyName, propertyType, node), new JType[] {});
            propertyConditional._then()._return(invoke(propertyGetter));
        }
    }

    JClass extendsType = jclass._extends();
    JBlock lastBlock = propertyConditional == null ? body : propertyConditional._else();
    if (extendsType != null && extendsType instanceof JDefinedClass) {
        JDefinedClass parentClass = (JDefinedClass) extendsType;
        JMethod parentMethod = parentClass.getMethod(DEFINED_GETTER_NAME,
                new JType[] { parentClass.owner()._ref(String.class), parentClass.owner()._ref(Object.class) });
        lastBlock._return(_super().invoke(parentMethod).arg(nameParam).arg(notFoundParam));
    } else {
        lastBlock._return(notFoundParam);
    }

    return method;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:40,代码来源:DynamicPropertiesRule.java

示例15: addInternalSetMethodJava6

import com.sun.codemodel.JConditional; //导入依赖的package包/类
private JMethod addInternalSetMethodJava6(JDefinedClass jclass, JsonNode propertiesNode) {
    JMethod method = jclass.method(PROTECTED, jclass.owner().BOOLEAN, DEFINED_SETTER_NAME);
    JVar nameParam = method.param(String.class, "name");
    JVar valueParam = method.param(Object.class, "value");
    JBlock body = method.body();
    JConditional propertyConditional = null;
    if (propertiesNode != null) {
        for (Iterator<Map.Entry<String, JsonNode>> properties = propertiesNode.fields(); properties.hasNext();) {
            Map.Entry<String, JsonNode> property = properties.next();
            String propertyName = property.getKey();
            JsonNode node = property.getValue();
            String fieldName = ruleFactory.getNameHelper().getPropertyName(propertyName, node);
            JType propertyType = jclass.fields().get(fieldName).type();
            JExpression condition = lit(propertyName).invoke("equals").arg(nameParam);
            propertyConditional = propertyConditional == null ? propertyConditional = body._if(condition)
                    : propertyConditional._elseif(condition);

            JBlock callSite = propertyConditional._then();
            addSetProperty(jclass, callSite, propertyName, propertyType, valueParam, node);
            callSite._return(TRUE);
        }
    }
    JClass extendsType = jclass._extends();
    JBlock lastBlock = propertyConditional == null ? body : propertyConditional._else();

    if (extendsType != null && extendsType instanceof JDefinedClass) {
        JDefinedClass parentClass = (JDefinedClass) extendsType;
        JMethod parentMethod = parentClass.getMethod(DEFINED_SETTER_NAME,
                new JType[] { parentClass.owner()._ref(String.class), parentClass.owner()._ref(Object.class) });
        lastBlock._return(_super().invoke(parentMethod).arg(nameParam).arg(valueParam));
    } else {
        lastBlock._return(FALSE);
    }
    return method;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:36,代码来源:DynamicPropertiesRule.java


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