Skip to content

Commit

Permalink
class-factory: Add toString() method to types and field (#278)
Browse files Browse the repository at this point in the history
  • Loading branch information
yotamN authored Apr 14, 2023
1 parent c065086 commit 4ac5c89
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/class-factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -1978,6 +1978,22 @@ Object.defineProperties(Field.prototype, {
get () {
return this._p[2];
}
},
toString: {
enumerable: true,
value () {
const inlineString = `Java.Field{holder: ${this.holder}, fieldType: ${this.fieldType}, fieldReturnType: ${this.fieldReturnType}, value: ${this.value}}`;
if (inlineString.length < 200) {
return inlineString;
}
const multilineString = `Java.Field{
\tholder: ${this.holder},
\tfieldType: ${this.fieldType},
\tfieldReturnType: ${this.fieldReturnType},
\tvalue: ${this.value},
}`;
return multilineString.split('\n').map(l => l.length > 200 ? l.slice(0, l.indexOf(' ') + 1) + '...,' : l).join('\n');
},
}
});

Expand Down
30 changes: 30 additions & 0 deletions lib/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ const primitiveTypes = {
},
write (address, value) {
address.writeU8(value);
},
toString () {
return this.name;
}
},
byte: {
Expand All @@ -69,6 +72,9 @@ const primitiveTypes = {
},
write (address, value) {
address.writeS8(value);
},
toString () {
return this.name;
}
},
char: {
Expand Down Expand Up @@ -96,6 +102,9 @@ const primitiveTypes = {
},
write (address, value) {
address.writeU16(value);
},
toString () {
return this.name;
}
},
short: {
Expand All @@ -114,6 +123,9 @@ const primitiveTypes = {
},
write (address, value) {
address.writeS16(value);
},
toString () {
return this.name;
}
},
int: {
Expand All @@ -132,6 +144,9 @@ const primitiveTypes = {
},
write (address, value) {
address.writeS32(value);
},
toString () {
return this.name;
}
},
long: {
Expand All @@ -150,6 +165,9 @@ const primitiveTypes = {
},
write (address, value) {
address.writeS64(value);
},
toString () {
return this.name;
}
},
float: {
Expand All @@ -168,6 +186,9 @@ const primitiveTypes = {
},
write (address, value) {
address.writeFloat(value);
},
toString () {
return this.name;
}
},
double: {
Expand All @@ -186,6 +207,9 @@ const primitiveTypes = {
},
write (address, value) {
address.writeDouble(value);
},
toString () {
return this.name;
}
},
void: {
Expand All @@ -202,6 +226,9 @@ const primitiveTypes = {
},
toJni () {
return NULL;
},
toString () {
return this.name;
}
}
};
Expand Down Expand Up @@ -345,6 +372,9 @@ function getAnyObjectType (typeName, unbox, factory) {
}

return o.$h;
},
toString () {
return this.name;
}
};
}
Expand Down

0 comments on commit 4ac5c89

Please sign in to comment.