Quantity implements Comparable<Quantity> { @NotNull public static String addUnit(@NotNull NlProperty property, @NotNull String value) { AttributeDefinition definition = property.getDefinition(); boolean isDimension = definition != null && definition.getFormats().contains(AttributeFormat.DIMENSION); if (!isDimension) { return value; } Quantity quantity = parse(value); if (quantity == null || !quantity.myUnit.isEmpty()) { return value; } switch (property.getName()) { case SdkConstants.ATTR_TEXT_SIZE: case SdkConstants.ATTR_LINE_SPACING_EXTRA: return quantity.myValue + SdkConstants.UNIT_SP; default: return quantity.myValue + SdkConstants.UNIT_DP; } } private  Quantity(int value, @NotNull String unit); @Nullable static Quantity parse(@NotNull String value); @NotNull static String addUnit(@NotNull NlProperty property, @NotNull String value); static String addUnit(@NotNull ResourceType type, @NotNull String value); int getValue(); @NotNull String getUnit(); @Override int compareTo(@Nullable Quantity other);  }
@Test public void testAddUnit() { assertThat(Quantity.addUnit(mockProperty(ATTR_TEXT_SIZE, DIMENSION), "13")).isEqualTo("13sp"); assertThat(Quantity.addUnit(mockProperty(ATTR_LINE_SPACING_EXTRA, DIMENSION), "10")).isEqualTo("10sp"); assertThat(Quantity.addUnit(mockProperty(ATTR_LAYOUT_WIDTH, DIMENSION), "53")).isEqualTo("53dp"); assertThat(Quantity.addUnit(mockProperty(ATTR_LAYOUT_WIDTH, DIMENSION), "53px")).isEqualTo("53px"); assertThat(Quantity.addUnit(mockProperty(ATTR_LAYOUT_WIDTH, DIMENSION), "wrap_content")).isEqualTo("wrap_content"); assertThat(Quantity.addUnit(mockProperty(ATTR_TEXT, STRING), "13")).isEqualTo("13"); assertThat(Quantity.addUnit(mockProperty(ATTR_MIN_SDK_VERSION, INTEGER), "22")).isEqualTo("22"); }