diff options
author | Tor Norbye <tnorbye@google.com> | 2012-05-30 14:54:39 -0700 |
---|---|---|
committer | Tor Norbye <tnorbye@google.com> | 2012-05-30 17:25:18 -0700 |
commit | 7e4b8e9d595e45baa9d87cdb8282f02759e73abc (patch) | |
tree | 2da5fccd6c1e00c972c69323e3cf10df2e5ab264 /eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/BaseLayoutRule.java | |
parent | 5ee7da2ae31dcbe781ed81c07f31b31d0a0a7d7f (diff) | |
download | sdk-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 'eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/BaseLayoutRule.java')
-rw-r--r-- | eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/BaseLayoutRule.java | 58 |
1 files changed, 35 insertions, 23 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/BaseLayoutRule.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/BaseLayoutRule.java index 581788b..6f76b51 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/BaseLayoutRule.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/BaseLayoutRule.java @@ -16,7 +16,6 @@ package com.android.ide.common.layout; -import static com.android.util.XmlUtils.ANDROID_URI; import static com.android.ide.common.layout.LayoutConstants.ATTR_ID; import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_ABOVE; import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_ALIGN_BASELINE; @@ -52,7 +51,10 @@ import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_Y; import static com.android.ide.common.layout.LayoutConstants.VALUE_FILL_PARENT; import static com.android.ide.common.layout.LayoutConstants.VALUE_MATCH_PARENT; import static com.android.ide.common.layout.LayoutConstants.VALUE_WRAP_CONTENT; +import static com.android.util.XmlUtils.ANDROID_URI; +import com.android.annotations.NonNull; +import com.android.annotations.Nullable; import com.android.ide.common.api.DrawingStyle; import com.android.ide.common.api.DropFeedback; import com.android.ide.common.api.IAttributeInfo; @@ -114,11 +116,13 @@ public class BaseLayoutRule extends BaseViewRule { IMenuCallback actionCallback = new IMenuCallback() { @Override - public void action(RuleAction action, List<? extends INode> selectedNodes, - final String valueId, final Boolean newValue) { + public void action(@NonNull RuleAction action, + @NonNull List<? extends INode> selectedNodes, + final @Nullable String valueId, + final @Nullable Boolean newValue) { parentNode.editXml("Change Margins", new INodeHandler() { @Override - public void handle(INode n) { + public void handle(@NonNull INode n) { String uri = ANDROID_URI; String all = first.getStringAttr(uri, ATTR_LAYOUT_MARGIN); String left = first.getStringAttr(uri, ATTR_LAYOUT_MARGIN_LEFT); @@ -154,8 +158,8 @@ public class BaseLayoutRule extends BaseViewRule { final INode first = targets.get(0); ChoiceProvider provider = new ChoiceProvider() { @Override - public void addChoices(List<String> titles, List<URL> iconUrls, - List<String> ids) { + public void addChoices(@NonNull List<String> titles, @NonNull List<URL> iconUrls, + @NonNull List<String> ids) { IAttributeInfo info = first.getAttributeInfo(ANDROID_URI, attributeName); if (info != null) { // Generate list of possible gravity value constants @@ -180,8 +184,10 @@ public class BaseLayoutRule extends BaseViewRule { } @Override - public void addLayoutActions(List<RuleAction> actions, final INode parentNode, - final List<? extends INode> children) { + public void addLayoutActions( + @NonNull List<RuleAction> actions, + final @NonNull INode parentNode, + final @NonNull List<? extends INode> children) { super.addLayoutActions(actions, parentNode, children); final List<? extends INode> targets = children == null || children.size() == 0 ? @@ -192,8 +198,11 @@ public class BaseLayoutRule extends BaseViewRule { // Shared action callback IMenuCallback actionCallback = new IMenuCallback() { @Override - public void action(RuleAction action, List<? extends INode> selectedNodes, - final String valueId, final Boolean newValue) { + public void action( + @NonNull RuleAction action, + @NonNull List<? extends INode> selectedNodes, + final @Nullable String valueId, + final @Nullable Boolean newValue) { final String actionId = action.getId(); final String undoLabel; if (actionId.equals(ACTION_FILL_WIDTH)) { @@ -205,7 +214,7 @@ public class BaseLayoutRule extends BaseViewRule { } parentNode.editXml(undoLabel, new INodeHandler() { @Override - public void handle(INode n) { + public void handle(@NonNull INode n) { String attribute = actionId.equals(ACTION_FILL_WIDTH) ? ATTR_LAYOUT_WIDTH : ATTR_LAYOUT_HEIGHT; String value; @@ -244,7 +253,8 @@ public class BaseLayoutRule extends BaseViewRule { * Derived layouts should override this behavior if not appropriate. */ @Override - public void onPaste(INode targetNode, Object targetView, IDragElement[] elements) { + public void onPaste(@NonNull INode targetNode, @Nullable Object targetView, + @NonNull IDragElement[] elements) { DropFeedback feedback = onDropEnter(targetNode, targetView, elements); if (feedback != null) { Point p = targetNode.getBounds().getTopLeft(); @@ -576,7 +586,7 @@ public class BaseLayoutRule extends BaseViewRule { targetNode.editXml("Insert Elements", new INodeHandler() { @Override - public void handle(INode node) { + public void handle(@NonNull INode node) { // Now write the new elements. int insertPos = initialInsertPos; for (IDragElement element : elements) { @@ -606,9 +616,9 @@ public class BaseLayoutRule extends BaseViewRule { } @Override - 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) { ResizeState state = createResizeState(parent, parentView, child); state.horizontalEdgeType = horizontalEdge; state.verticalEdgeType = verticalEdge; @@ -618,7 +628,8 @@ public class BaseLayoutRule extends BaseViewRule { Map<INode, Rect> sizes = mRulesEngine.measureChildren(parent, new IClientRulesEngine.AttributeFilter() { @Override - public String getAttribute(INode node, String namespace, String localName) { + public String getAttribute(@NonNull INode node, @Nullable String namespace, + @NonNull String localName) { // Change attributes to wrap_content if (ATTR_LAYOUT_WIDTH.equals(localName) && SdkConstants.NS_RESOURCES.equals(namespace)) { @@ -638,7 +649,8 @@ public class BaseLayoutRule extends BaseViewRule { return new DropFeedback(state, new IFeedbackPainter() { @Override - public void paint(IGraphics gc, INode node, DropFeedback feedback) { + public void paint(@NonNull IGraphics gc, @NonNull INode node, + @NonNull DropFeedback feedback) { ResizeState resizeState = (ResizeState) feedback.userData; if (resizeState != null && resizeState.bounds != null) { paintResizeFeedback(gc, node, resizeState); @@ -737,8 +749,8 @@ public class BaseLayoutRule extends BaseViewRule { } @Override - public void onResizeUpdate(DropFeedback feedback, INode child, INode parent, - Rect newBounds, int modifierMask) { + public void onResizeUpdate(@Nullable DropFeedback feedback, @NonNull INode child, + @NonNull INode parent, @NonNull Rect newBounds, int modifierMask) { ResizeState state = (ResizeState) feedback.userData; state.bounds = newBounds; state.modifierMask = modifierMask; @@ -799,14 +811,14 @@ public class BaseLayoutRule extends BaseViewRule { } @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) { final Rect oldBounds = child.getBounds(); if (oldBounds.w != newBounds.w || oldBounds.h != newBounds.h) { final ResizeState state = (ResizeState) feedback.userData; child.editXml("Resize", new INodeHandler() { @Override - public void handle(INode n) { + public void handle(@NonNull INode n) { setNewSizeBounds(state, n, parent, oldBounds, newBounds, state.horizontalEdgeType, state.verticalEdgeType); } |