List of usage examples for org.aspectj.apache.bcel.classfile JavaClass getPackageName
public String getPackageName()
From source file:br.jabuti.lookup.java.bytecode.ClassClosure.java
License:Open Source License
/** * Method responsable to parse the code of a given class name and found a list * of all classes related with this one. In this list will be included neither system class * if the variable <code> noSys </code> is true nor the ones spaecified in <code>toAvoid</code>. * * @param className The name of the starting class. From it all the * referenced classes are found and included in the structure. The * class should be found in the classpath * * @param noSys This param tells whether "system" classes should be part * of the main program structure or just as peripheral classes. If * <code>true</code>, classes with the following prefix are kept out * of the main structure:<BR>//from w w w .ja v a2 s .c o m * <UL> * <LI> java. * <LI> javax.lang * <LI> org.omg * </UL> <BR> * In addition, any referenced class for wich the code (a .class) file * can not be found is considered out of the main structure. * * @param toAvoid This is a string that indicates other classes that should be * avoided in the main structure of the program. For example, if the * program uses library packages <code>org.dummy</code> and * <code>br.din.foo</code> the use of "org.dummy br.din.foo" as the third * argument will keep the classes in these packages out of the program * structure, even if their class files can be found in the classpath */ public String[] getClosure(String className, boolean noSys, String toAvoid) { String s = className; JavaClass classFile = null; s = findFile(s); if (s == null) { return new String[0]; } try { classFile = new ClassParser(s).parse(); String pck = RClass.getPackName(className); if (!pck.equals(classFile.getPackageName())) { Debug.D(pck + " " + classFile.getPackageName() + " " + pck.equals(classFile.getPackageName())); return new String[0]; } } catch (IOException e) { return new String[0]; } return getJCClosure(classFile, noSys, toAvoid); }
From source file:br.jabuti.lookup.java.bytecode.ClassClosure.java
License:Open Source License
public String[] getJCClosure(JavaClass classFile, boolean noSys, String toAvoid) { Hashtable interestedClasses = new Hashtable(); Vector classesToProcess = new Vector(); Vector classesToAvoid = new Vector(); if (!doMatch(classFile.getClassName(), noSys, toAvoid)) { interestedClasses.put(classFile.getClassName(), classFile); classesToProcess.add(classFile); } else {/*from w ww. j ava2s .co m*/ classesToAvoid.add(classFile.getClassName()); } for (int i = 0; i < classesToProcess.size(); i++) { classFile = (JavaClass) classesToProcess.elementAt(i); String[] cl = accessedClasses(classFile); for (int j = 0; j < cl.length; j++) { try { if (!doMatch(cl[j], noSys, toAvoid)) { // May throw IOException String h = findFile(cl[j]); if (h != null) { classFile = new ClassParser(h).parse(); String pck = RClass.getPackName(cl[j]); if (pck.equals(classFile.getPackageName()) && (!interestedClasses.containsKey(classFile.getClassName()))) { classesToProcess.add(classFile); interestedClasses.put(classFile.getClassName(), classFile); } } } } catch (FileNotFoundException e) {// System.out.println("Skipped " + s1); } catch (IOException e) {// System.out.println("Skipped " + s1); } if (!classesToAvoid.contains(cl[j])) { classesToAvoid.add(cl[j]); } } } return (String[]) classesToAvoid.toArray(new String[0]); }