javassist.bytecode.annotation.Annotation.createMemberValue()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(11.6k)|赞(0)|评价(0)|浏览(162)

本文整理了Java中javassist.bytecode.annotation.Annotation.createMemberValue()方法的一些代码示例,展示了Annotation.createMemberValue()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Annotation.createMemberValue()方法的具体详情如下:
包路径:javassist.bytecode.annotation.Annotation
类名称:Annotation
方法名:createMemberValue

Annotation.createMemberValue介绍

[英]Makes an instance of MemberValue.
[中]生成MemberValue的实例。

代码示例

代码示例来源:origin: redisson/redisson

/**
 * Constructs an annotation that can be accessed through the interface
 * represented by <code>clazz</code>.  The values of the members are
 * not specified.
 *
 * @param cp        the constant pool table.
 * @param clazz     the interface.
 * @throws NotFoundException when the clazz is not found 
 */
public Annotation(ConstPool cp, CtClass clazz)
  throws NotFoundException
{
  // todo Enums are not supported right now.
  this(cp.addUtf8Info(Descriptor.of(clazz.getName())), cp);
  if (!clazz.isInterface())
    throw new RuntimeException(
      "Only interfaces are allowed for Annotation creation.");
  CtMethod methods[] = clazz.getDeclaredMethods();
  if (methods.length > 0) {
    members = new LinkedHashMap();
  }
  for (int i = 0; i < methods.length; i++) {
    CtClass returnType = methods[i].getReturnType();
    addMemberValue(methods[i].getName(),
            createMemberValue(cp, returnType));
    
  }
}

代码示例来源:origin: apache/incubator-dubbo

private static MemberValue createMemberValue(ConstPool cp, CtClass type, Object value) throws NotFoundException {
  MemberValue memberValue = javassist.bytecode.annotation.Annotation.createMemberValue(cp, type);
  if (memberValue instanceof BooleanMemberValue) {
    ((BooleanMemberValue) memberValue).setValue((Boolean) value);

代码示例来源:origin: apache/incubator-dubbo

private static MemberValue createMemberValue(ConstPool cp, CtClass type, Object value) throws NotFoundException {
  MemberValue memberValue = javassist.bytecode.annotation.Annotation.createMemberValue(cp, type);
  if (memberValue instanceof BooleanMemberValue) {
    ((BooleanMemberValue) memberValue).setValue((Boolean) value);

代码示例来源:origin: org.javassist/javassist

/**
 * Constructs an annotation that can be accessed through the interface
 * represented by <code>clazz</code>.  The values of the members are
 * not specified.
 *
 * @param cp        the constant pool table.
 * @param clazz     the interface.
 * @throws NotFoundException when the clazz is not found 
 */
public Annotation(ConstPool cp, CtClass clazz)
  throws NotFoundException
{
  // todo Enums are not supported right now.
  this(cp.addUtf8Info(Descriptor.of(clazz.getName())), cp);
  if (!clazz.isInterface())
    throw new RuntimeException(
      "Only interfaces are allowed for Annotation creation.");
  CtMethod[] methods = clazz.getDeclaredMethods();
  if (methods.length > 0)
    members = new LinkedHashMap<String,Pair>();
  for (CtMethod m:methods)
    addMemberValue(m.getName(),
            createMemberValue(cp, m.getReturnType()));
}

代码示例来源:origin: BroadleafCommerce/BroadleafCommerce

pool.importPackage("javax.persistence");
pool.importPackage("java.lang");
EnumMemberValue strategy = (EnumMemberValue) Annotation.createMemberValue(constantPool, pool.makeClass("InheritanceType"));
strategy.setType(InheritanceType.class.getName());
strategy.setValue(InheritanceType.SINGLE_TABLE.name());
  name.setValue(myInfo.getDiscriminatorName());
  discriminator.addMemberValue("name", name);
  EnumMemberValue discriminatorType = (EnumMemberValue) Annotation.createMemberValue(constantPool, pool.makeClass("DiscriminatorType"));
  discriminatorType.setType(DiscriminatorType.class.getName());
  discriminatorType.setValue(myInfo.getDiscriminatorType().name());

代码示例来源:origin: BroadleafCommerce/BroadleafCommerce

namedQuery.addMemberValue("query", queryString);
EnumMemberValue lockMode = (EnumMemberValue) Annotation.createMemberValue(constantPool, pool.makeClass("LockModeType"));
lockMode.setType(LockModeType.class.getName());
lockMode.setValue(query.lockMode().toString());

代码示例来源:origin: redisson/redisson

else if (type.isArray()) {
  CtClass arrayType = type.getComponentType();
  MemberValue member = createMemberValue(cp, arrayType);
  return new ArrayMemberValue(member, cp);

代码示例来源:origin: org.javassist/javassist

else if (type.isArray()) {
  CtClass arrayType = type.getComponentType();
  MemberValue member = createMemberValue(cp, arrayType);
  return new ArrayMemberValue(member, cp);

代码示例来源:origin: com.github.vindell/javassist-plus

/**
 * Makes an instance of <code>MemberValue</code>.
 * @param cp     the constant pool table.
 * @param type     the type of the member.
 * @return the member value
 * @throws NotFoundException if not found
 */
public static MemberValue createMemberValue(ConstPool cp, CtClass type) throws NotFoundException {
  return javassist.bytecode.annotation.Annotation.createMemberValue(cp, type);
}

代码示例来源:origin: ru.vyarus/guice-ext-annotations

/**
 * @param classPool class pool to use
 * @param constPool constants pool
 * @param ann       annotation to copy
 * @return javassist annotation object (copy of original annotation)
 * @throws Exception on errors
 */
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
public static Annotation copyAnnotation(final ClassPool classPool, final ConstPool constPool,
                    final java.lang.annotation.Annotation ann) throws Exception {
  final Class<? extends java.lang.annotation.Annotation> annotationType = ann.annotationType();
  final Annotation copy = new Annotation(annotationType.getName(), constPool);
  final Method[] methods = annotationType.getDeclaredMethods();
  for (final Method method : methods) {
    final CtClass ctType = classPool.get(method.getReturnType().getName());
    final MemberValue memberValue = Annotation.createMemberValue(constPool, ctType);
    final Object value = method.invoke(ann);
    memberValue.accept(new AnnotationMemberValueVisitor(classPool, constPool, value));
    copy.addMemberValue(method.getName(), memberValue);
  }
  return copy;
}

代码示例来源:origin: org.seedstack.business/business-core

private Annotation copyAnnotation(ConstPool constPool,
    java.lang.annotation.Annotation annotation) throws NotFoundException {
  // Create annotation from specified type
  Annotation byteCodeAnnotation = createAnnotation(
      constPool,
      annotation.annotationType()
  );
  // Copy annotation methods
  for (Method m : annotation.annotationType().getDeclaredMethods()) {
    Object value = invoke(m, annotation);
    MemberValue memberValue = createMemberValue(
        constPool,
        classPool.get(value.getClass().getName())
    );
    invoke(Classes.from(memberValue.getClass())
            .method("setValue", value.getClass())
            .orElseThrow(() -> new NotFoundException("Cannot copy value of qualifier parameter "
                + m.getName())),
        memberValue,
        value);
    byteCodeAnnotation.addMemberValue(
        m.getName(),
        memberValue
    );
  }
  return byteCodeAnnotation;
}

代码示例来源:origin: ru.vyarus/guice-ext-annotations

private MemberValue createValue(final Object value) throws Exception {
  final MemberValue memberValue = Annotation.createMemberValue(
      this.constPool, getCtClass(classPool, getClass(value)));
  memberValue.accept(new AnnotationMemberValueVisitor(this.classPool, this.constPool, value));
  return memberValue;
}

代码示例来源:origin: hstaudacher/osgi-jax-rs-connector

/**
 * Constructs an annotation that can be accessed through the interface
 * represented by <code>clazz</code>.  The values of the members are
 * not specified.
 *
 * @param cp        the constant pool table.
 * @param clazz     the interface.
 * @throws NotFoundException when the clazz is not found 
 */
public Annotation(ConstPool cp, CtClass clazz)
  throws NotFoundException
{
  // todo Enums are not supported right now.
  this(cp.addUtf8Info(Descriptor.of(clazz.getName())), cp);
  if (!clazz.isInterface())
    throw new RuntimeException(
      "Only interfaces are allowed for Annotation creation.");
  CtMethod methods[] = clazz.getDeclaredMethods();
  if (methods.length > 0) {
    members = new LinkedHashMap();
  }
  for (int i = 0; i < methods.length; i++) {
    CtClass returnType = methods[i].getReturnType();
    addMemberValue(methods[i].getName(),
            createMemberValue(cp, returnType));
    
  }
}

代码示例来源:origin: org.jboss/javassist

/**
 * Constructs an annotation that can be accessed through the interface
 * represented by <code>clazz</code>.  The values of the members are
 * not specified.
 *
 * @param cp        the constant pool table.
 * @param clazz     the interface.
 * @throws NotFoundException when the clazz is not found 
 */
public Annotation(ConstPool cp, CtClass clazz)
  throws NotFoundException
{
  // todo Enums are not supported right now.
  this(cp.addUtf8Info(Descriptor.of(clazz.getName())), cp);
  if (!clazz.isInterface())
    throw new RuntimeException(
      "Only interfaces are allowed for Annotation creation.");
  CtMethod methods[] = clazz.getDeclaredMethods();
  if (methods.length > 0) {
    members = new HashMap();
  }
  for (int i = 0; i < methods.length; i++) {
    CtClass returnType = methods[i].getReturnType();
    addMemberValue(methods[i].getName(),
            createMemberValue(cp, returnType));
    
  }
}

代码示例来源:origin: org.jboss.javassist/com.springsource.javassist

/**
 * Constructs an annotation that can be accessed through the interface
 * represented by <code>clazz</code>.  The values of the members are
 * not specified.
 *
 * @param cp        the constant pool table.
 * @param clazz     the interface.
 * @throws NotFoundException when the clazz is not found 
 */
public Annotation(ConstPool cp, CtClass clazz)
  throws NotFoundException
{
  // todo Enums are not supported right now.
  this(cp.addUtf8Info(Descriptor.of(clazz.getName())), cp);
  if (!clazz.isInterface())
    throw new RuntimeException(
      "Only interfaces are allowed for Annotation creation.");
  CtMethod methods[] = clazz.getDeclaredMethods();
  if (methods.length > 0) {
    members = new LinkedHashMap();
  }
  for (int i = 0; i < methods.length; i++) {
    CtClass returnType = methods[i].getReturnType();
    addMemberValue(methods[i].getName(),
            createMemberValue(cp, returnType));
    
  }
}

代码示例来源:origin: com.eclipsesource.jaxrs/jersey-all

/**
 * Constructs an annotation that can be accessed through the interface
 * represented by <code>clazz</code>.  The values of the members are
 * not specified.
 *
 * @param cp        the constant pool table.
 * @param clazz     the interface.
 * @throws NotFoundException when the clazz is not found 
 */
public Annotation(ConstPool cp, CtClass clazz)
  throws NotFoundException
{
  // todo Enums are not supported right now.
  this(cp.addUtf8Info(Descriptor.of(clazz.getName())), cp);
  if (!clazz.isInterface())
    throw new RuntimeException(
      "Only interfaces are allowed for Annotation creation.");
  CtMethod methods[] = clazz.getDeclaredMethods();
  if (methods.length > 0) {
    members = new LinkedHashMap();
  }
  for (int i = 0; i < methods.length; i++) {
    CtClass returnType = methods[i].getReturnType();
    addMemberValue(methods[i].getName(),
            createMemberValue(cp, returnType));
    
  }
}

代码示例来源:origin: hstaudacher/osgi-jax-rs-connector

/**
 * Constructs an annotation that can be accessed through the interface
 * represented by <code>clazz</code>.  The values of the members are
 * not specified.
 *
 * @param cp        the constant pool table.
 * @param clazz     the interface.
 * @throws NotFoundException when the clazz is not found 
 */
public Annotation(ConstPool cp, CtClass clazz)
  throws NotFoundException
{
  // todo Enums are not supported right now.
  this(cp.addUtf8Info(Descriptor.of(clazz.getName())), cp);
  if (!clazz.isInterface())
    throw new RuntimeException(
      "Only interfaces are allowed for Annotation creation.");
  CtMethod methods[] = clazz.getDeclaredMethods();
  if (methods.length > 0) {
    members = new LinkedHashMap();
  }
  for (int i = 0; i < methods.length; i++) {
    CtClass returnType = methods[i].getReturnType();
    addMemberValue(methods[i].getName(),
            createMemberValue(cp, returnType));
    
  }
}

代码示例来源:origin: org.apache.dubbo/dubbo-filter-validation

private static MemberValue createMemberValue(ConstPool cp, CtClass type, Object value) throws NotFoundException {
  MemberValue memberValue = javassist.bytecode.annotation.Annotation.createMemberValue(cp, type);
  if (memberValue instanceof BooleanMemberValue) {
    ((BooleanMemberValue) memberValue).setValue((Boolean) value);

代码示例来源:origin: org.apache.dubbo/dubbo

private static MemberValue createMemberValue(ConstPool cp, CtClass type, Object value) throws NotFoundException {
  MemberValue memberValue = javassist.bytecode.annotation.Annotation.createMemberValue(cp, type);
  if (memberValue instanceof BooleanMemberValue) {
    ((BooleanMemberValue) memberValue).setValue((Boolean) value);

代码示例来源:origin: com.alibaba/dubbo

private static MemberValue createMemberValue(ConstPool cp, CtClass type, Object value) throws NotFoundException {
  MemberValue memberValue = javassist.bytecode.annotation.Annotation.createMemberValue(cp, type);
  if (memberValue instanceof BooleanMemberValue)
    ((BooleanMemberValue) memberValue).setValue((Boolean) value);

相关文章