當前位置: 首頁>>代碼示例>>Java>>正文


Java Annotation.getTypeName方法代碼示例

本文整理匯總了Java中javassist.bytecode.annotation.Annotation.getTypeName方法的典型用法代碼示例。如果您正苦於以下問題:Java Annotation.getTypeName方法的具體用法?Java Annotation.getTypeName怎麽用?Java Annotation.getTypeName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javassist.bytecode.annotation.Annotation的用法示例。


在下文中一共展示了Annotation.getTypeName方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: addAnnotation

import javassist.bytecode.annotation.Annotation; //導入方法依賴的package包/類
/**
 * Adds an annotation.  If there is an annotation with the same type,
 * it is removed before the new annotation is added.
 *
 * @param annotation        the added annotation.
 */
public void addAnnotation(Annotation annotation) {
    String type = annotation.getTypeName();
    Annotation[] annotations = getAnnotations();
    for (int i = 0; i < annotations.length; i++) {
        if (annotations[i].getTypeName().equals(type)) {
            annotations[i] = annotation;
            setAnnotations(annotations);
            return;
        }
    }

    Annotation[] newlist = new Annotation[annotations.length + 1];
    System.arraycopy(annotations, 0, newlist, 0, annotations.length);
    newlist[annotations.length] = annotation;
    setAnnotations(newlist);
}
 
開發者ID:scouter-project,項目名稱:bytescope,代碼行數:23,代碼來源:AnnotationsAttribute.java

示例2: analizePotentialPlugins

import javassist.bytecode.annotation.Annotation; //導入方法依賴的package包/類
private static void analizePotentialPlugins(InputStream input, Set<DiscoveredPlugin> discovered, boolean isClasspath, File file) throws IOException {
    DataInputStream in;
    if(input instanceof DataInputStream){
        in = ((DataInputStream) input);
    }else{
        in = new DataInputStream(input);
    }

    ClassFile classFile = new ClassFile(in);

    AnnotationsAttribute annotations = ((AnnotationsAttribute) classFile.getAttribute(AnnotationsAttribute.visibleTag));
    if(annotations == null){
        return;
    }
    for(Annotation annotation : annotations.getAnnotations()){
        String annName = annotation.getTypeName();
        if(annName.equals("jk_5.nailed.api.plugin.Plugin")){
            StringMemberValue idValue = ((StringMemberValue) annotation.getMemberValue("id"));
            String id = idValue == null ? null : idValue.getValue();
            StringMemberValue nameValue = ((StringMemberValue) annotation.getMemberValue("name"));
            String name = nameValue == null ? null : nameValue.getValue();
            StringMemberValue versionValue = ((StringMemberValue) annotation.getMemberValue("version"));
            String version = versionValue == null ? "unknown" : versionValue.getValue();
            discovered.add(new DiscoveredPlugin(classFile.getName(), id, name, version, isClasspath, file));
        }
    }
}
 
開發者ID:nailed,項目名稱:nailed,代碼行數:28,代碼來源:PluginDiscoverer.java

示例3: addAnnotations

import javassist.bytecode.annotation.Annotation; //導入方法依賴的package包/類
private void addAnnotations(@Nonnull CtClass clazz, Set<String> knownAnnotations) {
    for (Annotation annotation : getAnnotations(clazz, PACKAGE, TYPE)) {
        String annotationClassName = annotation.getTypeName();
        if (!knownAnnotations.add(annotationClassName)) {
            continue;
        }
        if (DEAD_ENDS.contains(annotationClassName)) {
            continue;
        }
        CtClass annotationClazz = getCtClass(clazz.getClassPool(), annotationClassName);
        if (annotationClazz != null) {
            addAnnotations(annotationClazz, knownAnnotations);
        }
    }
}
 
開發者ID:ImmobilienScout24,項目名稱:deadcode4j,代碼行數:16,代碼來源:AnnotationsAnalyzer.java

示例4: cloneAnnotationsAttribute

import javassist.bytecode.annotation.Annotation; //導入方法依賴的package包/類
/**
 * This function will take the given annotations attribute and create a new
 * attribute, cloning all the annotations and specified values within the
 * attribute. The annotations attribute can then be set on a method, class,
 * or field.
 * 
 * @param attr
 * @return
 */
public static AnnotationsAttribute cloneAnnotationsAttribute(
		ConstPool constPool,
		AnnotationsAttribute attr,
		ElementType validElementType ) {

	// We can use system class loader here because the annotations for
	// Target
	// are part of the Java System.
	ClassLoader cl = ClassLoader.getSystemClassLoader();

	AnnotationsAttribute attrNew = new AnnotationsAttribute(
			constPool,
			AnnotationsAttribute.visibleTag);

	if (attr != null) {
		for (Annotation annotation : attr.getAnnotations()) {
			Annotation newAnnotation = new Annotation(
					annotation.getTypeName(),
					constPool);

			// If this must target a certain type of field, then ensure we
			// only
			// copy over annotations that can target that type of field.
			// For instances, a METHOD annotation can't be applied to a
			// FIELD or TYPE.
			Class<?> annoClass;
			try {
				annoClass = cl.loadClass(annotation.getTypeName());
				Target target = annoClass.getAnnotation(Target.class);
				if (target != null && !Arrays.asList(
						target.value()).contains(
						validElementType)) {
					continue;
				}
			}
			catch (ClassNotFoundException e) {
				// Cannot apply this annotation because its type cannot be
				// found.
				LOGGER.error(
						"Cannot apply this annotation because it's type cannot be found",
						e);
				continue;
			}

			// Copy over the options for this annotation. For example:
			// @Parameter(names = "-blah")
			// For this, a member value would be "names" which would be a
			// StringMemberValue
			if (annotation.getMemberNames() != null) {
				for (Object memberName : annotation.getMemberNames()) {
					MemberValue memberValue = annotation.getMemberValue((String) memberName);
					if (memberValue != null) {
						newAnnotation.addMemberValue(
								(String) memberName,
								memberValue);
					}
				}
			}
			attrNew.addAnnotation(newAnnotation);
		}
	}
	return attrNew;
}
 
開發者ID:locationtech,項目名稱:geowave,代碼行數:73,代碼來源:JavassistUtils.java


注:本文中的javassist.bytecode.annotation.Annotation.getTypeName方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。