本文整理匯總了Java中com.sun.codemodel.JFieldVar.annotate方法的典型用法代碼示例。如果您正苦於以下問題:Java JFieldVar.annotate方法的具體用法?Java JFieldVar.annotate怎麽用?Java JFieldVar.annotate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.sun.codemodel.JFieldVar
的用法示例。
在下文中一共展示了JFieldVar.annotate方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: apply
import com.sun.codemodel.JFieldVar; //導入方法依賴的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;
}
示例2: apply
import com.sun.codemodel.JFieldVar; //導入方法依賴的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;
}
示例3: testClassWithPersistenceContextWithKonfiguredUnitNameSpecified
import com.sun.codemodel.JFieldVar; //導入方法依賴的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"));
}
示例4: apply
import com.sun.codemodel.JFieldVar; //導入方法依賴的package包/類
@Override
public JFieldVar apply(ApiResourceMetadata controllerMetadata, JDefinedClass generatableType) {
JFieldVar field = generatableType.field(JMod.PRIVATE, this.fieldClazz, this.fieldName);
//add @Autowired field annoation
if (autowire) {
field.annotate(Autowired.class);
}
//add @Qualifier("qualifierBeanName")
if (qualifierAnnotation && !StringUtils.isEmpty(qualifier)){
field.annotate(Qualifier.class).param("value", qualifier);
}
//add @Value(value="") annotation to the field
if (valueAnnotation){
field.annotate(Value.class).param("value", valueAnnotationValue);
}
return field;
}
示例5: apply
import com.sun.codemodel.JFieldVar; //導入方法依賴的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;
}
示例6: apply
import com.sun.codemodel.JFieldVar; //導入方法依賴的package包/類
@Override
public JFieldVar apply(String nodeName, JsonNode node, JFieldVar field, Schema currentSchema) {
if (ruleFactory.getGenerationConfig().isIncludeJsr303Annotations()) {
JAnnotationUse annotation = field.annotate(Pattern.class);
annotation.param("regexp", node.asText());
}
return field;
}
示例7: apply
import com.sun.codemodel.JFieldVar; //導入方法依賴的package包/類
@Override
public JFieldVar apply(String nodeName, JsonNode node, JFieldVar field, Schema currentSchema) {
if (ruleFactory.getGenerationConfig().isIncludeJsr303Annotations()) {
field.annotate(Valid.class);
}
return field;
}
示例8: testClassWithoutPersistenceContextField
import com.sun.codemodel.JFieldVar; //導入方法依賴的package包/類
@Test
public void testClassWithoutPersistenceContextField() 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 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());
try {
// WHEN
new JpaUnitRule(cut);
fail("IllegalArgumentException expected");
} catch (final IllegalArgumentException e) {
// THEN
assertThat(e.getMessage(), containsString("EntityManagerFactory or EntityManager field annotated"));
}
}
示例9: testClassWithMultiplePersistenceContextFields
import com.sun.codemodel.JFieldVar; //導入方法依賴的package包/類
@Test
public void testClassWithMultiplePersistenceContextFields() 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 em1Field = jClass.field(JMod.PRIVATE, EntityManager.class, "em1");
em1Field.annotate(PersistenceContext.class);
final JFieldVar em2Field = jClass.field(JMod.PRIVATE, EntityManager.class, "em2");
em2Field.annotate(PersistenceContext.class);
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());
try {
// WHEN
new JpaUnitRule(cut);
fail("IllegalArgumentException expected");
} catch (final IllegalArgumentException e) {
// THEN
assertThat(e.getMessage(), containsString("Only single field is allowed"));
}
}
示例10: testClassWithMultiplePersistenceUnitFields
import com.sun.codemodel.JFieldVar; //導入方法依賴的package包/類
@Test
public void testClassWithMultiplePersistenceUnitFields() 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 emf1Field = jClass.field(JMod.PRIVATE, EntityManagerFactory.class, "emf1");
emf1Field.annotate(PersistenceUnit.class);
final JFieldVar emf2Field = jClass.field(JMod.PRIVATE, EntityManagerFactory.class, "emf2");
emf2Field.annotate(PersistenceUnit.class);
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());
try {
// WHEN
new JpaUnitRule(cut);
fail("IllegalArgumentException expected");
} catch (final IllegalArgumentException e) {
// THEN
assertThat(e.getMessage(), containsString("Only single field is allowed"));
}
}
示例11: testClassWithPersistenceContextFieldOfWrongType
import com.sun.codemodel.JFieldVar; //導入方法依賴的package包/類
@Test
public void testClassWithPersistenceContextFieldOfWrongType() 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, EntityManagerFactory.class, "em");
emField.annotate(PersistenceContext.class);
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());
try {
// WHEN
new JpaUnitRule(cut);
fail("IllegalArgumentException expected");
} catch (final IllegalArgumentException e) {
// THEN
assertThat(e.getMessage(), containsString("annotated with @PersistenceContext is not of type EntityManager"));
}
}
示例12: testClassWithPersistenceUnitFieldOfWrongType
import com.sun.codemodel.JFieldVar; //導入方法依賴的package包/類
@Test
public void testClassWithPersistenceUnitFieldOfWrongType() 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, "emf");
emField.annotate(PersistenceUnit.class);
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());
try {
// WHEN
new JpaUnitRule(cut);
fail("IllegalArgumentException expected");
} catch (final IllegalArgumentException e) {
// THEN
assertThat(e.getMessage(), containsString("annotated with @PersistenceUnit is not of type EntityManagerFactory"));
}
}
示例13: testClassWithPersistenceContextWithoutUnitNameSpecified
import com.sun.codemodel.JFieldVar; //導入方法依賴的package包/類
@Test
public void testClassWithPersistenceContextWithoutUnitNameSpecified() 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");
emField.annotate(PersistenceContext.class);
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());
try {
// WHEN
new JpaUnitRule(cut);
fail("JpaUnitException expected");
} catch (final JpaUnitException e) {
// THEN
assertThat(e.getMessage(), containsString("No Persistence"));
}
}
示例14: testJpaUnitRunnerAndJpaUnitRuleFieldExcludeEachOther
import com.sun.codemodel.JFieldVar; //導入方法依賴的package包/類
@Test
public void testJpaUnitRunnerAndJpaUnitRuleFieldExcludeEachOther() throws Exception {
// GIVEN
final JCodeModel jCodeModel = new JCodeModel();
final JPackage jp = jCodeModel.rootPackage();
final JDefinedClass jClass = jp._class(JMod.PUBLIC, "ClassUnderTest");
final JAnnotationUse jAnnotationUse = jClass.annotate(RunWith.class);
jAnnotationUse.param("value", JpaUnitRunner.class);
final JFieldVar emField = jClass.field(JMod.PRIVATE, EntityManagerFactory.class, "emf");
final JAnnotationUse jAnnotation = emField.annotate(PersistenceUnit.class);
jAnnotation.param("unitName", "test-unit-1");
final JFieldVar ruleField = jClass.field(JMod.PUBLIC, JpaUnitRule.class, "rule");
ruleField.annotate(Rule.class);
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());
try {
// WHEN
new JpaUnitRunner(cut);
fail("InitializationError expected");
} catch (final InitializationError e) {
// expected
assertThat(e.getCauses().get(0).getMessage(), containsString("exclude each other"));
}
}
示例15: testClassWithPersistenceUnitWithKonfiguredUnitNameSpecified
import com.sun.codemodel.JFieldVar; //導入方法依賴的package包/類
@Test
public void testClassWithPersistenceUnitWithKonfiguredUnitNameSpecified() 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, EntityManagerFactory.class, "emf");
final JAnnotationUse jAnnotation = emField.annotate(PersistenceUnit.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"));
}