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


Java ClassParser类代码示例

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


ClassParser类属于org.apache.bcel.classfile包,在下文中一共展示了ClassParser类的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: addClass

import org.apache.bcel.classfile.ClassParser; //导入依赖的package包/类
public void addClass(final InputStream classStream, final boolean doNotify) throws IOException {
  final JavaClass jclazz = new ClassParser(classStream, null).parse();

  String packageName = jclazz.getPackageName();
  if (packageName == null || packageName.length() == 0) {
    packageName = "<default>";
  }

  PackageItem packageItem = getPackageForName(packageName);
  if (packageItem == null) {
    packageItem = addPackage(packageName);
  }

  packageItem.addClass(new ClassItem(packageItem, jclazz));

  if (doNotify) {
    for (final TreeModelListener l : this.treeModelListeners) {
      l.treeStructureChanged(new TreeModelEvent(this, new TreePath(this)));
    }
  }
}
 
开发者ID:raydac,项目名称:j-j-jvm,代码行数:22,代码来源:Storage.java

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

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

示例5: embeddedNameMismatch

import org.apache.bcel.classfile.ClassParser; //导入依赖的package包/类
private boolean embeddedNameMismatch(ZipFile zipInputFile, ZipEntry ze) throws IOException {
    InputStream zipIn = zipInputFile.getInputStream(ze);
    String name = ze.getName();
    JavaClass j = new ClassParser(zipIn, name).parse();
    zipIn.close();
    String className = j.getClassName();
    String computedFileName = ClassName.toSlashedClassName(className)+".class";
    if (name.charAt(0) == '1') {
        System.out.println(name);
        System.out.println("  " + className);
    }
    if (computedFileName.equals(name))
        return false;
    System.out.println("In " + name + " found " + className);
    return true;
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:17,代码来源:RejarClassesForAnalysis.java

示例6: analyze

import org.apache.bcel.classfile.ClassParser; //导入依赖的package包/类
private <T extends IPersistenceDAO> T analyze(Class<T> klass)
        throws Exception {
    DAOAnalysisSimple analysis = amap.get(klass);
    T instance = null;
    if (analysis == null) {
        analysis = new DAOAnalysisSimple(klass);
        analysis.setDebug(true);
        amap.put(klass, analysis);
        instance = klass.cast(createInstance(analysis));
        JavaClass parse =
            new ClassParser(analysis.getClassFile(), instance.getClass()
                    .getCanonicalName()).parse();
        Repository.addClass(parse);
        // new BCELifier(parse, System.out).start();
        // Verifier.main(new String[] { parse.getClassName() });
    } else {
        instance = klass.cast(createInstance(analysis));
    }
    return instance;
}
 
开发者ID:abassouk,项目名称:autodao,代码行数:21,代码来源:DAOAnalysisTest.java

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

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

示例9: getJavaClassFromJar

import org.apache.bcel.classfile.ClassParser; //导入依赖的package包/类
/**
 * Get JavaClass object list from a jar file.
 * 
 * @param jarPath the jar file path that we get java classes from
 * @return the java classes we get from jarPath
 */
private Vector<JavaClass> getJavaClassFromJar(final File jarPath) {
	Vector<JavaClass> jarClasses = new Vector<JavaClass>();
	if (!jarPath.getPath().endsWith(".jar")) {
		return null;
	}
	try {
		JarFile jarFile = new JarFile(jarPath);
		Enumeration<JarEntry> entries = jarFile.entries();
		while (entries.hasMoreElements()) {
			JarEntry entry = entries.nextElement();
			String name = entry.getName();
			if (name.endsWith(".class")) {
				jarClasses.add(new ClassParser(
						jarFile.getInputStream(entry), 
						name.substring(name.lastIndexOf('/') + 1)).parse());
			}
		}
	} catch (IOException e) {
		System.err.println("IO problem encountered " 
				+ "when trying to get classes from " + jarPath + ".");
		e.printStackTrace();
	}
	return jarClasses;
}
 
开发者ID:freeVM,项目名称:freeVM,代码行数:31,代码来源:StaticDependencyAnalyzer.java

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

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

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

示例13: updateEditPanes

import org.apache.bcel.classfile.ClassParser; //导入依赖的package包/类
private void updateEditPanes() {
    internalFrame = (BrowserInternalFrame) services;
    ClassFile classFile = services.getClassFile();
    MethodInfo[] methods = classFile.getMethods();
    String contents;
    try {
        JavaClass javaClass = new ClassParser(internalFrame.getFileName()).parse();
        ClassGen cg = new ClassGen(javaClass);
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        BCELifier v = new BCELifier(javaClass, out);
        v.start();
        contents = out.toString();
    } catch (Exception e) {
        contents = "Failed to load/bcelify file";
    }
    for (int i = 0; i < methods.length; i++) {
        String methodIndex = Integer.toString(i);
        addEditPane(contents, methodIndex);
    }
}
 
开发者ID:miuirussia,项目名称:KJBE,代码行数:21,代码来源:BCELifyPane.java

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

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


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