ij-16.png   inspectorJ -- JavaTM Profiler
sf project site browse source checkout source
SourceForge.net Logo



src/inspectorj/toolset/toolsetutils.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   inspectorJ - java profiler                                            *
00003  *   Copyright (C) 2007 by James May
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 
00027 #include "inspectorj/toolset/toolsetutils.h"
00028 #include <iostream>
00029 
00030 namespace inspectorj {
00031 namespace toolset {
00032 
00033 // Initialize static members
00034 QRegExp ToolSetUtils::JNI_CLASS_START = QRegExp("^\\[*L");
00035 QRegExp ToolSetUtils::JNI_REFERENCE_START = QRegExp("^\\[*L{0,1}");
00036 QRegExp ToolSetUtils::JNI_CLASS_END = QRegExp(";$");
00037 QString ToolSetUtils::SINGLE_STAR = QString("*");
00038 QString ToolSetUtils::DOUBLE_STAR = QString("**");
00039 
00040 QString ToolSetUtils::DOLLAR_SIGN = QString(";$");
00041 QString ToolSetUtils::JNI_PACKAGE_SEPARATOR = QString("/");
00042 QString ToolSetUtils::DOT = QString(".");
00043 QString ToolSetUtils::WILDCARD = QString("[^/]*");
00044 QString ToolSetUtils::GREEDY_WILDCARD = QString(".*");
00045 QString ToolSetUtils::GREEDY_WILDCARD_TEMP = QString("GREEDY_WILDCARD_TEMP");
00046 QString ToolSetUtils::BRACKETS = QString("[]");
00047 
00048 QChar ToolSetUtils::ARRAY_DESIGNATOR = QChar(0x005B);
00049 
00053 ToolSetUtils::ToolSetUtils()
00054 {
00055 
00056 }
00057 
00061 ToolSetUtils::~ToolSetUtils()
00062 {
00063 }
00064 
00070 QString& ToolSetUtils::normalizeClassSignature(QString &signature)
00071 {
00072     int arrayDepth = signature.count(ARRAY_DESIGNATOR);
00073     
00074     if (signature.contains(JNI_CLASS_START)) {
00075         signature
00076             .remove(JNI_CLASS_START)
00077             .remove(JNI_CLASS_END)
00078             .replace(JNI_PACKAGE_SEPARATOR, DOT);
00079     } else {
00080         signature.remove(JNI_REFERENCE_START);
00081         signature.replace("B", "byte");
00082         signature.replace("C", "char");
00083         signature.replace("D", "double");
00084         signature.replace("F", "float");
00085         signature.replace("I", "int");
00086         signature.replace("J", "long");
00087         signature.replace("S", "short");
00088         signature.replace("Z", "boolean");
00089     }
00090     
00091     while (arrayDepth > 0) {
00092         signature.append(BRACKETS);
00093         arrayDepth--;
00094     }
00095 
00096     return signature;
00097 }
00098 
00110 QString& ToolSetUtils::normalizeMethodSignature(QString &signature, QString &methodName, QString className)
00111 {
00112     QRegExp arrayType = QRegExp("^\\[+");
00113     QString tmp;
00114     QStringList methodParts = signature.split(")");
00115     if (methodParts.size() == 2) {
00116         QString params = methodParts[0];
00117         QString returnVal = methodParts[1];
00118         
00119         if (returnVal == "V") {
00120             returnVal = "void";
00121         } else {
00122             normalizeClassSignature(returnVal);
00123         }
00124                                         
00125         if (methodName == "<init>") {
00126             if  (!className.isEmpty()) {
00127                 tmp.append(className).append("(");
00128             } else {
00129                 tmp.append(methodName).append("(");
00130             }
00131         } else if (methodName == "<clinit>") {
00132             tmp.append("synthetic ").append(methodName).append("(");
00133         } else {
00134             tmp.append(returnVal).append(" ");            
00135             tmp.append(methodName).append("(");            
00136         }
00137             
00138         params.remove(0, 1);
00139         
00140         bool moreParams = false;
00141         QString param;
00142         while (params.size() > 0) {
00143             int paramsLength = params.length();
00144             int arrayDepth = paramsLength - params.remove(arrayType).length();
00145             
00146             if (moreParams) {
00147                 tmp.append(", ");
00148             }                
00149             QChar ch = params[0];
00150             if (ch == 'L') {
00151                 int classSigEnd = params.indexOf(';');
00152                 param = params.left(classSigEnd + 1);              
00153                 params.remove(0, param.length());
00154             } else {
00155                 param = params.left(1);
00156                 params.remove(0, param.length());
00157             }
00158                 normalizeClassSignature(param);
00159                 tmp.append(param);   
00160                 
00161                 while (arrayDepth > 0) {
00162                     tmp.append(BRACKETS);
00163                     arrayDepth--;
00164                 }                         
00165                 moreParams = true;
00166         }
00167 
00168         tmp.append(")");
00169         signature.clear();                            
00170         signature.append(tmp);
00171         
00172         return signature;
00173     }
00174 }
00175 
00181 QString& ToolSetUtils::createJNIClassSignature(QString &signature)
00182 {
00183     return signature
00184         .prepend("L")
00185         .replace(DOT, JNI_PACKAGE_SEPARATOR)
00186         .append(";");
00187 }
00188 
00201 void ToolSetUtils::createClassFilter(QRegExp &regexp, QString filterString) {
00202     filterString
00203         .replace(DOT, JNI_PACKAGE_SEPARATOR)
00204         .replace(DOUBLE_STAR, GREEDY_WILDCARD_TEMP)
00205         .replace(SINGLE_STAR, WILDCARD)
00206         .replace(GREEDY_WILDCARD_TEMP, GREEDY_WILDCARD)
00207         .append(DOLLAR_SIGN);
00208     regexp.setPattern(filterString);
00209 }
00210         
00211 } // end namespace toolset
00212 } // end namespace inspectorj

Generated on Sun Aug 19 17:07:54 2007 for inspectorJ by  doxygen 1.5.1