butterknife.internal.Utils Java Examples
The following examples show how to use
butterknife.internal.Utils.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ButterKnife.java From butterknife with Apache License 2.0 | 6 votes |
private static @Nullable Unbinder parseBindView(Object target, Field field, View source) { BindView bindView = field.getAnnotation(BindView.class); if (bindView == null) { return null; } validateMember(field); int id = bindView.value(); Class<?> viewClass = field.getType(); if (!View.class.isAssignableFrom(viewClass) && !viewClass.isInterface()) { throw new IllegalStateException( "@BindView fields must extend from View or be an interface. (" + field.getDeclaringClass().getName() + '.' + field.getName() + ')'); } String who = "field '" + field.getName() + "'"; Object view = Utils.findOptionalViewAsType(source, id, who, viewClass); trySet(field, target, view); return new FieldUnbinder(target, field); }
Example #2
Source File: ButterKnife.java From butterknife with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") private static <T extends View> List<T> findViews(View source, int[] ids, boolean isRequired, String name, Class<? extends View> cls) { if (ids.length == 1 && ids[0] == View.NO_ID) { return singletonList((T) cls.cast(source)); } String who = "method '" + name + "'"; List<T> views = new ArrayList<>(ids.length); for (int id : ids) { if (isRequired) { views.add((T) Utils.findRequiredViewAsType(source, id, who, cls)); } else { T view = (T) Utils.findOptionalViewAsType(source, id, who, cls); if (view != null) { views.add(view); } } } return views; }
Example #3
Source File: UtilsTest.java From butterknife with Apache License 2.0 | 5 votes |
@Test public void testCastParam() { try { Utils.castParam("abc", "Foo", 3, "foo()", 4, Integer.class); fail(); } catch (IllegalStateException ise) { assertThat(ise.getMessage()).isEqualTo( "Parameter #4 of method 'Foo' was of the wrong type for parameter #5 of method 'foo()'. See cause for more info."); } }