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


Java AnnotationsAttribute类代码示例

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


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

示例1: main

import javassist.bytecode.AnnotationsAttribute; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    Reflections reflections = new Reflections();
    LukkitPlus.BUKKIT_EVENTS = reflections.getSubTypesOf(Event.class);
    ClassPool classpath = ClassPool.getDefault();
    CtClass eventClass = classpath.makeClass("online.pizzacrust.lukkitplus" +
            ".EventCallback");
    for (Class<? extends Event> event : LukkitPlus.BUKKIT_EVENTS) {
        CtMethod eventMethod = CtNewMethod.make(CtClass.voidType, "on" + event.getSimpleName
                (), new CtClass[] { classpath.get(event.getName()) }, new CtClass[0], "online" +
                ".pizzacrust.lukkitplus.EventCallbackGenerator.call($1);", eventClass);
        eventClass.addMethod(eventMethod);
        AnnotationsAttribute attribute = new AnnotationsAttribute(eventClass.getClassFile()
                .getConstPool(), AnnotationsAttribute.visibleTag);
        Annotation eventHandlerAnnt = new Annotation(EventHandler.class.getName(), eventClass
                .getClassFile().getConstPool());
        attribute.addAnnotation(eventHandlerAnnt);
        eventMethod.getMethodInfo().addAttribute(attribute);
    }
    System.out.println("Done!");
    eventClass.writeFile();
}
 
开发者ID:LukkitPlus,项目名称:Lukkit,代码行数:22,代码来源:EventCallbackGenerator.java

示例2: generateClass

import javassist.bytecode.AnnotationsAttribute; //导入依赖的package包/类
public static Class<?> generateClass() throws NotFoundException, CannotCompileException {
    ClassPool classpath = ClassPool.getDefault();
    classpath.insertClassPath(new ClassClassPath(EventCallbackGenerator.class));
    CtClass eventClass = classpath.makeClass("online.pizzacrust.lukkitplus" +
            ".EventCallback");
    eventClass.addInterface(classpath.get(Listener.class.getName()));
    for (Class<? extends Event> event : LukkitPlus.BUKKIT_EVENTS) {
        if (containsStaticHandlerList(event)) {
            CtMethod eventMethod = CtNewMethod.make(CtClass.voidType, "on" + event.getSimpleName
                    (), new CtClass[]{classpath.get(event.getName())}, new CtClass[0], "online" +
                    ".pizzacrust.lukkitplus.EventCallbackGenerator.call($1);", eventClass);
            eventClass.addMethod(eventMethod);
            AnnotationsAttribute attribute = new AnnotationsAttribute(eventClass.getClassFile()
                    .getConstPool(), AnnotationsAttribute.visibleTag);
            Annotation eventHandlerAnnt = new Annotation(EventHandler.class.getName(), eventClass
                    .getClassFile().getConstPool());
            attribute.addAnnotation(eventHandlerAnnt);
            eventMethod.getMethodInfo().addAttribute(attribute);
        }
    }
    return eventClass.toClass(LukkitPlus.class.getClassLoader());
}
 
开发者ID:LukkitPlus,项目名称:Lukkit,代码行数:23,代码来源:EventCallbackGenerator.java

示例3: getAnnotationDescriptors

import javassist.bytecode.AnnotationsAttribute; //导入依赖的package包/类
private List<AnnotationDescriptor> getAnnotationDescriptors(AnnotationsAttribute annotationsAttr) {
  List<AnnotationDescriptor> annotationDescriptors = new ArrayList<>(annotationsAttr.numAnnotations());
  for (javassist.bytecode.annotation.Annotation annotation : annotationsAttr.getAnnotations()) {
    // Sigh: javassist uses raw collections (is this 2002?)
    @SuppressWarnings("unchecked")
    Set<String> memberNames = annotation.getMemberNames();
    List<AttributeDescriptor> attributes = new ArrayList<>();
    if (memberNames != null) {
      for (String name : memberNames) {
        MemberValue memberValue = annotation.getMemberValue(name);
        final List<String> values = new ArrayList<>();
        memberValue.accept(new ListingMemberValueVisitor(values));
        attributes.add(new AttributeDescriptor(name, values));
      }
    }
    annotationDescriptors.add(new AnnotationDescriptor(annotation.getTypeName(), attributes));
  }
  return annotationDescriptors;
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:20,代码来源:ClassPathScanner.java

示例4: scan

import javassist.bytecode.AnnotationsAttribute; //导入依赖的package包/类
@Override
public void scan(final Object cls) {
  final ClassFile classFile = (ClassFile)cls;
  AnnotationsAttribute annotations = ((AnnotationsAttribute)classFile.getAttribute(AnnotationsAttribute.visibleTag));
  if (annotations != null) {
    boolean isAnnotated = false;
    for (javassist.bytecode.annotation.Annotation a : annotations.getAnnotations()) {
      if (annotationsToScan.contains(a.getTypeName())) {
        isAnnotated = true;
      }
    }
    if (isAnnotated) {
      List<AnnotationDescriptor> classAnnotations = getAnnotationDescriptors(annotations);
      @SuppressWarnings("unchecked")
      List<FieldInfo> classFields = classFile.getFields();
      List<FieldDescriptor> fieldDescriptors = new ArrayList<>(classFields.size());
      for (FieldInfo field : classFields) {
        String fieldName = field.getName();
        AnnotationsAttribute fieldAnnotations = ((AnnotationsAttribute)field.getAttribute(AnnotationsAttribute.visibleTag));
        fieldDescriptors.add(new FieldDescriptor(fieldName, field.getDescriptor(), getAnnotationDescriptors(fieldAnnotations)));
      }
      functions.add(new AnnotatedClassDescriptor(classFile.getName(), classAnnotations, fieldDescriptors));
    }
  }
}
 
开发者ID:axbaretto,项目名称:drill,代码行数:26,代码来源:ClassPathScanner.java

示例5: discoverAndIntimateForClassAnnotations

import javassist.bytecode.AnnotationsAttribute; //导入依赖的package包/类
/**
   * Discovers Class Annotations
   * 
   * @param classFile
   */
  private void discoverAndIntimateForClassAnnotations (ClassFile classFile) {
  	Set<Annotation> annotations = new HashSet<Annotation>();
  	
AnnotationsAttribute visible 	= (AnnotationsAttribute) classFile.getAttribute(AnnotationsAttribute.visibleTag);
AnnotationsAttribute invisible 	= (AnnotationsAttribute) classFile.getAttribute(AnnotationsAttribute.invisibleTag);

if (visible != null) {
	annotations.addAll(Arrays.asList(visible.getAnnotations()));
}
if (invisible != null) {
	annotations.addAll(Arrays.asList(invisible.getAnnotations()));
}

// now tell listeners
for (Annotation annotation : annotations) {
	Set<ClassAnnotationDiscoveryListener> listeners = classAnnotationListeners.get(annotation.getTypeName());
	if (null == listeners) {
		continue;
	}

	for (ClassAnnotationDiscoveryListener listener : listeners) {
		listener.discovered(classFile.getName(), annotation.getTypeName());
	}
}
  }
 
开发者ID:guci314,项目名称:playorm,代码行数:31,代码来源:Discoverer.java

示例6: instrumentMethod

import javassist.bytecode.AnnotationsAttribute; //导入依赖的package包/类
protected void instrumentMethod(final CtMethod ctm, final ConstPool constpool) {
	try {
		if(ctm.getAnnotation(susAnn)==null) {
			AnnotationsAttribute attr = new AnnotationsAttribute(constpool, AnnotationsAttribute.visibleTag);
			javassist.bytecode.annotation.Annotation annot = new javassist.bytecode.annotation.Annotation(susAnn.getName(), constpool);
			attr.addAnnotation(annot);
			ctm.getMethodInfo().addAttribute(attr);
		}
		/*
		 * Install latch. Needs to be accessible in finally block, so we need a singleton registry.
		 * Spin up fiber and invoke this method in fiber
		 * 	-- static method
		 *  -- non static method
		 * Fiber execution: accumulate all pending sub-fibers
		 * finally block:
		 *  -- if running in thread, skip.
		 * 	-- send batch
		 *  -- wait for all sub-fibers to complete
		 *  -- drop thread latch
		 *  
		 */
	} catch (Exception ex) {
		ex.printStackTrace(System.err);
		throw new RuntimeException(ex);
	}
}
 
开发者ID:nickman,项目名称:JMXMPAgent,代码行数:27,代码来源:FibonnoitreClassFileTransformer.java

示例7: scanClass

import javassist.bytecode.AnnotationsAttribute; //导入依赖的package包/类
/**
 * Scans a class representation for annotations.
 * @param cf The ClassFile
 * @return A lit of annotations
 */
private List<Annotation> scanClass(final ClassFile cf) {

   AnnotationsAttribute visible = (AnnotationsAttribute) cf.getAttribute(AnnotationsAttribute.visibleTag);
   AnnotationsAttribute invisible = (AnnotationsAttribute) cf.getAttribute(AnnotationsAttribute.invisibleTag);
   
   ArrayList<Annotation> list = new ArrayList<Annotation>();

   if (visible != null) {
       list.addAll(Arrays.asList(visible.getAnnotations()));
   }
   
   if (invisible != null) {
       list.addAll(Arrays.asList(invisible.getAnnotations()));
   }
   
   return list;
}
 
开发者ID:akberc,项目名称:ceylon-jboss-loader,代码行数:23,代码来源:CarScanner.java

示例8: addMimicAnnotation

import javassist.bytecode.AnnotationsAttribute; //导入依赖的package包/类
private void addMimicAnnotation(CtClass dst, String sourceClassName,
        boolean isMimicingInterfaces, boolean isMimicingFields,
        boolean isMimicingConstructors, boolean isMimicingMethods) {
    ClassFile cf = dst.getClassFile();
    ConstPool cp = cf.getConstPool();
    AnnotationsAttribute attr = new AnnotationsAttribute(cp,
            AnnotationsAttribute.visibleTag);

    Annotation a = new Annotation(Mimic.class.getName(), cp);
    a.addMemberValue("sourceClass", new ClassMemberValue(sourceClassName,
            cp));
    a.addMemberValue("isMimicingInterfaces", new BooleanMemberValue(
            isMimicingInterfaces, cp));
    a.addMemberValue("isMimicingFields", new BooleanMemberValue(
            isMimicingFields, cp));
    a.addMemberValue("isMimicingConstructors", new BooleanMemberValue(
            isMimicingConstructors, cp));
    a.addMemberValue("isMimicingMethods", new BooleanMemberValue(
            isMimicingMethods, cp));
    attr.setAnnotation(a);
    cf.addAttribute(attr);
    cf.setVersionToJava5();
}
 
开发者ID:stephanenicolas,项目名称:mimic,代码行数:24,代码来源:MimicProcessorTest.java

示例9: metaGenerate

import javassist.bytecode.AnnotationsAttribute; //导入依赖的package包/类
private void metaGenerate(boolean hasDisplay, boolean hasDescription, Object ct, JavaAnnotatedElement element) {
    if (!hasDisplay || !hasDescription) {
        Meta meta = parseComment(element.getComment());
        if (meta != null) {
            AnnotationsAttribute attribute = null;
            if (ct instanceof CtMethod)
                attribute = getAnnotations((CtMethod) ct);
            else if (ct instanceof CtClass)
                attribute = getAnnotations((CtClass) ct);
            else if (ct instanceof CtField)
                attribute = getAnnotations((CtField) ct);
            meta.docletTags = element.getTags();
            metaGenerate(hasDisplay, hasDescription, attribute, meta);
        }
    }
}
 
开发者ID:icode,项目名称:ameba-dev,代码行数:17,代码来源:MetaEnhancer.java

示例10: enhance

import javassist.bytecode.AnnotationsAttribute; //导入依赖的package包/类
@Override
public void enhance(ClassDescription desc) throws Exception {
    byte[] result;
    try (InputStream in = desc.getEnhancedByteCodeStream()) {
        result = transformer.transform(desc.className, in);
    }
    if (result != null)
        desc.enhancedByteCode = result;
    else
        logger.trace("{} class not change.", desc.className);
    CtClass ctClass = makeClass(desc);
    if (ctClass.hasAnnotation(Entity.class)) {
        AnnotationsAttribute classAttribute = getAnnotations(ctClass);
        addDbCommentAnnotation(classAttribute);

        for (CtField field : ctClass.getFields()) {
            AnnotationsAttribute attribute = getAnnotations(field);
            addDbCommentAnnotation(attribute);
        }

        desc.enhancedByteCode = ctClass.toBytecode();
    }
    ctClass.defrost();
}
 
开发者ID:icode,项目名称:ameba-dev,代码行数:25,代码来源:EbeanEnhancer.java

示例11: addDbCommentAnnotation

import javassist.bytecode.AnnotationsAttribute; //导入依赖的package包/类
private void addDbCommentAnnotation(AnnotationsAttribute attribute) {
    if (attribute.getAnnotation(DbComment.class.getName()) != null) return;

    StringBuilder builder = new StringBuilder();
    String display = appendDbCommentValue(attribute, Display.class);
    if (StringUtils.isNotBlank(display))
        builder.append(display);
    String desc = appendDbCommentValue(attribute, Description.class);
    if (StringUtils.isNotBlank(desc))
        builder.append(" ").append(desc);

    if (builder.length() > 0) {
        Map<String, MemberValue> valueMap = Maps.newHashMap();
        ConstPool cp = attribute.getConstPool();
        valueMap.put("value", new StringMemberValue(builder.toString()
                .replace("'", "''")
                .replace("\r", " ")
                .replace("\n", " "), cp));
        addAnnotation(attribute, DbComment.class, valueMap);
    }
}
 
开发者ID:icode,项目名称:ameba-dev,代码行数:22,代码来源:EbeanEnhancer.java

示例12: addAnnotation

import javassist.bytecode.AnnotationsAttribute; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void addAnnotation(IClass cls, Class<? extends Annotation> ann, 
    HashMap<String, Object> values) 
    throws InstrumenterException {
    CtClass cl = ((JAClass) cls).getCtClass();
    ClassFile ccFile = cl.getClassFile();
    ConstPool constpool = ccFile.getConstPool();
    AnnotationsAttribute attr = new AnnotationsAttribute(constpool, 
        AnnotationsAttribute.visibleTag);
    javassist.bytecode.annotation.Annotation marker 
        = new javassist.bytecode.annotation.Annotation(
            ann.getName(), constpool);
    setValues(marker, constpool, values);
    attr.addAnnotation(marker);
    cl.getClassFile().addAttribute(attr);
}
 
开发者ID:SSEHUB,项目名称:spassMeter,代码行数:20,代码来源:CodeModifier.java

示例13: isAnnotated

import javassist.bytecode.AnnotationsAttribute; //导入依赖的package包/类
private static boolean isAnnotated(ClassFile cfile, Class<? extends Annotation>[] annotated) throws IOException {
	List attributes = U.safe(cfile.getAttributes());

	for (Object attribute : attributes) {
		if (attribute instanceof AnnotationsAttribute) {
			AnnotationsAttribute annotations = (AnnotationsAttribute) attribute;

			for (Class<? extends Annotation> ann : annotated) {
				if (annotations.getAnnotation(ann.getName()) != null) {
					return true;
				}
			}
		}
	}

	return false;
}
 
开发者ID:rapidoid,项目名称:rapidoid,代码行数:18,代码来源:ClasspathScanner.java

示例14: addEndpointMapping

import javassist.bytecode.AnnotationsAttribute; //导入依赖的package包/类
@Override
protected void addEndpointMapping(CtMethod ctMethod, String method, String request) {
	MethodInfo methodInfo = ctMethod.getMethodInfo();
	ConstPool constPool = methodInfo.getConstPool();

	AnnotationsAttribute attr = new AnnotationsAttribute(constPool, AnnotationsAttribute.visibleTag);
	Annotation requestMapping = new Annotation(RequestMapping.class.getName(), constPool);

	ArrayMemberValue valueVals = new ArrayMemberValue(constPool);
	StringMemberValue valueVal = new StringMemberValue(constPool);
	valueVal.setValue(request);
	valueVals.setValue(new MemberValue[]{valueVal});

	requestMapping.addMemberValue("value", valueVals);

	ArrayMemberValue methodVals = new ArrayMemberValue(constPool);
	EnumMemberValue methodVal = new EnumMemberValue(constPool);
	methodVal.setType(RequestMethod.class.getName());
	methodVal.setValue(method);
	methodVals.setValue(new MemberValue[]{methodVal});

	requestMapping.addMemberValue("method", methodVals);
	attr.addAnnotation(requestMapping);
	methodInfo.addAttribute(attr);
}
 
开发者ID:statefulj,项目名称:statefulj,代码行数:26,代码来源:SpringMVCBinder.java

示例15: addClassAnnotation

import javassist.bytecode.AnnotationsAttribute; //导入依赖的package包/类
public static void addClassAnnotation(CtClass clazz, Class<?> annotationClass, Object... values) {
	ClassFile ccFile = clazz.getClassFile();
	ConstPool constPool = ccFile.getConstPool();
	AnnotationsAttribute attr = getAnnotationsAttribute(ccFile);
	Annotation annot = new Annotation(annotationClass.getName(), constPool);
	
	for(int i = 0; i < values.length; i = i + 2) {
		String valueName = (String)values[i];
		Object value = values[i+1];
		if (valueName != null && value != null) {
			MemberValue memberValue = createMemberValue(constPool, value);
			annot.addMemberValue(valueName, memberValue);
		}
	}
	
	attr.addAnnotation(annot);
}
 
开发者ID:statefulj,项目名称:statefulj,代码行数:18,代码来源:JavassistUtils.java


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