java.lang.annotation.IncompleteAnnotationException Java Examples

The following examples show how to use java.lang.annotation.IncompleteAnnotationException. 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: AVIMMessageManager.java    From java-unified-sdk with Apache License 2.0 6 votes vote down vote up
/**
 * 注册自定义的消息类型
 *
 * @param messageType message type.
 */
public static void registerAVIMMessageType(Class<? extends AVIMTypedMessage> messageType) {
  AVIMMessageType type = messageType.getAnnotation(AVIMMessageType.class);
  if (type == null) {
    throw new IncompleteAnnotationException(AVIMMessageType.class, "type");
  }
  int messageTypeValue = type.type();

  messageTypesRepository.put(messageTypeValue, messageType);
  try {
    Method initializeMethod = messageType.getDeclaredMethod("computeFieldAttribute", Class.class);
    initializeMethod.setAccessible(true);
    initializeMethod.invoke(null, messageType);
  } catch (Exception e) {
    LOGGER.d("failed to initialize message Fields");
  }
}
 
Example #2
Source File: MappedElementExtractor.java    From nb-springboot with Apache License 2.0 6 votes vote down vote up
/**
 * Extracts the type level mapping if any. Makes sure that at least "/" is mapped and restricted to the given methods, if
 * there any.
 *
 * @param parentRequestMapping
 * @return
 */
Map<String, List<RequestMethod>> extractTypeLevelMappings(final RequestMapping parentRequestMapping) {
    final Map<String, List<RequestMethod>> parentUrls = new TreeMap<>();
    List<String> urls = new ArrayList<>();
    List<RequestMethod> methods = new ArrayList<>();
    if (parentRequestMapping != null) {
        try {
            urls = concatValues(parentRequestMapping.value(), parentRequestMapping.path());
            methods = Arrays.asList(parentRequestMapping.method());
        } catch (IncompleteAnnotationException ex) {
            // ignore as may be thrown while typing annotations
        }
    }
    final List<String> usedUrls = urls.isEmpty() ? Arrays.asList("/") : urls;
    for (final String url : usedUrls) {
        final String usedUrl = url.startsWith("/") ? url : "/" + url;
        parentUrls.put(usedUrl, methods);
    }
    return parentUrls;
}
 
Example #3
Source File: AbstractOptionElement.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private String readDescription(Option option, String optionName, Class<?> declaringClass) {
    try {
        return option.description();
    } catch (IncompleteAnnotationException ex) {
        throw new OptionValidationException(String.format("No description set on option '%s' at for class '%s'.", optionName, declaringClass.getName()));
    }
}
 
Example #4
Source File: AbstractOptionElement.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private String readDescription(Option option, String optionName, Class<?> declaringClass) {
    try {
        return option.description();
    } catch (IncompleteAnnotationException ex) {
        throw new OptionValidationException(String.format("No description set on option '%s' at for class '%s'.", optionName, declaringClass.getName()));
    }
}
 
Example #5
Source File: SimpleAnnoInvocationHandler.java    From java-di with Apache License 2.0 5 votes vote down vote up
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    String methodName = method.getName();

    if (S.eq("hashCode", methodName)) {
        return hashCode();
    } else if (S.eq("equals", methodName)) {
        return equals(args[0]);
    } else if (S.eq("annotationType", methodName)) {
        return type;
    } else if (S.eq("toString", methodName)) {
        return toString();
    }

    Object result = memberValues.get(methodName);
    if (null != result) {
        return result;
    }

    result = method.getDefaultValue();

    if (result == null) {
        throw new IncompleteAnnotationException(type, methodName);
    }

    return result;
}
 
Example #6
Source File: SimpleAnnoInvocationHandler.java    From java-di with Apache License 2.0 5 votes vote down vote up
@Override
public int hashCode() {
    int result = 0;
    for (Method m : type.getDeclaredMethods()) {
        Object o = m.getDefaultValue();
        if (null == o) {
            throw new IncompleteAnnotationException(type, m.getName());
        }
        result += AnnotationUtil.hashMember(m.getName(), o);
    }
    return result;
}
 
Example #7
Source File: AbstractOptionElement.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private String readDescription(Option option, String optionName, Class<?> declaringClass) {
    try {
        return option.description();
    } catch (IncompleteAnnotationException ex) {
        throw new OptionValidationException(String.format("No description set on option '%s' at for class '%s'.", optionName, declaringClass.getName()));
    }
}
 
Example #8
Source File: AbstractOptionElement.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private String readDescription(Option option, String optionName, Class<?> declaringClass) {
    try {
        return option.description();
    } catch (IncompleteAnnotationException ex) {
        throw new OptionValidationException(String.format("No description set on option '%s' at for class '%s'.", optionName, declaringClass.getName()));
    }
}
 
Example #9
Source File: IncompleteAnnotationExceptionTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
public void testNullType() {
    try {
        new IncompleteAnnotationException(null, "str");
        fail("NullPointerException must be thrown");
    } catch (NullPointerException e) {
        // Expected
    }
}
 
Example #10
Source File: IncompleteAnnotationExceptionTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * @throws Exception
 * @tests java.lang.annotation.IncompleteAnnotationException#IncompleteAnnotationException(Class,
 *        String)
 */
@SuppressWarnings("nls")
public void test_constructorLjava_lang_Class_Ljava_lang_String()
        throws Exception {
    Class clazz = String.class;
    String elementName = "some element";
    IncompleteAnnotationException e = new IncompleteAnnotationException(
            clazz, elementName);
    assertNotNull("can not instantiate IncompleteAnnotationException", e);
    assertSame("wrong annotation type", clazz, e.annotationType());
    assertSame("wrong element name", elementName, e.elementName());
}
 
Example #11
Source File: AnnotationDescriptionAnnotationInvocationHandlerTest.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
@Test(expected = IncompleteAnnotationException.class)
@SuppressWarnings("unchecked")
public void testIncompleteAnnotationException() throws Throwable {
    when(freeAnnotationValue.load(getClass().getClassLoader())).thenReturn((AnnotationValue.Loaded)
            new AnnotationValue.ForMissingValue.Loaded<Void>(Foo.class, "foo"));
    Proxy.getInvocationHandler(AnnotationDescription.AnnotationInvocationHandler.of(getClass().getClassLoader(),
            Foo.class,
            Collections.<String, AnnotationValue<?, ?>>singletonMap(FOO, freeAnnotationValue)))
            .invoke(new Object(), Foo.class.getDeclaredMethod("foo"), new Object[0]);
}
 
Example #12
Source File: AnnotationValue.java    From byte-buddy with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public W resolve() {
    throw new IncompleteAnnotationException(type, property);
}
 
Example #13
Source File: AnnotationDescriptionLatentTest.java    From byte-buddy with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
private static AnnotationDescription build(Annotation annotation) throws Exception {
    AnnotationDescription.Builder builder = AnnotationDescription.Builder.ofType(annotation.annotationType());
    for (Method method : annotation.annotationType().getDeclaredMethods()) {
        try {
            Object value = method.invoke(annotation);
            if (value instanceof Annotation) {
                builder = builder.define(method.getName(), (Annotation) value);
            } else if (value instanceof Annotation[]) {
                builder = builder.defineAnnotationArray(method.getName(), (Class) method.getReturnType().getComponentType(), (Annotation[]) value);
            } else if (value instanceof Enum<?>) {
                builder = builder.define(method.getName(), (Enum<?>) value);
            } else if (value instanceof Enum<?>[]) {
                builder = builder.defineEnumerationArray(method.getName(), (Class) method.getReturnType().getComponentType(), (Enum[]) value);
            } else if (value instanceof Class<?>) {
                builder = builder.define(method.getName(), (Class<?>) value);
            } else if (value instanceof Class<?>[]) {
                builder = builder.defineTypeArray(method.getName(), (Class<?>[]) value);
            } else if (value instanceof String) {
                builder = builder.define(method.getName(), (String) value);
            } else if (value instanceof String[]) {
                builder = builder.defineArray(method.getName(), (String[]) value);
            } else if (value instanceof Boolean) {
                builder = builder.define(method.getName(), (Boolean) value);
            } else if (value instanceof Byte) {
                builder = builder.define(method.getName(), (Byte) value);
            } else if (value instanceof Character) {
                builder = builder.define(method.getName(), (Character) value);
            } else if (value instanceof Short) {
                builder = builder.define(method.getName(), (Short) value);
            } else if (value instanceof Integer) {
                builder = builder.define(method.getName(), (Integer) value);
            } else if (value instanceof Long) {
                builder = builder.define(method.getName(), (Long) value);
            } else if (value instanceof Float) {
                builder = builder.define(method.getName(), (Float) value);
            } else if (value instanceof Double) {
                builder = builder.define(method.getName(), (Double) value);
            } else if (value instanceof boolean[]) {
                builder = builder.defineArray(method.getName(), (boolean[]) value);
            } else if (value instanceof byte[]) {
                builder = builder.defineArray(method.getName(), (byte[]) value);
            } else if (value instanceof char[]) {
                builder = builder.defineArray(method.getName(), (char[]) value);
            } else if (value instanceof short[]) {
                builder = builder.defineArray(method.getName(), (short[]) value);
            } else if (value instanceof int[]) {
                builder = builder.defineArray(method.getName(), (int[]) value);
            } else if (value instanceof long[]) {
                builder = builder.defineArray(method.getName(), (long[]) value);
            } else if (value instanceof float[]) {
                builder = builder.defineArray(method.getName(), (float[]) value);
            } else if (value instanceof double[]) {
                builder = builder.defineArray(method.getName(), (double[]) value);
            } else {
                throw new IllegalArgumentException("Unexpected annotation property: " + method);
            }
        } catch (InvocationTargetException exception) {
            Throwable cause = exception.getCause();
            if (cause instanceof TypeNotPresentException) {
                builder = builder.define(method.getName(), new AnnotationValue.ForMissingType<Void, Void>(((TypeNotPresentException) cause).typeName()));
            } else if (cause instanceof EnumConstantNotPresentException) {
                builder = builder.define(method.getName(), new AnnotationValue.ForEnumerationDescription.WithUnknownConstant(
                        new TypeDescription.ForLoadedType(((EnumConstantNotPresentException) cause).enumType()),
                        ((EnumConstantNotPresentException) cause).constantName()));
            } else if (cause instanceof AnnotationTypeMismatchException) {
                builder = builder.define(method.getName(), new AnnotationValue.ForMismatchedType<Void, Void>(
                        new MethodDescription.ForLoadedMethod(((AnnotationTypeMismatchException) cause).element()),
                        ((AnnotationTypeMismatchException) cause).foundType()));
            } else if (!(cause instanceof IncompleteAnnotationException)) {
                throw exception;
            }
        }
    }
    return builder.build(false);
}