Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-24009] Properly generate properties and methods from protocols #121

Merged
merged 6 commits into from
Mar 3, 2017
27 changes: 18 additions & 9 deletions metabase/ios/lib/generate/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,25 @@ function merge (src, dest) {
}
}

function superClassImplementsProxy (json, cls, proto) {
var prev;
while (cls && cls.superclass) {
prev = cls;
cls = cls.superclass;
if (cls) {
cls = json.classes[cls];
/**
* Checks if a parent class in the inheritance path already implemented
* the given protocol.
*
* @param {Object} json Native code metabase
* @param {Object} cls Class to traverse upwards from
* @param {String} proto The protocoll to look for in parent classes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo protocoll

* @return {bool} True if protocol already implemented in a parent class, false otherwise.
*/
function isProtocolImplementedBySuperClass (json, cls, proto) {
var currentClass = cls.superclass;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was checked against null before. Are there no cases where cls could be null?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No because in the previous implementation cls was overwritten by cls.superclass and that could be undefined once NSObject was reached. Nevertheless i'll make an additional check just to be sure ;)

while (currentClass) {
if (currentClass.protocols && currentClass.protocols.indexOf(proto) !== -1) {
return true;
}
currentClass = json.classes[currentClass.superclass];
}
return (prev && prev.protocols && prev.protocols.indexOf(proto) !== -1);

return false;
}

function generateBuiltins (json, callback) {
Expand Down Expand Up @@ -155,7 +164,7 @@ function generateFromJSON (name, dir, json, state, callback, includes) {
// add protocols
if (cls.protocols && cls.protocols.length) {
cls.protocols.forEach(function (p) {
if (superClassImplementsProxy(json, cls, p)) {
if (isProtocolImplementedBySuperClass(json, cls, p)) {
return;
}
var protocol = json.protocols[p];
Expand Down