當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。