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

Improve kotlin support by allowing property access #393

Merged
merged 2 commits into from
Dec 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 49 additions & 49 deletions sdk/lint-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,39 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<issues format="4" by="lint 3.2.1" client="gradle" variant="all" version="3.2.1">

<issue
id="KotlinPropertyAccess"
message="This method should be called `getAutoCaptureSessions` such that `autoCaptureSessions` can be accessed as a property from Kotlin; see https://android.github.io/kotlin-guides/interop.html#property-prefixes"
errorLine1=" public boolean shouldAutoCaptureSessions() {"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/java/com/bugsnag/android/Configuration.java"
line="409"
column="20"/>
</issue>

<issue
id="KotlinPropertyAccess"
message="This getter should be public such that `codeBundleId` can be accessed as a property from Kotlin; see https://android.github.io/kotlin-guides/interop.html#property-prefixes"
errorLine1=" String getCodeBundleId() {"
errorLine2=" ~~~~~~~~~~~~~~~">
<location
file="src/main/java/com/bugsnag/android/Configuration.java"
line="558"
column="12"/>
</issue>

<issue
id="KotlinPropertyAccess"
message="This getter should be public such that `notifierType` can be accessed as a property from Kotlin; see https://android.github.io/kotlin-guides/interop.html#property-prefixes"
errorLine1=" String getNotifierType() {"
errorLine2=" ~~~~~~~~~~~~~~~">
<location
file="src/main/java/com/bugsnag/android/Configuration.java"
line="562"
column="12"/>
</issue>

<issue
id="UnknownNullness"
message="Unknown nullability; explicitly declare as `@Nullable` or `@NonNull` to improve Kotlin interoperability; see https://android.github.io/kotlin-guides/interop.html#nullability-annotations"
Expand Down Expand Up @@ -1152,7 +1119,7 @@
errorLine2=" ~~~~~~">
<location
file="src/main/java/com/bugsnag/android/Configuration.java"
line="546"
line="557"
column="33"/>
</issue>

Expand All @@ -1163,18 +1130,40 @@
errorLine2=" ~~~~~~">
<location
file="src/main/java/com/bugsnag/android/Configuration.java"
line="554"
line="565"
column="33"/>
</issue>

<issue
id="UnknownNullness"
message="Unknown nullability; explicitly declare as `@Nullable` or `@NonNull` to improve Kotlin interoperability; see https://android.github.io/kotlin-guides/interop.html#nullability-annotations"
errorLine1=" public String getCodeBundleId() {"
errorLine2=" ~~~~~~">
<location
file="src/main/java/com/bugsnag/android/Configuration.java"
line="569"
column="12"/>
</issue>

<issue
id="UnknownNullness"
message="Unknown nullability; explicitly declare as `@Nullable` or `@NonNull` to improve Kotlin interoperability; see https://android.github.io/kotlin-guides/interop.html#nullability-annotations"
errorLine1=" public String getNotifierType() {"
errorLine2=" ~~~~~~">
<location
file="src/main/java/com/bugsnag/android/Configuration.java"
line="573"
column="12"/>
</issue>

<issue
id="UnknownNullness"
message="Unknown nullability; explicitly declare as `@Nullable` or `@NonNull` to improve Kotlin interoperability; see https://android.github.io/kotlin-guides/interop.html#nullability-annotations"
errorLine1=" public Map&lt;String, String> getErrorApiHeaders() {"
errorLine2=" ~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/java/com/bugsnag/android/Configuration.java"
line="627"
line="638"
column="12"/>
</issue>

Expand All @@ -1185,7 +1174,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/java/com/bugsnag/android/Configuration.java"
line="640"
line="651"
column="12"/>
</issue>

Expand All @@ -1196,7 +1185,7 @@
errorLine2=" ~~~~~~~~~~">
<location
file="src/main/java/com/bugsnag/android/Configuration.java"
line="669"
line="680"
column="28"/>
</issue>

Expand All @@ -1207,7 +1196,7 @@
errorLine2=" ~~~~~~">
<location
file="src/main/java/com/bugsnag/android/Configuration.java"
line="681"
line="692"
column="51"/>
</issue>

Expand All @@ -1218,7 +1207,7 @@
errorLine2=" ~~~~~~">
<location
file="src/main/java/com/bugsnag/android/Configuration.java"
line="696"
line="707"
column="41"/>
</issue>

Expand All @@ -1229,7 +1218,7 @@
errorLine2=" ~~~~~~~~~~~~">
<location
file="src/main/java/com/bugsnag/android/Configuration.java"
line="710"
line="721"
column="33"/>
</issue>

Expand All @@ -1240,7 +1229,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/java/com/bugsnag/android/Configuration.java"
line="721"
line="732"
column="43"/>
</issue>

Expand All @@ -1251,7 +1240,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/java/com/bugsnag/android/Configuration.java"
line="750"
line="761"
column="15"/>
</issue>

Expand Down Expand Up @@ -1827,14 +1816,25 @@
column="44"/>
</issue>

<issue
id="UnknownNullness"
message="Unknown nullability; explicitly declare as `@Nullable` or `@NonNull` to improve Kotlin interoperability; see https://android.github.io/kotlin-guides/interop.html#nullability-annotations"
errorLine1=" public static void setBinaryArch(final String binaryArch) {"
errorLine2=" ~~~~~~">
<location
file="src/main/java/com/bugsnag/android/NativeInterface.java"
line="350"
column="44"/>
</issue>

<issue
id="UnknownNullness"
message="Unknown nullability; explicitly declare as `@Nullable` or `@NonNull` to improve Kotlin interoperability; see https://android.github.io/kotlin-guides/interop.html#nullability-annotations"
errorLine1=" public static String getAppVersion() {"
errorLine2=" ~~~~~~">
<location
file="src/main/java/com/bugsnag/android/NativeInterface.java"
line="350"
line="357"
column="19"/>
</issue>

Expand All @@ -1845,7 +1845,7 @@
errorLine2=" ~~~~~~~~">
<location
file="src/main/java/com/bugsnag/android/NativeInterface.java"
line="357"
line="364"
column="19"/>
</issue>

Expand All @@ -1856,7 +1856,7 @@
errorLine2=" ~~~~~~~~">
<location
file="src/main/java/com/bugsnag/android/NativeInterface.java"
line="364"
line="371"
column="47"/>
</issue>

Expand All @@ -1867,7 +1867,7 @@
errorLine2=" ~~~~~~">
<location
file="src/main/java/com/bugsnag/android/NativeInterface.java"
line="376"
line="383"
column="38"/>
</issue>

Expand All @@ -1878,7 +1878,7 @@
errorLine2=" ~~~~~~">
<location
file="src/main/java/com/bugsnag/android/NativeInterface.java"
line="376"
line="383"
column="59"/>
</issue>

Expand All @@ -1889,7 +1889,7 @@
errorLine2=" ~~~~~~~~">
<location
file="src/main/java/com/bugsnag/android/NativeInterface.java"
line="396"
line="403"
column="37"/>
</issue>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void testSetReleaseStage() throws Exception {
@Test
public void testSetAutoCaptureSessions() throws Exception {
client.setAutoCaptureSessions(true);
assertEquals(true, config.shouldAutoCaptureSessions());
assertEquals(true, config.getAutoCaptureSessions());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public void testFullManifestConfig() {
assertEquals(false, protoConfig.getSendThreads());
assertEquals(false, protoConfig.getEnableExceptionHandler());
assertEquals(true, protoConfig.getPersistUserBetweenSessions());
assertEquals(true, protoConfig.shouldAutoCaptureSessions());
assertEquals(true, protoConfig.getAutoCaptureSessions());
}

@SuppressWarnings("deprecation") // test backwards compatibility of client.setMaxBreadcrumbs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,23 @@ public void testEmptyNotifyEndpoint() {
public void testInvalidSessionEndpoint() {
//noinspection ConstantConditions
config.setEndpoints("http://example.com", null);
assertFalse(config.shouldAutoCaptureSessions());
assertFalse(config.getAutoCaptureSessions());
assertNull(config.getSessionEndpoint());

config.setEndpoints("http://example.com", "");
assertFalse(config.shouldAutoCaptureSessions());
assertFalse(config.getAutoCaptureSessions());
assertNull(config.getSessionEndpoint());

config.setEndpoints("http://example.com", "http://sessions.example.com");
assertFalse(config.shouldAutoCaptureSessions());
assertFalse(config.getAutoCaptureSessions());
assertEquals("http://sessions.example.com", config.getSessionEndpoint());
}

@Test
public void testAutoCaptureOverride() {
config.setAutoCaptureSessions(false);
config.setEndpoints("http://example.com", "http://example.com");
assertFalse(config.shouldAutoCaptureSessions());
assertFalse(config.getAutoCaptureSessions());
}

@SuppressWarnings("deprecation")
Expand Down Expand Up @@ -163,9 +163,9 @@ public void testLaunchThreshold() throws Exception {

@Test
public void testAutoCaptureSessions() throws Exception {
assertTrue(config.shouldAutoCaptureSessions());
assertTrue(config.getAutoCaptureSessions());
config.setAutoCaptureSessions(false);
assertFalse(config.shouldAutoCaptureSessions());
assertFalse(config.getAutoCaptureSessions());
}

@Test
Expand Down
15 changes: 13 additions & 2 deletions sdk/src/main/java/com/bugsnag/android/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,19 @@ public void setEnableExceptionHandler(boolean enableExceptionHandler) {
* Get whether or not User sessions are captured automatically.
*
* @return true if sessions are captured automatically
* @deprecated use {@link #getAutoCaptureSessions()}
*/
@Deprecated
public boolean shouldAutoCaptureSessions() {
return getAutoCaptureSessions();
}

/**
* Get whether or not User sessions are captured automatically.
*
* @return true if sessions are captured automatically
*/
public boolean getAutoCaptureSessions() {
return autoCaptureSessions;
}

Expand Down Expand Up @@ -555,11 +566,11 @@ public void setCodeBundleId(String codeBundleId) {
this.codeBundleId = codeBundleId;
}

String getCodeBundleId() {
public String getCodeBundleId() {
return codeBundleId;
}

String getNotifierType() {
public String getNotifierType() {
return notifierType;
}

Expand Down
2 changes: 1 addition & 1 deletion sdk/src/main/java/com/bugsnag/android/Error.java
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ static class Builder {
this.severityReasonType = HandledState.REASON_USER_SPECIFIED; // default

if (session != null
&& !config.shouldAutoCaptureSessions() && session.isAutoCaptured()) {
&& !config.getAutoCaptureSessions() && session.isAutoCaptured()) {
this.session = null;
} else {
this.session = session;
Expand Down
6 changes: 3 additions & 3 deletions sdk/src/main/java/com/bugsnag/android/SessionTracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class SessionTracker extends Observable implements Application.ActivityLifecycle
/**
* Starts a new session with the given date and user.
* <p>
* A session will only be created if {@link Configuration#shouldAutoCaptureSessions()} returns
* A session will only be created if {@link Configuration#getAutoCaptureSessions()} returns
* true.
*
* @param date the session start date
Expand Down Expand Up @@ -88,7 +88,7 @@ private void trackSessionIfNeeded(final Session session) {
boolean notifyForRelease = configuration.shouldNotifyForReleaseStage(getReleaseStage());

if (notifyForRelease
&& (configuration.shouldAutoCaptureSessions() || !session.isAutoCaptured())
&& (configuration.getAutoCaptureSessions() || !session.isAutoCaptured())
&& session.isTracked().compareAndSet(false, true)) {
try {
final String endpoint = configuration.getSessionEndpoint();
Expand Down Expand Up @@ -288,7 +288,7 @@ void updateForegroundTracker(String activityName, boolean activityStarting, long
//FUTURE:SM Race condition between isEmpty and put
if (foregroundActivities.isEmpty()
&& noActivityRunningForMs >= timeoutMs
&& configuration.shouldAutoCaptureSessions()) {
&& configuration.getAutoCaptureSessions()) {

activityFirstStartedAtMs.set(nowMs);
startNewSession(new Date(nowMs), client.getUser(), true);
Expand Down