public void visit(Class clazz) { Document document = null; try { document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); } catch (Exception e) { e.printStackTrace(); } String className = clazz.getName(); Element eClazz = document.createElement("class"); eClazz.setAttribute("name", className); document.appendChild(eClazz); if (classes.contains(className)) { JavaClass jc = repo.findClass(className); ClassGen cg = new ClassGen(jc); if (className.indexOf("$") == -1) { org.apache.bcel.classfile.Method[] ms = jc.getMethods(); log.debug("Cleaning class: " + className); for (int i = 0; i < ms.length; i++) { Method m = new Method(className, ms[i].getName(), ms[i].getSignature()); if (!usedMethods.contains(m)) {   cg.removeMethod(ms[i]); if (true) { Element eMethod = document.createElement("method"); eMethod.setAttribute("name", ms[i].getName()); Element eArguments = document.createElement("arguments"); Type[] args = Type.getArgumentTypes(ms[i].getSignature()); for (int j = 0; j < args.length; j++) { Element eArg; if (args[j] instanceof BasicType) { eArg = document.createElement("primitiveType"); } else { eArg = document.createElement("classType"); } eArg.setAttribute("name", args[j].toString()); eArguments.appendChild(eArg); } Element eReturn = document.createElement("return"); Type type = Type.getReturnType(ms[i].getSignature()); if (type.getType() == Constants.T_VOID) { eReturn.appendChild(document.createElement("void")); } else { Element temp = null; if (type instanceof BasicType) { temp = document.createElement("primitiveType"); } else { temp = document.createElement("classType"); } temp.setAttribute("name", type.toString()); eReturn.appendChild(temp); } eMethod.appendChild(eArguments); eMethod.appendChild(eReturn); eClazz.appendChild(eMethod); } }  } org.apache.bcel.classfile.Field[] fs = jc.getFields(); for (int i = 0; i < fs.length; i++) { if (!clazz.containsField(fs[i].getName(), fs[i].getSignature())) { log.debug("Removing field: " + fs[i]); cg.removeField(fs[i]); } } cg.update(); } File file = new File(directory, className.replace('.', File.separatorChar).concat(".class")); log.debug("Dumping class: " + className + " to file: " + file); try { cg.getJavaClass().dump(file); } catch (IOException e) { log.error("Error on dumping class: " + className + " to file: " + file, e); } try { javax.xml.transform.Transformer trans = TransformerFactory.newInstance().newTransformer(); trans.setOutputProperty(OutputKeys.INDENT, "yes"); trans.transform(new DOMSource(document), new StreamResult(new File("report", className + ".xml"))); } catch (Exception e) { e.printStackTrace(); } } log.debug("\n\n"); }
public void visit(String className) throws Exception { Document document = null; document = DocumentBuilderFactory.newInstance().newDocumentBuilder() .newDocument(); Element eClazz = document.createElement("class"); eClazz.setAttribute("name", className); document.appendChild(eClazz); if (classes.contains(className)) { JavaClass jc = repo.findClass(className); ClassGen cg = new ClassGen(jc); if (className.indexOf("$") == -1) { org.apache.bcel.classfile.Method[] ms = jc.getMethods(); log.debug("Cleaning class: " + className); for (int i = 0; i < ms.length; i++) { Method m = new Method(className, ms[i].getName(), ms[i] .getSignature()); if (!usedMethods.contains(m)) { cg.removeMethod(ms[i]); if (true) { eClazz.appendChild(this.reportMethod(document, ms[i])); } } else { cg.removeAttribute(ms[i].getLineNumberTable()); cg.removeAttribute(ms[i].getLocalVariableTable()); } } } else {   } Attribute[] attrs = cg.getAttributes(); for (int i = 0; i < attrs.length; i++) { if (attrs[i] instanceof SourceFile) {   } else {  } } cg.update(); this.dump(cg.getJavaClass()); if (eClazz.hasChildNodes()) { File directory = configurator.getReportDirectory(); directory.mkdirs(); File report = new File(directory, className + ".xml"); javax.xml.transform.Transformer trans = TransformerFactory .newInstance().newTransformer(); trans.setOutputProperty(OutputKeys.INDENT, "yes"); trans.transform(new DOMSource(document), new StreamResult( report)); } } log.debug("\n\n"); }
	public void visit(Class clazz) {		Document document = null;		try {			document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();		} catch (Exception e) {			e.printStackTrace();		}		String className = clazz.getName();		Element eClazz = document.createElement("class");		eClazz.setAttribute("name", className);		document.appendChild(eClazz);		if (classes.contains(className)) {			JavaClass jc = repo.findClass(className);			ClassGen cg = new ClassGen(jc);			if (className.indexOf("$") == -1) {				org.apache.bcel.classfile.Method[] ms = jc.getMethods();				log.debug("Cleaning class: " + className);				for (int i = 0; i < ms.length; i++) {					Method m = new Method(className, ms[i].getName(), ms[i].getSignature());					if (!usedMethods.contains(m)) {						//System.out.println("REMOVENDO: " + className + "__"						// +ms[i]);						cg.removeMethod(ms[i]);						if (true) {							Element eMethod = document.createElement("method");							eMethod.setAttribute("name", ms[i].getName());							Element eArguments = document.createElement("arguments");							Type[] args = Type.getArgumentTypes(ms[i].getSignature());							for (int j = 0; j < args.length; j++) {								Element eArg;								if (args[j] instanceof BasicType) {									eArg = document.createElement("primitiveType");								} else {									eArg = document.createElement("classType");								}								eArg.setAttribute("name", args[j].toString());								eArguments.appendChild(eArg);							}							Element eReturn = document.createElement("return");							Type type = Type.getReturnType(ms[i].getSignature());							if (type.getType() == Constants.T_VOID) {								eReturn.appendChild(document.createElement("void"));							} else {								Element temp = null;								if (type instanceof BasicType) {									temp = document.createElement("primitiveType");								} else {									temp = document.createElement("classType");								}								temp.setAttribute("name", type.toString());								eReturn.appendChild(temp);							}							eMethod.appendChild(eArguments);							eMethod.appendChild(eReturn);							eClazz.appendChild(eMethod);						}					}					/*					 * try { if (!clazz.containsMethod(ms[i].getName(),					 * ms[i].getSignature()) && mi.remove(new					 * net.java.dev.jminimizer.beans.Method(clazz.getName(),					 * ms[i].getName(), ms[i].getSignature()))) {					 * log.debug("Removing method: " + ms[i]);					 * System.out.println("Removendo: " + ms[i]);					 * cg.removeMethod(ms[i]); } } catch (ClassNotFoundException					 * e1) { // TODO Auto-generated catch block					 * e1.printStackTrace(); }					 */				}				org.apache.bcel.classfile.Field[] fs = jc.getFields();				for (int i = 0; i < fs.length; i++) {					if (!clazz.containsField(fs[i].getName(), fs[i].getSignature())) {						log.debug("Removing field: " + fs[i]);						cg.removeField(fs[i]);					}				}				cg.update();			}			File file = new File(directory, className.replace('.', File.separatorChar).concat(".class"));			log.debug("Dumping class: " + className + " to file: " + file);			try {				cg.getJavaClass().dump(file);			} catch (IOException e) {				log.error("Error on dumping class: " + className + " to file: " + file, e);			}			try {				javax.xml.transform.Transformer trans = TransformerFactory.newInstance().newTransformer();				trans.setOutputProperty(OutputKeys.INDENT, "yes");				trans.transform(new DOMSource(document), new StreamResult(new File("report", className + ".xml")));			} catch (Exception e) {				e.printStackTrace();			}		}		log.debug("\n\n");	}