use of org.apache.bcel.classfile.JavaClass in project jop by jop-devel.
the class TransitiveHull method start.
/**
* Start traversal using DescendingVisitor pattern.
*/
public void start() {
while (!_queue.empty()) {
JavaClass clazz = _queue.dequeue();
_cp = clazz.getConstantPool();
new org.apache.bcel.classfile.DescendingVisitor(clazz, this).visit();
}
}
use of org.apache.bcel.classfile.JavaClass in project jop by jop-devel.
the class OldAppInfo method load.
/**
* Load all classes that belong to the application.
* @throws ClassNotFoundException
*/
public void load() throws IOException, ClassNotFoundException {
JavaClass[] jcl = new JavaClass[clsArgs.size()];
Repository.setRepository(SyntheticRepository.getInstance(classpath));
Iterator<String> i = clsArgs.iterator();
for (int nr = 0; i.hasNext(); ++nr) {
String clname = i.next();
jcl[nr] = Repository.lookupClass(clname);
if (jcl[nr] == null)
throw new IOException("lookupClass(" + clname + ") failed");
System.out.println(jcl[nr].getClassName());
}
TransitiveHull hull = new TransitiveHull(classpath, jcl);
String[] excl = new String[exclude.size()];
hull.setExcluded(exclude.toArray(excl));
hull.start();
System.out.println(Arrays.asList(hull.getClassNames()));
JavaClass[] jclazz = hull.getClasses();
// jclazz now contains the closure of the application
cliMap = template.genClassInfoMap(jclazz, this);
}
use of org.apache.bcel.classfile.JavaClass in project jop by jop-devel.
the class ConstantPoolReferenceFinder method findReferencedMembers.
/**
* Find all referenced members in a class.
* @param classInfo the class to search.
* @param checkMembers if false, do not check fields and methods. Else check everything.
* @return a set of class names and class member signatures found in the class.
*/
public static Set<String> findReferencedMembers(ClassInfo classInfo, boolean checkMembers) {
// Else we need to go into details..
Set<String> members = new HashSet<String>();
ClassMemberVisitor visitor = new ClassMemberVisitor(members);
JavaClass javaClass = classInfo.compile();
Set<Integer> ids = findPoolReferences(classInfo, javaClass);
List<InvokeSite> invokes = new ArrayList<InvokeSite>();
if (checkMembers) {
for (Field field : javaClass.getFields()) {
FieldInfo fieldInfo = classInfo.getFieldInfo(field.getName());
// add members found in the field
visitor.visitField(fieldInfo);
// there are no invokesites in a field, only add found ids
ids.addAll(findPoolReferences(fieldInfo, field));
}
for (Method method : javaClass.getMethods()) {
MethodInfo methodInfo = classInfo.getMethodInfo(method.getName() + method.getSignature());
// add members found in the method
visitor.visitMethod(methodInfo);
// add all ids for checking, add all invoke sites
ids.addAll(findPoolReferences(methodInfo, method));
}
}
// fill the members list with all found constantpool references
visitor.visitClass(classInfo);
visitPoolReferences(classInfo, visitor, ids);
return members;
}
use of org.apache.bcel.classfile.JavaClass in project candle-decompiler by bradsdavis.
the class CandleDecompiler method decompile.
public void decompile(String clazzName, Writer writer) throws DecompilerException {
Validate.isTrue(org.apache.commons.lang.StringUtils.isNotBlank(clazzName), "Classname is required field, but was not provided.");
Validate.notNull(writer, "Writer is required, but not provided.");
JavaClass clz;
try {
clz = Repository.lookupClass(clazzName);
decompile(clz, writer);
} catch (ClassNotFoundException e) {
throw new DecompilerException("Exception while decompiling.", e);
}
}
use of org.apache.bcel.classfile.JavaClass in project kanonizo by kanonizo.
the class Framework method loadClassFromFile.
private Class<?> loadClassFromFile(File file) {
Class<?> cl = null;
try {
ClassParser parser = new ClassParser(file.getAbsolutePath());
JavaClass jcl = parser.parse();
List<String> forbiddenClasses = Arrays.asList(FORBIDDEN_CLASSNAMES.split(","));
forbiddenClasses = forbiddenClasses.stream().filter(name -> !name.isEmpty()).collect(Collectors.toList());
if (forbiddenClasses.size() > 0 && forbiddenClasses.stream().anyMatch(f -> jcl.getClassName().substring(jcl.getPackageName().length() + 1).startsWith(f))) {
logger.info("Ignoring class " + jcl.getClassName() + " because it is forbidden");
return null;
} else {
cl = Class.forName(jcl.getClassName(), true, Thread.currentThread().getContextClassLoader());
}
} catch (ClassNotFoundException | NoClassDefFoundError e) {
logger.error(e);
} catch (IOException e) {
logger.error(e);
} catch (ExceptionInInitializerError e) {
logger.error(e);
}
return cl;
}
Aggregations