Skip to content

Commit

Permalink
Filled out @nullable and @nonnull annotations throughout the library
Browse files Browse the repository at this point in the history
  • Loading branch information
EricKuck committed Nov 9, 2016
1 parent e0f40a9 commit 104d96e
Show file tree
Hide file tree
Showing 33 changed files with 322 additions and 247 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.0'
classpath 'com.android.tools.build:gradle:2.2.2'
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.ViewGroup;

import com.bluelinelabs.conductor.ControllerChangeHandler.ControllerChangeListener;
Expand All @@ -30,13 +31,13 @@ public final void setHost(@NonNull LifecycleHandler lifecycleHandler, @NonNull V
}
}

@Override
@Override @Nullable
public Activity getActivity() {
return lifecycleHandler != null ? lifecycleHandler.getLifecycleActivity() : null;
}

@Override
public void onActivityDestroyed(Activity activity) {
public void onActivityDestroyed(@NonNull Activity activity) {
super.onActivityDestroyed(activity);
lifecycleHandler = null;
}
Expand All @@ -49,37 +50,37 @@ public final void invalidateOptionsMenu() {
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
lifecycleHandler.onActivityResult(requestCode, resultCode, data);
}

@Override
void startActivity(Intent intent) {
void startActivity(@NonNull Intent intent) {
lifecycleHandler.startActivity(intent);
}

@Override
void startActivityForResult(String instanceId, Intent intent, int requestCode) {
void startActivityForResult(@NonNull String instanceId, @NonNull Intent intent, int requestCode) {
lifecycleHandler.startActivityForResult(instanceId, intent, requestCode);
}

@Override
void startActivityForResult(String instanceId, Intent intent, int requestCode, Bundle options) {
void startActivityForResult(@NonNull String instanceId, @NonNull Intent intent, int requestCode, @Nullable Bundle options) {
lifecycleHandler.startActivityForResult(instanceId, intent, requestCode, options);
}

@Override
void registerForActivityResult(String instanceId, int requestCode) {
void registerForActivityResult(@NonNull String instanceId, int requestCode) {
lifecycleHandler.registerForActivityResult(instanceId, requestCode);
}

@Override
void unregisterForActivityResults(String instanceId) {
void unregisterForActivityResults(@NonNull String instanceId) {
lifecycleHandler.unregisterForActivityResults(instanceId);
}

@Override
void requestPermissions(String instanceId, @NonNull String[] permissions, int requestCode) {
void requestPermissions(@NonNull String instanceId, @NonNull String[] permissions, int requestCode) {
lifecycleHandler.requestPermissions(instanceId, permissions, requestCode);
}

Expand All @@ -88,12 +89,12 @@ boolean hasHost() {
return lifecycleHandler != null;
}

@Override
@Override @NonNull
List<Router> getSiblingRouters() {
return lifecycleHandler.getRouters();
}

@Override
@Override @NonNull
Router getRootRouter() {
return this;
}
Expand Down
22 changes: 15 additions & 7 deletions conductor/src/main/java/com/bluelinelabs/conductor/Backstack.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.bluelinelabs.conductor;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import java.util.ArrayDeque;
import java.util.ArrayList;
Expand All @@ -24,20 +26,23 @@ public int size() {
return backStack.size();
}

@Nullable
public RouterTransaction root() {
return backStack.size() > 0 ? backStack.getLast() : null;
}

@Override
@Override @NonNull
public Iterator<RouterTransaction> iterator() {
return backStack.iterator();
}

@NonNull
public Iterator<RouterTransaction> reverseIterator() {
return backStack.descendingIterator();
}

public List<RouterTransaction> popTo(RouterTransaction transaction) {
@NonNull
public List<RouterTransaction> popTo(@NonNull RouterTransaction transaction) {
List<RouterTransaction> popped = new ArrayList<>();
if (backStack.contains(transaction)) {
while (backStack.peek() != transaction) {
Expand All @@ -50,24 +55,27 @@ public List<RouterTransaction> popTo(RouterTransaction transaction) {
return popped;
}

@NonNull
public RouterTransaction pop() {
RouterTransaction popped = backStack.pop();
popped.controller.destroy();
return popped;
}

@Nullable
public RouterTransaction peek() {
return backStack.peek();
}

public void remove(RouterTransaction transaction) {
public void remove(@NonNull RouterTransaction transaction) {
backStack.removeFirstOccurrence(transaction);
}

public void push(RouterTransaction transaction) {
public void push(@NonNull RouterTransaction transaction) {
backStack.push(transaction);
}

@NonNull
public List<RouterTransaction> popAll() {
List<RouterTransaction> list = new ArrayList<>();
while (!isEmpty()) {
Expand All @@ -76,7 +84,7 @@ public List<RouterTransaction> popAll() {
return list;
}

public void setBackstack(List<RouterTransaction> backstack) {
public void setBackstack(@NonNull List<RouterTransaction> backstack) {
for (RouterTransaction existingTransaction : backStack) {
boolean contains = false;
for (RouterTransaction newTransaction : backstack) {
Expand All @@ -97,7 +105,7 @@ public void setBackstack(List<RouterTransaction> backstack) {
}
}

public void saveInstanceState(Bundle outState) {
public void saveInstanceState(@NonNull Bundle outState) {
ArrayList<Bundle> entryBundles = new ArrayList<>(backStack.size());
for (RouterTransaction entry : backStack) {
entryBundles.add(entry.saveInstanceState());
Expand All @@ -106,7 +114,7 @@ public void saveInstanceState(Bundle outState) {
outState.putParcelableArrayList(KEY_ENTRIES, entryBundles);
}

public void restoreInstanceState(Bundle savedInstanceState) {
public void restoreInstanceState(@NonNull Bundle savedInstanceState) {
ArrayList<Bundle> entryBundles = savedInstanceState.getParcelableArrayList(KEY_ENTRIES);
if (entryBundles != null) {
Collections.reverse(entryBundles);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.ViewGroup;
Expand Down Expand Up @@ -42,12 +44,12 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
}

@Override
public void onChangeStarted(Controller to, Controller from, boolean isPush, ViewGroup container, ControllerChangeHandler handler) {
public void onChangeStarted(@Nullable Controller to, @Nullable Controller from, boolean isPush, @NonNull ViewGroup container, @NonNull ControllerChangeHandler handler) {
inProgressTransactionCount++;
}

@Override
public void onChangeCompleted(Controller to, Controller from, boolean isPush, ViewGroup container, ControllerChangeHandler handler) {
public void onChangeCompleted(@Nullable Controller to, @Nullable Controller from, boolean isPush, @NonNull ViewGroup container, @NonNull ControllerChangeHandler handler) {
inProgressTransactionCount--;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.ViewGroup;

import com.bluelinelabs.conductor.internal.LifecycleHandler;
Expand All @@ -26,7 +27,8 @@ private Conductor() {}
* for restoring the Router's state if possible.
* @return A fully configured {@link Router} instance for use with this Activity/ViewGroup pair.
*/
public static Router attachRouter(@NonNull Activity activity, @NonNull ViewGroup container, Bundle savedInstanceState) {
@NonNull
public static Router attachRouter(@NonNull Activity activity, @NonNull ViewGroup container, @Nullable Bundle savedInstanceState) {
LifecycleHandler lifecycleHandler = LifecycleHandler.install(activity);

Router router = lifecycleHandler.getRouter(container, savedInstanceState);
Expand Down
Loading

1 comment on commit 104d96e

@PaulWoitaschek
Copy link
Collaborator

Choose a reason for hiding this comment

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

That's a super annoying change. Now I have to suppress thousands of warnings when calling for example getActivity, getResources in onCreateView etc.

I like this change in regular places but not on obvious lifecycle dependent places.

Please sign in to comment.