@Test
  public void testFieldId() throws SecurityException, NoSuchFieldException {
    TestAnnotatedTypeBuilder<Chair> builder = new TestAnnotatedTypeBuilder<Chair>(Chair.class);
    builder.addToField(Chair.class.getField("legs"), new ProducesLiteral());
    AnnotatedType<Chair> chair3 = builder.create();
    AnnotatedField<? super Chair> field = chair3.getFields().iterator().next();
    String id = AnnotatedTypes.createFieldId(field);
    Assert.assertEquals(
        "org.jboss.weld.tests.unit.util.Chair.legs[@javax.enterprise.inject.Produces()]",
        id,
        "wrong id for field :" + id);

    builder = new TestAnnotatedTypeBuilder<Chair>(Chair.class);
    chair3 = builder.create();
    field = chair3.getFields().iterator().next();
    id = AnnotatedTypes.createFieldId(field);
    Assert.assertEquals(
        "org.jboss.weld.tests.unit.util.Chair.legs", id, "wrong id for field :" + id);

    builder = new TestAnnotatedTypeBuilder<Chair>(Chair.class);
    builder.addToField(Chair.class.getField("legs"), new ComfyChairLiteral());
    chair3 = builder.create();
    field = chair3.getFields().iterator().next();
    id = AnnotatedTypes.createFieldId(field);
    Assert.assertEquals(
        "org.jboss.weld.tests.unit.util.Chair.legs[@org.jboss.weld.tests.unit.util.ComfyChair(softness=1)]",
        id,
        "wrong id for field :" + id);
  }
Example #2
0
 public static String forProducerField(
     EnhancedAnnotatedField<?, ?> field, AbstractClassBean<?> declaringBean) {
   StringBuilder sb =
       getPrefix(ProducerField.class)
           .append(declaringBean.getAnnotated().getIdentifier().asString())
           .append(BEAN_ID_SEPARATOR);
   if (declaringBean.getEnhancedAnnotated().isDiscovered()) {
     sb.append(field.getName());
   } else {
     sb.append(AnnotatedTypes.createFieldId(field));
   }
   return sb.toString();
 }
 private Object writeReplace() throws ObjectStreamException {
   return new UnbackedMemberIdentifier<X>(getDeclaringType(), AnnotatedTypes.createFieldId(this));
 }