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


Java ClassFile.getFields方法代碼示例

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


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

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

示例2: addReadWriteMethods

import javassist.bytecode.ClassFile; //導入方法依賴的package包/類
private void addReadWriteMethods(ClassFile classfile)
		throws CannotCompileException {
	List fields = classfile.getFields();
	for (Iterator field_iter = fields.iterator(); field_iter.hasNext();) {
		FieldInfo finfo = (FieldInfo) field_iter.next();
		if ((finfo.getAccessFlags() & AccessFlag.STATIC) == 0
		    && (!finfo.getName().equals(HANDLER_FIELD_NAME))) {
			// case of non-static field
			if (filter.handleRead(finfo.getDescriptor(), finfo
					.getName())) {
				addReadMethod(classfile, finfo);
				readableFields.put(finfo.getName(), finfo
						.getDescriptor());
			}
			if (filter.handleWrite(finfo.getDescriptor(), finfo
					.getName())) {
				addWriteMethod(classfile, finfo);
				writableFields.put(finfo.getName(), finfo
						.getDescriptor());
			}
		}
	}
}
 
開發者ID:cacheonix,項目名稱:cacheonix-core,代碼行數:24,代碼來源:FieldTransformer.java

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

示例4: addReadWriteMethods

import javassist.bytecode.ClassFile; //導入方法依賴的package包/類
private void addReadWriteMethods(ClassFile classfile) throws CannotCompileException, BadBytecode {
	final List fields = classfile.getFields();
	for ( Object field : fields ) {
		final FieldInfo finfo = (FieldInfo) field;
		if ( (finfo.getAccessFlags() & AccessFlag.STATIC) == 0 && (!finfo.getName().equals( HANDLER_FIELD_NAME )) ) {
			// case of non-static field
			if ( filter.handleRead( finfo.getDescriptor(), finfo.getName() ) ) {
				addReadMethod( classfile, finfo );
			}
			if ( filter.handleWrite( finfo.getDescriptor(), finfo.getName() ) ) {
				addWriteMethod( classfile, finfo );
			}
		}
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:16,代碼來源:FieldTransformer.java

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

示例6: discoverAndIntimateForFieldAnnotations

import javassist.bytecode.ClassFile; //導入方法依賴的package包/類
/**
   * Discovers Field Annotations
   * 
   * @param classFile
   */
  private void discoverAndIntimateForFieldAnnotations (ClassFile classFile) {
@SuppressWarnings("unchecked") 
List<FieldInfo> fields = classFile.getFields();
if (fields == null) {
	return;
}

for (FieldInfo fieldInfo : fields) {
	Set<Annotation> annotations = new HashSet<Annotation>();
	
	AnnotationsAttribute visible = (AnnotationsAttribute) fieldInfo.getAttribute(AnnotationsAttribute.visibleTag);
	AnnotationsAttribute invisible = (AnnotationsAttribute) fieldInfo.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<FieldAnnotationDiscoveryListener> listeners = fieldAnnotationListeners.get(annotation.getTypeName());
		if (null == listeners) {
			continue;
		}
		
		for (FieldAnnotationDiscoveryListener listener : listeners) {
			listener.discovered(classFile.getName(), fieldInfo.getName(), annotation.getTypeName());
		}
	}
}
  }
 
開發者ID:guci314,項目名稱:playorm,代碼行數:39,代碼來源:Discoverer.java

示例7: scanFields

import javassist.bytecode.ClassFile; //導入方法依賴的package包/類
protected void scanFields(ClassFile cf) {
    List<ClassFile> fields = cf.getFields();
    if (fields == null)
        return;
    for (Object obj : fields) {
        FieldInfo field = (FieldInfo) obj;
        AnnotationsAttribute visible = (AnnotationsAttribute) field.getAttribute(AnnotationsAttribute.visibleTag);
        AnnotationsAttribute invisible = (AnnotationsAttribute) field
                .getAttribute(AnnotationsAttribute.invisibleTag);
        if (visible != null)
            populate(visible.getAnnotations(), cf.getName());
        if (invisible != null)
            populate(invisible.getAnnotations(), cf.getName());
    }
}
 
開發者ID:audit4j,項目名稱:audit4j-core,代碼行數:16,代碼來源:AnnotationDB.java

示例8: renameClasses

import javassist.bytecode.ClassFile; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public static void renameClasses(CtClass c, ClassNameReplacer replacer) {
	
	// sadly, we can't use CtClass.renameClass() because SignatureAttribute.renameClass() is extremely buggy =(
	
	ReplacerClassMap map = new ReplacerClassMap(replacer);
	ClassFile classFile = c.getClassFile();
	
	// rename the constant pool (covers ClassInfo, MethodTypeInfo, and NameAndTypeInfo)
	ConstPool constPool = c.getClassFile().getConstPool();
	constPool.renameClass(map);
	
	// rename class attributes
	renameAttributes(classFile.getAttributes(), map, SignatureType.Class);
	
	// rename methods
	for (MethodInfo methodInfo : (List<MethodInfo>)classFile.getMethods()) {
		methodInfo.setDescriptor(Descriptor.rename(methodInfo.getDescriptor(), map));
		renameAttributes(methodInfo.getAttributes(), map, SignatureType.Method);
	}
	
	// rename fields
	for (FieldInfo fieldInfo : (List<FieldInfo>)classFile.getFields()) {
		fieldInfo.setDescriptor(Descriptor.rename(fieldInfo.getDescriptor(), map));
		renameAttributes(fieldInfo.getAttributes(), map, SignatureType.Field);
	}
	
	// rename the class name itself last
	// NOTE: don't use the map here, because setName() calls the buggy SignatureAttribute.renameClass()
	// we only want to replace exactly this class name
	String newName = renameClassName(c.getName(), map);
	if (newName != null) {
		c.setName(newName);
	}
	
	// replace simple names in the InnerClasses attribute too
	InnerClassesAttribute attr = (InnerClassesAttribute)c.getClassFile().getAttribute(InnerClassesAttribute.tag);
	if (attr != null) {
		for (int i = 0; i < attr.tableLength(); i++) {
			
			// get the inner class full name (which has already been translated)
			ClassEntry classEntry = new ClassEntry(Descriptor.toJvmName(attr.innerClass(i)));
			
			if (attr.innerNameIndex(i) != 0) {
				// update the inner name
				attr.setInnerNameIndex(i, constPool.addUtf8Info(classEntry.getInnermostClassName()));
			}
			
			/* DEBUG
			System.out.println(String.format("\tDEOBF: %s-> ATTR: %s,%s,%s", classEntry, attr.outerClass(i), attr.innerClass(i), attr.innerName(i)));
			*/
		}
	}
}
 
開發者ID:cccssw,項目名稱:enigma-vk,代碼行數:55,代碼來源:ClassRenamer.java


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