Permalink
Browse files

Merge pull request #318 from Thrameos/method_patch

Work of jp_method bug
  • Loading branch information...
marscher committed Nov 4, 2018
2 parents 7802a53 + 09ec730 commit 580285d7007ee756558040b45f3e14c2d1c70511
@@ -90,12 +90,13 @@ def __setattr__(self, attr, value):
else:
raise AttributeError("%s does not have field %s"%(self.__name__, attr), self)
def _isIterable(obj):
if isinstance(obj, collections.Sequence):
return True
if hasattr(obj,'__len__') and hasattr(obj,'__iter__'):
return True
return False
def _isIterable(obj):
if isinstance(obj, collections.Sequence):
return True
if hasattr(obj,'__len__') and hasattr(obj,'__iter__'):
return True
return False
def _jarrayInit(self, *args):
if len(args) == 2 and args[0] == _jclass._SPECIAL_CONSTRUCTOR_KEY:
@@ -106,7 +107,7 @@ def _jarrayInit(self, *args):
.format(len(args) + 1))
else:
values = None
if _isIterable(args[0]):
if _isIterable(args[0]):
sz = len(args[0])
values = args[0]
else:
@@ -39,17 +39,8 @@ public :
JPField* getInstanceField(const string& name);
JPField* getStaticField(const string& name);
JPMethod* getMethod(const string& name);
vector<JPMethod*> getMethods() const
{
vector<JPMethod*> res;
res.reserve(m_Methods.size());
for (map<string, JPMethod*>::const_iterator cur = m_Methods.begin(); cur != m_Methods.end(); cur++)
{
res.push_back(cur->second);
}
return res;
}
JPMethod* getMethod(const string& name);
vector<JPMethod*> getMethods();
jclass getClass()
{
@@ -96,12 +87,12 @@ private :
private :
bool m_IsInterface;
JPClass* m_SuperClass;
vector<JPClass*> m_SuperInterfaces;
JPClass* m_SuperClass;
vector<JPClass*> m_SuperInterfaces;
map<string, JPField*> m_StaticFields;
map<string, JPField*> m_InstanceFields;
map<string, JPMethod*> m_Methods;
JPMethod* m_Constructors;
JPMethod* m_Constructors;
};
@@ -148,6 +148,8 @@ public :
virtual void printReferenceInfo(HostRef* obj) = 0;
virtual bool isByteBuffer(HostRef*) = 0;
virtual void getByteBufferPtr(HostRef*, char**, long&) = 0;
virtual const char* getTypeName(HostRef*) = 0;
};
#endif // _JPHOSTENV_H_
@@ -45,6 +45,7 @@ namespace JPJni
JPTypeName getClassName(jobject obj);
jclass getClass(jobject obj);
jstring toString(jobject obj);
string toStringC(jobject obj);
/**
* java.lang.Class.isInterface()
@@ -17,25 +17,35 @@
#ifndef _JPMETHOD_H_
#define _JPMETHOD_H_
#include <list>
class JPObject;
class JPMethod
{
public :
typedef std::list<JPMethodOverload*> OverloadList;
/**
* Create a new method based on class and a name;
*/
JPMethod(jclass clazz, const string& name, bool isConstructor);
virtual ~JPMethod();
private:
JPMethod(const JPMethod& method);
JPMethod& operator=(const JPMethod& method);
public :
const string& getName() const;
string getClassName() const;
void addOverload(JPClass* clazz, jobject mth);
void addOverloads(JPMethod* o);
bool hasStatic();
bool hasStatic()
{
return m_hasStatic;
}
size_t getCount()
{
return m_Overloads.size();
@@ -52,23 +62,18 @@ public :
string describe(string prefix);
string matchReport(vector<HostRef*>&);
void ensureOverloadOrderCache();
private :
JPMethodOverload* findOverload(vector<HostRef*>& arg, bool needStatic);
JPMethodOverload* findOverload(vector<HostRef*>& arg, bool searchStatic, bool searchInstance);
void ensureOverloadCache();
void dumpOverloads();
jclass m_Class;
string m_Name;
map<string, JPMethodOverload> m_Overloads;
struct OverloadData {
OverloadData(JPMethodOverload* o) : m_Overload(o) {}
JPMethodOverload* m_Overload;
std::vector<JPMethodOverload*> m_MoreSpecificOverloads;
};
std::vector<OverloadData> m_OverloadOrderCache;
OverloadList m_Overloads;
bool m_IsConstructor;
bool m_hasStatic;
bool m_Cached;
};
@@ -17,12 +17,15 @@
#ifndef _JPMETHODOVERLOAD_H_
#define _JPMETHODOVERLOAD_H_
#include <list>
class JPObject;
class JPMethod;
class JPMethodOverload
{
public :
JPMethodOverload();
JPMethodOverload(const JPMethodOverload& o);
friend class JPMethod;
typedef std::list<JPMethodOverload*> OverloadList;
JPMethodOverload(JPClass* claz, jobject mth);
virtual ~JPMethodOverload();
@@ -35,9 +38,11 @@ public :
JPObject* invokeConstructor(jclass, vector<HostRef*>& arg);
public :
string getSignature();
private:
JPMethodOverload(const JPMethodOverload& o);
JPMethodOverload& operator=(const JPMethodOverload&);
public :
bool isStatic() const
{
return m_IsStatic;
@@ -63,13 +68,26 @@ public :
return (unsigned char)m_Arguments.size();
}
string getArgumentString();
string toString();
void packArgs(vector<jvalue>& v, vector<HostRef*>& arg, size_t skip);
bool isSameOverload(JPMethodOverload& o);
string matchReport(vector<HostRef*>& args);
bool isMoreSpecificThan(JPMethodOverload& other) const;
bool checkMoreSpecificThan(JPMethodOverload* other) const
{
for (OverloadList::const_iterator it = m_MoreSpecificOverloads.begin();
it != m_MoreSpecificOverloads.end();
++it)
{
if (other == *it)
return true;
}
return false;
}
private:
void packArgs(vector<jvalue>& v, vector<HostRef*>& arg, size_t skip);
void ensureTypeCache() const;
private :
JPClass* m_Class;
@@ -83,6 +101,8 @@ private :
bool m_IsConstructor;
mutable vector<JPType*> m_ArgumentsTypeCache;
mutable JPType* m_ReturnTypeCache;
OverloadList m_MoreSpecificOverloads;
bool m_Ordered;
};
#endif // _JPMETHODOVERLOAD_H_
@@ -23,6 +23,11 @@ public :
JPObject(JPClass* clazz, jobject inst);
JPObject(JPTypeName& clazz, jobject inst);
virtual ~JPObject();
private:
JPObject(const JPObject&);
JPObject& operator=(const JPObject&);
public:
JPClass* getClass()
@@ -201,10 +201,20 @@ JPMethod* JPClass::getMethod(const string& name)
{
return NULL;
}
return it->second;
}
vector<JPMethod*> JPClass::getMethods()
{
vector<JPMethod*> res;
res.reserve(m_Methods.size());
for (map<string, JPMethod*>::const_iterator cur = m_Methods.begin(); cur != m_Methods.end(); cur++)
{
res.push_back(cur->second);
}
return res;
}
HostRef* JPClass::getStaticAttribute(const string& name)
{
// static fields
@@ -209,7 +209,6 @@ string asciiFromJava(jstring str)
}
frame.ReleaseStringUTFChars(str, cstr);
return res;
}
@@ -258,6 +257,13 @@ jstring toString(jobject o)
return str;
}
string toStringC(jobject o)
{
JPJavaFrame frame;
jstring jname = (jstring)frame.CallObjectMethod(o, toStringID);
return asciiFromJava(jname);
}
static string convertToSimpleName(jclass c)
{
JPJavaFrame frame;
Oops, something went wrong.

0 comments on commit 580285d

Please sign in to comment.