use of org.apache.bcel.classfile.JavaClass in project jop by jop-devel.
the class OldAppInfo method iterate.
/**
* Iterate over all classes and run the visitor.
*
* @param v
*/
public void iterate(Visitor v) {
Iterator<? extends OldClassInfo> it = cliMap.values().iterator();
while (it.hasNext()) {
JavaClass clz = it.next().clazz;
new DescendingVisitor(clz, v).visit();
}
}
use of org.apache.bcel.classfile.JavaClass in project jop by jop-devel.
the class OldClassInfo method genClassInfoMap.
/**
* Create ClassInfos and the map from class names to ClassInfo
* @param jc
* @return
*/
Map<String, ? extends OldClassInfo> genClassInfoMap(JavaClass[] jc, OldAppInfo ai) {
Map<String, OldClassInfo> map = new HashMap<String, OldClassInfo>();
for (int i = 0; i < jc.length; ++i) {
OldClassInfo cli = newClassInfo(jc[i], ai);
map.put(cli.clazz.getClassName(), cli);
}
// second iteration over all class infos for additional information setting
CliVisitor v = newCliVisitor(map);
Iterator<? extends OldClassInfo> it = map.values().iterator();
while (it.hasNext()) {
JavaClass clz = it.next().clazz;
new DescendingVisitor(clz, v).visit();
}
return map;
}
use of org.apache.bcel.classfile.JavaClass in project jop by jop-devel.
the class ConstantPoolReferenceFinder method findPoolReferences.
////////////////////////////////////////////////////////////////
// Find/replace references, member names, Pool entries
////////////////////////////////////////////////////////////////
public static Set<Integer> findPoolReferences(ClassInfo classInfo, boolean checkMembers) {
JavaClass javaClass = classInfo.compile();
Set<Integer> ids = findPoolReferences(classInfo, javaClass);
if (checkMembers) {
for (Field field : javaClass.getFields()) {
FieldInfo fieldInfo = classInfo.getFieldInfo(field.getName());
ids.addAll(findPoolReferences(fieldInfo, field));
}
for (Method method : javaClass.getMethods()) {
MethodInfo methodInfo = classInfo.getMethodInfo(method.getName() + method.getSignature());
ids.addAll(findPoolReferences(methodInfo, method));
}
}
return ids;
}
use of org.apache.bcel.classfile.JavaClass in project jop by jop-devel.
the class ClassWriter method write.
public void write(String writeDir) throws IOException {
AppInfo appInfo = AppInfo.getSingleton();
if (logger.isInfoEnabled()) {
logger.info("Start writing classes to '" + writeDir + "' ..");
}
File classDir = new File(writeDir);
if (classDir.exists()) {
if (classDir.isFile()) {
throw new IOException("Output directory '" + classDir + "' is a file.");
}
} else if (!classDir.mkdirs()) {
throw new IOException("Could not create output directory " + classDir);
}
for (ClassInfo cls : appInfo.getClassInfos()) {
if (logger.isDebugEnabled()) {
logger.debug("Writing class: " + cls.getClassName());
}
JavaClass jc = cls.compile();
String filename = classDir + File.separator + cls.getClassName().replace(".", File.separator) + ".class";
File file = new File(filename);
String parent = file.getParent();
if (parent != null) {
File pDir = new File(parent);
//noinspection ResultOfMethodCallIgnored
pDir.mkdirs();
}
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(file));
DataOutputStream stream = new DataOutputStream(out);
jc.dump(stream);
stream.close();
}
if (logger.isInfoEnabled()) {
logger.info(appInfo.getClassInfos().size() + " classes written.");
}
}
use of org.apache.bcel.classfile.JavaClass in project android-classyshark by google.
the class RootBuilder method fillFromJar.
private ClassNode fillFromJar(File file) {
if (JayceReader.isJackAndJillArchive(file)) {
return fillFromJayce(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;
}
Aggregations