/* * Copyright 2008 Wishnu Prasetya. * * This file is part of T2. * T2 is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License (GPL) as published by the * Free Software Foundation; either version 3 of the License, or any * later version. * * T2 is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. * * A copy of the GNU General Public License can be found in T2 distribution. * If it is missing, see http://www.gnu.org/licenses. */ package Sequenic.T2ext.util; import java.io.File; import java.net.URI; import java.net.URISyntaxException; /* import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; import t2ext.xml.XMLBuilder; */ import org.apache.bcel.classfile.Method; import org.apache.bcel.generic.Type; /** * @author Maaike Gerritsen * @author Wishnu Prasetya */ public class util { /** * Returns the path to the location of a class. */ public static String getClassLocation(Class C) { URI uri = null; try { uri = C.getResource("").toURI() ; } catch (Exception e) { throw new Error(e) ; } return uri.getPath() ; } /* public static String newFileName(String byteClass){ byteClass = byteClass.replace(".", ":"); String[] split = byteClass.split(":"); String result = ""; for (int i = 0; i < split.length-1; i++) { String s = split[i]; result += s+"/"; } String cleanMethodsDir = new File(result).getAbsolutePath().toString(); result = cleanMethodsDir+"/"+split[split.length-1]+".class"; return result; } */ // Never used? /* public static String directoryName(String byteClass){ byteClass = byteClass.replace(".", ":"); String[] split = byteClass.split(":"); String result = ""; if(split.length>1){ for (int i = 0; i < split.length-1; i++) { String s = split[i]; result += s+"/"; } return result; } return ""; } */ public static String completeMethodName(String methodname, Type[] arguments){ String name = "" + methodname ; // name = name +"_"+arguments.length; for (int i = 0; i < arguments.length; i++) { Type arg = arguments[i]; String argName = arg.toString(); //argName = replaceIllegalChars(argName); name = name + "_" + argName; } return name; } public static String completeMethodName(java.lang.reflect.Method m) { //String packageName = m.getDeclaringClass().getPackage().getName() ; String className = m.getDeclaringClass().getName() ; Class[] argtypes = m.getParameterTypes() ; return completeMethodName(className + "#" + m.getName(), Type.getTypes(argtypes)) ; } /* public static String officialMethodName(String className, String methodName, Type[] arguments){ String complete = className+"."+methodName+"("; boolean argsPresent = false; for (int i = 0; i < arguments.length; i++) { Type arg = arguments[i]; String argName = arg.toString(); argName = argName.replace("$", "."); complete = complete + argName + ", "; argsPresent = true; } if(argsPresent) complete = complete.substring(0, complete.length()-2); complete = complete + ")"; return complete; } public static String officialMethodName(String className, String methodName, java.lang.reflect.Type[] arguments){ String complete = className+"."+methodName+"("; boolean argsPresent = false; for (int i = 0; i < arguments.length; i++) { java.lang.reflect.Type arg = arguments[i]; String argName = arg.toString(); if(argName.startsWith("class ")) argName = argName.replace("class ", ""); if(argName.startsWith("interface ")) argName = argName.replace("interface ", ""); argName = argName.replace("$", "."); complete = complete + argName + ", "; argsPresent = true; } if(argsPresent) complete = complete.substring(0, complete.length()-2); complete = complete + ")"; return complete; } public static String officialMethodName(Class C, Method m) { return officialMethodName(C.getName(), m.getName(), m.getArgumentTypes()) ; } public static String replaceIllegalChars(String name){ name = name.replace("$", ""); name = name.replace(".", ""); name = name.replace("[]", "Array"); return name; } */ /* public static boolean foundPath(Integer id, String originalName) { XMLBuilder xmlBuilder = new XMLBuilder(); Document doc = xmlBuilder.readXMLFile("paths.xml"); String condition = "//method[@official='"+originalName+"']/path[@id='"+id+"']"; NodeList list = xmlBuilder.getNodesFromXML(doc, condition); Element path = (Element) list.item(0); boolean found = new Boolean(path.getAttribute("found")); return found; } */ }