aboutsummaryrefslogtreecommitdiffstats
path: root/rule_api
diff options
context:
space:
mode:
authorTor Norbye <tnorbye@google.com>2012-05-30 14:54:39 -0700
committerTor Norbye <tnorbye@google.com>2012-05-30 17:25:18 -0700
commit7e4b8e9d595e45baa9d87cdb8282f02759e73abc (patch)
tree2da5fccd6c1e00c972c69323e3cf10df2e5ab264 /rule_api
parent5ee7da2ae31dcbe781ed81c07f31b31d0a0a7d7f (diff)
downloadsdk-7e4b8e9d595e45baa9d87cdb8282f02759e73abc.zip
sdk-7e4b8e9d595e45baa9d87cdb8282f02759e73abc.tar.gz
sdk-7e4b8e9d595e45baa9d87cdb8282f02759e73abc.tar.bz2
Fix nullness annotations
Eclipse 4.2 includes analysis support for @Nullable and @NonNull annotations. However, it requires these annotations to be *repeated* on every single method implementing or overriding a superclass or interface method (!). This changeset basically applies the quickfixes to inline these annotations. It also changes the retention of our nullness annotations from source to class, since without this Eclipse believes that a @NonNull annotation downstream is a redefinition of a @Nullable annotation. Finally, the null analysis revealed a dozen or so places where the nullness annotation was either wrong, or some null checking on parameters or return values needed to be done. Change-Id: I43b4e56e2d025a8a4c92a8873f55c13cdbc4c1cb
Diffstat (limited to 'rule_api')
-rw-r--r--rule_api/src/com/android/ide/common/api/AbstractViewRule.java49
-rw-r--r--rule_api/src/com/android/ide/common/api/IClientRulesEngine.java4
-rw-r--r--rule_api/src/com/android/ide/common/api/IMenuCallback.java13
-rw-r--r--rule_api/src/com/android/ide/common/api/INode.java2
-rw-r--r--rule_api/src/com/android/ide/common/api/RuleAction.java10
-rw-r--r--rule_api/src/com/android/ide/common/api/Segment.java4
-rw-r--r--rule_api/src/com/android/ide/common/api/SegmentType.java17
7 files changed, 64 insertions, 35 deletions
diff --git a/rule_api/src/com/android/ide/common/api/AbstractViewRule.java b/rule_api/src/com/android/ide/common/api/AbstractViewRule.java
index 3bbf8e7..7f05809 100644
--- a/rule_api/src/com/android/ide/common/api/AbstractViewRule.java
+++ b/rule_api/src/com/android/ide/common/api/AbstractViewRule.java
@@ -15,6 +15,7 @@
*/
package com.android.ide.common.api;
+import com.android.annotations.NonNull;
import com.android.annotations.Nullable;
import com.google.common.annotations.Beta;
@@ -31,7 +32,7 @@ import java.util.List;
@Beta
public class AbstractViewRule implements IViewRule {
@Override
- public boolean onInitialize(String fqcn, IClientRulesEngine engine) {
+ public boolean onInitialize(@NonNull String fqcn, @NonNull IClientRulesEngine engine) {
return true;
}
@@ -50,22 +51,22 @@ public class AbstractViewRule implements IViewRule {
@Override
@Nullable
- public List<String> getSelectionHint(INode parentNode, INode childNode) {
+ public List<String> getSelectionHint(@NonNull INode parentNode, @NonNull INode childNode) {
return null;
}
@Override
- public void addLayoutActions(List<RuleAction> actions, INode parentNode,
- List<? extends INode> children) {
+ public void addLayoutActions(@NonNull List<RuleAction> actions, @NonNull INode parentNode,
+ @NonNull List<? extends INode> children) {
}
@Override
- public void addContextMenuActions(List<RuleAction> actions, INode node) {
+ public void addContextMenuActions(@NonNull List<RuleAction> actions, @NonNull INode node) {
}
@Override
- public void paintSelectionFeedback(IGraphics graphics, INode parentNode,
- List<? extends INode> childNodes, Object view) {
+ public void paintSelectionFeedback(@NonNull IGraphics graphics, @NonNull INode parentNode,
+ @NonNull List<? extends INode> childNodes, @Nullable Object view) {
}
// ==== Drag & drop support ====
@@ -73,66 +74,66 @@ public class AbstractViewRule implements IViewRule {
// By default Views do not accept drag'n'drop.
@Override
@Nullable
- public DropFeedback onDropEnter(INode targetNode, Object targetView, IDragElement[] elements) {
+ public DropFeedback onDropEnter(@NonNull INode targetNode, @Nullable Object targetView, @Nullable IDragElement[] elements) {
return null;
}
@Override
@Nullable
- public DropFeedback onDropMove(INode targetNode, IDragElement[] elements,
- DropFeedback feedback, Point p) {
+ public DropFeedback onDropMove(@NonNull INode targetNode, @NonNull IDragElement[] elements,
+ @Nullable DropFeedback feedback, @NonNull Point p) {
return null;
}
@Override
- public void onDropLeave(INode targetNode, IDragElement[] elements, DropFeedback feedback) {
+ public void onDropLeave(@NonNull INode targetNode, @NonNull IDragElement[] elements, @Nullable DropFeedback feedback) {
// ignore
}
@Override
public void onDropped(
- INode targetNode,
- IDragElement[] elements,
- DropFeedback feedback,
- Point p) {
+ @NonNull INode targetNode,
+ @NonNull IDragElement[] elements,
+ @Nullable DropFeedback feedback,
+ @NonNull Point p) {
// ignore
}
@Override
- public void onPaste(INode targetNode, Object targetView, IDragElement[] pastedElements) {
+ public void onPaste(@NonNull INode targetNode, @Nullable Object targetView, @NonNull IDragElement[] pastedElements) {
}
// ==== Create/Remove hooks ====
@Override
- public void onCreate(INode node, INode parent, InsertType insertType) {
+ public void onCreate(@NonNull INode node, @NonNull INode parent, @NonNull InsertType insertType) {
}
@Override
- public void onChildInserted(INode child, INode parent, InsertType insertType) {
+ public void onChildInserted(@NonNull INode child, @NonNull INode parent, @NonNull InsertType insertType) {
}
@Override
- public void onRemovingChildren(List<INode> deleted, INode parent) {
+ public void onRemovingChildren(@NonNull List<INode> deleted, @NonNull INode parent) {
}
// ==== Resizing ====
@Override
@Nullable
- public DropFeedback onResizeBegin(INode child, INode parent, SegmentType horizontalEdge,
- SegmentType verticalEdge, Object childView, Object parentView) {
+ public DropFeedback onResizeBegin(@NonNull INode child, @NonNull INode parent, @Nullable SegmentType horizontalEdge,
+ @Nullable SegmentType verticalEdge, @Nullable Object childView, @Nullable Object parentView) {
return null;
}
@Override
- public void onResizeUpdate(DropFeedback feedback, INode child, INode parent, Rect newBounds,
+ public void onResizeUpdate(@Nullable DropFeedback feedback, @NonNull INode child, @NonNull INode parent, @NonNull Rect newBounds,
int modifierMask) {
}
@Override
- public void onResizeEnd(DropFeedback feedback, INode child, final INode parent,
- final Rect newBounds) {
+ public void onResizeEnd(@Nullable DropFeedback feedback, @NonNull INode child, final @NonNull INode parent,
+ final @NonNull Rect newBounds) {
}
}
diff --git a/rule_api/src/com/android/ide/common/api/IClientRulesEngine.java b/rule_api/src/com/android/ide/common/api/IClientRulesEngine.java
index ec28520..b9ea6cb 100644
--- a/rule_api/src/com/android/ide/common/api/IClientRulesEngine.java
+++ b/rule_api/src/com/android/ide/common/api/IClientRulesEngine.java
@@ -106,10 +106,10 @@ public interface IClientRulesEngine {
/**
* Returns a resource name validator for the current project
*
- * @return an {@link IValidator} for validating new resource name in the current
+ * @return an {@link IValidator} for validating a new resource name in the current
* project
*/
- @NonNull
+ @Nullable
IValidator getResourceValidator();
/**
diff --git a/rule_api/src/com/android/ide/common/api/IMenuCallback.java b/rule_api/src/com/android/ide/common/api/IMenuCallback.java
index fd100ee..2ff3f8d 100644
--- a/rule_api/src/com/android/ide/common/api/IMenuCallback.java
+++ b/rule_api/src/com/android/ide/common/api/IMenuCallback.java
@@ -49,4 +49,17 @@ public interface IMenuCallback {
@NonNull List<? extends INode> selectedNodes,
@Nullable String valueId,
@Nullable Boolean newValue);
+
+ /** Callback which does nothing */
+ @NonNull
+ public static final IMenuCallback NONE = new IMenuCallback() {
+ @Override
+ public void action(
+ @NonNull RuleAction action,
+ @NonNull
+ List<? extends INode> selectedNodes,
+ @Nullable String valueId,
+ @Nullable Boolean newValue) {
+ }
+ };
}
diff --git a/rule_api/src/com/android/ide/common/api/INode.java b/rule_api/src/com/android/ide/common/api/INode.java
index d957419..b137699 100644
--- a/rule_api/src/com/android/ide/common/api/INode.java
+++ b/rule_api/src/com/android/ide/common/api/INode.java
@@ -180,7 +180,7 @@ public interface INode {
* @param value It's value. Cannot be null. An empty value <em>removes</em> the attribute.
* @return Whether the attribute was actually set or not.
*/
- boolean setAttribute(@Nullable String uri, @NonNull String localName, @NonNull String value);
+ boolean setAttribute(@Nullable String uri, @NonNull String localName, @Nullable String value);
/**
* Returns a given XML attribute.
diff --git a/rule_api/src/com/android/ide/common/api/RuleAction.java b/rule_api/src/com/android/ide/common/api/RuleAction.java
index f6c7e8c..489a3cc 100644
--- a/rule_api/src/com/android/ide/common/api/RuleAction.java
+++ b/rule_api/src/com/android/ide/common/api/RuleAction.java
@@ -448,9 +448,9 @@ public class RuleAction implements Comparable<RuleAction> {
return mCallback;
}
- // Implements Comparable<MenuAciton>
+ // Implements Comparable<MenuAction>
@Override
- public int compareTo(@NonNull RuleAction other) {
+ public int compareTo(RuleAction other) {
if (mSortPriority != other.mSortPriority) {
return mSortPriority - other.mSortPriority;
}
@@ -468,7 +468,7 @@ public class RuleAction implements Comparable<RuleAction> {
public static class Separator extends RuleAction {
/** Construct using the factory {@link #createSeparator(int)} */
private Separator(int sortPriority, boolean supportsMultipleNodes) {
- super("_separator", "", null, sortPriority, //$NON-NLS-1$ //$NON-NLS-2$
+ super("_separator", "", IMenuCallback.NONE, sortPriority, //$NON-NLS-1$ //$NON-NLS-2$
supportsMultipleNodes);
}
}
@@ -689,13 +689,13 @@ public class RuleAction implements Comparable<RuleAction> {
}
@Override
- public List<String> getIds() {
+ public @NonNull List<String> getIds() {
ensureInitialized();
return mIds;
}
@Override
- public List<String> getTitles() {
+ public @NonNull List<String> getTitles() {
ensureInitialized();
return mTitles;
}
diff --git a/rule_api/src/com/android/ide/common/api/Segment.java b/rule_api/src/com/android/ide/common/api/Segment.java
index 9f03286..d31d9f8 100644
--- a/rule_api/src/com/android/ide/common/api/Segment.java
+++ b/rule_api/src/com/android/ide/common/api/Segment.java
@@ -51,7 +51,7 @@ public class Segment {
public final MarginType marginType;
/** The node that contains this edge */
- @NonNull
+ @Nullable
public final INode node;
/**
@@ -61,7 +61,7 @@ public class Segment {
@Nullable
public final String id;
- public Segment(int at, int from, int to, @NonNull INode node, @Nullable String id,
+ public Segment(int at, int from, int to, @Nullable INode node, @Nullable String id,
@NonNull SegmentType edgeType, @NonNull MarginType marginType) {
this.at = at;
this.from = from;
diff --git a/rule_api/src/com/android/ide/common/api/SegmentType.java b/rule_api/src/com/android/ide/common/api/SegmentType.java
index 25635c7..9da248a 100644
--- a/rule_api/src/com/android/ide/common/api/SegmentType.java
+++ b/rule_api/src/com/android/ide/common/api/SegmentType.java
@@ -27,7 +27,22 @@ import com.google.common.annotations.Beta;
*/
@Beta
public enum SegmentType {
- LEFT, TOP, RIGHT, BOTTOM, BASELINE, CENTER_VERTICAL, CENTER_HORIZONTAL, UNKNOWN;
+ /** Segment is on the left edge */
+ @NonNull LEFT,
+ /** Segment is on the top edge */
+ @NonNull TOP,
+ /** Segment is on the right edge */
+ @NonNull RIGHT,
+ /** Segment is on the bottom edge */
+ @NonNull BOTTOM,
+ /** Segment is along the baseline */
+ @NonNull BASELINE,
+ /** Segment is along the center vertically */
+ @NonNull CENTER_VERTICAL,
+ /** Segment is along the center horizontally */
+ @NonNull CENTER_HORIZONTAL,
+ /** Segment is on an unknown edge */
+ @NonNull UNKNOWN;
public boolean isHorizontal() {
return this == TOP || this == BOTTOM || this == BASELINE || this == CENTER_HORIZONTAL;