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


Java ClassReader类代码示例

本文整理汇总了Java中org.springframework.asm.ClassReader的典型用法代码示例。如果您正苦于以下问题:Java ClassReader类的具体用法?Java ClassReader怎么用?Java ClassReader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: getClassMeta

import org.springframework.asm.ClassReader; //导入依赖的package包/类
/**
 * 获取字节码类信息
 * @param file 文件路径字符串 E:\\
 * @return
 */
public static ClassMeta getClassMeta(String file){
	FileInputStream fileInputStream = null;

	try {
		fileInputStream = new FileInputStream(file);
		byte[] bytes = toBytes(fileInputStream);

		ClassReader reader = new ClassReader(bytes);
		ClassMetaVisitor clzVisitor = new ClassMetaVisitor();
		reader.accept(clzVisitor, true);

		return clzVisitor;
	} catch (IOException e) {
		e.printStackTrace();
	} finally {
		if (fileInputStream != null) {
			try {
				fileInputStream.close();
			} catch (IOException e1) { }
		}
	}
	
	return null;
}
 
开发者ID:Jakegogo,项目名称:concurrent,代码行数:30,代码来源:ClassMetaUtil.java

示例2: getInterfaceNames

import org.springframework.asm.ClassReader; //导入依赖的package包/类
private List<String> getInterfaceNames(String className) throws IOException {
	// Use ASM to avoid unwanted side-effects of loading JDBC drivers
	ClassReader classReader = new ClassReader(
			getClass().getResourceAsStream("/" + className + ".class"));
	List<String> interfaceNames = new ArrayList<String>();
	for (String name : classReader.getInterfaces()) {
		interfaceNames.add(name);
		interfaceNames.addAll(getInterfaceNames(name));
	}
	return interfaceNames;
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:12,代码来源:DatabaseDriverClassNameTests.java

示例3: isMainClass

import org.springframework.asm.ClassReader; //导入依赖的package包/类
private static boolean isMainClass(InputStream inputStream) {
	try {
		ClassReader classReader = new ClassReader(inputStream);
		MainMethodFinder mainMethodFinder = new MainMethodFinder();
		classReader.accept(mainMethodFinder, ClassReader.SKIP_CODE);
		return mainMethodFinder.isFound();
	}
	catch (IOException ex) {
		return false;
	}
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:12,代码来源:MainClassFinder.java

示例4: afterPropertiesSet

import org.springframework.asm.ClassReader; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public void afterPropertiesSet() throws Exception {
	byte[] bytes = FileCopyUtils.copyToByteArray(this.resource.getInputStream());
	String className = new ClassReader(bytes).getClassName().replace("/", ".");
	Class<?> factoryClass = this.classLoader.defineClass(className, bytes);
	try {
		this.target = ((CompilationResultFactory<T>) factoryClass.newInstance()).getResult();
		this.method = findFactoryMethod(factoryClass);
	}
	catch (InstantiationException | IllegalAccessException e) {
		throw new IllegalArgumentException("failed to load Function byte code", e);
	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-function,代码行数:15,代码来源:AbstractByteCodeLoadingProxy.java

示例5: processRes2BeanData

import org.springframework.asm.ClassReader; //导入依赖的package包/类
private List<BeanData> processRes2BeanData(Resource[] rs) {
	Assert.notEmpty(rs);
	List<BeanData> beanDatas = new ArrayList<>(rs.length);
	try {
		for(int i = 0; i < rs.length; i++) {
			Resource r = rs[i];
			if(r.isReadable()) {
				BeanData data = new BeanData();
				ClassReader cr = new ClassReader(r.getInputStream());
				String className = cr.getClassName();
				Class<?> clazz = Classes.getClass(className
						.replace(Symbol.SLASH, Symbol.PERIOD));
				if (clazz.isAnnotation() || clazz.isAnonymousClass() || clazz.isArray() || clazz.isEnum()) {
					continue;
				}
				GenerateRes res = clazz.getAnnotation(GenerateRes.class);
				if (res != null && !res.value()) {
					continue;
				}
				List<String> properties = new ArrayList<>();
				data.setClazz(clazz.getName() + ".class");
				data.setClassName(clazz.getSimpleName());
				if(Classes.isAssignable(clazz, Entity.class))
					data.setEntity(true);
				else
					data.setEntity(false);
				for(Class<?> curClazz = clazz; 
						curClazz != null && curClazz != Object.class; 
						curClazz = curClazz.getSuperclass()) {
					Field[] fields = curClazz.getDeclaredFields();
					for(Field f : fields) {
						if(Modifier.isFinal(f.getModifiers())
								|| Modifier.isStatic(f.getModifiers())) 
							continue;
						properties.add(f.getName());
					}
				}
				if (properties.size() == 0) {
					continue;
				}
				data.setProperties(properties);
				if(log.isInfoEnabled()) {
					log.info("==== Add {} class to resources.", clazz);
				}
				beanDatas.add(data);
			}
		}
	} catch (IOException | ClassNotFoundException e) {
		log.error("generate value-object resource error.", e);
	}
	return beanDatas;
}
 
开发者ID:easycodebox,项目名称:easycode,代码行数:53,代码来源:GenerateBeanRes.java


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