diff options
Diffstat (limited to 'rule_api/src')
20 files changed, 366 insertions, 126 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 86e7896..3bbf8e7 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.Nullable; import com.google.common.annotations.Beta; import java.util.List; @@ -39,6 +40,7 @@ public class AbstractViewRule implements IViewRule { } @Override + @Nullable public String getDisplayName() { // Default is to not override the selection display name. return null; @@ -47,6 +49,7 @@ public class AbstractViewRule implements IViewRule { // ==== Selection ==== @Override + @Nullable public List<String> getSelectionHint(INode parentNode, INode childNode) { return null; } @@ -69,11 +72,13 @@ 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) { return null; } @Override + @Nullable public DropFeedback onDropMove(INode targetNode, IDragElement[] elements, DropFeedback feedback, Point p) { return null; @@ -115,6 +120,7 @@ public class AbstractViewRule implements IViewRule { // ==== Resizing ==== @Override + @Nullable public DropFeedback onResizeBegin(INode child, INode parent, SegmentType horizontalEdge, SegmentType verticalEdge, Object childView, Object parentView) { return null; diff --git a/rule_api/src/com/android/ide/common/api/DropFeedback.java b/rule_api/src/com/android/ide/common/api/DropFeedback.java index 4a526e5..3920958 100755..100644 --- a/rule_api/src/com/android/ide/common/api/DropFeedback.java +++ b/rule_api/src/com/android/ide/common/api/DropFeedback.java @@ -16,6 +16,7 @@ package com.android.ide.common.api; +import com.android.annotations.Nullable; import com.google.common.annotations.Beta; /** @@ -33,6 +34,7 @@ public class DropFeedback { * <p/> * Filled and owned by the view rule. */ + @Nullable public Object userData; /** @@ -67,6 +69,7 @@ public class DropFeedback { * Filled by the view rule, called by the engine. * <p/> */ + @Nullable public IFeedbackPainter painter; /** @@ -78,6 +81,7 @@ public class DropFeedback { * <p/> * Filled by the view rule, read by the engine. */ + @Nullable public Rect captureArea; /** @@ -98,6 +102,7 @@ public class DropFeedback { * NOTE: The coordinate units will be in layout/view coordinates. In other words, they * are unaffected by the canvas zoom. */ + @Nullable public Rect dragBounds; /** @@ -126,7 +131,7 @@ public class DropFeedback { * @param userData Data stored for later retrieval by the client * @param painter A callback invoked to paint the drop feedback */ - public DropFeedback(Object userData, IFeedbackPainter painter) { + public DropFeedback(@Nullable Object userData, @Nullable IFeedbackPainter painter) { this.userData = userData; this.painter = painter; this.requestPaint = painter != null; @@ -136,28 +141,33 @@ public class DropFeedback { /** * A message to be displayed to the user, if any. Should not contain line separators. */ + @Nullable public String message; /** * An error message to be displayed to the user, if any. Should not contain line * separators. */ + @Nullable public String errorMessage; /** * A message to be displayed in a tooltip to the user, which should be short, but * can be multiple lines (use embedded newlines) */ + @Nullable public String tooltip; /** * Horizontal alignment for the tooltip, or null if no preference */ + @Nullable public SegmentType tooltipX; /** * Vertical alignment for the tooltip, or null if no preference */ + @Nullable public SegmentType tooltipY; /** diff --git a/rule_api/src/com/android/ide/common/api/IAttributeInfo.java b/rule_api/src/com/android/ide/common/api/IAttributeInfo.java index 3dcb241..e1bb067 100755..100644 --- a/rule_api/src/com/android/ide/common/api/IAttributeInfo.java +++ b/rule_api/src/com/android/ide/common/api/IAttributeInfo.java @@ -16,6 +16,8 @@ package com.android.ide.common.api; +import com.android.annotations.NonNull; +import com.android.annotations.Nullable; import com.google.common.annotations.Beta; /** @@ -51,7 +53,7 @@ public interface IAttributeInfo { * @return True if and only if the given array (if any) contains this * format. */ - public boolean in(Format[] formats) { + public boolean in(@Nullable Format[] formats) { if (formats == null) { return false; } @@ -66,24 +68,31 @@ public interface IAttributeInfo { } /** Returns the XML Name of the attribute */ + @NonNull public String getName(); /** Returns the formats of the attribute. Cannot be null. * Should have at least one format. */ + @NonNull public Format[] getFormats(); /** Returns the values for enums. null for other types. */ + @Nullable public String[] getEnumValues(); /** Returns the values for flags. null for other types. */ + @Nullable public String[] getFlagValues(); /** Returns a short javadoc, .i.e. the first sentence. */ + @NonNull public String getJavaDoc(); /** Returns the documentation for deprecated attributes. Null if not deprecated. */ + @Nullable public String getDeprecatedDoc(); /** Returns the fully qualified class name of the view defining this attribute */ + @NonNull public String getDefinedBy(); } 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 490ef0c..ec28520 100755..100644 --- a/rule_api/src/com/android/ide/common/api/IClientRulesEngine.java +++ b/rule_api/src/com/android/ide/common/api/IClientRulesEngine.java @@ -17,6 +17,7 @@ package com.android.ide.common.api; +import com.android.annotations.NonNull; import com.android.annotations.Nullable; import com.google.common.annotations.Beta; @@ -39,6 +40,7 @@ public interface IClientRulesEngine { * * @return the fully qualified name of the rule */ + @NonNull String getFqcn(); /** @@ -47,7 +49,7 @@ public interface IClientRulesEngine { * @param msg A String format message. * @param params Optional parameters for the message. */ - void debugPrintf(String msg, Object...params); + void debugPrintf(@NonNull String msg, Object...params); /** * Loads and returns an {@link IViewRule} for the given FQCN. @@ -57,22 +59,28 @@ public interface IClientRulesEngine { * inheritance chain. Rules are cached and requesting the same FQCN twice * is fast and will return the same rule instance. */ - IViewRule loadRule(String fqcn); + @Nullable + IViewRule loadRule(@NonNull String fqcn); /** - * Returns the metadata associated with the given fully qualified class name. + * Returns the metadata associated with the given fully qualified class name. Note that + * this will always return an {@link IViewMetadata} instance, even when the class name + * is unknown to the layout editor, such as for custom views. In that case, some + * heuristics will be applied to return metadata information such as guesses for + * what the most common attribute is, and so on. * * @param fqcn a fully qualified class name for an Android view class * @return the metadata associated with the given fully qualified class name. */ - IViewMetadata getMetadata(String fqcn); + @NonNull + IViewMetadata getMetadata(@NonNull String fqcn); /** * Displays the given message string in an alert dialog with an "OK" button. * * @param message the message to be shown */ - void displayAlert(String message); + void displayAlert(@NonNull String message); /** * Displays a simple input alert dialog with an OK and Cancel buttons. @@ -83,10 +91,10 @@ public interface IClientRulesEngine { * a validator which always returns true) if you do not want * input validation. * @return Null if canceled by the user. Otherwise the possibly-empty input string. - * @null Return value is null if dialog was canceled by the user. */ @Nullable - String displayInput(String message, @Nullable String value, @Nullable IValidator filter); + String displayInput(@NonNull String message, @Nullable String value, + @Nullable IValidator filter); /** * Returns the minimum API level that the current Android project is targeting. @@ -101,6 +109,7 @@ public interface IClientRulesEngine { * @return an {@link IValidator} for validating new resource name in the current * project */ + @NonNull IValidator getResourceValidator(); /** @@ -109,6 +118,7 @@ public interface IClientRulesEngine { * @param currentValue the current reference to select * @return the reference selected by the user, or null */ + @Nullable String displayReferenceInput(String currentValue); /** @@ -121,7 +131,8 @@ public interface IClientRulesEngine { * @return the margins selected by the user in the same order as the input arguments, * or null */ - String displayResourceInput(String resourceTypeName, String currentValue); + @Nullable + String displayResourceInput(@NonNull String resourceTypeName, @Nullable String currentValue); /** * Displays an input dialog tailored for editing margin properties. @@ -133,9 +144,15 @@ public interface IClientRulesEngine { * @param top The current, initial value to display for the "top" margin * @param bottom The current, initial value to display for the "bottom" margin * @return an array of length 5 containing the user entered values for the all, left, - * right, top and bottom margins respectively + * right, top and bottom margins respectively, or null if canceled */ - String[] displayMarginInput(String all, String left, String right, String top, String bottom); + @Nullable + String[] displayMarginInput( + @Nullable String all, + @Nullable String left, + @Nullable String right, + @Nullable String top, + @Nullable String bottom); /** * Displays an input dialog tailored for inputing the source of an {@code <include>} @@ -143,16 +160,18 @@ public interface IClientRulesEngine { * "layout", but should also attempt to filter out layout resources that cannot be * included from the current context (because it would result in a cyclic dependency). * - * @return the layout resource to include + * @return the layout resource to include, or null if canceled */ + @Nullable String displayIncludeSourceInput(); /** * Displays an input dialog tailored for inputing the source of a {@code <fragment>} * layout tag. * - * @return the fully qualified class name of the fragment activity + * @return the fully qualified class name of the fragment activity, or null if canceled */ + @Nullable String displayFragmentSourceInput(); /** @@ -160,7 +179,7 @@ public interface IClientRulesEngine { * * @param nodes the nodes to be selected, never null */ - void select(Collection<INode> nodes); + void select(@NonNull Collection<INode> nodes); /** * Triggers a redraw @@ -206,9 +225,10 @@ public interface IClientRulesEngine { * @param filter a filter to change attributes in the process of measuring, for * example forcing the layout_width to wrap_content or the layout_weight to * unset - * @return the corresponding bounds of the nodes + * @return the corresponding bounds of the nodes, or null if a rendering error occurs */ - Map<INode, Rect> measureChildren(INode parent, AttributeFilter filter); + @Nullable + Map<INode, Rect> measureChildren(@NonNull INode parent, @Nullable AttributeFilter filter); /** * The {@link AttributeFilter} allows a client of @@ -222,14 +242,18 @@ public interface IClientRulesEngine { * allows a client to adjust the attribute values that a node presents to the * layout library. * <p> - * Return "" to unset an attribute. Return null to return the unfiltered value. + * Returns "" to unset an attribute. Returns null to return the unfiltered value. * * @param node the node for which the attribute value should be returned * @param namespace the attribute namespace * @param localName the attribute local name * @return an override value, or null to return the unfiltered value */ - String getAttribute(INode node, String namespace, String localName); + @Nullable + String getAttribute( + @NonNull INode node, + @Nullable String namespace, + @NonNull String localName); } /** @@ -242,7 +266,8 @@ public interface IClientRulesEngine { * @return A suitable generated id in the attribute form needed by the XML id tag * (e.g. "@+id/something") */ - public String getUniqueId(String fqcn); + @NonNull + public String getUniqueId(@NonNull String fqcn); /** * Returns the namespace URI for attributes declared and used inside the @@ -250,6 +275,7 @@ public interface IClientRulesEngine { * * @return the namespace URI */ + @NonNull public String getAppNameSpace(); } diff --git a/rule_api/src/com/android/ide/common/api/IDragElement.java b/rule_api/src/com/android/ide/common/api/IDragElement.java index e03b718..885ba35 100755..100644 --- a/rule_api/src/com/android/ide/common/api/IDragElement.java +++ b/rule_api/src/com/android/ide/common/api/IDragElement.java @@ -16,6 +16,8 @@ package com.android.ide.common.api; +import com.android.annotations.NonNull; +import com.android.annotations.Nullable; import com.google.common.annotations.Beta; /** @@ -35,6 +37,7 @@ public interface IDragElement { * Returns the element name, which must match a fully qualified class name of * a View to inflate. */ + @NonNull public abstract String getFqcn(); /** @@ -44,6 +47,7 @@ public interface IDragElement { * * The bounds are absolute for the canvas. */ + @NonNull public abstract Rect getBounds(); /** @@ -51,6 +55,7 @@ public interface IDragElement { * from an existing canvas. Returns null if the element has no parent, such as a top * level element or an element originating from the object palette. */ + @Nullable public abstract String getParentFqcn(); /** @@ -59,21 +64,25 @@ public interface IDragElement { * * The returned rectangle can be invalid. It is never null. */ + @NonNull public abstract Rect getParentBounds(); /** * Returns a list of attributes. The list can be empty but is never null. */ + @NonNull public abstract IDragAttribute[] getAttributes(); /** * Returns the requested attribute or null if not found. */ - public abstract IDragAttribute getAttribute(String uri, String localName); + @Nullable + public abstract IDragAttribute getAttribute(@Nullable String uri, @NonNull String localName); /** * Returns a list of inner elements. The list can be empty but is never null. */ + @NonNull public abstract IDragElement[] getInnerElements(); /** @@ -90,12 +99,15 @@ public interface IDragElement { * Returns the namespace URI of the attribute. * Can be empty for an attribute without a namespace but is never null. */ + @NonNull public abstract String getUri(); /** Returns the XML local name of the attribute. Cannot be null nor empty. */ + @NonNull public abstract String getName(); /** Returns the value of the attribute. Cannot be null. Can be empty. */ + @NonNull public abstract String getValue(); } } diff --git a/rule_api/src/com/android/ide/common/api/IFeedbackPainter.java b/rule_api/src/com/android/ide/common/api/IFeedbackPainter.java index d6e256d..2b3d14d 100644 --- a/rule_api/src/com/android/ide/common/api/IFeedbackPainter.java +++ b/rule_api/src/com/android/ide/common/api/IFeedbackPainter.java @@ -16,6 +16,7 @@ package com.android.ide.common.api; +import com.android.annotations.NonNull; import com.google.common.annotations.Beta; /** @@ -34,5 +35,5 @@ public interface IFeedbackPainter { * @param targetNode The node being dragged * @param feedback The feedback data */ - void paint(IGraphics gc, INode targetNode, DropFeedback feedback); + void paint(@NonNull IGraphics gc, @NonNull INode targetNode, @NonNull DropFeedback feedback); } diff --git a/rule_api/src/com/android/ide/common/api/IGraphics.java b/rule_api/src/com/android/ide/common/api/IGraphics.java index cb1cac5..1a7f64a 100755..100644 --- a/rule_api/src/com/android/ide/common/api/IGraphics.java +++ b/rule_api/src/com/android/ide/common/api/IGraphics.java @@ -16,6 +16,7 @@ package com.android.ide.common.api; +import com.android.annotations.NonNull; import com.google.common.annotations.Beta; import java.util.List; @@ -45,7 +46,7 @@ public interface IGraphics { * Draws a line between 2 points, using the current foreground color and * alpha. */ - void drawLine(Point p1, Point p2); + void drawLine(@NonNull Point p1, @NonNull Point p2); /** * Draws an arrow from (x1, y1) to (x2, y2). @@ -76,13 +77,13 @@ public interface IGraphics { * Draws a rectangle outline between 2 points, using the current foreground * color and alpha. */ - void drawRect(Point p1, Point p2); + void drawRect(@NonNull Point p1, @NonNull Point p2); /** * Draws a rectangle outline between 2 points, using the current foreground * color and alpha. */ - void drawRect(Rect r); + void drawRect(@NonNull Rect r); /** * Fills a rectangle outline between 2 points, using the current background @@ -94,13 +95,13 @@ public interface IGraphics { * Fills a rectangle outline between 2 points, using the current background * color and alpha. */ - void fillRect(Point p1, Point p2); + void fillRect(@NonNull Point p1, @NonNull Point p2); /** * Fills a rectangle outline between 2 points, using the current background * color and alpha. */ - void fillRect(Rect r); + void fillRect(@NonNull Rect r); /** * Draws the given string, using the current foreground color. No tab @@ -110,7 +111,7 @@ public interface IGraphics { * @param x the x coordinate of the top left corner of the text. * @param y the y coordinate of the top left corner of the text. */ - void drawString(String string, int x, int y); + void drawString(@NonNull String string, int x, int y); /** * Draws the given string, using the current foreground color. No tab @@ -119,7 +120,7 @@ public interface IGraphics { * @param string the string to be drawn. * @param topLeft the top left corner of the text. */ - void drawString(String string, Point topLeft); + void drawString(@NonNull String string, @NonNull Point topLeft); /** * Draw the given strings, using the current stroke color and alpha for the @@ -134,7 +135,7 @@ public interface IGraphics { * The actual String used is the {@link Object#toString()} value * of each list item. */ - void drawBoxedStrings(int x, int y, List<?> strings); + void drawBoxedStrings(int x, int y, @NonNull List<?> strings); /** * Set up the graphics context to use the given style for subsequent drawing @@ -142,7 +143,7 @@ public interface IGraphics { * * @param style The drawing style to be used. May not be null. */ - void useStyle(DrawingStyle style); + void useStyle(@NonNull DrawingStyle style); /** * Registers a color using 0x00rrggbb where each component is 0..0xFF. @@ -155,6 +156,7 @@ public interface IGraphics { * to ensure that your colors work properly across multiple current and * future themes. */ + @NonNull IColor registerColor(int rgb); /** @@ -166,25 +168,27 @@ public interface IGraphics { * Returns the current foreground color. * The foreground color is used for drawing operations including when text is drawn. */ + @NonNull IColor getForeground(); /** * Sets the foreground color. The foreground color is used for drawing * operations including when text is drawn. */ - void setForeground(IColor color); + void setForeground(@NonNull IColor color); /** * Returns the current background color. The background color is used for * fill operations. */ + @NonNull IColor getBackground(); /** * Sets the background color. The background color is used for fill * operations. */ - void setBackground(IColor color); + void setBackground(@NonNull IColor color); /** * Returns the current alpha value (varies between 0 for transparent and 255 @@ -226,7 +230,7 @@ public interface IGraphics { /** * Sets the current line style. */ - void setLineStyle(LineStyle style); + void setLineStyle(@NonNull LineStyle style); /** * Sets the width that will be used when drawing lines. 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 6c55222..fd100ee 100644 --- a/rule_api/src/com/android/ide/common/api/IMenuCallback.java +++ b/rule_api/src/com/android/ide/common/api/IMenuCallback.java @@ -16,6 +16,8 @@ package com.android.ide.common.api; +import com.android.annotations.NonNull; +import com.android.annotations.Nullable; import com.google.common.annotations.Beta; import java.util.List; @@ -42,6 +44,9 @@ public interface IMenuCallback { * useful; however for flags it allows one to add or remove items * to the flag's choices. */ - void action(RuleAction action, List<? extends INode> selectedNodes, String valueId, - Boolean newValue); + 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 7c60d82..d957419 100755..100644 --- a/rule_api/src/com/android/ide/common/api/INode.java +++ b/rule_api/src/com/android/ide/common/api/INode.java @@ -17,6 +17,8 @@ package com.android.ide.common.api; +import com.android.annotations.NonNull; +import com.android.annotations.Nullable; import com.android.ide.common.api.IDragElement.IDragAttribute; import com.google.common.annotations.Beta; @@ -46,6 +48,7 @@ public interface INode { /** * Returns the FQCN of the view class represented by this node. */ + @NonNull String getFqcn(); /** @@ -60,6 +63,7 @@ public interface INode { * * @return A non-null rectangle, in canvas coordinates. */ + @NonNull Rect getBounds(); /** @@ -67,6 +71,7 @@ public interface INode { * * @return the margins for this node, never null */ + @NonNull Margins getMargins(); /** @@ -86,6 +91,7 @@ public interface INode { * This may return null if the {@link INode} was not created using a correct UiNode, * which is unlikely. */ + @Nullable INode getRoot(); /** @@ -93,11 +99,13 @@ public interface INode { * The returned parent can be null when the node is the root element, or when the node is * not yet or no longer attached to the hierarchy. */ + @Nullable INode getParent(); /** * Returns the list of valid children nodes. The list can be empty but not null. */ + @NonNull INode[] getChildren(); @@ -111,7 +119,7 @@ public interface INode { * @param undoName The UI name that will be given to the undo action. * @param callback The code to execute. */ - void editXml(String undoName, final INodeHandler callback); + void editXml(@NonNull String undoName, @NonNull INodeHandler callback); // TODO define an exception that methods below will throw if editXml() is not wrapping // these calls. @@ -127,7 +135,8 @@ public interface INode { * depend on whether this is an Android view or a custom project view. * @return The node for the newly created element. Can be null if we failed to create it. */ - INode appendChild(String viewFqcn); + @NonNull + INode appendChild(@NonNull String viewFqcn); /** * Creates a new XML element as a child of this node's XML element and inserts @@ -143,7 +152,8 @@ public interface INode { * (less than zero or larger that current last child), appends at the end. * @return The node for the newly created element. Can be null if we failed to create it. */ - INode insertChildAt(String viewFqcn, int index); + @NonNull + INode insertChildAt(@NonNull String viewFqcn, int index); /** * Removes the given XML element child from this node's list of children. @@ -152,7 +162,7 @@ public interface INode { * * @param node The child to be deleted. */ - void removeChild(INode node); + void removeChild(@NonNull INode node); /** * Sets an attribute for the underlying XML element. @@ -170,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(String uri, String localName, String value); + boolean setAttribute(@Nullable String uri, @NonNull String localName, @NonNull String value); /** * Returns a given XML attribute. @@ -184,7 +194,8 @@ public interface INode { * @param attrName The <em>local</em> name of the attribute. * @return the attribute as a {@link String}, if it exists, or <code>null</code>. */ - String getStringAttr(String uri, String attrName); + @Nullable + String getStringAttr(@Nullable String uri, @NonNull String attrName); /** * Returns the {@link IAttributeInfo} for a given attribute. @@ -204,7 +215,8 @@ public interface INode { * @param attrName The <em>local</em> name of the attribute. * @return the {@link IAttributeInfo} if the attribute is known, or <code>null</code>. */ - public IAttributeInfo getAttributeInfo(String uri, String attrName); + @Nullable + public IAttributeInfo getAttributeInfo(@Nullable String uri, @NonNull String attrName); /** * Returns the list of all attributes declared by this node's descriptor. @@ -223,6 +235,7 @@ public interface INode { * * @return A non-null possibly-empty list of {@link IAttributeInfo}. */ + @NonNull public IAttributeInfo[] getDeclaredAttributes(); /** @@ -237,6 +250,7 @@ public interface INode { * which is never null because at least android.view.View will * contribute attributes. */ + @NonNull public List<String> getAttributeSources(); /** @@ -252,6 +266,7 @@ public interface INode { * * @return A non-null possibly-empty list of {@link IAttribute}. */ + @NonNull public IAttribute[] getLiveAttributes(); // ----------- diff --git a/rule_api/src/com/android/ide/common/api/INodeHandler.java b/rule_api/src/com/android/ide/common/api/INodeHandler.java index 8a9b504..e810487 100644 --- a/rule_api/src/com/android/ide/common/api/INodeHandler.java +++ b/rule_api/src/com/android/ide/common/api/INodeHandler.java @@ -16,6 +16,7 @@ package com.android.ide.common.api; +import com.android.annotations.NonNull; import com.google.common.annotations.Beta; /** @@ -34,5 +35,5 @@ public interface INodeHandler { * * @param node The node to be operated on */ - void handle(INode node); + void handle(@NonNull INode node); } diff --git a/rule_api/src/com/android/ide/common/api/IValidator.java b/rule_api/src/com/android/ide/common/api/IValidator.java index 29f43d5..0b88a4b 100644 --- a/rule_api/src/com/android/ide/common/api/IValidator.java +++ b/rule_api/src/com/android/ide/common/api/IValidator.java @@ -16,6 +16,8 @@ package com.android.ide.common.api; +import com.android.annotations.NonNull; +import com.android.annotations.Nullable; import com.google.common.annotations.Beta; /** @@ -37,5 +39,6 @@ public interface IValidator { * @return Null if the text is valid, and otherwise a description (possibly * empty) for why the text is not valid. */ - String validate(String text); + @Nullable + String validate(@NonNull String text); } diff --git a/rule_api/src/com/android/ide/common/api/IViewMetadata.java b/rule_api/src/com/android/ide/common/api/IViewMetadata.java index 190a497..ea79e29 100644 --- a/rule_api/src/com/android/ide/common/api/IViewMetadata.java +++ b/rule_api/src/com/android/ide/common/api/IViewMetadata.java @@ -16,6 +16,7 @@ package com.android.ide.common.api; +import com.android.annotations.NonNull; import com.google.common.annotations.Beta; import java.util.List; @@ -40,6 +41,7 @@ public interface IViewMetadata { * * @return the user visible name of views of this type (never null) */ + @NonNull public String getDisplayName(); /** @@ -47,13 +49,16 @@ public interface IViewMetadata { * * @return the insets for this view */ + @NonNull public Margins getInsets(); /** * Returns the {@link FillPreference} of this view * - * @return the {@link FillPreference} of this view + * @return the {@link FillPreference} of this view, never null but may be + * {@link FillPreference#NONE} */ + @NonNull public FillPreference getFillPreference(); /** @@ -62,6 +67,7 @@ public interface IViewMetadata { * @return a list of attribute names (not including a namespace prefix) that * are commonly set for this type of view, never null */ + @NonNull public List<String> getTopAttributes(); /** @@ -114,5 +120,4 @@ public interface IViewMetadata { (!verticalContext && (this == OPPOSITE || this == HEIGHT_IN_HORIZONTAL))); } } - } diff --git a/rule_api/src/com/android/ide/common/api/IViewRule.java b/rule_api/src/com/android/ide/common/api/IViewRule.java index c11f500..bcf4e89 100755..100644 --- a/rule_api/src/com/android/ide/common/api/IViewRule.java +++ b/rule_api/src/com/android/ide/common/api/IViewRule.java @@ -16,6 +16,9 @@ package com.android.ide.common.api; +import com.android.annotations.NonNull; +import com.android.annotations.Nullable; + import java.util.List; @@ -54,7 +57,7 @@ public interface IViewRule { * @return True if this rule can handle the given FQCN. False if the rule can't handle the * given FQCN, in which case the rule engine will find another rule matching a parent class. */ - boolean onInitialize(String fqcn, IClientRulesEngine engine); + boolean onInitialize(@NonNull String fqcn, @NonNull IClientRulesEngine engine); /** * This method is called by the rules engine just before the script is unloaded. @@ -62,15 +65,16 @@ public interface IViewRule { void onDispose(); /** - * Returns the class name to display when an element is selected in the GLE. + * Returns the class name to display when an element is selected in the layout editor. * <p/> - * If null is returned, the GLE will automatically shorten the class name using its + * If null is returned, the layout editor will automatically shorten the class name using its * own heuristic, which is to keep the first 2 package components and the class name. * The class name is the <code>fqcn</code> argument that was given * to {@link #onInitialize(String,IClientRulesEngine)}. * * @return Null for the default behavior or a shortened string. */ + @Nullable String getDisplayName(); /** @@ -95,7 +99,7 @@ public interface IViewRule { * {@link RuleAction#getSortPriority()} later. * @param node the node to add actions for. */ - void addContextMenuActions(List<RuleAction> actions, INode node); + void addContextMenuActions(@NonNull List<RuleAction> actions, @NonNull INode node); /** * Invoked by the Rules Engine to ask the parent layout for the set of layout actions @@ -109,8 +113,10 @@ public interface IViewRule { * @param parentNode the parent of the selection, or the selection itself if the root * @param targets the targeted/selected nodes, if any */ - void addLayoutActions(List<RuleAction> actions, - INode parentNode, List<? extends INode> targets); + void addLayoutActions( + @NonNull List<RuleAction> actions, + @NonNull INode parentNode, + @NonNull List<? extends INode> targets); // ==== Selection ==== @@ -126,7 +132,8 @@ public interface IViewRule { * @param childNode The child node that was selected. Never null. * @return a list of strings to be displayed, or null or empty to display nothing */ - List<String> getSelectionHint(INode parentNode, INode childNode); + @Nullable + List<String> getSelectionHint(@NonNull INode parentNode, @NonNull INode childNode); /** * Paints any layout-specific selection feedback for the given parent layout. @@ -136,8 +143,11 @@ public interface IViewRule { * @param childNodes the child nodes selected in the parent layout * @param view An instance of the view to be painted (may be null) */ - void paintSelectionFeedback(IGraphics graphics, INode parentNode, - List<? extends INode> childNodes, Object view); + void paintSelectionFeedback( + @NonNull IGraphics graphics, + @NonNull INode parentNode, + @NonNull List<? extends INode> childNodes, + @Nullable Object view); // ==== Drag'n'drop support ==== @@ -156,7 +166,9 @@ public interface IViewRule { * supplied to a follow-up {@link #onDropMove} call), or null if the * drop should be ignored */ - DropFeedback onDropEnter(INode targetNode, Object targetView, IDragElement[] elements); + @Nullable + DropFeedback onDropEnter(@NonNull INode targetNode, @Nullable Object targetView, + @Nullable IDragElement[] elements); /** * Called after onDropEnter. Returns a DropFeedback passed to @@ -173,10 +185,12 @@ public interface IViewRule { * @return a {@link DropFeedback} (which is usually just the same one passed * into this method) */ - DropFeedback onDropMove(INode targetNode, - IDragElement[] elements, - DropFeedback feedback, - Point where); + @Nullable + DropFeedback onDropMove( + @NonNull INode targetNode, + @NonNull IDragElement[] elements, + @Nullable DropFeedback feedback, + @NonNull Point where); /** * Called when drop leaves the target without actually dropping. @@ -201,9 +215,10 @@ public interface IViewRule { * @param feedback the {@link DropFeedback} object created by * {@link #onDropEnter(INode, Object, IDragElement[])} */ - void onDropLeave(INode targetNode, - IDragElement[] elements, - DropFeedback feedback); + void onDropLeave( + @NonNull INode targetNode, + @NonNull IDragElement[] elements, + @Nullable DropFeedback feedback); /** * Called when drop is released over the target to perform the actual drop. @@ -220,10 +235,11 @@ public interface IViewRule { * {@link #onDropEnter(INode, Object, IDragElement[])} * @param where the mouse drop position */ - void onDropped(INode targetNode, - IDragElement[] elements, - DropFeedback feedback, - Point where); + void onDropped( + @NonNull INode targetNode, + @NonNull IDragElement[] elements, + @Nullable DropFeedback feedback, + @NonNull Point where); /** * Called when pasting elements in an existing document on the selected target. @@ -233,7 +249,8 @@ public interface IViewRule { * null if not known * @param pastedElements The elements being pasted. */ - void onPaste(INode targetNode, Object targetView, IDragElement[] pastedElements); + void onPaste(@NonNull INode targetNode, @Nullable Object targetView, + @NonNull IDragElement[] pastedElements); // ==== XML Creation ==== @@ -254,7 +271,7 @@ public interface IViewRule { * @param insertType whether this node was created as part of a newly created view, or * as a copy, or as a move, etc. */ - void onCreate(INode node, INode parent, InsertType insertType); + void onCreate(@NonNull INode node, @NonNull INode parent, @NonNull InsertType insertType); /** * Called when a child for this view has been created and is being inserted into the @@ -269,7 +286,8 @@ public interface IViewRule { * @param insertType whether this node was created as part of a newly created view, or * as a copy, or as a move, etc. */ - void onChildInserted(INode child, INode parent, InsertType insertType); + void onChildInserted(@NonNull INode child, @NonNull INode parent, + @NonNull InsertType insertType); /** * Called when one or more children are about to be deleted by the user. Note that @@ -284,7 +302,7 @@ public interface IViewRule { * @param parent the parent of the deleted children (which still contains the children * since this method is called before the deletion is performed) */ - void onRemovingChildren(List<INode> deleted, INode parent); + void onRemovingChildren(@NonNull List<INode> deleted, @NonNull INode parent); /** * Called by the IDE on the parent layout when a child widget is being resized. This @@ -300,10 +318,14 @@ public interface IViewRule { * @return a {@link DropFeedback} object which performs an update painter callback * etc. */ + @Nullable DropFeedback onResizeBegin( - INode child, INode parent, - SegmentType horizEdge, SegmentType verticalEdge, - Object childView, Object parentView); + @NonNull INode child, + @NonNull INode parent, + @Nullable SegmentType horizEdge, + @Nullable SegmentType verticalEdge, + @Nullable Object childView, + @Nullable Object parentView); /** * Called by the IDE on the parent layout when a child widget is being resized. This @@ -320,7 +342,11 @@ public interface IViewRule { * of the constants {@link DropFeedback#MODIFIER1}, {@link DropFeedback#MODIFIER2} * and {@link DropFeedback#MODIFIER3}. */ - void onResizeUpdate(DropFeedback feedback, INode child, INode parent, Rect newBounds, + void onResizeUpdate( + @Nullable DropFeedback feedback, + @NonNull INode child, + @NonNull INode parent, + @NonNull Rect newBounds, int modifierMask); /** @@ -335,5 +361,9 @@ public interface IViewRule { * @param newBounds the new bounds the user has chosen to resize the widget to, * in absolute coordinates */ - void onResizeEnd(DropFeedback feedback, INode child, INode parent, Rect newBounds); + void onResizeEnd( + @Nullable DropFeedback feedback, + @NonNull INode child, + @NonNull INode parent, + @NonNull Rect newBounds); } diff --git a/rule_api/src/com/android/ide/common/api/Margins.java b/rule_api/src/com/android/ide/common/api/Margins.java index 969d068..f38066f 100644 --- a/rule_api/src/com/android/ide/common/api/Margins.java +++ b/rule_api/src/com/android/ide/common/api/Margins.java @@ -17,6 +17,7 @@ package com.android.ide.common.api; import com.google.common.annotations.Beta; +import com.android.annotations.NonNull; /** * Set of margins - distances to outer left, top, right and bottom edges. These objects @@ -56,6 +57,7 @@ public class Margins { this.bottom = bottom; } + @NonNull @Override public String toString() { return "Margins [left=" + left + ", right=" + right + ", top=" + top + ", bottom=" + bottom diff --git a/rule_api/src/com/android/ide/common/api/Point.java b/rule_api/src/com/android/ide/common/api/Point.java index 199701a..b13f12a 100755..100644 --- a/rule_api/src/com/android/ide/common/api/Point.java +++ b/rule_api/src/com/android/ide/common/api/Point.java @@ -17,6 +17,7 @@ package com.android.ide.common.api; import com.google.common.annotations.Beta; +import com.android.annotations.NonNull; /** @@ -35,7 +36,7 @@ public class Point { this.y = y; } - public Point(Point p) { + public Point(@NonNull Point p) { x = p.x; y = p.y; } @@ -47,6 +48,7 @@ public class Point { } /** Returns a new instance of a point with the same values. */ + @NonNull public Point copy() { return new Point(x, y); } @@ -55,6 +57,7 @@ public class Point { * Offsets this point by adding the given x,y deltas to the x,y coordinates. * @return Returns self, for chaining. */ + @NonNull public Point offsetBy(int x, int y) { this.x += x; this.y += y; diff --git a/rule_api/src/com/android/ide/common/api/Rect.java b/rule_api/src/com/android/ide/common/api/Rect.java index 0ae7a74..0fb791b 100755..100644 --- a/rule_api/src/com/android/ide/common/api/Rect.java +++ b/rule_api/src/com/android/ide/common/api/Rect.java @@ -17,7 +17,8 @@ package com.android.ide.common.api; import com.google.common.annotations.Beta; - +import com.android.annotations.NonNull; +import com.android.annotations.Nullable; /** @@ -46,11 +47,12 @@ public class Rect { } /** Initialize rectangle to the given values. They can be invalid. */ - public Rect(Rect r) { + public Rect(@NonNull Rect r) { set(r); } /** Initialize rectangle to the given values. They can be invalid. */ + @NonNull public Rect set(int x, int y, int w, int h) { this.x = x; this.y = y; @@ -60,12 +62,14 @@ public class Rect { } /** Initialize rectangle to match the given one. */ - public Rect set(Rect r) { + @NonNull + public Rect set(@NonNull Rect r) { set(r.x, r.y, r.w, r.h); return this; } /** Returns a new instance of a rectangle with the same values. */ + @NonNull public Rect copy() { return new Rect(x, y, w, h); } @@ -85,7 +89,7 @@ public class Rect { } /** Returns true if the rectangle contains the x,y coordinates, borders included. */ - public boolean contains(Point p) { + public boolean contains(@Nullable Point p) { return p != null && contains(p.x, p.y); } @@ -93,6 +97,7 @@ public class Rect { * Moves this rectangle by setting it's x,y coordinates to the new values. * @return Returns self, for chaining. */ + @NonNull public Rect moveTo(int x, int y) { this.x = x; this.y = y; @@ -103,31 +108,37 @@ public class Rect { * Offsets this rectangle by adding the given x,y deltas to the x,y coordinates. * @return Returns self, for chaining. */ + @NonNull public Rect offsetBy(int x, int y) { this.x += x; this.y += y; return this; } + @NonNull public Point getCenter() { return new Point(x + (w > 0 ? w / 2 : 0), y + (h > 0 ? h / 2 : 0)); } + @NonNull public Point getTopLeft() { return new Point(x, y); } + @NonNull public Point getBottomLeft() { return new Point(x, y + (h > 0 ? h : 0)); } + @NonNull public Point getTopRight() { return new Point(x + (w > 0 ? w : 0), y); } + @NonNull public Point getBottomRight() { return new Point(x + (w > 0 ? w : 0), y + (h > 0 ? h : 0)); @@ -207,6 +218,7 @@ public class Rect { * * @return the center point in the rectangle */ + @NonNull public Point center() { return new Point(x + w / 2, y + h / 2); } diff --git a/rule_api/src/com/android/ide/common/api/ResizePolicy.java b/rule_api/src/com/android/ide/common/api/ResizePolicy.java index 3383cd0..f48095a 100644 --- a/rule_api/src/com/android/ide/common/api/ResizePolicy.java +++ b/rule_api/src/com/android/ide/common/api/ResizePolicy.java @@ -15,6 +15,7 @@ */ package com.android.ide.common.api; +import com.android.annotations.NonNull; import com.google.common.annotations.Beta; /** @@ -40,7 +41,7 @@ public class ResizePolicy { // Shared objects for common policies - public static final ResizePolicy sAny = new ResizePolicy(ANY); + private static final ResizePolicy sAny = new ResizePolicy(ANY); private static final ResizePolicy sNone = new ResizePolicy(NONE); private static final ResizePolicy sHorizontal = new ResizePolicy(HORIZONTAL); private static final ResizePolicy sVertical = new ResizePolicy(VERTICAL); @@ -113,6 +114,7 @@ public class ResizePolicy { * * @return a resize policy allowing resizing in any direction */ + @NonNull public static ResizePolicy full() { return sAny; } @@ -122,6 +124,7 @@ public class ResizePolicy { * * @return a policy which does not allow any resizing */ + @NonNull public static ResizePolicy none() { return sNone; } @@ -131,6 +134,7 @@ public class ResizePolicy { * * @return a policy which allows horizontal resizing only */ + @NonNull public static ResizePolicy horizontal() { return sHorizontal; } @@ -140,6 +144,7 @@ public class ResizePolicy { * * @return a policy which allows vertical resizing only */ + @NonNull public static ResizePolicy vertical() { return sVertical; } @@ -149,6 +154,7 @@ public class ResizePolicy { * * @return a resize policy allowing scaled / aspect-ratio preserving resizing only */ + @NonNull public static ResizePolicy scaled() { return sScaled; } @@ -163,6 +169,7 @@ public class ResizePolicy { * @param preserve whether the policy requires the aspect ratio to be preserved * @return a resize policy recording the constraints required by the parameters */ + @NonNull public static ResizePolicy create(boolean top, boolean right, boolean bottom, boolean left, boolean preserve) { int mask = NONE; 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 5b6dc7f..f6c7e8c 100755..100644 --- a/rule_api/src/com/android/ide/common/api/RuleAction.java +++ b/rule_api/src/com/android/ide/common/api/RuleAction.java @@ -16,6 +16,8 @@ package com.android.ide.common.api; +import com.android.annotations.NonNull; +import com.android.annotations.Nullable; import com.android.util.Pair; import com.google.common.annotations.Beta; @@ -99,6 +101,7 @@ public class RuleAction implements Comparable<RuleAction> { * @param sortPriority a priority used for sorting this action * @return a new separator */ + @NonNull public static Separator createSeparator(int sortPriority) { return new Separator(sortPriority, true /* supportsMultipleNodes*/); } @@ -116,8 +119,14 @@ public class RuleAction implements Comparable<RuleAction> { * see {@link #supportsMultipleNodes()} for details * @return the new {@link RuleAction} */ - public static RuleAction createAction(String id, String title, - IMenuCallback callback, URL iconUrl, int sortPriority, boolean supportsMultipleNodes) { + @NonNull + public static RuleAction createAction( + @NonNull String id, + @NonNull String title, + @NonNull IMenuCallback callback, + @Nullable URL iconUrl, + int sortPriority, + boolean supportsMultipleNodes) { RuleAction action = new RuleAction(id, title, callback, sortPriority, supportsMultipleNodes); action.setIconUrl(iconUrl); @@ -139,8 +148,14 @@ public class RuleAction implements Comparable<RuleAction> { * see {@link #supportsMultipleNodes()} for details * @return the new {@link Toggle} */ - public static Toggle createToggle(String id, String title, boolean isChecked, - IMenuCallback callback, URL iconUrl, int sortPriority, + @NonNull + public static Toggle createToggle( + @NonNull String id, + @NonNull String title, + boolean isChecked, + @NonNull IMenuCallback callback, + @Nullable URL iconUrl, + int sortPriority, boolean supportsMultipleNodes) { Toggle toggle = new Toggle(id, title, isChecked, callback, sortPriority, supportsMultipleNodes); @@ -165,9 +180,15 @@ public class RuleAction implements Comparable<RuleAction> { * see {@link #supportsMultipleNodes()} for details * @return the new {@link NestedAction} */ - public static NestedAction createChoices(String id, String title, - IMenuCallback callback, URL iconUrl, - int sortPriority, boolean supportsMultipleNodes, ActionProvider provider) { + @NonNull + public static NestedAction createChoices( + @NonNull String id, + @NonNull String title, + @NonNull IMenuCallback callback, + @Nullable URL iconUrl, + int sortPriority, + boolean supportsMultipleNodes, + @NonNull ActionProvider provider) { NestedAction choices = new NestedAction(id, title, provider, callback, sortPriority, supportsMultipleNodes); choices.setIconUrl(iconUrl); @@ -196,9 +217,18 @@ public class RuleAction implements Comparable<RuleAction> { * see {@link #supportsMultipleNodes()} for details * @return the new {@link Choices} */ - public static Choices createChoices(String id, String title, - IMenuCallback callback, List<String> titles, List<URL> iconUrls, List<String> ids, - String current, URL iconUrl, int sortPriority, boolean supportsMultipleNodes) { + @NonNull + public static Choices createChoices( + @NonNull String id, + @NonNull String title, + @NonNull IMenuCallback callback, + @NonNull List<String> titles, + @Nullable List<URL> iconUrls, + @NonNull List<String> ids, + @Nullable String current, + @Nullable URL iconUrl, + int sortPriority, + boolean supportsMultipleNodes) { Choices choices = new Choices(id, title, callback, titles, iconUrls, ids, current, sortPriority, supportsMultipleNodes); choices.setIconUrl(iconUrl); @@ -228,10 +258,17 @@ public class RuleAction implements Comparable<RuleAction> { * menu items * @return the new {@link Choices} */ - public static Choices createChoices(String id, String title, - IMenuCallback callback, List<URL> iconUrls, - String current, URL iconUrl, int sortPriority, - boolean supportsMultipleNodes, List<Pair<String, String>> idsAndTitles) { + @NonNull + public static Choices createChoices( + @NonNull String id, + @NonNull String title, + @NonNull IMenuCallback callback, + @Nullable List<URL> iconUrls, + @Nullable String current, + @Nullable URL iconUrl, + int sortPriority, + boolean supportsMultipleNodes, + @NonNull List<Pair<String, String>> idsAndTitles) { int itemCount = idsAndTitles.size(); List<String> titles = new ArrayList<String>(itemCount); List<String> ids = new ArrayList<String>(itemCount); @@ -264,9 +301,16 @@ public class RuleAction implements Comparable<RuleAction> { * see {@link #supportsMultipleNodes()} for details * @return the new {@link Choices} */ - public static Choices createChoices(String id, String title, - IMenuCallback callback, ChoiceProvider provider, - String current, URL iconUrl, int sortPriority, boolean supportsMultipleNodes) { + @NonNull + public static Choices createChoices( + @NonNull String id, + @NonNull String title, + IMenuCallback callback, + @NonNull ChoiceProvider provider, + @Nullable String current, + @Nullable URL iconUrl, + int sortPriority, + boolean supportsMultipleNodes) { Choices choices = new DelayedChoices(id, title, callback, current, provider, sortPriority, supportsMultipleNodes); choices.setIconUrl(iconUrl); @@ -286,7 +330,11 @@ public class RuleAction implements Comparable<RuleAction> { * @param supportsMultipleNodes the new return value for * {@link #supportsMultipleNodes()} */ - private RuleAction(String id, String title, IMenuCallback callback, int sortPriority, + private RuleAction( + @NonNull String id, + @NonNull String title, + @NonNull IMenuCallback callback, + int sortPriority, boolean supportsMultipleNodes) { mId = id; mTitle = title; @@ -302,6 +350,7 @@ public class RuleAction implements Comparable<RuleAction> { * * @return the unique id of the action, never null */ + @NonNull public String getId() { return mId; } @@ -312,6 +361,7 @@ public class RuleAction implements Comparable<RuleAction> { * * @return the user name of the action, never null */ + @NonNull public String getTitle() { return mTitle; } @@ -371,6 +421,7 @@ public class RuleAction implements Comparable<RuleAction> { * @param iconUrl a URL pointing to an icon to use for this action, or null * @return this action, to allow setter chaining */ + @NonNull public RuleAction setIconUrl(URL iconUrl) { mIconUrl = iconUrl; @@ -392,13 +443,14 @@ public class RuleAction implements Comparable<RuleAction> { * * @return the callback, never null */ + @NonNull public IMenuCallback getCallback() { return mCallback; } // Implements Comparable<MenuAciton> @Override - public int compareTo(RuleAction other) { + public int compareTo(@NonNull RuleAction other) { if (mSortPriority != other.mSortPriority) { return mSortPriority - other.mSortPriority; } @@ -406,6 +458,7 @@ public class RuleAction implements Comparable<RuleAction> { return mTitle.compareTo(other.mTitle); } + @NonNull @Override public String toString() { return "RuleAction [id=" + mId + ", title=" + mTitle + ", priority=" + mSortPriority + "]"; @@ -442,8 +495,13 @@ public class RuleAction implements Comparable<RuleAction> { * @param callback A callback to execute when the context menu item is * selected. */ - private Toggle(String id, String title, boolean isChecked, - IMenuCallback callback, int sortPriority, boolean supportsMultipleNodes) { + private Toggle( + @NonNull String id, + @NonNull String title, + boolean isChecked, + @NonNull IMenuCallback callback, + int sortPriority, + boolean supportsMultipleNodes) { super(id, title, callback, sortPriority, supportsMultipleNodes); mIsChecked = isChecked; } @@ -491,9 +549,16 @@ public class RuleAction implements Comparable<RuleAction> { */ protected final String mCurrent; - private Choices(String id, String title, IMenuCallback callback, - List<String> titles, List<URL> iconUrls, List<String> ids, String current, - int sortPriority, boolean supportsMultipleNodes) { + private Choices( + @NonNull String id, + @NonNull String title, + @NonNull IMenuCallback callback, + @NonNull List<String> titles, + @Nullable List<URL> iconUrls, + @NonNull List<String> ids, + @Nullable String current, + int sortPriority, + boolean supportsMultipleNodes) { super(id, title, callback, sortPriority, supportsMultipleNodes); mTitles = titles; mIconUrls = iconUrls; @@ -506,6 +571,7 @@ public class RuleAction implements Comparable<RuleAction> { * * @return the list of urls to icons to display for each choice, or null */ + @Nullable public List<URL> getIconUrls() { return mIconUrls; } @@ -515,6 +581,7 @@ public class RuleAction implements Comparable<RuleAction> { * * @return the list of ids for the menu choices, never null */ + @NonNull public List<String> getIds() { return mIds; } @@ -524,6 +591,7 @@ public class RuleAction implements Comparable<RuleAction> { * * @return the titles to be displayed for the menu choices, never null */ + @NonNull public List<String> getTitles() { return mTitles; } @@ -533,6 +601,7 @@ public class RuleAction implements Comparable<RuleAction> { * * @return the current value of the choice, possibly null */ + @Nullable public String getCurrent() { return mCurrent; } @@ -566,8 +635,12 @@ public class RuleAction implements Comparable<RuleAction> { /** The provider to produce the list of nested actions when needed */ private final ActionProvider mProvider; - private NestedAction(String id, String title, ActionProvider provider, - IMenuCallback callback, int sortPriority, + private NestedAction( + @NonNull String id, + @NonNull String title, + @NonNull ActionProvider provider, + @NonNull IMenuCallback callback, + int sortPriority, boolean supportsMultipleNodes) { super(id, title, callback, sortPriority, supportsMultipleNodes); mProvider = provider; @@ -579,7 +652,8 @@ public class RuleAction implements Comparable<RuleAction> { * @param node the node to look up nested actions for * @return a list of nested actions */ - public List<RuleAction> getNestedActions(INode node) { + @NonNull + public List<RuleAction> getNestedActions(@NonNull INode node) { return mProvider.getNestedActions(node); } } @@ -587,21 +661,23 @@ public class RuleAction implements Comparable<RuleAction> { /** Like {@link Choices}, but the set of choices is computed lazily */ private static class DelayedChoices extends Choices { private final ChoiceProvider mProvider; - - private DelayedChoices(String id, String title, - IMenuCallback callback, String current, ChoiceProvider provider, + private boolean mInitialized; + + private DelayedChoices( + @NonNull String id, + @NonNull String title, + @NonNull IMenuCallback callback, + @Nullable String current, + @NonNull ChoiceProvider provider, int sortPriority, boolean supportsMultipleNodes) { - super(id, title, callback, null, null, null, current, sortPriority, - supportsMultipleNodes); + super(id, title, callback, new ArrayList<String>(), new ArrayList<URL>(), + new ArrayList<String>(), current, sortPriority, supportsMultipleNodes); mProvider = provider; } private void ensureInitialized() { - if (mTitles == null) { - mTitles = new ArrayList<String>(); - mIconUrls = new ArrayList<URL>(); - mIds = new ArrayList<String>(); - + if (!mInitialized) { + mInitialized = true; mProvider.addChoices(mTitles, mIconUrls, mIds); } } @@ -637,7 +713,8 @@ public class RuleAction implements Comparable<RuleAction> { * @param node the node to look up nested actions for * @return a list of nested actions */ - public List<RuleAction> getNestedActions(INode node); + @NonNull + public List<RuleAction> getNestedActions(@NonNull INode node); } /** @@ -654,6 +731,9 @@ public class RuleAction implements Comparable<RuleAction> { * @param iconUrls a list of icon URLs that the provider should append to * @param ids a list of ids that the provider should append to */ - 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); } } 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 681fd14..9f03286 100644 --- a/rule_api/src/com/android/ide/common/api/Segment.java +++ b/rule_api/src/com/android/ide/common/api/Segment.java @@ -16,6 +16,8 @@ package com.android.ide.common.api; +import com.android.annotations.NonNull; +import com.android.annotations.Nullable; import com.google.common.annotations.Beta; /** @@ -38,25 +40,29 @@ public class Segment { public final int to; /** Whether the edge is a top edge, a baseline edge, a left edge, etc */ + @NonNull public final SegmentType edgeType; /** * Whether the edge is offset from the node by a margin or not, or whether it has no * margin */ + @NonNull public final MarginType marginType; /** The node that contains this edge */ + @NonNull public final INode node; /** * The id of the node. May be null (in which case id should be generated when * move/resize is completed */ + @Nullable public final String id; - public Segment(int at, int from, int to, INode node, String id, SegmentType edgeType, - MarginType marginType) { + public Segment(int at, int from, int to, @NonNull INode node, @Nullable String id, + @NonNull SegmentType edgeType, @NonNull MarginType marginType) { this.at = at; this.from = from; this.to = to; @@ -66,6 +72,7 @@ public class Segment { this.marginType = marginType; } + @NonNull @Override public String toString() { String nodeStr = node == null ? "null" : node.getFqcn().substring( 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 191d753..25635c7 100644 --- a/rule_api/src/com/android/ide/common/api/SegmentType.java +++ b/rule_api/src/com/android/ide/common/api/SegmentType.java @@ -16,6 +16,8 @@ package com.android.ide.common.api; +import com.android.annotations.NonNull; +import com.android.annotations.Nullable; import com.google.common.annotations.Beta; /** A segment type describes the different roles or positions a segment can have in a node @@ -38,7 +40,7 @@ public enum SegmentType { * @param bounds the bounds of the node * @return the X coordinate for an edge of this type given its bounds */ - public int getX(INode node, Rect bounds) { + public int getX(@Nullable INode node, @NonNull Rect bounds) { // We pass in the bounds rather than look it up via node.getBounds() because // during a resize or move operation, we call this method to look up proposed // bounds rather than actual bounds @@ -66,7 +68,7 @@ public enum SegmentType { * @param bounds the bounds of the node * @return the Y coordinate for an edge of this type given its bounds */ - public int getY(INode node, Rect bounds) { + public int getY(@Nullable INode node, @NonNull Rect bounds) { switch (this) { case TOP: return bounds.y; |