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


Java AnnotationsAttribute.getAnnotations方法代码示例

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


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

示例1: 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

示例2: 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

示例3: addAnnotations

import javassist.bytecode.AnnotationsAttribute; //导入方法依赖的package包/类
private void addAnnotations(Collection<String> imports, AnnotationsAttribute annotations) {
    if (annotations != null) {
        for (Annotation each : annotations.getAnnotations()) {
            imports.add(each.getTypeName());
        }
    }
}
 
开发者ID:arquillian,项目名称:smart-testing,代码行数:8,代码来源:JavaAssistClass.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));
        final List<AnnotationDescriptor> annotationDescriptors =
            (fieldAnnotations != null) ? getAnnotationDescriptors(fieldAnnotations) : Collections.<AnnotationDescriptor>emptyList();
        fieldDescriptors.add(new FieldDescriptor(fieldName, field.getDescriptor(), annotationDescriptors));
      }
      functions.add(new AnnotatedClassDescriptor(classFile.getName(), classAnnotations, fieldDescriptors));
    }
  }
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:28,代码来源:ClassPathScanner.java

示例5: hasAnnotationType

import javassist.bytecode.AnnotationsAttribute; //导入方法依赖的package包/类
static boolean hasAnnotationType(Class<?> clz, ClassPool cp,
                                 AnnotationsAttribute a1, AnnotationsAttribute a2)
{
    Annotation[] anno1, anno2;

    if (a1 == null)
        anno1 = null;
    else
        anno1 = a1.getAnnotations();

    if (a2 == null)
        anno2 = null;
    else
        anno2 = a2.getAnnotations();

    String typeName = clz.getName();
    if (anno1 != null)
       for (int i = 0; i < anno1.length; i++)
          if (anno1[i].getTypeName().equals(typeName))
              return true;

    if (anno2 != null)
       for (int i = 0; i < anno2.length; i++)
          if (anno2[i].getTypeName().equals(typeName))
              return true;

    return false;
}
 
开发者ID:AndreJCL,项目名称:JCL,代码行数:29,代码来源:CtClassType.java

示例6: getAnnotationType

import javassist.bytecode.AnnotationsAttribute; //导入方法依赖的package包/类
static Object getAnnotationType(Class<?> clz, ClassPool cp,
                                AnnotationsAttribute a1, AnnotationsAttribute a2)
    throws ClassNotFoundException
{
    Annotation[] anno1, anno2;

    if (a1 == null)
        anno1 = null;
    else
        anno1 = a1.getAnnotations();

    if (a2 == null)
        anno2 = null;
    else
        anno2 = a2.getAnnotations();

    String typeName = clz.getName();
    if (anno1 != null)
       for (int i = 0; i < anno1.length; i++)
          if (anno1[i].getTypeName().equals(typeName))
              return toAnnoType(anno1[i], cp);

    if (anno2 != null)
       for (int i = 0; i < anno2.length; i++)
          if (anno2[i].getTypeName().equals(typeName))
              return toAnnoType(anno2[i], cp);

    return null;
}
 
开发者ID:AndreJCL,项目名称:JCL,代码行数:30,代码来源:CtClassType.java

示例7: isAnnotationPresent

import javassist.bytecode.AnnotationsAttribute; //导入方法依赖的package包/类
protected boolean isAnnotationPresent(AnnotationsAttribute attr) {
	if (attr != null) {
		Annotation[] annotations = attr.getAnnotations();
		if (annotations != null) {
			for (Annotation ann : annotations) {
				if (ann.getTypeName().equals(Iri.class.getName()))
					return true;
				if (ann.getTypeName().equals(Matching.class.getName()))
					return true;
			}
		}
	}
	return false;
}
 
开发者ID:anno4j,项目名称:anno4j,代码行数:15,代码来源:CheckForConcept.java

示例8: analyzeClassAnnotations

import javassist.bytecode.AnnotationsAttribute; //导入方法依赖的package包/类
private void analyzeClassAnnotations(AnalyzedClass analyzedClass, CtClass ctClass) {
  List<AnalyzedAnnotation> annotations = new ArrayList<>();
  for (Object o : ctClass.getClassFile2().getAttributes()) {
    if (o instanceof AnnotationsAttribute) {
      AnnotationsAttribute attribute = (AnnotationsAttribute) o;
      for (Annotation analyzedAnnotation : attribute.getAnnotations()) {
        annotations.add(new AnalyzedAnnotation(analyzedAnnotation.toString()));
      }
    }
  }
  analyzedClass.setAnnotations(annotations);
}
 
开发者ID:mestachs,项目名称:archeo4j,代码行数:13,代码来源:ClassAnalyzer.java

示例9: checkAnnotation

import javassist.bytecode.AnnotationsAttribute; //导入方法依赖的package包/类
/**
 * Checks for an annotation, returns the assigned annotation object and
 * removes the annotation if required.
 * 
 * @param attribute the attribute to be searched for the annotation
 * @param typeName the type name of the annotation to be returned
 * @param cp the current class pool (needed for type conversion)
 * @param remove if <code>true</code> remove the found annotation as a 
 *   side effect, <code>false</code> do not modify anything
 * 
 * @return the attached annotation or <b>null</b> if none of the given
 *   type is attached
 * @throws ClassNotFoundException in case that the target class for casting
 *   cannot be found
 * 
 * @since 1.00
 */
private static Object checkAnnotation(AnnotationsAttribute attribute, 
    String typeName, javassist.ClassPool cp, boolean remove)
    throws ClassNotFoundException {
    Object result = null;
    if (attribute != null) {
        javassist.bytecode.annotation.Annotation[] annotations 
            = attribute.getAnnotations();
        if (annotations != null) {
            for (int i = 0; i < annotations.length; i++) {
                if (annotations[i].getTypeName().equals(typeName)) {
                    result = toAnnoType(annotations[i], cp);
                    if (remove) {
                        javassist.bytecode.annotation.Annotation[] tmp 
                            = new javassist.bytecode.annotation.Annotation[
                                annotations.length - 1];
                        int pos = 0;
                        for (int j = 0; j < annotations.length; j++) {
                            if (i != j) {
                                tmp[pos++] = annotations[j];
                            }
                        }
                        attribute.setAnnotations(tmp);
                    }
                }
            }
        }
    }
    return result;
}
 
开发者ID:SSEHUB,项目名称:spassMeter,代码行数:47,代码来源:Annotations.java

示例10: analizePotentialPlugins

import javassist.bytecode.AnnotationsAttribute; //导入方法依赖的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

示例11: hasAnnotationType

import javassist.bytecode.AnnotationsAttribute; //导入方法依赖的package包/类
static boolean hasAnnotationType(Class clz, ClassPool cp,
                                 AnnotationsAttribute a1, AnnotationsAttribute a2)
{
    Annotation[] anno1, anno2;

    if (a1 == null)
        anno1 = null;
    else
        anno1 = a1.getAnnotations();

    if (a2 == null)
        anno2 = null;
    else
        anno2 = a2.getAnnotations();

    String typeName = clz.getName();
    if (anno1 != null)
       for (int i = 0; i < anno1.length; i++)
          if (anno1[i].getTypeName().equals(typeName))
              return true;

    if (anno2 != null)
       for (int i = 0; i < anno2.length; i++)
          if (anno2[i].getTypeName().equals(typeName))
              return true;

    return false;
}
 
开发者ID:MeRPG2,项目名称:EndHQ-Libraries,代码行数:29,代码来源:CtClassType.java

示例12: getAnnotationType

import javassist.bytecode.AnnotationsAttribute; //导入方法依赖的package包/类
static Object getAnnotationType(Class clz, ClassPool cp,
                                AnnotationsAttribute a1, AnnotationsAttribute a2)
    throws ClassNotFoundException
{
    Annotation[] anno1, anno2;

    if (a1 == null)
        anno1 = null;
    else
        anno1 = a1.getAnnotations();

    if (a2 == null)
        anno2 = null;
    else
        anno2 = a2.getAnnotations();

    String typeName = clz.getName();
    if (anno1 != null)
       for (int i = 0; i < anno1.length; i++)
          if (anno1[i].getTypeName().equals(typeName))
              return toAnnoType(anno1[i], cp);

    if (anno2 != null)
       for (int i = 0; i < anno2.length; i++)
          if (anno2[i].getTypeName().equals(typeName))
              return toAnnoType(anno2[i], cp);

    return null;
}
 
开发者ID:MeRPG2,项目名称:EndHQ-Libraries,代码行数:30,代码来源:CtClassType.java

示例13: disableBooleanMember

import javassist.bytecode.AnnotationsAttribute; //导入方法依赖的package包/类
/**
 * Iterate the annotations, look for a 'required' parameter, and set it to
 * false.
 * 
 * @param field
 * @param prefix
 */
private void disableBooleanMember(
		String booleanMemberName,
		CtField field ) {

	// This is the JCommander package name
	String packageName = JCommander.class.getPackage().getName();

	AnnotationsAttribute fieldAttributes = (AnnotationsAttribute) field.getFieldInfo().getAttribute(
			AnnotationsAttribute.visibleTag);

	// Look for annotations that have a 'names' attribute, and whose package
	// starts with the expected JCommander package.
	for (Annotation annotation : fieldAttributes.getAnnotations()) {
		if (annotation.getTypeName().startsWith(
				packageName)) {
			// See if it has a 'names' member variable.
			MemberValue requiredMember = annotation.getMemberValue(booleanMemberName);

			// We have a names member!!!
			if (requiredMember != null) {
				BooleanMemberValue booleanRequiredMember = (BooleanMemberValue) requiredMember;

				// Set it to not required.
				booleanRequiredMember.setValue(false);

				// This is KEY! For some reason, the existing annotation
				// will not be modified unless
				// you call 'setAnnotation' here. I'm guessing
				// 'getAnnotation()' creates a copy.
				fieldAttributes.setAnnotation(annotation);

				// Finished processing names.
				break;
			}
		}
	}
}
 
开发者ID:locationtech,项目名称:geowave,代码行数:45,代码来源:JCommanderTranslationMap.java

示例14: findAnnotationsForAnnotationsAttribute

import javassist.bytecode.AnnotationsAttribute; //导入方法依赖的package包/类
private static Set<Annotation> findAnnotationsForAnnotationsAttribute(AnnotationsAttribute attr) {

		if (attr != null) {
			javassist.bytecode.annotation.Annotation[] anns = attr.getAnnotations();
			return findAnnotationsForAnnotationsArray(anns);
		}
		return Collections.emptySet();
	}
 
开发者ID:JadiraOrg,项目名称:jadira,代码行数:9,代码来源:JavassistAnnotationsHelper.java

示例15: hasAnnotation

import javassist.bytecode.AnnotationsAttribute; //导入方法依赖的package包/类
public static boolean hasAnnotation(List attributes, String annotationClassName) {
	for (Object obj : attributes) {
		if (obj instanceof AnnotationsAttribute) {
			AnnotationsAttribute annotationsAttribute = (AnnotationsAttribute) obj;
			Annotation[] annotations = annotationsAttribute.getAnnotations();
			for (Annotation annotation : annotations) {
				if (annotation.getTypeName().equals(annotationClassName)) {
					return true;
				}
			}
		}
	}
	return false;
}
 
开发者ID:siom79,项目名称:japicmp,代码行数:15,代码来源:AnnotationHelper.java


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