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



src/inspectorj/model/javaclass.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/model/javaclass.h"
00028 
00029 using inspectorj::jdwp::ReferenceTypeID;
00030 
00031 namespace inspectorj {
00032 namespace model {
00033 
00037 JavaClass::JavaClass()
00038     : fieldsSet(false), methodsSet(false)
00039 {
00040 }
00041 
00045 JavaClass::JavaClass(const JavaClass& otherClass)
00046 {
00047     refTypeTag = otherClass.refTypeTag;
00048     refTypeId = otherClass.refTypeId;
00049     jniClassSignature = otherClass.jniClassSignature;
00050     classSignature = otherClass.classSignature;
00051     fields = otherClass.fields;
00052     methods = otherClass.methods;
00053     status = otherClass.status;  
00054 }
00055 
00056 JavaClass& JavaClass::operator=(const JavaClass& otherClass)
00057 {
00058     refTypeTag = otherClass.refTypeTag;
00059     refTypeId = otherClass.refTypeId;
00060     jniClassSignature = otherClass.jniClassSignature;
00061     classSignature = otherClass.classSignature;
00062     fields = otherClass.fields;
00063     methods = otherClass.methods;
00064     status = otherClass.status;
00065     return *this;
00066 }
00067 
00071 JavaClass::~JavaClass()
00072 {
00073     qDeleteAll(fields.begin(), fields.end());
00074     qDeleteAll(methods.begin(), methods.end());
00075 }
00076 
00080 int JavaClass::getStatus()
00081 {
00082     return status;
00083 }
00084 
00088 jbyte JavaClass::getRefTypeTag()
00089 {
00090     return refTypeTag;
00091 }
00092 
00096 ReferenceTypeID& JavaClass::getRefTypeId()
00097 {
00098     return refTypeId;
00099 }
00100         
00104 QString JavaClass::getJNIClassSignature()
00105 {
00106     return jniClassSignature;
00107 }
00108 
00112 QString JavaClass::getClassSignature() const
00113 {
00114     return classSignature;
00115 }
00116 
00120 void JavaClass::setRefTypeTag(jbyte refTypeTag)
00121 {
00122     this->refTypeTag = refTypeTag;
00123 }
00124 
00128 void JavaClass::setRefTypeId(ReferenceTypeID refTypeId)
00129 {
00130     this->refTypeId = refTypeId;
00131 }
00132 
00136 void JavaClass::setJNIClassSignature(QString jniSignature)
00137 {
00138     this->jniClassSignature = jniSignature;
00139 }
00140 
00144 void JavaClass::setClassSignature(QString signature)
00145 {
00146     this-> classSignature = signature;
00147 }
00148 
00152 void JavaClass::setStatus(int status)
00153 {
00154     this->status = status;
00155 }
00156 
00161 bool JavaClass::isInitialized()
00162 {
00163     return methodsSet && fieldsSet;
00164 }
00165 
00169 bool JavaClass::isMethodsSet()
00170 {
00171     return methodsSet;
00172 }
00173 
00177 bool JavaClass::isFieldsSet()
00178 {
00179     return fieldsSet;
00180 }
00181 
00186 void JavaClass::addField(JavaField *field)
00187 {
00188     fields << field;
00189 }
00190 
00195 void JavaClass::addMethod(JavaMethod *method)
00196 {
00197     methods << method;
00198 }
00199 
00204 void JavaClass::setFields(JDWPPacket& packet)
00205 {
00206     if( !ClientPacketHandler::handleJDWPError(packet) ) {    
00207         int numFields;
00208         packet >> numFields;
00209         
00210         while (numFields > 0) {
00211             FieldID fieldId;
00212             QString name;
00213             QString jniSignature;
00214             QString signature;
00215             int modBits;
00216             
00217             packet >> fieldId;
00218             packet >> name;
00219             packet >> jniSignature;
00220             packet >> modBits;
00221             
00222             JavaField *field = new JavaField();
00223             field->setFieldId(fieldId);
00224             field->setFieldName(name);
00225             field->setJNIFieldSignature(jniSignature);
00226             field->setFieldSignature(ToolSetUtils::normalizeClassSignature(jniSignature));
00227             field->setModBits(modBits);
00228             
00229             addField(field);
00230             numFields--;                        
00231         }
00232     }
00233     fieldsSet = true;
00234     if(methodsSet) {
00235         emit initialized();
00236     }
00237 }
00238 
00243 void JavaClass::setMethods(JDWPPacket& packet)
00244 {
00245     if( !ClientPacketHandler::handleJDWPError(packet) ) {
00246         int numMethods;
00247         packet >> numMethods;
00248         QString numStr; 
00249         while (numMethods > 0) {
00250             MethodID methodId;
00251             QString methodName;
00252             QString jniSignature;
00253             QString methodSignature;
00254             int modBits;
00255 
00256             packet >> methodId;
00257             packet >> methodName;
00258             packet >> jniSignature;
00259             packet >> modBits;
00260             
00261             JavaMethod *method = new JavaMethod();
00262             method->setMethodId(methodId);
00263             method->setMethodName(methodName);
00264             method->setJNIMethodSignature(jniSignature);
00265             method->setMethodSignature(ToolSetUtils::normalizeMethodSignature(jniSignature, methodName, getClassSignature()));
00266             method->setModBits(modBits);
00267             
00268             addMethod(method);
00269             numMethods--;        
00270         }   
00271     }  
00272     methodsSet = true;
00273     if(fieldsSet) {
00274         emit initialized();
00275     }    
00276 }
00277 
00281 QList<JavaField*>& JavaClass::getFields()
00282 {
00283     return fields;
00284 }
00285 
00289 QList<JavaMethod*>& JavaClass::getMethods()
00290 {
00291     return methods;
00292 }
00293 
00294 bool JavaClass::operator<(const JavaClass& rhs)
00295 {
00296     return this->getClassSignature().toLower() < rhs.getClassSignature().toLower(); 
00297 }
00298 
00299 bool JavaClass::operator==(const ReferenceTypeID& refTypeId)
00300 {
00301     return refTypeId.value == refTypeId.value; 
00302 }
00303 
00304 bool const JavaClass::operator==(const JavaClass& another)
00305 {
00306     return refTypeId.value == another.refTypeId.value
00307             && refTypeTag == another.refTypeTag;   
00308 }
00309 
00310 } // end namespace inspectorj
00311 } // end namespace model

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