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


Java ClassParser.parse方法代码示例

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


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

示例1: fillFromJar

import org.apache.bcel.classfile.ClassParser; //导入方法依赖的package包/类
private ClassNode fillFromJar(File file) {

        ClassNode rootNode = new ClassNode(file.getName());
        try {
            JarFile theJar = new JarFile(file);
            Enumeration<? extends JarEntry> en = theJar.entries();

            while (en.hasMoreElements()) {
                JarEntry entry = en.nextElement();
                if (entry.getName().endsWith(".class")) {
                    ClassParser cp = new ClassParser(
                            theJar.getInputStream(entry), entry.getName());
                    JavaClass jc = cp.parse();
                    ClassInfo classInfo = new ClassInfo(jc.getClassName(),
                            jc.getMethods().length);
                    rootNode.add(classInfo);
                }
            }
        } catch (IOException e) {
            System.err.println("Error reading file: " + file + ". " + e.getMessage());
            e.printStackTrace(System.err);
        }

        return rootNode;
    }
 
开发者ID:google,项目名称:android-classyshark,代码行数:26,代码来源:RootBuilder.java

示例2: downgrade

import org.apache.bcel.classfile.ClassParser; //导入方法依赖的package包/类
void downgrade(String filename) throws IOException
{
    byte[] b = new byte[(int) new File(filename).length()];
    InputStream in = new FileInputStream(filename);
    new DataInputStream(in).readFully(b);
    in.close();

    ClassParser parser = new ClassParser(new ByteArrayInputStream(b), filename);
    JavaClass jc = parser.parse();
    boolean changed;
    changed = downgrade(jc);

    if (changed)
    {
        b = jc.getBytes();

        FileOutputStream out = new FileOutputStream(filename);
        out.write(b);
        out.close();
    }
}
 
开发者ID:BowlerHatLLC,项目名称:feathers-sdk,代码行数:22,代码来源:Downgrader.java

示例3: printClass

import org.apache.bcel.classfile.ClassParser; //导入方法依赖的package包/类
private static void printClass(ClassParser parser) throws IOException {
    JavaClass java_class;
    java_class = parser.parse();

    if (superClasses) {
        try {
            while (java_class != null) {
                System.out.print(java_class.getClassName() + "  ");
                java_class = java_class.getSuperClass();
            }
        } catch (ClassNotFoundException e) {
            System.out.println(e.getMessage());

        }
        System.out.println();
        return;
    }
    if (constants || code)
        System.out.println(java_class); // Dump the contents
    if (constants) // Dump the constant pool ?
        System.out.println(java_class.getConstantPool());

    if (code) // Dump the method code ?
        printCode(java_class.getMethods());
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:26,代码来源:PrintClass.java

示例4: loadClass

import org.apache.bcel.classfile.ClassParser; //导入方法依赖的package包/类
/**
 * Lookup a JavaClass object from the Class Name provided.
 */
public JavaClass loadClass( String className ) throws ClassNotFoundException {
    String classFile = className.replace('.', '/');
    JavaClass RC = findClass(className);
    if (RC != null) {
        return RC;
    }
    try {
        InputStream is = loader.getResourceAsStream(classFile + ".class");
        if (is == null) {
            throw new ClassNotFoundException(className + " not found.");
        }
        ClassParser parser = new ClassParser(is, className);
        RC = parser.parse();
        storeClass(RC);
        return RC;
    } catch (IOException e) {
        throw new ClassNotFoundException(e.toString());
    }
}
 
开发者ID:Hu6,项目名称:VestaClient,代码行数:23,代码来源:ClassLoaderRepository.java

示例5: createClass

import org.apache.bcel.classfile.ClassParser; //导入方法依赖的package包/类
/** 
 * Override this method to create you own classes on the fly. The
 * name contains the special token $$BCEL$$. Everything before that
 * token is consddered to be a package name. You can encode you own
 * arguments into the subsequent string. You must regard however not
 * to use any "illegal" characters, i.e., characters that may not
 * appear in a Java class name too<br>
 *
 * The default implementation interprets the string as a encoded compressed
 * Java class, unpacks and decodes it with the Utility.decode() method, and
 * parses the resulting byte array and returns the resulting JavaClass object.
 *
 * @param class_name compressed byte code with "$$BCEL$$" in it
 */
protected JavaClass createClass( String class_name ) {
    int index = class_name.indexOf("$$BCEL$$");
    String real_name = class_name.substring(index + 8);
    JavaClass clazz = null;
    try {
        byte[] bytes = Utility.decode(real_name, true);
        ClassParser parser = new ClassParser(new ByteArrayInputStream(bytes), "foo");
        clazz = parser.parse();
    } catch (Throwable e) {
        e.printStackTrace();
        return null;
    }
    // Adapt the class name to the passed value
    ConstantPool cp = clazz.getConstantPool();
    ConstantClass cl = (ConstantClass) cp.getConstant(clazz.getClassNameIndex(),
            Constants.CONSTANT_Class);
    ConstantUtf8 name = (ConstantUtf8) cp.getConstant(cl.getNameIndex(),
            Constants.CONSTANT_Utf8);
    name.setBytes(class_name.replace('.', '/'));
    return clazz;
}
 
开发者ID:Hu6,项目名称:VestaClient,代码行数:36,代码来源:ClassLoader.java

示例6: iterateDirectory

import org.apache.bcel.classfile.ClassParser; //导入方法依赖的package包/类
private static void iterateDirectory(File directory, HashMap<String, HashSet<String>> dependencies,
        HashSet<String> tests, boolean isTestDirectory) throws IOException, ClassNotFoundException {
    if (false == directory.isDirectory()) {
        throw new RuntimeException("passed directory is not directory");
    }
    for (File file : directory.listFiles()) {
        if (file.isDirectory()) {
            iterateDirectory(file, dependencies, tests, isTestDirectory);
        } else if (file.getName().endsWith(".class")) {
            ClassParser parser = new ClassParser(file.getAbsolutePath());
            JavaClass javaClass = parser.parse();

            DependencyVisitor dependencyVisitor = new DependencyVisitor(javaClass);
            dependencyVisitor.addDependencies(dependencies);

            if (isTestDirectory) {
                TestVisitor testVisitor = new TestVisitor(javaClass);
                testVisitor.flagTests(tests);
            }
        }
    }
}
 
开发者ID:burkemw3,项目名称:turbo-athena,代码行数:23,代码来源:TurboAthena.java

示例7: JavaClass

import org.apache.bcel.classfile.ClassParser; //导入方法依赖的package包/类
/**
 * Read class definition from an input stream.
 * 
 * @param filename
 *          the name of the class file (used to determine the class name)
 * @param is
 *          the input stream to read the class file from
 * @throws IOException
 *           if I/O exception occurs while reading from the input stream
 */
public JavaClass(String filename, InputStream is) throws IOException {
  ClassParser parser = new ClassParser(is, filename);
  org.apache.bcel.classfile.JavaClass clazz = parser.parse();
  ConstantPool cp = clazz.getConstantPool();
  name = clazz.getClassName();

  for (Constant c : cp.getConstantPool()) {
    if (c instanceof ConstantClass) {
      ConstantClass cc = (ConstantClass) c;
      ConstantUtf8 cs = (ConstantUtf8) cp.getConstant(cc.getNameIndex());
      String cn = new String(cs.getBytes());
      if (cn.contains("["))
        continue;
      cn = cn.replaceAll("^\\[L", "");
      cn = cn.replaceAll(";", "");
      cn = cn.replaceAll("/", ".");
      getDependencies().add(cn);
    }
  }
}
 
开发者ID:mizdebsk,项目名称:java-deptools,代码行数:31,代码来源:JavaClass.java

示例8: loadClass

import org.apache.bcel.classfile.ClassParser; //导入方法依赖的package包/类
private JavaClass loadClass(InputStream is, String className)
        throws ClassNotFoundException {
    JavaClass clazz = findClass(className);

    if (clazz != null) {
        return clazz;
    }

    try {
        if (is != null) {
            ClassParser parser = new ClassParser(is, className);
            clazz = parser.parse();

            storeClass(clazz);

            return clazz;
        }
    } catch (IOException e) {
        throw new ClassNotFoundException("Exception while looking for class " +
                className + ": " + e.toString());
    }

    throw new ClassNotFoundException("SyntheticRepository could not load " +
            className);
}
 
开发者ID:miuirussia,项目名称:KJBE,代码行数:26,代码来源:SyntheticRepository.java

示例9: main1

import org.apache.bcel.classfile.ClassParser; //导入方法依赖的package包/类
public static void main1(String[] args) throws Throwable {
    ClassParser cp = new ClassParser("/home/kinow/Development/java/apache/tests-for-commons/target/classes/br/eti/kinoshita/commons/bcel/Test.class");
    ClassGen cg = new ClassGen(cp.parse());
    MethodGen mg = new MethodGen(cg.getMethodAt(0), cg.getClassName(), cg.getConstantPool());
    mg.getAnnotationsOnParameter(0);
    System.out.println("OK!");
}
 
开发者ID:kinow,项目名称:commons-sandbox,代码行数:8,代码来源:BCEL_289.java

示例10: main

import org.apache.bcel.classfile.ClassParser; //导入方法依赖的package包/类
public static void main(String[] args) throws Throwable {
    ClassParser cp = new ClassParser("/home/kinow/Development/java/apache/tests-for-commons/target/classes/br/eti/kinoshita/commons/bcel/Test$Inner.class");
    ClassGen cg = new ClassGen(cp.parse());
    MethodGen mg = new MethodGen(cg.getMethodAt(0), cg.getClassName(), cg.getConstantPool());
    // here..args.
    System.out.println(mg.getAnnotationsOnParameter(0));
    System.out.println("OK!");
}
 
开发者ID:kinow,项目名称:commons-sandbox,代码行数:9,代码来源:BCEL_289.java

示例11: lookupClass

import org.apache.bcel.classfile.ClassParser; //导入方法依赖的package包/类
/**
 * Look up a class from the classpath.
 * 
 * @param className name of class to look up
 * @return the JavaClass object for the class
 * @throws ClassNotFoundException if the class couldn't be found
 * @throws ClassFormatException if the classfile format is invalid
 */
public JavaClass lookupClass(String className) throws ClassNotFoundException {
	String resourceName = className.replace('.', '/') + ".class";
	InputStream in = null;
	boolean parsedClass = false;
	
	try {
		in = getInputStreamForResource(resourceName);
		if (in == null)
			throw new ClassNotFoundException("Error while looking for class " + 
					className + ": class not found");
		
		ClassParser classParser = new ClassParser(in, resourceName);
		JavaClass javaClass = classParser.parse();
		parsedClass = true;
		
		return javaClass;
	} catch (IOException e) {
		throw new ClassNotFoundException("IOException while looking for class " +
				className + ": " + e.toString());
	} finally {
		if (in != null && !parsedClass) {
			try {
				in.close();
			} catch (IOException ignore) {
				// Ignore
			}
		}
	}
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:38,代码来源:URLClassPath.java

示例12: debugify

import org.apache.bcel.classfile.ClassParser; //导入方法依赖的package包/类
public static byte[] debugify(String className, byte[] bytes) {
    if (!Debugger.INSTRUMENT)
        return bytes;
    if (Debugger.TRACE_LOADER)
        println("debugifying " + className);

    ClassParser parser = new ClassParser(new ByteArrayInputStream(bytes),
            "<generated>");
    JavaClass javaClass;
    try {
        javaClass = parser.parse();
    } catch (IOException e) {
        System.out.println("IMPOSSIBLE");
        e.printStackTrace();
        return bytes;
    }

    Class clazz;
    if (javaClass == null)
        return null;

    if (Debugger.TRACE_LOADER)
        println(spacesExact() + "DebugifyingClassLoader debugifying: "
                + className);
    if (Debugger.TRACE_LOADER_STACK)
        (new Exception("Just used to get stack trace")).printStackTrace();
    long start = System.currentTimeMillis();
    javaClass = Debugify.debugifyClass(javaClass, className);
    long end = System.currentTimeMillis();
    Debugger.timeDebugifying += (end - start);
    bytes = javaClass.getBytes();

    return bytes;
}
 
开发者ID:OmniscientDebugger,项目名称:LewisOmniscientDebugger,代码行数:35,代码来源:DebugifyingClassLoader.java

示例13: addGeneratedLibraryClassFiles

import org.apache.bcel.classfile.ClassParser; //导入方法依赖的package包/类
/**
 * Add all the generated class files to the Jar file.
 * 
 * @throws IOException
 */
public void addGeneratedLibraryClassFiles() throws IOException {
	Set<String> classFiles = new HashSet<String>();
	File dir = Paths.libraryClassesOutputDirectory();
	File placeholderJar = Paths.placeholderLibraryJarFile();

	// Add the class files to the crafted JAR file.
	FileUtils.listFiles(dir, new String[] { "class" }, true).stream()
			.filter(f -> !relativize(dir, f).equals(Names.AVERROES_LIBRARY_CLASS_BC_SIG + ".class"))
			.forEach(file -> {
				try {
					String className = relativize(dir, file);
					add(dir, file);
					classFiles.add(className);
				} catch (IOException e) {
					e.printStackTrace();
				}
			});
	close();

	// Now add all those class files in the crafted JAR file to the BCEL
	// repository.
	for (String classFile : classFiles) {
		ClassParser parser = new ClassParser(placeholderJar.getPath(), classFile);
		JavaClass cls = parser.parse();
		bcelClasses.add(cls);
	}
}
 
开发者ID:karimhamdanali,项目名称:averroes,代码行数:33,代码来源:JarFile.java

示例14: addAverroesLibraryClassFile

import org.apache.bcel.classfile.ClassParser; //导入方法依赖的package包/类
/**
 * Add the generated AverroesLibraryClass file to the Jar file.
 * 
 * @throws IOException
 * @throws URISyntaxException
 */
public void addAverroesLibraryClassFile() throws IOException, URISyntaxException {
	File dir = Paths.libraryClassesOutputDirectory();
	File placeholderJar = Paths.placeholderLibraryJarFile();
	File averroesLibraryClassJar = Paths.averroesLibraryClassJarFile();

	File file = FileUtils.listFiles(dir, new String[] { "class" }, true).stream()
			.filter(f -> relativize(dir, f).equals(Names.AVERROES_LIBRARY_CLASS_BC_SIG + ".class"))
			.collect(Collectors.toList()).get(0);
	String className = relativize(dir, file);

	// Add the class file to the separately crafted JAR file.
	if (file.isFile()) {
		add(dir, file);
	} else {
		throw new IllegalStateException("cannot find " + Names.AVERROES_LIBRARY_CLASS
				+ System.getProperty("line.separator") + "Invalid path given: " + fileName);
	}
	close();

	// Set BCEL's repository class path.
	SyntheticRepository rep = SyntheticRepository.getInstance(new ClassPath(averroesLibraryClassJar
			+ File.pathSeparator + placeholderJar + File.pathSeparator + Paths.organizedApplicationJarFile()));
	Repository.setRepository(rep);

	// Now add the class files (including ones from placeholder JAR) to the
	// BCEL repository.
	ClassParser parser = new ClassParser(averroesLibraryClassJar.getPath(), className);
	JavaClass cls = parser.parse();
	bcelClasses.add(cls);

	// Now we need to add all the BCEL classes (including ones from previous
	// placeholder JAR to force BCEL to load
	// those crafted files when it looks them up
	bcelClasses.forEach(c -> Repository.getRepository().storeClass(c));

	// Now verify all the generated class files
	verify();
}
 
开发者ID:karimhamdanali,项目名称:averroes,代码行数:45,代码来源:JarFile.java

示例15: extractClass

import org.apache.bcel.classfile.ClassParser; //导入方法依赖的package包/类
private static JavaClass extractClass( File f, Repository repository )
    throws CheckerException
{
    InputStream is = null;
    try
    {
        is = new FileInputStream( f );

        ClassParser parser = new ClassParser( is, f.getName() );
        JavaClass clazz = parser.parse();
        clazz.setRepository( repository );
        return clazz;
    }
    catch ( IOException ex )
    {
        throw new CheckerException( "Cannot read " + f, ex );
    }
    finally
    {
        IOUtil.close( is );
    }
}
 
开发者ID:mojohaus,项目名称:clirr-maven-plugin,代码行数:23,代码来源:AbstractClirrMojo.java


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