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


Java JAnnotationUse类代码示例

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


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

示例1: apply

import com.sun.codemodel.JAnnotationUse; //导入依赖的package包/类
@Override
public JFieldVar apply(String nodeName, JsonNode node, JFieldVar field, Schema currentSchema) {

    if (ruleFactory.getGenerationConfig().isIncludeJsr303Annotations()
            && (node.has("minItems") || node.has("maxItems"))) {

        JAnnotationUse annotation = field.annotate(Size.class);

        if (node.has("minItems")) {
            annotation.param("min", node.get("minItems").asInt());
        }

        if (node.has("maxItems")) {
            annotation.param("max", node.get("maxItems").asInt());
        }
    }

    return field;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:20,代码来源:MinItemsMaxItemsRule.java

示例2: addJsonTypeInfo

import com.sun.codemodel.JAnnotationUse; //导入依赖的package包/类
private void addJsonTypeInfo(JDefinedClass klass, ObjectTypeDeclaration type) {
    if (!context.getConfig().isJacksonTypeInfo()) {
        return;
    }
    if (type.discriminator() == null) {
        return;
    }
    List<String> derivedTypes = context.getApiModel().findDerivedTypes(type.name());
    if (derivedTypes.isEmpty()) {
        return;
    }
    JAnnotationUse typeInfo = klass.annotate(JsonTypeInfo.class);
    typeInfo.param("use", Id.NAME);
    typeInfo.param("include", As.EXISTING_PROPERTY);
    typeInfo.param("property", type.discriminator());

    JAnnotationUse subTypes = klass.annotate(JsonSubTypes.class);
    JAnnotationArrayMember typeArray = subTypes.paramArray(VALUE);

    for (String derivedType : derivedTypes) {
        JDefinedClass subtype = pkg._getClass(derivedType);
        typeArray.annotate(Type.class).param(VALUE, subtype);
    }
}
 
开发者ID:ops4j,项目名称:org.ops4j.ramler,代码行数:25,代码来源:PojoGeneratingApiVisitor.java

示例3: apply

import com.sun.codemodel.JAnnotationUse; //导入依赖的package包/类
@Override
public JFieldVar apply(String nodeName, JsonNode node, JFieldVar field, Schema currentSchema) {
    
    if (ruleFactory.getGenerationConfig().isIncludeJsr303Annotations()
            && (node.has("minLength") || node.has("maxLength"))) {

        JAnnotationUse annotation = field.annotate(Size.class);

        if (node.has("minLength")) {
            annotation.param("min", node.get("minLength").asInt());
        }

        if (node.has("maxLength")) {
            annotation.param("max", node.get("maxLength").asInt());
        }
    }

    return field;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:20,代码来源:MinLengthMaxLengthRule.java

示例4: addAnnotParam

import com.sun.codemodel.JAnnotationUse; //导入依赖的package包/类
/**
 * Calls the correct {@link JAnnotationUse} <code>param</code> method.
 * 
 * @param annot
 *            The annotation in which the parameter will be added.
 * @param key
 *            The parameter's key.
 * @param value
 *            The parameter's value.
 */
public static void addAnnotParam(JAnnotationUse annot, String key, Object value) {
    if (value == null) {
        // Null values not accepted
        throw new RuntimeException("Null values not supported as annotation parameters");
    } else if (value instanceof Boolean) {
        annot.param(key, (Boolean) value);
    } else if (value instanceof Integer) {
        annot.param(key, (Integer) value);
    } else if (value instanceof String) {
        annot.param(key, (String) value);
    } else if (value instanceof Class<?>) {
        annot.param(key, (Class<?>) value);
    } else if (value instanceof JType) {
        annot.param(key, (JType) value);
    } else if (value.getClass().isArray()) {
        Object[] valueArr = (Object[]) value;
        JAnnotationArrayMember aux = annot.paramArray(key);
        for (int i = 0; i < valueArr.length; ++i) {
            addAnnotArrayParam(aux, valueArr[i]);
        }
    } else {
        throw new RuntimeException("Impossible to construct annotation param for: " + value);
    }
}
 
开发者ID:hibernate,项目名称:beanvalidation-benchmark,代码行数:35,代码来源:Util.java

示例5: addJsr303Annotations

import com.sun.codemodel.JAnnotationUse; //导入依赖的package包/类
private void addJsr303Annotations(final INamedParam parameter,
		final JVar argumentVariable) {
	if (isNotBlank(parameter.getPattern())) {
		JAnnotationUse patternAnnotation = argumentVariable.annotate(Pattern.class);
		patternAnnotation.param("regexp", parameter.getPattern());
	}

	final Integer minLength = parameter.getMinLength();
	final Integer maxLength = parameter.getMaxLength();
	if ((minLength != null) || (maxLength != null)) {
		final JAnnotationUse sizeAnnotation = argumentVariable
				.annotate(Size.class);

		if (minLength != null) {
			sizeAnnotation.param("min", minLength);
		}

		if (maxLength != null) {
			sizeAnnotation.param("max", maxLength);
		}
	}

	final BigDecimal minimum = parameter.getMinimum();
	if (minimum != null) {
		addMinMaxConstraint(parameter, "minimum", Min.class, minimum,
				argumentVariable);
	}

	final BigDecimal maximum = parameter.getMaximum();
	if (maximum != null) {
		addMinMaxConstraint(parameter, "maximum", Max.class, maximum,
				argumentVariable);
	}

	if (parameter.isRequired()) {
		argumentVariable.annotate(NotNull.class);
	}
}
 
开发者ID:OnPositive,项目名称:aml,代码行数:39,代码来源:AbstractGenerator.java

示例6: getOrAddXmlSchemaAnnotation

import com.sun.codemodel.JAnnotationUse; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private static JAnnotationUse getOrAddXmlSchemaAnnotation(JPackage p, JClass xmlSchemaClass) {

	JAnnotationUse xmlAnn = null;

	final List<JAnnotationUse> annotations = getAnnotations(p);
	if (annotations != null) {
		for (JAnnotationUse annotation : annotations) {
			final JClass clazz = getAnnotationJClass(annotation);
			if (clazz == xmlSchemaClass) {
				xmlAnn = annotation;
				break;
			}
		}
	}

	if (xmlAnn == null) {
		// XmlSchema annotation not found, let's add one
		xmlAnn = p.annotate(xmlSchemaClass);
	}

	return xmlAnn;
}
 
开发者ID:Siggen,项目名称:jaxb2-namespace-prefix,代码行数:24,代码来源:NamespacePrefixPlugin.java

示例7: testClassWithPersistenceContextWithKonfiguredUnitNameSpecified

import com.sun.codemodel.JAnnotationUse; //导入依赖的package包/类
@Test
public void testClassWithPersistenceContextWithKonfiguredUnitNameSpecified() throws Exception {
    // GIVEN
    final JCodeModel jCodeModel = new JCodeModel();
    final JPackage jp = jCodeModel.rootPackage();
    final JDefinedClass jClass = jp._class(JMod.PUBLIC, "ClassUnderTest");
    final JFieldVar ruleField = jClass.field(JMod.PUBLIC, JpaUnitRule.class, "rule");
    ruleField.annotate(Rule.class);
    final JInvocation instance = JExpr._new(jCodeModel.ref(JpaUnitRule.class)).arg(JExpr.direct("getClass()"));
    ruleField.init(instance);
    final JFieldVar emField = jClass.field(JMod.PRIVATE, EntityManager.class, "em");
    final JAnnotationUse jAnnotation = emField.annotate(PersistenceContext.class);
    jAnnotation.param("unitName", "test-unit-1");
    final JMethod jMethod = jClass.method(JMod.PUBLIC, jCodeModel.VOID, "testMethod");
    jMethod.annotate(Test.class);

    buildModel(testFolder.getRoot(), jCodeModel);
    compileModel(testFolder.getRoot());

    final Class<?> cut = loadClass(testFolder.getRoot(), jClass.name());
    final BlockJUnit4ClassRunner runner = new BlockJUnit4ClassRunner(cut);

    final RunListener listener = mock(RunListener.class);
    final RunNotifier notifier = new RunNotifier();
    notifier.addListener(listener);

    // WHEN
    runner.run(notifier);

    // THEN
    final ArgumentCaptor<Description> descriptionCaptor = ArgumentCaptor.forClass(Description.class);
    verify(listener).testStarted(descriptionCaptor.capture());
    assertThat(descriptionCaptor.getValue().getClassName(), equalTo("ClassUnderTest"));
    assertThat(descriptionCaptor.getValue().getMethodName(), equalTo("testMethod"));

    verify(listener).testFinished(descriptionCaptor.capture());
    assertThat(descriptionCaptor.getValue().getClassName(), equalTo("ClassUnderTest"));
    assertThat(descriptionCaptor.getValue().getMethodName(), equalTo("testMethod"));
}
 
开发者ID:dadrus,项目名称:jpa-unit,代码行数:40,代码来源:JpaUnitRuleTest.java

示例8: generateModel

import com.sun.codemodel.JAnnotationUse; //导入依赖的package包/类
@BeforeClass
public static void generateModel() throws Exception {
    final JCodeModel jCodeModel = new JCodeModel();
    final JPackage jp = jCodeModel.rootPackage();
    final JDefinedClass jClass = jp._class(JMod.PUBLIC, "ClassUnderTest");
    JAnnotationUse jAnnotationUse = jClass.annotate(InitialDataSets.class);
    jAnnotationUse.param("value", "Script.file");
    jClass.annotate(Cleanup.class);
    final JFieldVar jField = jClass.field(JMod.PRIVATE, String.class, "testField");
    jField.annotate(PersistenceContext.class);
    final JMethod jMethod = jClass.method(JMod.PUBLIC, jCodeModel.VOID, "testMethod");
    jAnnotationUse = jMethod.annotate(InitialDataSets.class);
    jAnnotationUse.param("value", "InitialDataSets.file");
    jAnnotationUse = jMethod.annotate(ApplyScriptsAfter.class);
    jAnnotationUse.param("value", "ApplyScriptsAfter.file");

    buildModel(testFolder.getRoot(), jCodeModel);

    compileModel(testFolder.getRoot());

    cut = loadClass(testFolder.getRoot(), jClass.name());
}
 
开发者ID:dadrus,项目名称:jpa-unit,代码行数:23,代码来源:AnnotationInspectorTest.java

示例9: visitAttributePropertyInfo

import com.sun.codemodel.JAnnotationUse; //导入依赖的package包/类
public Void visitAttributePropertyInfo(
		MAttributePropertyInfo<NType, NClass> info) {

	JAnnotationUse annotation = this.annotatable
			.annotate(XmlAttribute.class);

	final String name = info.getAttributeName().getLocalPart();
	final String namespace = info.getAttributeName().getNamespaceURI();

	annotation.param("name", name);

	// generate namespace property?
	if (!namespace.equals("")) { // assume attributeFormDefault ==
									// unqualified
		annotation.param("namespace", namespace);
	}

	// TODO
	// if(info.isRequired()) {
	// xaw.required(true);
	// }

	return null;
}
 
开发者ID:highsource,项目名称:jaxb2-basics,代码行数:25,代码来源:AnnotatePropertyVisitor.java

示例10: annotate

import com.sun.codemodel.JAnnotationUse; //导入依赖的package包/类
public void annotate(JCodeModel codeModel, JAnnotatable annotatable,
		XAnnotation<?> xannotation) {
	final JClass annotationClass = codeModel.ref(xannotation
			.getAnnotationClass());
	JAnnotationUse annotationUse = null;
	for (JAnnotationUse annotation : annotatable.annotations()) {
		if (annotationClass.equals(annotation.getAnnotationClass())) {
			annotationUse = annotation;
		}
	}
	if (annotationUse == null) {
		annotationUse = annotatable.annotate(annotationClass);
	}
	final XAnnotationFieldVisitor<?> visitor = createAnnotationFieldVisitor(
			codeModel, annotationUse);
	for (XAnnotationField<?> field : xannotation.getFieldsList()) {
		field.accept(visitor);
	}
}
 
开发者ID:highsource,项目名称:jaxb2-annotate-plugin,代码行数:20,代码来源:Annotator.java

示例11: buildClassAnnotations

import com.sun.codemodel.JAnnotationUse; //导入依赖的package包/类
@Override
public void buildClassAnnotations(JDefinedClass jc) {
	
	// create Description annotation
	JAnnotationUse jad = jc.annotate(org.openhds.domain.annotations.Description.class);
	jad.param("description", "Standard Verbal Autopsy Questionnaire for adolescent and " +
	"adult deaths. (12 years and over)");
	
	// create Entity annotation
	jc.annotate(javax.persistence.Entity.class);
	
	JAnnotationUse jat = jc.annotate(javax.persistence.Table.class);
	jat.param("name", "adultvpm");
	
	JAnnotationUse jxmlRoot = jc.annotate(javax.xml.bind.annotation.XmlRootElement.class);
	jxmlRoot.param("name", "adultvpm");
}
 
开发者ID:OpenHDS,项目名称:openhds-server,代码行数:18,代码来源:AdultVPMTemplateBuilder.java

示例12: buildClassAnnotations

import com.sun.codemodel.JAnnotationUse; //导入依赖的package包/类
public void buildClassAnnotations(JDefinedClass jc) {
	
	// create Description annotation
	JAnnotationUse jad = jc.annotate(org.openhds.domain.annotations.Description.class);
	jad.param("description", "All distinct Locations within the area of study are " +
			"represented here. A Location is identified by a uniquely generated " +
			"identifier that the system uses internally. Each Location has a name associated " +
			"with it and resides at a particular level within the Location Hierarchy.");
	
	// create Entity annotation
	jc.annotate(javax.persistence.Entity.class);
	
	//Persistance annotation
	JAnnotationUse jat = jc.annotate(javax.persistence.Table.class);
	jat.param("name", "location");
	
	//XmlAnnotation
	jc.annotate(javax.xml.bind.annotation.XmlRootElement.class);
}
 
开发者ID:OpenHDS,项目名称:openhds-server,代码行数:20,代码来源:LocationTemplateBuilder.java

示例13: buildClassAnnotations

import com.sun.codemodel.JAnnotationUse; //导入依赖的package包/类
public void buildClassAnnotations(JDefinedClass jc) {
	
	// create Description annotation
	JAnnotationUse jad = jc.annotate(org.openhds.domain.annotations.Description.class);
	jad.param("description", "An Individual represents one who is a part of the study. " +
		"Each Individual is identified by a uniquely generated external identifier which " +
		"the system uses internally. Information about the Individual such as name, gender, " +
		"date of birth, and parents are stored here. An Individual may be associated with many " +
		"Residencies, Relationships, and Memberships.");
	
	jc.annotate(org.openhds.domain.constraint.CheckMotherFatherNotIndividual.class);
	
	// create Entity annotation
	jc.annotate(javax.persistence.Entity.class);
	
	JAnnotationUse jat = jc.annotate(javax.persistence.Table.class);
	jat.param("name", "individual");
	
	//XmlAnnotation
	JAnnotationUse jxmlRoot = jc.annotate(javax.xml.bind.annotation.XmlRootElement.class);
	jxmlRoot.param("name", "individual");
}
 
开发者ID:OpenHDS,项目名称:openhds-server,代码行数:23,代码来源:IndividualTemplateBuilder.java

示例14: buildClassAnnotations

import com.sun.codemodel.JAnnotationUse; //导入依赖的package包/类
@Override
public void buildClassAnnotations(JDefinedClass jc) {
	
	// create Description annotation
	JAnnotationUse jad = jc.annotate(org.openhds.domain.annotations.Description.class);
	jad.param("description", "A Vaccination is filled out for ever Pregnancy Outcome. It contains a list of " +
			"dates in which a child has received various immunications.");
			
	// create Entity annotation
	jc.annotate(javax.persistence.Entity.class);
	
	JAnnotationUse jat = jc.annotate(javax.persistence.Table.class);
	jat.param("name", "vaccination");
	
	JAnnotationUse jxmlRoot = jc.annotate(javax.xml.bind.annotation.XmlRootElement.class);
	jxmlRoot.param("name", "vaccination");
}
 
开发者ID:OpenHDS,项目名称:openhds-server,代码行数:18,代码来源:VaccinationTemplateBuilder.java

示例15: buildClassAnnotations

import com.sun.codemodel.JAnnotationUse; //导入依赖的package包/类
@Override
public void buildClassAnnotations(JDefinedClass jc) {
	
	// create Description annotation
	JAnnotationUse jad = jc.annotate(org.openhds.domain.annotations.Description.class);
	jad.param("description", "An InMigration represents a migration into the study area. " +
	"It contains information about the Individual who is in-migrating to a particular " +
	"Residency. It also contains information about the origin, date, and reason the " +
	"Individual is migrating as well as the Visit that is associated with the migration.");
			
	// create Entity annotation
	jc.annotate(javax.persistence.Entity.class);
	
	//create CheckDropdownMenuItemSelected constraint
	jc.annotate(org.openhds.domain.constraint.CheckDropdownMenuItemSelected.class);  
	
	jc.annotate(org.openhds.domain.constraint.CheckInMigrationAfterDob.class);
	
	JAnnotationUse jat = jc.annotate(javax.persistence.Table.class);
	jat.param("name", "inmigration");
	
	JAnnotationUse jxmlRoot = jc.annotate(javax.xml.bind.annotation.XmlRootElement.class);
	jxmlRoot.param("name", "inmigration");
	
}
 
开发者ID:OpenHDS,项目名称:openhds-server,代码行数:26,代码来源:InMigrationTemplateBuilder.java


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