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

The static binding generator should clean redundant files #467

Closed
atanasovg opened this issue May 31, 2016 · 3 comments
Closed

The static binding generator should clean redundant files #467

atanasovg opened this issue May 31, 2016 · 3 comments

Comments

@atanasovg
Copy link
Contributor

When changing extend implementation in a single file iteratively, like:

Step 1

var listener = new com.google.android.youtube.player.YouTubePlayer.OnInitializedListener({
...
});

tns build android

Step 2

// add some code here, to change the line number of the extend call
var dummy = 1;
var listener = new com.google.android.youtube.player.YouTubePlayer.OnInitializedListener({
...
});

tns build android

Result

This produces two *.java files and obviously the older one is redundant.

We need to figure a cleaning algorithm that prevents this erroneous behavior.

@atanasovg atanasovg added this to the 2.1 milestone May 31, 2016
@blagoev
Copy link
Contributor

blagoev commented May 31, 2016

if the java file contains the line number of the extend it should be easy to detect this.

One other problem is when there is a new override of the same extend on the same line.
Obviously the old generated file should be removed then.

In the runtime-binding-generator case this is handled by the app version code. If this is changed all bindings are considered outdated and are removed to be later generated by newer ones. In debug they are regenerated every time.

@blagoev
Copy link
Contributor

blagoev commented May 31, 2016

It seems we have all the information we need in the filename to detect if the extend have moved for pure javascript files. For Typescript extends we have this
DialogFragment_frnal_ts_helpers_l47_c38__DialogFragmentClassInner.java

, which is always referring to line 47 column 38 in ts_helpers instead of the caller of the ts_helpers functions. We can fix that and then rely on line number in the filename to detect if this is outdated.

Also the other problem of new overrides does not exists since we generate overrides for everything that can be overridden.

@petekanev
Copy link
Contributor

I implemented a simple solution to this problem. It is based on the proposal by @slavchev - to generate universal interface "implementations". Writing the following:

        var button = new android.widget.Button(utils.ad.getApplicationContext());
        button.setOnClickListener(new android.view.View.OnClickListener({
            onClick: function(view) {
                console.log("Meeeeeeep on line 27");
            }
        }));


        var button3 = new android.widget.Button(utils.ad.getApplicationContext());
        button.setOnClickListener(new android.view.View.OnClickListener({
            onClick: function(view) {
                console.log("Meeeeeeep on line 39");
            }
        })); 

The SBG would generate just one View_OnClickListener instead of one class each implementation (e.g View_OnClickListener_l1_c10__ and View_OnClickListener_l9_c10__) which resulted in loads of redundant code.

The changes to the SBG can be previewed and commented on in the android-static-binding-generator repo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants