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


Java ClassFile.getAttribute方法代码示例

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


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

示例1: updateInnerEntry

import javassist.bytecode.ClassFile; //导入方法依赖的package包/类
private static void updateInnerEntry(int mod, String name, CtClass clazz, boolean outer) {
    ClassFile cf = clazz.getClassFile2();
    InnerClassesAttribute ica = (InnerClassesAttribute)cf.getAttribute(
                                            InnerClassesAttribute.tag);
    if (ica == null)
        return;

    int n = ica.tableLength();
    for (int i = 0; i < n; i++)
        if (name.equals(ica.innerClass(i))) {
            int acc = ica.accessFlags(i) & AccessFlag.STATIC;
            ica.setAccessFlags(i, mod | acc);
            String outName = ica.outerClass(i);
            if (outName != null && outer)
                try {
                    CtClass parent = clazz.getClassPool().get(outName);
                    updateInnerEntry(mod, name, parent, false);
                }
                catch (NotFoundException e) {
                    throw new RuntimeException("cannot find the declaring class: "
                                               + outName);
                }

            break;
        }
}
 
开发者ID:AndreJCL,项目名称:JCL,代码行数:27,代码来源:CtNewNestedClass.java

示例2: getNestedClasses

import javassist.bytecode.ClassFile; //导入方法依赖的package包/类
public CtClass[] getNestedClasses() throws NotFoundException {
    ClassFile cf = getClassFile2();
    InnerClassesAttribute ica
        = (InnerClassesAttribute)cf.getAttribute(InnerClassesAttribute.tag);
    if (ica == null)
        return new CtClass[0];

    String thisName = cf.getName() + "$";
    int n = ica.tableLength();
    ArrayList<CtClass> list = new ArrayList<CtClass>(n);
    for (int i = 0; i < n; i++) {
        String name = ica.innerClass(i);
        if (name != null)
            if (name.startsWith(thisName)) {
                // if it is an immediate nested class
                if (name.lastIndexOf('$') < thisName.length())
                    list.add(classPool.get(name));
            }
    }

    return (CtClass[])list.toArray(new CtClass[list.size()]);
}
 
开发者ID:AndreJCL,项目名称:JCL,代码行数:23,代码来源:CtClassType.java

示例3: getDeclaringClass

import javassist.bytecode.ClassFile; //导入方法依赖的package包/类
public CtClass getDeclaringClass() throws NotFoundException {
    ClassFile cf = getClassFile2();
    InnerClassesAttribute ica = (InnerClassesAttribute)cf.getAttribute(
                                            InnerClassesAttribute.tag);
    if (ica == null)
        return null;

    String name = getName();
    int n = ica.tableLength();
    for (int i = 0; i < n; ++i)
        if (name.equals(ica.innerClass(i))) {
            String outName = ica.outerClass(i);
            if (outName != null)
                return classPool.get(outName);
            else {
                // maybe anonymous or local class.
                EnclosingMethodAttribute ema
                    = (EnclosingMethodAttribute)cf.getAttribute(
                                                EnclosingMethodAttribute.tag);
                if (ema != null)
                    return classPool.get(ema.className());
            }
        }

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

示例4: scan

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

import javassist.bytecode.ClassFile; //导入方法依赖的package包/类
private void removeFinalModifierFromClass(final CtClass clazz) {
    if (strategy != INST_REDEFINE) {
        if (Modifier.isFinal(clazz.getModifiers())) {
            clazz.setModifiers(clazz.getModifiers() ^ Modifier.FINAL);
        }

        ClassFile classFile = clazz.getClassFile2();
        AttributeInfo attribute = classFile.getAttribute(InnerClassesAttribute.tag);
        if (attribute != null && attribute instanceof InnerClassesAttribute) {
            InnerClassesAttribute ica = (InnerClassesAttribute) attribute;
            String name = classFile.getName();
            int n = ica.tableLength();
            for (int i = 0; i < n; ++i) {
                if (name.equals(ica.innerClass(i))) {
                    int accessFlags = ica.accessFlags(i);
                    if (Modifier.isFinal(accessFlags)) {
                        ica.setAccessFlags(i, accessFlags ^ Modifier.FINAL);
                    }
                }
            }
        }
    }
}
 
开发者ID:awenblue,项目名称:powermock,代码行数:24,代码来源:MainMockTransformer.java

示例6: discoverAndIntimateForClassAnnotations

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

示例7: scanClass

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

import javassist.bytecode.ClassFile; //导入方法依赖的package包/类
public CtClass[] getNestedClasses() throws NotFoundException {
    ClassFile cf = getClassFile2();
    InnerClassesAttribute ica
        = (InnerClassesAttribute)cf.getAttribute(InnerClassesAttribute.tag);
    if (ica == null)
        return new CtClass[0];

    String thisName = cf.getName() + "$";
    int n = ica.tableLength();
    ArrayList list = new ArrayList(n);
    for (int i = 0; i < n; i++) {
        String name = ica.innerClass(i);
        if (name != null)
            if (name.startsWith(thisName)) {
                // if it is an immediate nested class
                if (name.lastIndexOf('$') < thisName.length())
                    list.add(classPool.get(name));
            }
    }

    return (CtClass[])list.toArray(new CtClass[list.size()]);
}
 
开发者ID:MeRPG2,项目名称:EndHQ-Libraries,代码行数:23,代码来源:CtClassType.java

示例9: scanClass

import javassist.bytecode.ClassFile; //导入方法依赖的package包/类
/**
 * Scans passed {@link ClassFile} instance for specific annotations
 * 
 * @param cf
 * @param url
 */
protected void scanClass(ClassFile cf, URL url) {

    String className = cf.getName();

    AnnotationsAttribute visible = (AnnotationsAttribute) cf.getAttribute(AnnotationsAttribute.visibleTag);
    AnnotationsAttribute invisible = (AnnotationsAttribute) cf.getAttribute(AnnotationsAttribute.invisibleTag);

    if (ObjectUtils.notNull(visible)) {
        populate(visible.getAnnotations(), className, url);
    }

    if (ObjectUtils.notNull(invisible)) {
        populate(invisible.getAnnotations(), className, url);
    }
}
 
开发者ID:levants,项目名称:lightmare,代码行数:22,代码来源:AnnotationFinder.java

示例10: isConfigPropertyAnnotationPresent

import javassist.bytecode.ClassFile; //导入方法依赖的package包/类
private static boolean isConfigPropertyAnnotationPresent(ClassFile cf, Log log) {

        AttributeInfo classAttribute = cf.getAttribute(AnnotationsAttribute.visibleTag);
        if (classAttribute != null) {
            if (findAnnotation(cf, log, classAttribute, "com.avast.syringe.config.ConfigBean")) {
                return true;
            }
        }

        List<FieldInfo> fields = cf.getFields();
        for (FieldInfo field : fields) {
            AttributeInfo fieldAttribute = field.getAttribute(AnnotationsAttribute.visibleTag);
            if (fieldAttribute != null) {
                if (findAnnotation(cf, log, fieldAttribute, "com.avast.syringe.config.ConfigProperty")) {
                    return true;
                }
            }
        }
        return false;
    }
 
开发者ID:avast,项目名称:syringe-maven-plugin,代码行数:21,代码来源:ModuleScannerMojo.java

示例11: scan

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

示例12: hasAnnotation

import javassist.bytecode.ClassFile; //导入方法依赖的package包/类
public boolean hasAnnotation(Class<?> clz) {
    ClassFile cf = getClassFile2();
    AnnotationsAttribute ainfo = (AnnotationsAttribute)
            cf.getAttribute(AnnotationsAttribute.invisibleTag);  
    AnnotationsAttribute ainfo2 = (AnnotationsAttribute)
            cf.getAttribute(AnnotationsAttribute.visibleTag);  
    return hasAnnotationType(clz, getClassPool(), ainfo, ainfo2);
}
 
开发者ID:AndreJCL,项目名称:JCL,代码行数:9,代码来源:CtClassType.java

示例13: getAnnotation

import javassist.bytecode.ClassFile; //导入方法依赖的package包/类
public Object getAnnotation(Class<?> clz) throws ClassNotFoundException {
    ClassFile cf = getClassFile2();
    AnnotationsAttribute ainfo = (AnnotationsAttribute)
            cf.getAttribute(AnnotationsAttribute.invisibleTag);  
    AnnotationsAttribute ainfo2 = (AnnotationsAttribute)
            cf.getAttribute(AnnotationsAttribute.visibleTag);  
    return getAnnotationType(clz, getClassPool(), ainfo, ainfo2);
}
 
开发者ID:AndreJCL,项目名称:JCL,代码行数:9,代码来源:CtClassType.java

示例14: getAnnotations

import javassist.bytecode.ClassFile; //导入方法依赖的package包/类
private Object[] getAnnotations(boolean ignoreNotFound)
    throws ClassNotFoundException
{
    ClassFile cf = getClassFile2();
    AnnotationsAttribute ainfo = (AnnotationsAttribute)
            cf.getAttribute(AnnotationsAttribute.invisibleTag);  
    AnnotationsAttribute ainfo2 = (AnnotationsAttribute)
            cf.getAttribute(AnnotationsAttribute.visibleTag);  
    return toAnnotationType(ignoreNotFound, getClassPool(), ainfo, ainfo2);
}
 
开发者ID:AndreJCL,项目名称:JCL,代码行数:11,代码来源:CtClassType.java

示例15: getEnclosingMethod

import javassist.bytecode.ClassFile; //导入方法依赖的package包/类
public CtMethod getEnclosingMethod() throws NotFoundException {
    ClassFile cf = getClassFile2();
    EnclosingMethodAttribute ema
            = (EnclosingMethodAttribute)cf.getAttribute(
                                            EnclosingMethodAttribute.tag);
    if (ema != null) {
        CtClass enc = classPool.get(ema.className());
        return enc.getMethod(ema.methodName(), ema.methodDescriptor());
    }

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


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