use of org.apache.bcel.classfile.ClassParser in project ant by apache.
the class AncestorAnalyzer method determineDependencies.
/**
* Determine the dependencies of the configured root classes.
*
* @param files a vector to be populated with the files which contain
* the dependency classes
* @param classes a vector to be populated with the names of the
* dependency classes.
*/
@Override
protected void determineDependencies(Vector<File> files, Vector<String> classes) {
// we get the root classes and build up a set of
// classes upon which they depend
Set<String> dependencies = new HashSet<>();
Set<File> containers = new HashSet<>();
Set<String> toAnalyze = new HashSet<>();
Set<String> nextAnalyze = new HashSet<>();
for (Enumeration<String> e = getRootClasses(); e.hasMoreElements(); ) {
toAnalyze.add(e.nextElement());
}
int count = 0;
int maxCount = isClosureRequired() ? MAX_LOOPS : 2;
while (!toAnalyze.isEmpty() && count++ < maxCount) {
nextAnalyze.clear();
for (String classname : toAnalyze) {
dependencies.add(classname);
try {
File container = getClassContainer(classname);
if (container == null) {
continue;
}
containers.add(container);
ClassParser parser;
if (container.getName().endsWith(".class")) {
parser = new ClassParser(container.getPath());
} else {
parser = new ClassParser(container.getPath(), classname.replace('.', '/') + ".class");
}
JavaClass javaClass = parser.parse();
for (String interfaceName : javaClass.getInterfaceNames()) {
if (!dependencies.contains(interfaceName)) {
nextAnalyze.add(interfaceName);
}
}
if (javaClass.isClass()) {
String superClass = javaClass.getSuperclassName();
if (!dependencies.contains(superClass)) {
nextAnalyze.add(superClass);
}
}
} catch (IOException ioe) {
// ignore
}
}
Set<String> temp = toAnalyze;
toAnalyze = nextAnalyze;
nextAnalyze = temp;
}
files.clear();
files.addAll(containers);
classes.clear();
classes.addAll(dependencies);
}
use of org.apache.bcel.classfile.ClassParser in project ant by apache.
the class FullAnalyzer method determineDependencies.
/**
* Determine the dependencies of the configured root classes.
*
* @param files a vector to be populated with the files which contain
* the dependency classes
* @param classes a vector to be populated with the names of the
* dependency classes.
*/
@Override
protected void determineDependencies(Vector<File> files, Vector<String> classes) {
// we get the root classes and build up a set of
// classes upon which they depend
Set<String> dependencies = new HashSet<>();
Set<File> containers = new HashSet<>();
Set<String> toAnalyze = new HashSet<>(Collections.list(getRootClasses()));
int count = 0;
int maxCount = isClosureRequired() ? MAX_LOOPS : 2;
while (!toAnalyze.isEmpty() && count++ < maxCount) {
DependencyVisitor dependencyVisitor = new DependencyVisitor();
for (String classname : toAnalyze) {
dependencies.add(classname);
try {
File container = getClassContainer(classname);
if (container == null) {
continue;
}
containers.add(container);
ClassParser parser;
if (container.getName().endsWith(".class")) {
parser = new ClassParser(container.getPath());
} else {
parser = new ClassParser(container.getPath(), classname.replace('.', '/') + ".class");
}
JavaClass javaClass = parser.parse();
DescendingVisitor traverser = new DescendingVisitor(javaClass, dependencyVisitor);
traverser.visit();
} catch (IOException ioe) {
// ignore
}
}
toAnalyze.clear();
// now recover all the dependencies collected and add to the list.
Enumeration<String> depsEnum = dependencyVisitor.getDependencies();
while (depsEnum.hasMoreElements()) {
String className = depsEnum.nextElement();
if (!dependencies.contains(className)) {
toAnalyze.add(className);
}
}
}
files.clear();
files.addAll(containers);
classes.clear();
classes.addAll(dependencies);
}
use of org.apache.bcel.classfile.ClassParser in project candle-decompiler by bradsdavis.
the class CandleDecompiler method decompile.
public void decompile(File clz, File src) throws DecompilerException {
Validate.notNull(clz, "Input file is required, but not provided.");
Validate.notNull(src, "Output file is required, but not provided.");
LOG.info("Processing: " + clz.getAbsolutePath());
Writer writer = null;
try {
writer = new FileWriter(src);
ClassParser cp = new ClassParser(clz.getAbsolutePath());
decompile(cp.parse(), writer);
} catch (Exception e) {
throw new DecompilerException("Exception while decompiling.", e);
} finally {
if (writer != null) {
try {
writer.flush();
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
use of org.apache.bcel.classfile.ClassParser in project OpenGrok by OpenGrok.
the class JavaClassAnalyzer method analyze.
void analyze(Document doc, InputStream in, Writer xrefOut, JFieldBuilder jfbuilder) throws IOException {
List<String> defs = new ArrayList<>();
List<String> refs = new ArrayList<>();
List<String> full = new ArrayList<>();
StringWriter dout, rout, fout;
if (jfbuilder == null) {
dout = new StringWriter();
rout = new StringWriter();
fout = new StringWriter();
} else {
dout = jfbuilder.write(QueryBuilder.DEFS);
rout = jfbuilder.write(QueryBuilder.REFS);
fout = jfbuilder.write(QueryBuilder.FULL);
}
ClassParser classparser = new ClassParser(in, doc.get(QueryBuilder.PATH));
StringWriter xout = new StringWriter();
getContent(xout, fout, classparser.parse(), defs, refs, full);
String xref = xout.toString();
if (xrefOut != null) {
xrefOut.append(xref);
try {
xrefOut.flush();
} catch (IOException ex) {
LOGGER.log(Level.WARNING, "Couldn''t flush. Will retry once added to doc", ex);
}
}
appendValues(dout, defs);
appendValues(rout, refs);
appendValues(fout, full);
if (jfbuilder == null) {
String dstr = dout.toString();
doc.add(new OGKTextField(QueryBuilder.DEFS, dstr, Store.NO));
String rstr = rout.toString();
doc.add(new OGKTextField(QueryBuilder.REFS, rstr, Store.NO));
String fstr = fout.toString();
doc.add(new OGKTextField(QueryBuilder.FULL, fstr, Store.NO));
}
}
use of org.apache.bcel.classfile.ClassParser in project tycho by eclipse.
the class ExecutionEnvironmentTest method testCompilerSourceTargetConfigurationViaManifest.
@Test
public void testCompilerSourceTargetConfigurationViaManifest() throws Exception {
Verifier verifier = getVerifier("TYCHO476", false);
verifier.executeGoal("compile");
// compile only succeeds with source level 1.6 which
// is configured indirectly via Bundle-RequiredExecutionEnvironment: JavaSE-1.6
verifier.verifyErrorFreeLog();
File classFile = new File(verifier.getBasedir(), "target/classes/TestRunnable.class");
Assert.assertTrue(classFile.canRead());
JavaClass javaClass = new ClassParser(classFile.getAbsolutePath()).parse();
// bytecode major level 50 == target 1.6
Assert.assertEquals(50, javaClass.getMajor());
}
Aggregations