diff options
author | Yi Zhang <yizhan@google.com> | 2015-10-21 15:52:38 +0800 |
---|---|---|
committer | Yi Zhang <yizhan@google.com> | 2015-10-27 14:44:04 +0800 |
commit | 506dbdeaf007db9f4f7887767c73a366f33c8e30 (patch) | |
tree | 545cdc57680a41b68d77d1bdae1d58ed3db42d27 | |
parent | 634e7e4b4946919c549783e6646b422890ec0dd7 (diff) | |
download | appindexing-lldb-feature-10x.tar.gz |
Add tests for App Indexing API creationstudio-master-dev_before_27917934studio-master-dev_before_26911779studio-1.5gradle_1.5.0lldb-feature-10x
Change-Id: I3907daccf4b4934af5c2354b0ec4b53472b847ef
48 files changed, 2051 insertions, 0 deletions
diff --git a/src/com/google/appindexing/api/ApiCreator.java b/src/com/google/appindexing/api/ApiCreator.java index ead753d..bf58c9f 100644 --- a/src/com/google/appindexing/api/ApiCreator.java +++ b/src/com/google/appindexing/api/ApiCreator.java @@ -205,6 +205,12 @@ public final class ApiCreator { myImportClasses.put(CLASS_GOOGLE_API_CLIENT, CLASS_GOOGLE_API_CLIENT_FULL); } + @VisibleForTesting + void setGmsLibVersion(@Nullable String version) { + myHighestGmsLibVersion = version; + myAppIndexingLibVersion = version; + } + /** * If the current caret's position is eligible for creating App Indexing API code, * i.e. the caret is inside an 'Activity' class diff --git a/testData/ApiCreator/ActionNotInitialized.java b/testData/ApiCreator/ActionNotInitialized.java new file mode 100644 index 0000000..249e93a --- /dev/null +++ b/testData/ApiCreator/ActionNotInitialized.java @@ -0,0 +1,34 @@ +package com.example.creation; + +import android.app.Activity; +import android.net.Uri; +import android.os.Bundle; + +import com.google.android.gms.appindexing.Action; +import com.google.android.gms.appindexing.AppIndex; +import com.google.android.gms.common.api.GoogleApiClient; + +public class MainActivity extends Activity { + <caret> + private GoogleApiClient client; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build(); + } + + @Override + public void onStart() { + super.onStart(); + client.connect(); + Action viewAction; + AppIndex.AppIndexApi.start(client, viewAction); + } + + @Override + public void onStop() { + super.onStop(); + client.disconnect(); + } +} diff --git a/testData/ApiCreator/ActionNotInitialized_after.java b/testData/ApiCreator/ActionNotInitialized_after.java new file mode 100644 index 0000000..95344f4 --- /dev/null +++ b/testData/ApiCreator/ActionNotInitialized_after.java @@ -0,0 +1,47 @@ +package com.example.creation; + +import android.app.Activity; +import android.net.Uri; +import android.os.Bundle; + +import com.google.android.gms.appindexing.Action; +import com.google.android.gms.appindexing.AppIndex; +import com.google.android.gms.common.api.GoogleApiClient; + +public class MainActivity extends Activity { + + private GoogleApiClient client; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build(); + } + + @Override + public void onStart() { + super.onStart(); + client.connect(); + Action viewAction; + AppIndex.AppIndexApi.start(client, viewAction); + } + + @Override + public void onStop() { + super.onStop(); + // ATTENTION: This was auto-generated to implement the App Indexing API. + // See https://g.co/AppIndexing/AndroidStudio for more information. + Action viewAction2 = Action.newAction( + Action.TYPE_VIEW,// TODO: choose an action type. + "Main Page",// TODO: Define a title for the content shown. + // TODO: If you have web page content that matches this app activity's content, + // make sure this auto-generated web page URL is correct. + // Otherwise, set the URL to null. + Uri.parse("http://www.example.com/main"), + // TODO: Make sure this auto-generated app deep link URI is correct. + Uri.parse("android-app://com.example.creation/http/www.example.com/main") + ); + AppIndex.AppIndexApi.end(client, viewAction2); + client.disconnect(); + } +} diff --git a/testData/ApiCreator/AndroidManifest.xml b/testData/ApiCreator/AndroidManifest.xml new file mode 100644 index 0000000..7b8c8b0 --- /dev/null +++ b/testData/ApiCreator/AndroidManifest.xml @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="utf-8"?> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.example.creation"> + <application + android:allowBackup="true" + android:icon="@mipmap/ic_launcher"> + <activity + android:name=".AnotherActivity" + android:label="@string/app_name" > + </activity> + <activity + android:name=".MainActivity" + android:label="@string/app_name" > + <intent-filter> + <action android:name="android.intent.action.VIEW" /> + <category android:name="android.intent.category.DEFAULT" /> + <category android:name="android.intent.category.BROWSABLE" /> + <data + android:host="www.example.com" + android:pathPrefix="/main" + android:scheme="http" /> + </intent-filter> + </activity> + </application> +</manifest> diff --git a/testData/ApiCreator/AndroidManifest_after.xml b/testData/ApiCreator/AndroidManifest_after.xml new file mode 100644 index 0000000..d62cf28 --- /dev/null +++ b/testData/ApiCreator/AndroidManifest_after.xml @@ -0,0 +1,30 @@ +<?xml version="1.0" encoding="utf-8"?> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.example.creation"> + <application + android:allowBackup="true" + android:icon="@mipmap/ic_launcher"> + <activity + android:name=".AnotherActivity" + android:label="@string/app_name" > + </activity> + <activity + android:name=".MainActivity" + android:label="@string/app_name" > + <intent-filter> + <action android:name="android.intent.action.VIEW" /> + <category android:name="android.intent.category.DEFAULT" /> + <category android:name="android.intent.category.BROWSABLE" /> + <data + android:host="www.example.com" + android:pathPrefix="/main" + android:scheme="http" /> + </intent-filter> + </activity> + <!-- ATTENTION: This was auto-generated to add Google Play services to your project for + App Indexing. See https://g.co/AppIndexing/AndroidStudio for more information. --> + <meta-data + android:name="com.google.android.gms.version" + android:value="@integer/google_play_services_version" /> + </application> +</manifest> diff --git a/testData/ApiCreator/CaretOutsideActivity.java b/testData/ApiCreator/CaretOutsideActivity.java new file mode 100644 index 0000000..eaf7166 --- /dev/null +++ b/testData/ApiCreator/CaretOutsideActivity.java @@ -0,0 +1,6 @@ +package com.example.creation; + +import android.app.Activity; +<caret> +public class MainActivity extends Activity { +} diff --git a/testData/ApiCreator/ClientField.java b/testData/ApiCreator/ClientField.java new file mode 100644 index 0000000..690b1ff --- /dev/null +++ b/testData/ApiCreator/ClientField.java @@ -0,0 +1,12 @@ +package com.example.creation; + +import android.app.Activity; +import android.net.Uri; +import android.os.Bundle; + +import com.google.android.gms.common.api.GoogleApiClient; + +public class MainActivity extends Activity { + <caret> + private GoogleApiClient client = new GoogleApiClient.Builder(this).build(); +} diff --git a/testData/ApiCreator/ClientField_after.java b/testData/ApiCreator/ClientField_after.java new file mode 100644 index 0000000..b6def2a --- /dev/null +++ b/testData/ApiCreator/ClientField_after.java @@ -0,0 +1,58 @@ +package com.example.creation; + +import android.app.Activity; +import android.net.Uri; +import android.os.Bundle; + +import com.google.android.gms.appindexing.Action; +import com.google.android.gms.appindexing.AppIndex; +import com.google.android.gms.common.api.GoogleApiClient; + +public class MainActivity extends Activity { + + /** + * ATTENTION: This "addApi(AppIndex.API)" was auto-generated to implement the App Indexing API. + * See https://g.co/AppIndexing/AndroidStudio for more information. + */ + private GoogleApiClient client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build(); + + @Override + public void onStart() { + super.onStart(); + + // ATTENTION: This was auto-generated to implement the App Indexing API. + // See https://g.co/AppIndexing/AndroidStudio for more information. + client.connect(); + Action viewAction = Action.newAction( + Action.TYPE_VIEW,// TODO: choose an action type. + "Main Page",// TODO: Define a title for the content shown. + // TODO: If you have web page content that matches this app activity's content, + // make sure this auto-generated web page URL is correct. + // Otherwise, set the URL to null. + Uri.parse("http://www.example.com/main"), + // TODO: Make sure this auto-generated app deep link URI is correct. + Uri.parse("android-app://com.example.creation/http/www.example.com/main") + ); + AppIndex.AppIndexApi.start(client, viewAction); + } + + @Override + public void onStop() { + super.onStop(); + + // ATTENTION: This was auto-generated to implement the App Indexing API. + // See https://g.co/AppIndexing/AndroidStudio for more information. + Action viewAction = Action.newAction( + Action.TYPE_VIEW,// TODO: choose an action type. + "Main Page",// TODO: Define a title for the content shown. + // TODO: If you have web page content that matches this app activity's content, + // make sure this auto-generated web page URL is correct. + // Otherwise, set the URL to null. + Uri.parse("http://www.example.com/main"), + // TODO: Make sure this auto-generated app deep link URI is correct. + Uri.parse("android-app://com.example.creation/http/www.example.com/main") + ); + AppIndex.AppIndexApi.end(client, viewAction); + client.disconnect(); + } +} diff --git a/testData/ApiCreator/ClientInDeclarationStatement.java b/testData/ApiCreator/ClientInDeclarationStatement.java new file mode 100644 index 0000000..eacdd64 --- /dev/null +++ b/testData/ApiCreator/ClientInDeclarationStatement.java @@ -0,0 +1,36 @@ +package com.example.creation; + +import android.app.Activity; +import android.net.Uri; +import android.os.Bundle; + +import com.google.android.gms.appindexing.Action; +import com.google.android.gms.appindexing.AppIndex; +import com.google.android.gms.common.api.GoogleApiClient; +import com.google.android.gms.common.api.PendingResult; +import com.google.android.gms.common.api.Status; + +public class MainActivity extends Activity { + <caret> + private GoogleApiClient client; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build(); + } + + @Override + public void onStart() { + super.onStart(); + client.connect(); + Action viewAction = Action.newAction( + Action.TYPE_VIEW, + "Main Page", + Uri.parse("http://www.example.com/main"), + Uri.parse("android-app://com.example.creation/http/www.example.com/main") + ); + PendingResult<Status> status = AppIndex.AppIndexApi.start(client, viewAction); + } +} diff --git a/testData/ApiCreator/ClientInDeclarationStatement_after.java b/testData/ApiCreator/ClientInDeclarationStatement_after.java new file mode 100644 index 0000000..d6e35b3 --- /dev/null +++ b/testData/ApiCreator/ClientInDeclarationStatement_after.java @@ -0,0 +1,56 @@ +package com.example.creation; + +import android.app.Activity; +import android.net.Uri; +import android.os.Bundle; + +import com.google.android.gms.appindexing.Action; +import com.google.android.gms.appindexing.AppIndex; +import com.google.android.gms.common.api.GoogleApiClient; +import com.google.android.gms.common.api.PendingResult; +import com.google.android.gms.common.api.Status; + +public class MainActivity extends Activity { + + private GoogleApiClient client; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build(); + } + + @Override + public void onStart() { + super.onStart(); + client.connect(); + Action viewAction = Action.newAction( + Action.TYPE_VIEW, + "Main Page", + Uri.parse("http://www.example.com/main"), + Uri.parse("android-app://com.example.creation/http/www.example.com/main") + ); + PendingResult<Status> status = AppIndex.AppIndexApi.start(client, viewAction); + } + + @Override + public void onStop() { + super.onStop(); + + // ATTENTION: This was auto-generated to implement the App Indexing API. + // See https://g.co/AppIndexing/AndroidStudio for more information. + Action viewAction2 = Action.newAction( + Action.TYPE_VIEW,// TODO: choose an action type. + "Main Page",// TODO: Define a title for the content shown. + // TODO: If you have web page content that matches this app activity's content, + // make sure this auto-generated web page URL is correct. + // Otherwise, set the URL to null. + Uri.parse("http://www.example.com/main"), + // TODO: Make sure this auto-generated app deep link URI is correct. + Uri.parse("android-app://com.example.creation/http/www.example.com/main") + ); + AppIndex.AppIndexApi.end(client, viewAction2); + client.disconnect(); + } +} diff --git a/testData/ApiCreator/ClientInitializedWithoutBuilder.java b/testData/ApiCreator/ClientInitializedWithoutBuilder.java new file mode 100644 index 0000000..0d9cffd --- /dev/null +++ b/testData/ApiCreator/ClientInitializedWithoutBuilder.java @@ -0,0 +1,29 @@ +package com.example.creation; + +import android.app.Activity; +import android.net.Uri; +import android.os.Bundle; + +import com.google.android.gms.appindexing.Action; +import com.google.android.gms.appindexing.AppIndex; +import com.google.android.gms.common.api.GoogleApiClient; + +public class MainActivity extends Activity { + <caret> + private GoogleApiClient client; + + @Override + public void onStart() { + super.onStart(); + GoogleApiClient client2 = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build(); + client = client2; + client.connect(); + Action viewAction = Action.newAction( + Action.TYPE_VIEW, + "Main Page", + Uri.parse("http://www.example.com/main"), + Uri.parse("android-app://com.example.creation/http/www.example.com/main") + ); + AppIndex.AppIndexApi.start(client, viewAction); + } +} diff --git a/testData/ApiCreator/ClientInitializedWithoutBuilder_after.java b/testData/ApiCreator/ClientInitializedWithoutBuilder_after.java new file mode 100644 index 0000000..6e7563d --- /dev/null +++ b/testData/ApiCreator/ClientInitializedWithoutBuilder_after.java @@ -0,0 +1,79 @@ +package com.example.creation; + +import android.app.Activity; +import android.net.Uri; +import android.os.Bundle; + +import com.google.android.gms.appindexing.Action; +import com.google.android.gms.appindexing.AppIndex; +import com.google.android.gms.common.api.GoogleApiClient; + +public class MainActivity extends Activity { + + private GoogleApiClient client; + + /** + * ATTENTION: This was auto-generated to implement the App Indexing API. + * See https://g.co/AppIndexing/AndroidStudio for more information. + */ + private GoogleApiClient client3; + + @Override + public void onStart() { + super.onStart(); + // ATTENTION: This was auto-generated to implement the App Indexing API. + // See https://g.co/AppIndexing/AndroidStudio for more information. + client3.connect(); + GoogleApiClient client2 = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build(); + client = client2; + client.connect(); + Action viewAction = Action.newAction( + Action.TYPE_VIEW, + "Main Page", + Uri.parse("http://www.example.com/main"), + Uri.parse("android-app://com.example.creation/http/www.example.com/main") + ); + AppIndex.AppIndexApi.start(client, viewAction); + // ATTENTION: This was auto-generated to implement the App Indexing API. + // See https://g.co/AppIndexing/AndroidStudio for more information. + Action viewAction2 = Action.newAction( + Action.TYPE_VIEW,// TODO: choose an action type. + "Main Page",// TODO: Define a title for the content shown. + // TODO: If you have web page content that matches this app activity's content, + // make sure this auto-generated web page URL is correct. + // Otherwise, set the URL to null. + Uri.parse("http://www.example.com/main"), + // TODO: Make sure this auto-generated app deep link URI is correct. + Uri.parse("android-app://com.example.creation/http/www.example.com/main") + ); + AppIndex.AppIndexApi.start(client3, viewAction2); + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + // ATTENTION: This was auto-generated to implement the App Indexing API. + // See https://g.co/AppIndexing/AndroidStudio for more information. + client3 = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build(); + } + + @Override + public void onStop() { + super.onStop(); + + // ATTENTION: This was auto-generated to implement the App Indexing API. + // See https://g.co/AppIndexing/AndroidStudio for more information. + Action viewAction2 = Action.newAction( + Action.TYPE_VIEW,// TODO: choose an action type. + "Main Page",// TODO: Define a title for the content shown. + // TODO: If you have web page content that matches this app activity's content, + // make sure this auto-generated web page URL is correct. + // Otherwise, set the URL to null. + Uri.parse("http://www.example.com/main"), + // TODO: Make sure this auto-generated app deep link URI is correct. + Uri.parse("android-app://com.example.creation/http/www.example.com/main") + ); + AppIndex.AppIndexApi.end(client3, viewAction2); + client3.disconnect(); + } +} diff --git a/testData/ApiCreator/ClientLocalVariable.java b/testData/ApiCreator/ClientLocalVariable.java new file mode 100644 index 0000000..5ea9c16 --- /dev/null +++ b/testData/ApiCreator/ClientLocalVariable.java @@ -0,0 +1,26 @@ +package com.example.creation; + +import android.app.Activity; +import android.net.Uri; +import android.os.Bundle; + +import com.google.android.gms.appindexing.Action; +import com.google.android.gms.appindexing.AppIndex; +import com.google.android.gms.common.api.GoogleApiClient; + +public class MainActivity extends Activity { + <caret> + @Override + public void onStart() { + super.onStart(); + GoogleApiClient client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build(); + client.connect(); + Action viewAction = Action.newAction( + Action.TYPE_VIEW, + "Main Page", + Uri.parse("http://www.example.com/main"), + Uri.parse("android-app://com.example.creation/http/www.example.com/main") + ); + AppIndex.AppIndexApi.start(client, viewAction); + } +} diff --git a/testData/ApiCreator/ClientLocalVariable_after.java b/testData/ApiCreator/ClientLocalVariable_after.java new file mode 100644 index 0000000..293872a --- /dev/null +++ b/testData/ApiCreator/ClientLocalVariable_after.java @@ -0,0 +1,77 @@ +package com.example.creation; + +import android.app.Activity; +import android.net.Uri; +import android.os.Bundle; + +import com.google.android.gms.appindexing.Action; +import com.google.android.gms.appindexing.AppIndex; +import com.google.android.gms.common.api.GoogleApiClient; + +public class MainActivity extends Activity { + + /** + * ATTENTION: This was auto-generated to implement the App Indexing API. + * See https://g.co/AppIndexing/AndroidStudio for more information. + */ + private GoogleApiClient client2; + + @Override + public void onStart() { + super.onStart(); + // ATTENTION: This was auto-generated to implement the App Indexing API. + // See https://g.co/AppIndexing/AndroidStudio for more information. + client2.connect(); + GoogleApiClient client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build(); + client.connect(); + Action viewAction = Action.newAction( + Action.TYPE_VIEW, + "Main Page", + Uri.parse("http://www.example.com/main"), + Uri.parse("android-app://com.example.creation/http/www.example.com/main") + ); + AppIndex.AppIndexApi.start(client, viewAction); + // ATTENTION: This was auto-generated to implement the App Indexing API. + // See https://g.co/AppIndexing/AndroidStudio for more information. + Action viewAction2 = Action.newAction( + Action.TYPE_VIEW,// TODO: choose an action type. + "Main Page",// TODO: Define a title for the content shown. + // TODO: If you have web page content that matches this app activity's content, + // make sure this auto-generated web page URL is correct. + // Otherwise, set the URL to null. + Uri.parse("http://www.example.com/main"), + // TODO: Make sure this auto-generated app deep link URI is correct. + Uri.parse("android-app://com.example.creation/http/www.example.com/main") + ); + AppIndex.AppIndexApi.start(client2, viewAction2); + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + // ATTENTION: This was auto-generated to implement the App Indexing API. + // See https://g.co/AppIndexing/AndroidStudio for more information. + client2 = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build(); + } + + @Override + public void onStop() { + super.onStop(); + + // ATTENTION: This was auto-generated to implement the App Indexing API. + // See https://g.co/AppIndexing/AndroidStudio for more information. + Action viewAction2 = Action.newAction( + Action.TYPE_VIEW,// TODO: choose an action type. + "Main Page",// TODO: Define a title for the content shown. + // TODO: If you have web page content that matches this app activity's content, + // make sure this auto-generated web page URL is correct. + // Otherwise, set the URL to null. + Uri.parse("http://www.example.com/main"), + // TODO: Make sure this auto-generated app deep link URI is correct. + Uri.parse("android-app://com.example.creation/http/www.example.com/main") + ); + AppIndex.AppIndexApi.end(client2, viewAction2); + client2.disconnect(); + } +} diff --git a/testData/ApiCreator/ClientNotInitialized.java b/testData/ApiCreator/ClientNotInitialized.java new file mode 100644 index 0000000..4189f09 --- /dev/null +++ b/testData/ApiCreator/ClientNotInitialized.java @@ -0,0 +1,33 @@ +package com.example.creation; + +import android.app.Activity; +import android.net.Uri; +import android.os.Bundle; + +import com.google.android.gms.appindexing.Action; +import com.google.android.gms.appindexing.AppIndex; +import com.google.android.gms.common.api.GoogleApiClient; + +public class MainActivity extends Activity { + <caret> + private GoogleApiClient client; + + @Override + public void onStart() { + super.onStart(); + client.connect(); + Action viewAction = Action.newAction( + Action.TYPE_VIEW, + "Main Page", + Uri.parse("http://www.example.com/main"), + Uri.parse("android-app://com.example.creation/http/www.example.com/main") + ); + AppIndex.AppIndexApi.start(client, viewAction); + } + + @Override + public void onStop() { + super.onStop(); + client.disconnect(); + } +} diff --git a/testData/ApiCreator/ClientNotInitialized_after.java b/testData/ApiCreator/ClientNotInitialized_after.java new file mode 100644 index 0000000..efe08b0 --- /dev/null +++ b/testData/ApiCreator/ClientNotInitialized_after.java @@ -0,0 +1,80 @@ +package com.example.creation; + +import android.app.Activity; +import android.net.Uri; +import android.os.Bundle; + +import com.google.android.gms.appindexing.Action; +import com.google.android.gms.appindexing.AppIndex; +import com.google.android.gms.common.api.GoogleApiClient; + +public class MainActivity extends Activity { + + private GoogleApiClient client; + + /** + * ATTENTION: This was auto-generated to implement the App Indexing API. + * See https://g.co/AppIndexing/AndroidStudio for more information. + */ + private GoogleApiClient client2; + + @Override + public void onStart() { + super.onStart(); + // ATTENTION: This was auto-generated to implement the App Indexing API. + // See https://g.co/AppIndexing/AndroidStudio for more information. + client2.connect(); + client.connect(); + Action viewAction = Action.newAction( + Action.TYPE_VIEW, + "Main Page", + Uri.parse("http://www.example.com/main"), + Uri.parse("android-app://com.example.creation/http/www.example.com/main") + ); + AppIndex.AppIndexApi.start(client, viewAction); + // ATTENTION: This was auto-generated to implement the App Indexing API. + // See https://g.co/AppIndexing/AndroidStudio for more information. + Action viewAction2 = Action.newAction( + Action.TYPE_VIEW,// TODO: choose an action type. + "Main Page",// TODO: Define a title for the content shown. + // TODO: If you have web page content that matches this app activity's content, + // make sure this auto-generated web page URL is correct. + // Otherwise, set the URL to null. + Uri.parse("http://www.example.com/main"), + // TODO: Make sure this auto-generated app deep link URI is correct. + Uri.parse("android-app://com.example.creation/http/www.example.com/main") + ); + AppIndex.AppIndexApi.start(client2, viewAction2); + } + + @Override + public void onStop() { + super.onStop(); + // ATTENTION: This was auto-generated to implement the App Indexing API. + // See https://g.co/AppIndexing/AndroidStudio for more information. + Action viewAction2 = Action.newAction( + Action.TYPE_VIEW,// TODO: choose an action type. + "Main Page",// TODO: Define a title for the content shown. + // TODO: If you have web page content that matches this app activity's content, + // make sure this auto-generated web page URL is correct. + // Otherwise, set the URL to null. + Uri.parse("http://www.example.com/main"), + // TODO: Make sure this auto-generated app deep link URI is correct. + Uri.parse("android-app://com.example.creation/http/www.example.com/main") + ); + AppIndex.AppIndexApi.end(client2, viewAction2); + client.disconnect(); + // ATTENTION: This was auto-generated to implement the App Indexing API. + // See https://g.co/AppIndexing/AndroidStudio for more information. + client2.disconnect(); + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + // ATTENTION: This was auto-generated to implement the App Indexing API. + // See https://g.co/AppIndexing/AndroidStudio for more information. + client2 = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build(); + } +} diff --git a/testData/ApiCreator/ConflictImports.java b/testData/ApiCreator/ConflictImports.java new file mode 100644 index 0000000..8278cd5 --- /dev/null +++ b/testData/ApiCreator/ConflictImports.java @@ -0,0 +1,11 @@ +package com.example.creation; + +import a.Action; +import a.AppIndex; +import a.GoogleApiClient; + +import android.app.Activity; + +public class MainActivity extends Activity { + <caret> +} diff --git a/testData/ApiCreator/ConflictImports_after.java b/testData/ApiCreator/ConflictImports_after.java new file mode 100644 index 0000000..93d2cc6 --- /dev/null +++ b/testData/ApiCreator/ConflictImports_after.java @@ -0,0 +1,66 @@ +package com.example.creation; + +import a.Action; +import a.AppIndex; +import a.GoogleApiClient; + +import android.app.Activity; +import android.net.Uri; +import android.os.Bundle; + +public class MainActivity extends Activity { + + /** + * ATTENTION: This was auto-generated to implement the App Indexing API. + * See https://g.co/AppIndexing/AndroidStudio for more information. + */ + private com.google.android.gms.common.api.GoogleApiClient client; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + // ATTENTION: This was auto-generated to implement the App Indexing API. + // See https://g.co/AppIndexing/AndroidStudio for more information. + client = new com.google.android.gms.common.api.GoogleApiClient.Builder(this).addApi(com.google.android.gms.appindexing.AppIndex.API).build(); + } + + @Override + public void onStart() { + super.onStart(); + + // ATTENTION: This was auto-generated to implement the App Indexing API. + // See https://g.co/AppIndexing/AndroidStudio for more information. + client.connect(); + com.google.android.gms.appindexing.Action viewAction = com.google.android.gms.appindexing.Action.newAction( + com.google.android.gms.appindexing.Action.TYPE_VIEW,// TODO: choose an action type. + "Main Page",// TODO: Define a title for the content shown. + // TODO: If you have web page content that matches this app activity's content, + // make sure this auto-generated web page URL is correct. + // Otherwise, set the URL to null. + Uri.parse("http://www.example.com/main"), + // TODO: Make sure this auto-generated app deep link URI is correct. + Uri.parse("android-app://com.example.creation/http/www.example.com/main") + ); + com.google.android.gms.appindexing.AppIndex.AppIndexApi.start(client, viewAction); + } + + @Override + public void onStop() { + super.onStop(); + + // ATTENTION: This was auto-generated to implement the App Indexing API. + // See https://g.co/AppIndexing/AndroidStudio for more information. + com.google.android.gms.appindexing.Action viewAction = com.google.android.gms.appindexing.Action.newAction( + com.google.android.gms.appindexing.Action.TYPE_VIEW,// TODO: choose an action type. + "Main Page",// TODO: Define a title for the content shown. + // TODO: If you have web page content that matches this app activity's content, + // make sure this auto-generated web page URL is correct. + // Otherwise, set the URL to null. + Uri.parse("http://www.example.com/main"), + // TODO: Make sure this auto-generated app deep link URI is correct. + Uri.parse("android-app://com.example.creation/http/www.example.com/main") + ); + com.google.android.gms.appindexing.AppIndex.AppIndexApi.end(client, viewAction); + client.disconnect(); + } +} diff --git a/testData/ApiCreator/EmptyActivity.java b/testData/ApiCreator/EmptyActivity.java new file mode 100644 index 0000000..909edb2 --- /dev/null +++ b/testData/ApiCreator/EmptyActivity.java @@ -0,0 +1,7 @@ +package com.example.creation; + +import android.app.Activity; + +public class MainActivity extends Activity { + <caret> +} diff --git a/testData/ApiCreator/EmptyActivity_after.java b/testData/ApiCreator/EmptyActivity_after.java new file mode 100644 index 0000000..4d2c289 --- /dev/null +++ b/testData/ApiCreator/EmptyActivity_after.java @@ -0,0 +1,66 @@ +package com.example.creation; + +import android.app.Activity; +import android.net.Uri; +import android.os.Bundle; + +import com.google.android.gms.appindexing.Action; +import com.google.android.gms.appindexing.AppIndex; +import com.google.android.gms.common.api.GoogleApiClient; + +public class MainActivity extends Activity { + + /** + * ATTENTION: This was auto-generated to implement the App Indexing API. + * See https://g.co/AppIndexing/AndroidStudio for more information. + */ + private GoogleApiClient client; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + // ATTENTION: This was auto-generated to implement the App Indexing API. + // See https://g.co/AppIndexing/AndroidStudio for more information. + client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build(); + } + + @Override + public void onStart() { + super.onStart(); + + // ATTENTION: This was auto-generated to implement the App Indexing API. + // See https://g.co/AppIndexing/AndroidStudio for more information. + client.connect(); + Action viewAction = Action.newAction( + Action.TYPE_VIEW,// TODO: choose an action type. + "Main Page",// TODO: Define a title for the content shown. + // TODO: If you have web page content that matches this app activity's content, + // make sure this auto-generated web page URL is correct. + // Otherwise, set the URL to null. + Uri.parse("http://www.example.com/main"), + // TODO: Make sure this auto-generated app deep link URI is correct. + Uri.parse("android-app://com.example.creation/http/www.example.com/main") + ); + AppIndex.AppIndexApi.start(client, viewAction); + } + + @Override + public void onStop() { + super.onStop(); + + // ATTENTION: This was auto-generated to implement the App Indexing API. + // See https://g.co/AppIndexing/AndroidStudio for more information. + Action viewAction = Action.newAction( + Action.TYPE_VIEW,// TODO: choose an action type. + "Main Page",// TODO: Define a title for the content shown. + // TODO: If you have web page content that matches this app activity's content, + // make sure this auto-generated web page URL is correct. + // Otherwise, set the URL to null. + Uri.parse("http://www.example.com/main"), + // TODO: Make sure this auto-generated app deep link URI is correct. + Uri.parse("android-app://com.example.creation/http/www.example.com/main") + ); + AppIndex.AppIndexApi.end(client, viewAction); + client.disconnect(); + } +} diff --git a/testData/ApiCreator/HasAppIndexingStartAndEnd.java b/testData/ApiCreator/HasAppIndexingStartAndEnd.java new file mode 100644 index 0000000..914ce43 --- /dev/null +++ b/testData/ApiCreator/HasAppIndexingStartAndEnd.java @@ -0,0 +1,46 @@ +package com.example.creation; + +import android.app.Activity; +import android.net.Uri; +import android.os.Bundle; + +import com.google.android.gms.appindexing.Action; +import com.google.android.gms.appindexing.AppIndex; +import com.google.android.gms.common.api.GoogleApiClient; + +public class MainActivity extends Activity { + <caret> + private GoogleApiClient client; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build(); + } + + @Override + public void onStart() { + super.onStart(); + client.connect(); + Action viewAction = Action.newAction( + Action.TYPE_VIEW, + "Main Page", + Uri.parse("http://www.example.com/main"), + Uri.parse("android-app://com.example.creation/http/www.example.com/main") + ); + AppIndex.AppIndexApi.start(client, viewAction); + } + + @Override + public void onStop() { + super.onStop(); + Action viewAction = Action.newAction( + Action.TYPE_VIEW, + "Main Page", + Uri.parse("http://www.example.com/main"), + Uri.parse("android-app://com.example.creation/http/www.example.com/main") + ); + AppIndex.AppIndexApi.end(client, viewAction); + client.disconnect(); + } +} diff --git a/testData/ApiCreator/HasAppIndexingViewAndViewEnd.java b/testData/ApiCreator/HasAppIndexingViewAndViewEnd.java new file mode 100644 index 0000000..49c8d4e --- /dev/null +++ b/testData/ApiCreator/HasAppIndexingViewAndViewEnd.java @@ -0,0 +1,37 @@ +package com.example.creation; + +import android.app.Activity; +import android.net.Uri; +import android.os.Bundle; + +import com.google.android.gms.appindexing.Action; +import com.google.android.gms.appindexing.AppIndex; +import com.google.android.gms.common.api.GoogleApiClient; + +public class MainActivity extends Activity { + <caret> + private GoogleApiClient client; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build(); + } + + @Override + public void onStart() { + super.onStart(); + client.connect(); + AppIndex.AppIndexApi.view(client, this, + Uri.parse("android-app://com.example.creation/http/www.example.com/main"), + "Main Page", Uri.parse("http://www.example.com/main"), null); + } + + @Override + public void onStop() { + super.onStop(); + AppIndex.AppIndexApi.viewEnd(client, this, + Uri.parse("android-app://com.example.creation/http/www.example.com/main")); + client.disconnect(); + } +} diff --git a/testData/ApiCreator/NoKeywordSuper.java b/testData/ApiCreator/NoKeywordSuper.java new file mode 100644 index 0000000..7d43493 --- /dev/null +++ b/testData/ApiCreator/NoKeywordSuper.java @@ -0,0 +1,21 @@ +package com.example.creation; + +import android.app.Activity; +import android.net.Uri; +import android.os.Bundle; + +import com.google.android.gms.appindexing.Action; +import com.google.android.gms.appindexing.AppIndex; +import com.google.android.gms.common.api.GoogleApiClient; + +public class MainActivity extends Activity { + <caret> + @Override + protected void onCreate(Bundle savedInstanceState) {} + + @Override + public void onStart() {} + + @Override + public void onStop() {} +} diff --git a/testData/ApiCreator/NoKeywordSuper_after.java b/testData/ApiCreator/NoKeywordSuper_after.java new file mode 100644 index 0000000..77befe2 --- /dev/null +++ b/testData/ApiCreator/NoKeywordSuper_after.java @@ -0,0 +1,65 @@ +package com.example.creation; + +import android.app.Activity; +import android.net.Uri; +import android.os.Bundle; + +import com.google.android.gms.appindexing.Action; +import com.google.android.gms.appindexing.AppIndex; +import com.google.android.gms.common.api.GoogleApiClient; + +public class MainActivity extends Activity { + + /** + * ATTENTION: This was auto-generated to implement the App Indexing API. + * See https://g.co/AppIndexing/AndroidStudio for more information. + */ + private GoogleApiClient client; + + @Override + protected void onCreate(Bundle savedInstanceState) { + // ATTENTION: This was auto-generated to implement the App Indexing API. + // See https://g.co/AppIndexing/AndroidStudio for more information. + client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build(); + } + + @Override + public void onStart() { + // ATTENTION: This was auto-generated to implement the App Indexing API. + // See https://g.co/AppIndexing/AndroidStudio for more information. + client.connect(); + // ATTENTION: This was auto-generated to implement the App Indexing API. + // See https://g.co/AppIndexing/AndroidStudio for more information. + Action viewAction = Action.newAction( + Action.TYPE_VIEW,// TODO: choose an action type. + "Main Page",// TODO: Define a title for the content shown. + // TODO: If you have web page content that matches this app activity's content, + // make sure this auto-generated web page URL is correct. + // Otherwise, set the URL to null. + Uri.parse("http://www.example.com/main"), + // TODO: Make sure this auto-generated app deep link URI is correct. + Uri.parse("android-app://com.example.creation/http/www.example.com/main") + ); + AppIndex.AppIndexApi.start(client, viewAction); + } + + @Override + public void onStop() { + // ATTENTION: This was auto-generated to implement the App Indexing API. + // See https://g.co/AppIndexing/AndroidStudio for more information. + Action viewAction = Action.newAction( + Action.TYPE_VIEW,// TODO: choose an action type. + "Main Page",// TODO: Define a title for the content shown. + // TODO: If you have web page content that matches this app activity's content, + // make sure this auto-generated web page URL is correct. + // Otherwise, set the URL to null. + Uri.parse("http://www.example.com/main"), + // TODO: Make sure this auto-generated app deep link URI is correct. + Uri.parse("android-app://com.example.creation/http/www.example.com/main") + ); + AppIndex.AppIndexApi.end(client, viewAction); + // ATTENTION: This was auto-generated to implement the App Indexing API. + // See https://g.co/AppIndexing/AndroidStudio for more information. + client.disconnect(); + } +} diff --git a/testData/ApiCreator/NotActivity.java b/testData/ApiCreator/NotActivity.java new file mode 100644 index 0000000..6ec6273 --- /dev/null +++ b/testData/ApiCreator/NotActivity.java @@ -0,0 +1,7 @@ +package com.example.creation; + +import android.app.Fragment; + +public class MainActivity extends Fragment { + <caret> +} diff --git a/testData/ApiCreator/OnlyEndCallAndAdjustClientInitializingStatement.java b/testData/ApiCreator/OnlyEndCallAndAdjustClientInitializingStatement.java new file mode 100644 index 0000000..2277c8f --- /dev/null +++ b/testData/ApiCreator/OnlyEndCallAndAdjustClientInitializingStatement.java @@ -0,0 +1,37 @@ +package com.example.creation; + +import android.app.Activity; +import android.net.Uri; +import android.os.Bundle; + +import com.google.android.gms.appindexing.Action; +import com.google.android.gms.appindexing.AppIndex; +import com.google.android.gms.common.api.GoogleApiClient; + +public class MainActivity extends Activity { + <caret> + private GoogleApiClient client; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + client = new GoogleApiClient.Builder(this).build(); + } + + @Override + public void onStart() { + super.onStart(); + } + + @Override + public void onStop() { + super.onStop(); + Action viewAction = Action.newAction( + Action.TYPE_VIEW, + "Main Page", + Uri.parse("http://www.example.com/main"), + Uri.parse("android-app://com.example.creation/http/www.example.com/main") + ); + AppIndex.AppIndexApi.end(client, viewAction); + } +} diff --git a/testData/ApiCreator/OnlyEndCallAndAdjustClientInitializingStatement_after.java b/testData/ApiCreator/OnlyEndCallAndAdjustClientInitializingStatement_after.java new file mode 100644 index 0000000..4e3c521 --- /dev/null +++ b/testData/ApiCreator/OnlyEndCallAndAdjustClientInitializingStatement_after.java @@ -0,0 +1,58 @@ +package com.example.creation; + +import android.app.Activity; +import android.net.Uri; +import android.os.Bundle; + +import com.google.android.gms.appindexing.Action; +import com.google.android.gms.appindexing.AppIndex; +import com.google.android.gms.common.api.GoogleApiClient; + +public class MainActivity extends Activity { + + private GoogleApiClient client; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + // ATTENTION: This "addApi(AppIndex.API)" was auto-generated to implement the App Indexing API. + // See https://g.co/AppIndexing/AndroidStudio for more information. + client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build(); + } + + @Override + public void onStart() { + super.onStart(); + // ATTENTION: This was auto-generated to implement the App Indexing API. + // See https://g.co/AppIndexing/AndroidStudio for more information. + client.connect(); + // ATTENTION: This was auto-generated to implement the App Indexing API. + // See https://g.co/AppIndexing/AndroidStudio for more information. + Action viewAction2 = Action.newAction( + Action.TYPE_VIEW,// TODO: choose an action type. + "Main Page",// TODO: Define a title for the content shown. + // TODO: If you have web page content that matches this app activity's content, + // make sure this auto-generated web page URL is correct. + // Otherwise, set the URL to null. + Uri.parse("http://www.example.com/main"), + // TODO: Make sure this auto-generated app deep link URI is correct. + Uri.parse("android-app://com.example.creation/http/www.example.com/main") + ); + AppIndex.AppIndexApi.start(client, viewAction2); + } + + @Override + public void onStop() { + super.onStop(); + Action viewAction = Action.newAction( + Action.TYPE_VIEW, + "Main Page", + Uri.parse("http://www.example.com/main"), + Uri.parse("android-app://com.example.creation/http/www.example.com/main") + ); + AppIndex.AppIndexApi.end(client, viewAction); + // ATTENTION: This was auto-generated to implement the App Indexing API. + // See https://g.co/AppIndexing/AndroidStudio for more information. + client.disconnect(); + } +} diff --git a/testData/ApiCreator/OnlyStartCallAndAdjustClientFieldInitializer.java b/testData/ApiCreator/OnlyStartCallAndAdjustClientFieldInitializer.java new file mode 100644 index 0000000..8a46c64 --- /dev/null +++ b/testData/ApiCreator/OnlyStartCallAndAdjustClientFieldInitializer.java @@ -0,0 +1,33 @@ +package com.example.creation; + +import android.app.Activity; +import android.net.Uri; +import android.os.Bundle; + +import com.google.android.gms.appindexing.Action; +import com.google.android.gms.appindexing.AppIndex; +import com.google.android.gms.common.api.GoogleApiClient; + +public class MainActivity extends Activity { + <caret> + private GoogleApiClient client = new GoogleApiClient.Builder(this).build(); + + @Override + public void onStart() { + super.onStart(); + client.connect(); + Action viewAction = Action.newAction( + Action.TYPE_VIEW, + "Main Page", + Uri.parse("http://www.example.com/main"), + Uri.parse("android-app://com.example.creation/http/www.example.com/main") + ); + AppIndex.AppIndexApi.start(client, viewAction); + } + + @Override + public void onStop() { + super.onStop(); + client.disconnect(); + } +} diff --git a/testData/ApiCreator/OnlyStartCallAndAdjustClientFieldInitializer_after.java b/testData/ApiCreator/OnlyStartCallAndAdjustClientFieldInitializer_after.java new file mode 100644 index 0000000..ec32c08 --- /dev/null +++ b/testData/ApiCreator/OnlyStartCallAndAdjustClientFieldInitializer_after.java @@ -0,0 +1,50 @@ +package com.example.creation; + +import android.app.Activity; +import android.net.Uri; +import android.os.Bundle; + +import com.google.android.gms.appindexing.Action; +import com.google.android.gms.appindexing.AppIndex; +import com.google.android.gms.common.api.GoogleApiClient; + +public class MainActivity extends Activity { + + /** + * ATTENTION: This "addApi(AppIndex.API)" was auto-generated to implement the App Indexing API. + * See https://g.co/AppIndexing/AndroidStudio for more information. + */ + private GoogleApiClient client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build(); + + @Override + public void onStart() { + super.onStart(); + client.connect(); + Action viewAction = Action.newAction( + Action.TYPE_VIEW, + "Main Page", + Uri.parse("http://www.example.com/main"), + Uri.parse("android-app://com.example.creation/http/www.example.com/main") + ); + AppIndex.AppIndexApi.start(client, viewAction); + } + + @Override + public void onStop() { + super.onStop(); + // ATTENTION: This was auto-generated to implement the App Indexing API. + // See https://g.co/AppIndexing/AndroidStudio for more information. + Action viewAction2 = Action.newAction( + Action.TYPE_VIEW,// TODO: choose an action type. + "Main Page",// TODO: Define a title for the content shown. + // TODO: If you have web page content that matches this app activity's content, + // make sure this auto-generated web page URL is correct. + // Otherwise, set the URL to null. + Uri.parse("http://www.example.com/main"), + // TODO: Make sure this auto-generated app deep link URI is correct. + Uri.parse("android-app://com.example.creation/http/www.example.com/main") + ); + AppIndex.AppIndexApi.end(client, viewAction2); + client.disconnect(); + } +} diff --git a/testData/ApiCreator/OnlyViewCall.java b/testData/ApiCreator/OnlyViewCall.java new file mode 100644 index 0000000..ed96553 --- /dev/null +++ b/testData/ApiCreator/OnlyViewCall.java @@ -0,0 +1,33 @@ +package com.example.creation; + +import android.app.Activity; +import android.net.Uri; +import android.os.Bundle; + +import com.google.android.gms.appindexing.Action; +import com.google.android.gms.appindexing.AppIndex; +import com.google.android.gms.common.api.GoogleApiClient; + +public class MainActivity extends Activity { + <caret> + private GoogleApiClient client; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build(); + } + + @Override + public void onStart() { + super.onStart(); + AppIndex.AppIndexApi.view(client, this, + Uri.parse("android-app://com.example.creation/http/www.example.com/main"), + "Main Page", Uri.parse("http://www.example.com/main"), null); + } + + @Override + public void onStop() { + super.onStop(); + } +} diff --git a/testData/ApiCreator/OnlyViewCall_after.java b/testData/ApiCreator/OnlyViewCall_after.java new file mode 100644 index 0000000..ae6a541 --- /dev/null +++ b/testData/ApiCreator/OnlyViewCall_after.java @@ -0,0 +1,52 @@ +package com.example.creation; + +import android.app.Activity; +import android.net.Uri; +import android.os.Bundle; + +import com.google.android.gms.appindexing.Action; +import com.google.android.gms.appindexing.AppIndex; +import com.google.android.gms.common.api.GoogleApiClient; + +public class MainActivity extends Activity { + + private GoogleApiClient client; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build(); + } + + @Override + public void onStart() { + super.onStart(); + // ATTENTION: This was auto-generated to implement the App Indexing API. + // See https://g.co/AppIndexing/AndroidStudio for more information. + client.connect(); + AppIndex.AppIndexApi.view(client, this, + Uri.parse("android-app://com.example.creation/http/www.example.com/main"), + "Main Page", Uri.parse("http://www.example.com/main"), null); + } + + @Override + public void onStop() { + super.onStop(); + // ATTENTION: This was auto-generated to implement the App Indexing API. + // See https://g.co/AppIndexing/AndroidStudio for more information. + Action viewAction = Action.newAction( + Action.TYPE_VIEW,// TODO: choose an action type. + "Main Page",// TODO: Define a title for the content shown. + // TODO: If you have web page content that matches this app activity's content, + // make sure this auto-generated web page URL is correct. + // Otherwise, set the URL to null. + Uri.parse("http://www.example.com/main"), + // TODO: Make sure this auto-generated app deep link URI is correct. + Uri.parse("android-app://com.example.creation/http/www.example.com/main") + ); + AppIndex.AppIndexApi.end(client, viewAction); + // ATTENTION: This was auto-generated to implement the App Indexing API. + // See https://g.co/AppIndexing/AndroidStudio for more information. + client.disconnect(); + } +} diff --git a/testData/ApiCreator/OnlyViewEndCall.java b/testData/ApiCreator/OnlyViewEndCall.java new file mode 100644 index 0000000..25d4d13 --- /dev/null +++ b/testData/ApiCreator/OnlyViewEndCall.java @@ -0,0 +1,34 @@ +package com.example.creation; + +import android.app.Activity; +import android.net.Uri; +import android.os.Bundle; + +import com.google.android.gms.appindexing.AppIndex; +import com.google.android.gms.common.api.GoogleApiClient; + +public class MainActivity extends Activity { + <caret> + private GoogleApiClient client; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build(); + } + + @Override + public void onStart() { + super.onStart(); + client.connect(); + } + + @Override + public void onStop() { + super.onStop(); + AppIndex.AppIndexApi.viewEnd(client, this, + Uri.parse("android-app://com.example.creation/http/www.example.com/main")); + client.disconnect(); + } +} diff --git a/testData/ApiCreator/OnlyViewEndCall_after.java b/testData/ApiCreator/OnlyViewEndCall_after.java new file mode 100644 index 0000000..490ef36 --- /dev/null +++ b/testData/ApiCreator/OnlyViewEndCall_after.java @@ -0,0 +1,48 @@ +package com.example.creation; + +import android.app.Activity; +import android.net.Uri; +import android.os.Bundle; + +import com.google.android.gms.appindexing.Action; +import com.google.android.gms.appindexing.AppIndex; +import com.google.android.gms.common.api.GoogleApiClient; + +public class MainActivity extends Activity { + + private GoogleApiClient client; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build(); + } + + @Override + public void onStart() { + super.onStart(); + client.connect(); + // ATTENTION: This was auto-generated to implement the App Indexing API. + // See https://g.co/AppIndexing/AndroidStudio for more information. + Action viewAction = Action.newAction( + Action.TYPE_VIEW,// TODO: choose an action type. + "Main Page",// TODO: Define a title for the content shown. + // TODO: If you have web page content that matches this app activity's content, + // make sure this auto-generated web page URL is correct. + // Otherwise, set the URL to null. + Uri.parse("http://www.example.com/main"), + // TODO: Make sure this auto-generated app deep link URI is correct. + Uri.parse("android-app://com.example.creation/http/www.example.com/main") + ); + AppIndex.AppIndexApi.start(client, viewAction); + } + + @Override + public void onStop() { + super.onStop(); + AppIndex.AppIndexApi.viewEnd(client, this, + Uri.parse("android-app://com.example.creation/http/www.example.com/main")); + client.disconnect(); + } +} diff --git a/testData/ApiCreator/OverrideMethod.java b/testData/ApiCreator/OverrideMethod.java new file mode 100644 index 0000000..fbffdc3 --- /dev/null +++ b/testData/ApiCreator/OverrideMethod.java @@ -0,0 +1,22 @@ +package com.example.creation; + +import android.app.Activity; +import android.os.Bundle; + +public class MainActivity extends Activity { + <caret> + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + } + + @Override + public void onStart() { + super.onStart(); + } + + @Override + public void onStop() { + super.onStop(); + } +} diff --git a/testData/ApiCreator/OverrideMethod_after.java b/testData/ApiCreator/OverrideMethod_after.java new file mode 100644 index 0000000..10af3d9 --- /dev/null +++ b/testData/ApiCreator/OverrideMethod_after.java @@ -0,0 +1,70 @@ +package com.example.creation; + +import android.app.Activity; +import android.net.Uri; +import android.os.Bundle; + +import com.google.android.gms.appindexing.Action; +import com.google.android.gms.appindexing.AppIndex; +import com.google.android.gms.common.api.GoogleApiClient; + +public class MainActivity extends Activity { + + /** + * ATTENTION: This was auto-generated to implement the App Indexing API. + * See https://g.co/AppIndexing/AndroidStudio for more information. + */ + private GoogleApiClient client; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + // ATTENTION: This was auto-generated to implement the App Indexing API. + // See https://g.co/AppIndexing/AndroidStudio for more information. + client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build(); + } + + @Override + public void onStart() { + super.onStart(); + + // ATTENTION: This was auto-generated to implement the App Indexing API. + // See https://g.co/AppIndexing/AndroidStudio for more information. + client.connect(); + // ATTENTION: This was auto-generated to implement the App Indexing API. + // See https://g.co/AppIndexing/AndroidStudio for more information. + Action viewAction = Action.newAction( + Action.TYPE_VIEW,// TODO: choose an action type. + "Main Page",// TODO: Define a title for the content shown. + // TODO: If you have web page content that matches this app activity's content, + // make sure this auto-generated web page URL is correct. + // Otherwise, set the URL to null. + Uri.parse("http://www.example.com/main"), + // TODO: Make sure this auto-generated app deep link URI is correct. + Uri.parse("android-app://com.example.creation/http/www.example.com/main") + ); + AppIndex.AppIndexApi.start(client, viewAction); + } + + @Override + public void onStop() { + super.onStop(); + + // ATTENTION: This was auto-generated to implement the App Indexing API. + // See https://g.co/AppIndexing/AndroidStudio for more information. + Action viewAction = Action.newAction( + Action.TYPE_VIEW,// TODO: choose an action type. + "Main Page",// TODO: Define a title for the content shown. + // TODO: If you have web page content that matches this app activity's content, + // make sure this auto-generated web page URL is correct. + // Otherwise, set the URL to null. + Uri.parse("http://www.example.com/main"), + // TODO: Make sure this auto-generated app deep link URI is correct. + Uri.parse("android-app://com.example.creation/http/www.example.com/main") + ); + AppIndex.AppIndexApi.end(client, viewAction); + // ATTENTION: This was auto-generated to implement the App Indexing API. + // See https://g.co/AppIndexing/AndroidStudio for more information. + client.disconnect(); + } +} diff --git a/testData/ApiCreator/SpecialStatement.java b/testData/ApiCreator/SpecialStatement.java new file mode 100644 index 0000000..99503c9 --- /dev/null +++ b/testData/ApiCreator/SpecialStatement.java @@ -0,0 +1,66 @@ +package com.example.creation; + +import android.app.Activity; +import android.net.Uri; +import android.os.Bundle; + +import com.google.android.gms.appindexing.Action; +import com.google.android.gms.appindexing.AppIndex; +import com.google.android.gms.common.api.GoogleApiClient; +import com.google.android.gms.common.api.PendingResult; +import com.google.android.gms.common.api.Status; + +public class MainActivity extends Activity { + <caret> + private GoogleApiClient client; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build(); + } + + @Override + public void onStart() { + super.onStart(); + + Action viewAction = Action.newAction( + Action.TYPE_VIEW, + "Main Page", + Uri.parse("http://www.example.com/main"), + Uri.parse("android-app://com.example.creation/http/www.example.com/main") + ); + int b = 1; + switch(b) { + case 1: + b ++; + default: + PendingResult<Status> a = AppIndex.AppIndexApi.start(client, viewAction); + client.connect(); + } + } + + @Override + public void onStop() { + super.onStop(); + + Action viewAction = Action.newAction( + Action.TYPE_VIEW, + "Main Page", + Uri.parse("http://www.example.com/main"), + Uri.parse("android-app://com.example.creation/http/www.example.com/main") + ); + int b = 1; + boolean c= true; + try { + } catch (Exception e) { + } finally { + while (b-- > 0) + if (c) { + AppIndex.AppIndexApi.end(client, viewAction); + } + client.disconnect(); + } + } +} diff --git a/testData/ApiCreator/WildCardImports.java b/testData/ApiCreator/WildCardImports.java new file mode 100644 index 0000000..1b0e783 --- /dev/null +++ b/testData/ApiCreator/WildCardImports.java @@ -0,0 +1,10 @@ +package com.example.creation; + +import android.app.Activity; + +import com.google.android.gms.appindexing.*; +import com.google.android.gms.common.api.*; + +public class MainActivity extends Activity { + <caret> +} diff --git a/testData/ApiCreator/WildCardImports_after.java b/testData/ApiCreator/WildCardImports_after.java new file mode 100644 index 0000000..6f1d3cd --- /dev/null +++ b/testData/ApiCreator/WildCardImports_after.java @@ -0,0 +1,65 @@ +package com.example.creation; + +import android.app.Activity; +import android.net.Uri; +import android.os.Bundle; + +import com.google.android.gms.appindexing.*; +import com.google.android.gms.common.api.*; + +public class MainActivity extends Activity { + + /** + * ATTENTION: This was auto-generated to implement the App Indexing API. + * See https://g.co/AppIndexing/AndroidStudio for more information. + */ + private GoogleApiClient client; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + // ATTENTION: This was auto-generated to implement the App Indexing API. + // See https://g.co/AppIndexing/AndroidStudio for more information. + client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build(); + } + + @Override + public void onStart() { + super.onStart(); + + // ATTENTION: This was auto-generated to implement the App Indexing API. + // See https://g.co/AppIndexing/AndroidStudio for more information. + client.connect(); + Action viewAction = Action.newAction( + Action.TYPE_VIEW,// TODO: choose an action type. + "Main Page",// TODO: Define a title for the content shown. + // TODO: If you have web page content that matches this app activity's content, + // make sure this auto-generated web page URL is correct. + // Otherwise, set the URL to null. + Uri.parse("http://www.example.com/main"), + // TODO: Make sure this auto-generated app deep link URI is correct. + Uri.parse("android-app://com.example.creation/http/www.example.com/main") + ); + AppIndex.AppIndexApi.start(client, viewAction); + } + + @Override + public void onStop() { + super.onStop(); + + // ATTENTION: This was auto-generated to implement the App Indexing API. + // See https://g.co/AppIndexing/AndroidStudio for more information. + Action viewAction = Action.newAction( + Action.TYPE_VIEW,// TODO: choose an action type. + "Main Page",// TODO: Define a title for the content shown. + // TODO: If you have web page content that matches this app activity's content, + // make sure this auto-generated web page URL is correct. + // Otherwise, set the URL to null. + Uri.parse("http://www.example.com/main"), + // TODO: Make sure this auto-generated app deep link URI is correct. + Uri.parse("android-app://com.example.creation/http/www.example.com/main") + ); + AppIndex.AppIndexApi.end(client, viewAction); + client.disconnect(); + } +} diff --git a/testData/ApiCreator/build.gradle b/testData/ApiCreator/build.gradle new file mode 100644 index 0000000..02c954f --- /dev/null +++ b/testData/ApiCreator/build.gradle @@ -0,0 +1,12 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 22 + buildToolsVersion "22.0.1" +} + +dependencies { + compile fileTree(dir: 'libs', include: ['*.jar']) + testCompile 'junit:junit:4.12' + compile 'com.android.support:appcompat-v7:22.2.1' +} diff --git a/testData/ApiCreator/build_after.gradle b/testData/ApiCreator/build_after.gradle new file mode 100644 index 0000000..4c6042f --- /dev/null +++ b/testData/ApiCreator/build_after.gradle @@ -0,0 +1,13 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 22 + buildToolsVersion "22.0.1" +} + +dependencies { + compile fileTree(dir: 'libs', include: ['*.jar']) + testCompile 'junit:junit:4.12' + compile 'com.android.support:appcompat-v7:22.2.1' + compile 'com.google.android.gms:play-services-appindexing:8.1.0' +} diff --git a/testData/ApiCreator/caret_not_in_java_file.xml b/testData/ApiCreator/caret_not_in_java_file.xml new file mode 100644 index 0000000..a2d42d6 --- /dev/null +++ b/testData/ApiCreator/caret_not_in_java_file.xml @@ -0,0 +1,2 @@ +<?xml version="1.0" encoding="utf-8"?> +<caret> diff --git a/testData/ApiCreator/has_app_indexing_dependency.gradle b/testData/ApiCreator/has_app_indexing_dependency.gradle new file mode 100644 index 0000000..4c6042f --- /dev/null +++ b/testData/ApiCreator/has_app_indexing_dependency.gradle @@ -0,0 +1,13 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 22 + buildToolsVersion "22.0.1" +} + +dependencies { + compile fileTree(dir: 'libs', include: ['*.jar']) + testCompile 'junit:junit:4.12' + compile 'com.android.support:appcompat-v7:22.2.1' + compile 'com.google.android.gms:play-services-appindexing:8.1.0' +} diff --git a/testData/ApiCreator/has_gms_tag.xml b/testData/ApiCreator/has_gms_tag.xml new file mode 100644 index 0000000..d62cf28 --- /dev/null +++ b/testData/ApiCreator/has_gms_tag.xml @@ -0,0 +1,30 @@ +<?xml version="1.0" encoding="utf-8"?> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.example.creation"> + <application + android:allowBackup="true" + android:icon="@mipmap/ic_launcher"> + <activity + android:name=".AnotherActivity" + android:label="@string/app_name" > + </activity> + <activity + android:name=".MainActivity" + android:label="@string/app_name" > + <intent-filter> + <action android:name="android.intent.action.VIEW" /> + <category android:name="android.intent.category.DEFAULT" /> + <category android:name="android.intent.category.BROWSABLE" /> + <data + android:host="www.example.com" + android:pathPrefix="/main" + android:scheme="http" /> + </intent-filter> + </activity> + <!-- ATTENTION: This was auto-generated to add Google Play services to your project for + App Indexing. See https://g.co/AppIndexing/AndroidStudio for more information. --> + <meta-data + android:name="com.google.android.gms.version" + android:value="@integer/google_play_services_version" /> + </application> +</manifest> diff --git a/testData/ApiCreator/low_version_app_indexing_dependency.gradle b/testData/ApiCreator/low_version_app_indexing_dependency.gradle new file mode 100644 index 0000000..18af462 --- /dev/null +++ b/testData/ApiCreator/low_version_app_indexing_dependency.gradle @@ -0,0 +1,13 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 22 + buildToolsVersion "22.0.1" +} + +dependencies { + compile fileTree(dir: 'libs', include: ['*.jar']) + testCompile 'junit:junit:4.12' + compile 'com.android.support:appcompat-v7:22.2.1' + compile 'com.google.android.gms:play-services-appindexing:6.5.0' +} diff --git a/testData/ApiCreator/low_version_app_indexing_dependency_after.gradle b/testData/ApiCreator/low_version_app_indexing_dependency_after.gradle new file mode 100644 index 0000000..4c6042f --- /dev/null +++ b/testData/ApiCreator/low_version_app_indexing_dependency_after.gradle @@ -0,0 +1,13 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 22 + buildToolsVersion "22.0.1" +} + +dependencies { + compile fileTree(dir: 'libs', include: ['*.jar']) + testCompile 'junit:junit:4.12' + compile 'com.android.support:appcompat-v7:22.2.1' + compile 'com.google.android.gms:play-services-appindexing:8.1.0' +} diff --git a/testData/ApiCreator/low_version_play_services_dependency.gradle b/testData/ApiCreator/low_version_play_services_dependency.gradle new file mode 100644 index 0000000..49b474e --- /dev/null +++ b/testData/ApiCreator/low_version_play_services_dependency.gradle @@ -0,0 +1,13 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 22 + buildToolsVersion "22.0.1" +} + +dependencies { + compile fileTree(dir: 'libs', include: ['*.jar']) + testCompile 'junit:junit:4.12' + compile 'com.android.support:appcompat-v7:22.2.1' + compile 'com.google.android.gms:play-services:6.5.0' +} diff --git a/testData/ApiCreator/low_version_play_services_dependency_after.gradle b/testData/ApiCreator/low_version_play_services_dependency_after.gradle new file mode 100644 index 0000000..7b26800 --- /dev/null +++ b/testData/ApiCreator/low_version_play_services_dependency_after.gradle @@ -0,0 +1,13 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 22 + buildToolsVersion "22.0.1" +} + +dependencies { + compile fileTree(dir: 'libs', include: ['*.jar']) + testCompile 'junit:junit:4.12' + compile 'com.android.support:appcompat-v7:22.2.1' + compile 'com.google.android.gms:play-services:8.1.0' +} diff --git a/testSrc/com/google/appindexing/api/ApiCreatorTest.java b/testSrc/com/google/appindexing/api/ApiCreatorTest.java new file mode 100644 index 0000000..36dde7b --- /dev/null +++ b/testSrc/com/google/appindexing/api/ApiCreatorTest.java @@ -0,0 +1,391 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.appindexing.api; + +import com.google.common.base.CharMatcher; +import com.google.common.base.Splitter; + +import com.intellij.codeInsight.template.impl.TemplateManagerImpl; +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.application.PathManager; +import com.intellij.openapi.command.CommandProcessor; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.psi.PsiFile; +import com.intellij.psi.PsiManager; +import com.intellij.psi.codeStyle.CodeStyleSettings; +import com.intellij.psi.codeStyle.CodeStyleSettingsManager; +import com.intellij.psi.xml.XmlFile; +import org.jetbrains.android.AndroidTestCase; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public class ApiCreatorTest extends AndroidTestCase { + private static final String BASE_PATH = PathManager.getHomePath() + "/../studio/google/appindexing/testData/ApiCreator"; + + private static final String ANDROID_MANIFEST = "AndroidManifest.xml"; + private static final String ANDROID_MANIFEST_AFTER = "AndroidManifest_after.xml"; + private static final String ANDROID_MANIFEST_HAS_GMS_TAG = "has_gms_tag.xml"; + private static final String BUILD_GRADLE = "build.gradle"; + private static final String BUILD_GRADLE_AFTER = "build_after.gradle"; + private static final String BUILD_GRADLE_HAS_APP_INDEXING_DEPENDENCY = "has_app_indexing_dependency.gradle"; + private static final String BUILD_GRADLE_LOW_VERSION_APP_INDEXING_DEPENDENCY = "low_version_app_indexing_dependency.gradle"; + private static final String BUILD_GRADLE_LOW_VERSION_APP_INDEXING_DEPENDENCY_AFTER = "low_version_app_indexing_dependency_after.gradle"; + private static final String BUILD_GRADLE_LOW_VERSION_PLAY_SERVICES_DEPENDENCY = "low_version_play_services_dependency.gradle"; + private static final String BUILD_GRADLE_LOW_VERSION_PLAY_SERVICES_DEPENDENCY_AFTER = "low_version_play_services_dependency_after.gradle"; + private static final String CARET_NOT_IN_JAVA_FILE = "caret_not_in_java_file.xml"; + private static final String JAVA_FILE_CARET_OUTSIDE_ACTIVITY = "CaretOutsideActivity.java"; + private static final String JAVA_FILE_NOT_ACTIVITY = "NotActivity.java"; + private static final String JAVA_FILE_HAS_APP_INDEXING_START_AND_END = "HasAppIndexingStartAndEnd.java"; + private static final String JAVA_FILE_HAS_APP_INDEXING_VIEW_AND_VIEW_END = "HasAppIndexingViewAndViewEnd.java"; + private static final String JAVA_FILE_SPECIAL_STATEMENT = "SpecialStatement.java"; + private static final String JAVA_FILE_EMPTY_ACTIVITY = "EmptyActivity.java"; + private static final String JAVA_FILE_EMPTY_ACTIVITY_AFTER = "EmptyActivity_after.java"; + private static final String JAVA_FILE_CONFLICT_IMPORTS = "ConflictImports.java"; + private static final String JAVA_FILE_CONFLICT_IMPORTS_AFTER = "ConflictImports_after.java"; + private static final String JAVA_FILE_WILD_CARD_IMPORTS = "WildCardImports.java"; + private static final String JAVA_FILE_WILD_CARD_IMPORTS_AFTER = "WildCardImports_after.java"; + private static final String JAVA_FILE_ONLY_START_CALL_AND_ADJUST_CLIENT_FIELD_INITIALIZER = + "OnlyStartCallAndAdjustClientFieldInitializer.java"; + private static final String JAVA_FILE_ONLY_START_CALL_AND_ADJUST_CLIENT_FIELD_INITIALIZER_AFTER = + "OnlyStartCallAndAdjustClientFieldInitializer_after.java"; + private static final String JAVA_FILE_ONLY_END_CALL_AND_ADJUST_CLIENT_INITIALIZING_STATEMENT = + "OnlyEndCallAndAdjustClientInitializingStatement.java"; + private static final String JAVA_FILE_ONLY_END_CALL_AND_ADJUST_CLIENT_INITIALIZING_STATEMENT_AFTER = + "OnlyEndCallAndAdjustClientInitializingStatement_after.java"; + private static final String JAVA_FILE_ONLY_VIEW_CALL = "OnlyViewCall.java"; + private static final String JAVA_FILE_ONLY_VIEW_CALL_AFTER = "OnlyViewCall_after.java"; + private static final String JAVA_FILE_ONLY_VIEW_END_CALL = "OnlyViewEndCall.java"; + private static final String JAVA_FILE_ONLY_VIEW_END_CALL_AFTER = "OnlyViewEndCall_after.java"; + private static final String JAVA_FILE_ACTION_NOT_INITIALIZED = "ActionNotInitialized.java"; + private static final String JAVA_FILE_ACTION_NOT_INITIALIZED_AFTER = "ActionNotInitialized_after.java"; + private static final String JAVA_FILE_CLIENT_FIELD = "ClientField.java"; + private static final String JAVA_FILE_CLIENT_FIELD_AFTER = "ClientField_after.java"; + private static final String JAVA_FILE_CLIENT_LOCAL_VARIABLE = "ClientLocalVariable.java"; + private static final String JAVA_FILE_CLIENT_LOCAL_VARIABLE_FIELD_AFTER = "ClientLocalVariable_after.java"; + private static final String JAVA_FILE_CLIENT_NOT_INITIALIZED = "ClientNotInitialized.java"; + private static final String JAVA_FILE_CLIENT_NOT_INITIALIZED_AFTER = "ClientNotInitialized_after.java"; + private static final String JAVA_FILE_CLIENT_INITIALIZED_WITHOUT_BUILDER = "ClientInitializedWithoutBuilder.java"; + private static final String JAVA_FILE_CLIENT_INITIALIZED_WITHOUT_BUILDER_AFTER = "ClientInitializedWithoutBuilder_after.java"; + private static final String JAVA_FILE_CLIENT_IN_DECLARATION_STATEMENT = "ClientInDeclarationStatement.java"; + private static final String JAVA_FILE_CLIENT_IN_DECLARATION_STATEMENT_AFTER = "ClientInDeclarationStatement_after.java"; + private static final String JAVA_FILE_OVERRIDE_METHOD = "OverrideMethod.java"; + private static final String JAVA_FILE_OVERRIDE_METHOD_AFTER = "OverrideMethod_after.java"; + private static final String JAVA_FILE_NO_KEYWORD_SUPER = "NoKeywordSuper.java"; + private static final String JAVA_FILE_NO_KEYWORD_SUPER_AFTER = "NoKeywordSuper_after.java"; + private static final String ACTION_WITH_NULL_DEEP_LINK = + "com.google.android.gms.appindexing.Action viewAction = com.google.android.gms.appindexing.Action.newAction(\n" + + " com.google.android.gms.appindexing.Action.TYPE_VIEW, // TODO: choose an action type.\n" + + " \"Main Page\", // TODO: Define a title for the content shown.\n" + + " // TODO: If you have web page content that matches this app activity's content,\n" + + " // make sure this auto-generated web page URL is correct.\n" + + " // Otherwise, set the URL to null.\n" + + " android.net.Uri.parse(\"http://host/path\"), \n" + + " // TODO: Make sure this auto-generated app deep link URI is correct.\n" + + " android.net.Uri.parse(\"android-app://com.example.creation/http/host/path\")\n" + + ");"; + private static final String ACTION_WITH_SCHEME_ONLY = ACTION_WITH_NULL_DEEP_LINK; + private static final String ACTION_WITHOUT_PATH = + "com.google.android.gms.appindexing.Action viewAction = com.google.android.gms.appindexing.Action.newAction(\n" + + " com.google.android.gms.appindexing.Action.TYPE_VIEW, // TODO: choose an action type.\n" + + " \"Main Page\", // TODO: Define a title for the content shown.\n" + + " // TODO: If you have web page content that matches this app activity's content,\n" + + " // make sure this auto-generated web page URL is correct.\n" + + " // Otherwise, set the URL to null.\n" + + " android.net.Uri.parse(\"http://www.example.com/path\"), \n" + + " // TODO: Make sure this auto-generated app deep link URI is correct.\n" + + " android.net.Uri.parse(\"android-app://com.example.creation/http/www.example.com/path\")\n" + + ");"; + + public ApiCreatorTest() { + super(false); + } + + @Override + public void setUp() throws Exception { + super.setUp(); + myFixture.setTestDataPath(BASE_PATH); + TemplateManagerImpl.setTemplateTesting(getProject(), getTestRootDisposable()); + // Set an empty temporary code style. Otherwise, the variable name will follow users' custom setting. + CodeStyleSettings codeStyleSettings = CodeStyleSettingsManager.getSettings(myFixture.getProject()); + codeStyleSettings.clearCodeStyleSettings(); + CodeStyleSettingsManager.getInstance().setTemporarySettings(codeStyleSettings); + } + + @Override + public void tearDown() throws Exception { + super.tearDown(); + CodeStyleSettingsManager.getInstance().dropTemporarySettings(); + } + + public void testNoAppIndexingDependencyInGradle() throws Exception { + doGradleFileTest(BUILD_GRADLE, BUILD_GRADLE_AFTER, null, true); + } + + public void testHasAppIndexingDependencyInGradle() throws Exception { + doGradleFileTest(BUILD_GRADLE_HAS_APP_INDEXING_DEPENDENCY, BUILD_GRADLE_AFTER, "8.1.0", false); + } + + public void testLowVersionAppIndexingDependencyInGradle() throws Exception { + doGradleFileTest(BUILD_GRADLE_LOW_VERSION_APP_INDEXING_DEPENDENCY, BUILD_GRADLE_LOW_VERSION_APP_INDEXING_DEPENDENCY_AFTER, "6.5.0", + true); + } + + public void testLowVersionPlayServicesDependencyInGradle() throws Exception { + doGradleFileTest(BUILD_GRADLE_LOW_VERSION_PLAY_SERVICES_DEPENDENCY, BUILD_GRADLE_LOW_VERSION_PLAY_SERVICES_DEPENDENCY_AFTER, "6.5.0", + true); + } + + + public void testNoGmsTagInAndroidManifest() throws Exception { + doManifestFileTest(ANDROID_MANIFEST, ANDROID_MANIFEST_AFTER); + } + + public void testHasGmsTagInAndroidManifest() throws Exception { + doManifestFileTest(ANDROID_MANIFEST_HAS_GMS_TAG, ANDROID_MANIFEST_AFTER); + } + + public void testCaretInAndroidManifest() throws Exception { + doEnableTest(CARET_NOT_IN_JAVA_FILE, false); + } + + public void testCaretOutsideActivity() throws Exception { + doEnableTest(JAVA_FILE_CARET_OUTSIDE_ACTIVITY, false); + } + + public void testClassNotInheritActivity() throws Exception { + doEnableTest(JAVA_FILE_NOT_ACTIVITY, false); + } + + public void testHasAppIndexingApiStartAndEnd() throws Exception { + doEnableTest(JAVA_FILE_HAS_APP_INDEXING_START_AND_END, false); + } + + public void testHasAppIndexingApiViewAndViewEnd() throws Exception { + doEnableTest(JAVA_FILE_HAS_APP_INDEXING_VIEW_AND_VIEW_END, false); + } + + /** + * The app indexing APIs are used in special statements, + * such as block statements, declaration statements and loop statement. + */ + public void testSpecialStatement() throws Exception { + doEnableTest(JAVA_FILE_SPECIAL_STATEMENT, false); + } + + + public void testEmptyActivity() throws Exception { + doJavaFileTest(JAVA_FILE_EMPTY_ACTIVITY, JAVA_FILE_EMPTY_ACTIVITY_AFTER); + } + + public void testConflictImports() throws Exception { + doJavaFileTest(JAVA_FILE_CONFLICT_IMPORTS, JAVA_FILE_CONFLICT_IMPORTS_AFTER); + } + + public void testWildCardImports() throws Exception { + doJavaFileTest(JAVA_FILE_WILD_CARD_IMPORTS, JAVA_FILE_WILD_CARD_IMPORTS_AFTER); + } + + public void testOnlyAppIndexingStartAndAdjustGoogleApiClientFieldInitializer() throws Exception { + doJavaFileTest(JAVA_FILE_ONLY_START_CALL_AND_ADJUST_CLIENT_FIELD_INITIALIZER, + JAVA_FILE_ONLY_START_CALL_AND_ADJUST_CLIENT_FIELD_INITIALIZER_AFTER); + } + + public void testOnlyAppIndexingEndAndAdjustClientInitializingStatement() throws Exception { + doJavaFileTest(JAVA_FILE_ONLY_END_CALL_AND_ADJUST_CLIENT_INITIALIZING_STATEMENT, + JAVA_FILE_ONLY_END_CALL_AND_ADJUST_CLIENT_INITIALIZING_STATEMENT_AFTER); + } + + public void testOnlyAppIndexingView() throws Exception { + doJavaFileTest(JAVA_FILE_ONLY_VIEW_CALL, JAVA_FILE_ONLY_VIEW_CALL_AFTER); + } + + public void testOnlyAppIndexingViewEnd() throws Exception { + doJavaFileTest(JAVA_FILE_ONLY_VIEW_END_CALL, JAVA_FILE_ONLY_VIEW_END_CALL_AFTER); + } + + public void testGoogleApiActionNotInitialized() throws Exception { + doJavaFileTest(JAVA_FILE_ACTION_NOT_INITIALIZED, JAVA_FILE_ACTION_NOT_INITIALIZED_AFTER); + } + + public void testWithGoogleApiClientField() throws Exception { + doJavaFileTest(JAVA_FILE_CLIENT_FIELD, JAVA_FILE_CLIENT_FIELD_AFTER); + } + + public void testWithGoogleApiClientLocalVariable() throws Exception { + doJavaFileTest(JAVA_FILE_CLIENT_LOCAL_VARIABLE, JAVA_FILE_CLIENT_LOCAL_VARIABLE_FIELD_AFTER); + } + + public void testGoogleApiClientNotInitialized() throws Exception { + doJavaFileTest(JAVA_FILE_CLIENT_NOT_INITIALIZED, JAVA_FILE_CLIENT_NOT_INITIALIZED_AFTER); + } + + public void testGoogleApiClientInitializedWithoutBuilder() throws Exception { + doJavaFileTest(JAVA_FILE_CLIENT_INITIALIZED_WITHOUT_BUILDER, JAVA_FILE_CLIENT_INITIALIZED_WITHOUT_BUILDER_AFTER); + } + + public void testGetGoogleApiClientFromDeclarationStatement() throws Exception { + doJavaFileTest(JAVA_FILE_CLIENT_IN_DECLARATION_STATEMENT, JAVA_FILE_CLIENT_IN_DECLARATION_STATEMENT_AFTER); + } + + public void testWithOverridingMethod() throws Exception { + doJavaFileTest(JAVA_FILE_OVERRIDE_METHOD, JAVA_FILE_OVERRIDE_METHOD_AFTER); + } + + /** + * Tests class with overriding method but not invoking overridden method through keyword super + */ + public void testNoKeywordSuper() throws Exception { + doJavaFileTest(JAVA_FILE_NO_KEYWORD_SUPER, JAVA_FILE_NO_KEYWORD_SUPER_AFTER); + } + + public void testGenerateActionInitializerWithIncompleteDeepLink() throws Exception { + myFixture.configureByFiles(JAVA_FILE_EMPTY_ACTIVITY); + ApiCreator creator = new ApiCreator(myFixture.getProject(), myFixture.getEditor(), myFixture.getFile()); + assertEquals(creator.getActionStatement(null, "viewAction"), ACTION_WITH_NULL_DEEP_LINK); + assertEquals(creator.getActionStatement("http://", "viewAction"), ACTION_WITH_SCHEME_ONLY); + assertEquals(creator.getActionStatement("http://www.example.com", "viewAction"), ACTION_WITHOUT_PATH); + } + + /** + * Tests whether the project is eligible for App Indexing API code inserting. + * + * @param filePath The path of the Java source file. + * @param enable If the creator (generator / intention) should be enabled. + */ + private void doEnableTest(@NotNull String filePath, boolean enable) { + myFixture.configureByFiles(filePath); + assertEquals(ApiCreator.eligibleForInsertingAppIndexingApiCode(myFixture.getEditor(), myFixture.getFile()), enable); + } + + /** + * Test for creation in Java source file. + */ + private void doJavaFileTest(@NotNull String testFilePath, @NotNull String expectedFilePath) { + doEnableTest(testFilePath, true); + myFixture.copyFileToProject(ANDROID_MANIFEST); + final ApiCreator creator = new ApiCreator(myFixture.getProject(), myFixture.getEditor(), myFixture.getFile()); + CommandProcessor.getInstance().executeCommand(null, new Runnable() { + @Override + public void run() { + ApplicationManager.getApplication().runWriteAction(new Runnable() { + @Override + public void run() { + creator.insertAppIndexingApiCodeInJavaFile(creator.getDeepLinkOfActivity(), false); + } + }); + } + }, null, null); + VirtualFile expectedFile = myFixture.copyFileToProject(expectedFilePath); + PsiFile expectedPsiFile = PsiManager.getInstance(myFixture.getProject()).findFile(expectedFile); + assertNotNull(expectedPsiFile); + String normalizedTestFile = getNormalizedContent(myFixture.getFile()).replace("<caret>", ""); + assertEquals(normalizedTestFile, getNormalizedContent(expectedPsiFile)); + } + + /** + * Test for creation in build.gradle file. + */ + private void doGradleFileTest(@NotNull String testFilePath, + @NotNull String expectedFilePath, + @Nullable final String version, + final boolean needSync) { + VirtualFile testVirtual = myFixture.copyFileToProject(testFilePath, getGradleRelativePath()); + myFixture.configureByFile(JAVA_FILE_EMPTY_ACTIVITY); // This file is not used. It's for opening editor. + + final ApiCreator creator = new ApiCreator(myFixture.getProject(), myFixture.getEditor(), myFixture.getFile()); + creator.setGmsLibVersion(version); + CommandProcessor.getInstance().executeCommand(null, new Runnable() { + @Override + public void run() { + ApplicationManager.getApplication().runWriteAction(new Runnable() { + @Override + public void run() { + try { + assertEquals(creator.insertGmsCompileDependencyInGradleIfNeeded(), needSync); + } + catch (ApiCreator.ApiCreatorException e) { + e.printStackTrace(); + fail(); + } + } + }); + } + }, null, null); + + PsiFile testPsi = PsiManager.getInstance(myFixture.getProject()).findFile(testVirtual); + PsiFile expectedPsi = myFixture.configureByFile(expectedFilePath); + assertNotNull(testPsi); + assertEquals(getNormalizedContent(testPsi), getNormalizedContent(expectedPsi)); + } + + /** + * Test for creation in AndroidManifest.xml file. + */ + private void doManifestFileTest(@NotNull String testFilePath, @NotNull String expectedFilePath) { + PsiFile[] files = myFixture.configureByFiles(testFilePath, expectedFilePath); + final ApiCreator creator = new ApiCreator(myFixture.getProject(), myFixture.getEditor(), myFixture.getFile()); + CommandProcessor.getInstance().executeCommand(null, new Runnable() { + @Override + public void run() { + ApplicationManager.getApplication().runWriteAction(new Runnable() { + @Override + public void run() { + assertTrue(myFixture.getFile() instanceof XmlFile); + creator.insertGmsVersionTagInManifestIfNeeded((XmlFile)myFixture.getFile()); + } + }); + } + }, null, null); + assertEquals(getNormalizedContent(myFixture.getFile()), getNormalizedContent(files[1])); + } + + /** + * Normalizes file content: remove java.lang imports, comments, white space and line terminators. + * + * @param file The file to normalize. + * @return The normalized content. + */ + protected static String getNormalizedContent(@NotNull final PsiFile file) { + StringBuilder stringBuilder = new StringBuilder(); + // Removes line terminators. + Iterable<String> lines = Splitter.onPattern("\r?\n").omitEmptyStrings().split(file.getText()); + for (String line : lines) { + line = CharMatcher.WHITESPACE.removeFrom(line); + // Removes import statements of classes from java.lang package if it is a Java file. + // Because Android Studio will automatically import them. + if (line.startsWith("importjava.lang.")) { + continue; + } + stringBuilder.append(line); + } + return stringBuilder.toString(); + } + + @NotNull + protected String getGradleRelativePath() { + StringBuilder builder = new StringBuilder(); + String projectPath = myFixture.getProject().getBasePath(); + while (projectPath != null && projectPath.contains("/")) { + projectPath = projectPath.substring(0, projectPath.lastIndexOf("/")); + builder.append("../"); + } + builder.deleteCharAt(builder.length() - 1); + String moduleFilePath = myModule.getModuleFilePath(); + builder.append(moduleFilePath.substring(0, moduleFilePath.lastIndexOf("/"))); + builder.append("/build.gradle"); + return builder.toString(); + } +} |