java类java.lang.annotation.IncompleteAnnotationException的实例源码

MappedElementExtractor.java 文件源码 项目:nb-springboot 阅读 29 收藏 0 点赞 0 评论 0
/**
 * 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;
}
AnnotationInvocationHandler.java 文件源码 项目:Alchemy 阅读 39 收藏 0 点赞 0 评论 0
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    String name = method.getName();
    Class<?>[] types = method.getParameterTypes();
    InvocationHandler proxyMethod = memberProxys.get(name);
    if (proxyMethod != null)
        return proxyMethod.invoke(proxy, method, args);
    if (name.equals("equals") && types.length == 1 && types[0] == Object.class)
        return equalsImpl(args[0]);
    if (types.length != 0)
        throw new AssertionError("Too many parameters for an annotation method");
    switch (name) {
        case "toString":
            return toStringImpl();
        case "hashCode":
            return hashCodeImpl();
        case "annotationType":
            return type;
    }
    Object result = memberValues.get(name);
    if (result == null)
        throw new IncompleteAnnotationException(type, name);
    return result.getClass().isArray() ? Tool.cloneArray(result) : result;
}
SimpleAnnoInvocationHandler.java 文件源码 项目:java-di 阅读 29 收藏 0 点赞 0 评论 0
@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 = method.getDefaultValue();

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

    return result;
}
AbstractOptionElement.java 文件源码 项目:Reer 阅读 31 收藏 0 点赞 0 评论 0
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()));
    }
}
AnnotationUtils.java 文件源码 项目:jcomposition 阅读 42 收藏 0 点赞 0 评论 0
@SuppressWarnings("unchecked")
public static IMergeConflictPolicy getCompositionMergeConflictPolicy(TypeElement element, ProcessingEnvironment env) {
    Optional<AnnotationValue> value = getParameterFrom(element, Composition.class, "onConflict", env);

    if (value.isPresent()) {
        TypeElement typeElement = MoreTypes.asTypeElement((Type) value.get().getValue());
        try {
            return (IMergeConflictPolicy) Class.forName(typeElement.getQualifiedName().toString()).newInstance();
        } catch (Exception ignore) { }
    }

    throw new IncompleteAnnotationException(Composition.class, "onConflict");
}
SimpleAnnoInvocationHandler.java 文件源码 项目:java-di 阅读 29 收藏 0 点赞 0 评论 0
@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;
}
AbstractOptionElement.java 文件源码 项目:Pushjet-Android 阅读 32 收藏 0 点赞 0 评论 0
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()));
    }
}
AbstractOptionElement.java 文件源码 项目:Pushjet-Android 阅读 26 收藏 0 点赞 0 评论 0
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()));
    }
}
AnnotationFactory.java 文件源码 项目:In-the-Box-Fork 阅读 35 收藏 0 点赞 0 评论 0
/**
 * Processes a method invocation request to this annotation instance.
 * Recognizes the methods declared in the
 * {@link java.lang.annotation.Annotation java.lang.annotation.Annotation}
 * interface, and member-defining methods of the implemented annotation type.
 * @throws IllegalArgumentException If the specified method is none of the above
 * @return the invocation result
 */
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
{
    String name = method.getName();
    Class[] params = method.getParameterTypes();
    if (params.length == 0) {
        if ("annotationType".equals(name)) {
            return klazz;
        } else if ("toString".equals(name)) {
            return toString();
        } else if ("hashCode".equals(name)) {
            return hashCode();
        }

        // this must be element value request
        AnnotationMember element = null;
        for (AnnotationMember el : elements) {
            if (name.equals(el.name)) {
                element = el;
                break;
            }
        }
        if (element == null || !method.equals(element.definingMethod)) {
            throw new IllegalArgumentException(method.toString());
        } else {
            Object value = element.validateValue();
            if (value == null) {
                throw new IncompleteAnnotationException(klazz, name);
            }
            return value;
        }
    } else if (params.length == 1 && params[0] == Object.class && "equals".equals(name)){
        return Boolean.valueOf(equals(args[0]));
    }
    throw new IllegalArgumentException(
            "Invalid method for annotation type: " + method);
}
IncompleteAnnotationExceptionTest.java 文件源码 项目:In-the-Box-Fork 阅读 32 收藏 0 点赞 0 评论 0
public void testNullType() {
    try {
        new IncompleteAnnotationException(null, "str");
        fail("NullPointerException must be thrown");
    } catch (NullPointerException e) {
        // Expected
    }
}
IncompleteAnnotationExceptionTest.java 文件源码 项目:In-the-Box-Fork 阅读 22 收藏 0 点赞 0 评论 0
/**
 * @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());
}
CoreMetaDataCompatibility.java 文件源码 项目:TA-Lib 阅读 36 收藏 0 点赞 0 评论 0
RetCode taGetFuncInfo(FuncInfo retFuncInfo) {
    try {
        retFuncInfo = super.getFuncInfo();
        return RetCode.Success;
    } catch (IncompleteAnnotationException e) {
        return RetCode.InternalError;
    }
}
AnnotationFactory.java 文件源码 项目:cn1 阅读 32 收藏 0 点赞 0 评论 0
/**
   * Processes a method invocation request to this annotation instance.
   * Recognizes the methods declared in the 
   * {@link java.lang.annotation.Annotation java.lang.annotation.Annotation}
   * interface, and member-defining methods of the implemented annotation type.
   * @throws IllegalArgumentException If the specified method is none of the above
   * @return the invocation result 
   */
  public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
  {
      String name = method.getName();
      Class[] params = method.getParameterTypes();
      if (params.length == 0) {
          if ("annotationType".equals(name)) {
              return klazz;
          } else if ("toString".equals(name)) {
              return toString();
          } else if ("hashCode".equals(name)) {
              return hashCode();
          }

          // this must be element value request
          AnnotationMember element = null;
          for (AnnotationMember el : elements) {
              if (name.equals(el.name)) {
                  element = el;
                  break;
              }                
          }
          if (element == null || !method.equals(element.definingMethod)) {
              throw new IllegalArgumentException(method.toString());
          } else {
              Object value = element.validateValue();
              if (value == null) {
                  throw new IncompleteAnnotationException(klazz, name);
              }
              return value;
          }
} else if (params.length == 1 && params[0] == Object.class && "equals".equals(name)){
    return Boolean.valueOf(equals(args[0]));
      }
      throw new IllegalArgumentException(
              "Invalid method for annotation type: " + method);
  }
IncompleteAnnotationExceptionTest.java 文件源码 项目:cn1 阅读 28 收藏 0 点赞 0 评论 0
public void testNullType() {
    try {
        new IncompleteAnnotationException(null, "str");
        fail("NullPointerException must be thrown");
    } catch (NullPointerException e) {
        // Expected
    }
}
IncompleteAnnotationExceptionTest.java 文件源码 项目:cn1 阅读 30 收藏 0 点赞 0 评论 0
/**
 * @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());
}
Annotations.java 文件源码 项目:ev-oss 阅读 34 收藏 0 点赞 0 评论 0
public AnnotationHandler(final Class<? extends Annotation> type, final Map<String, ?> values) {
    this.type = type;
    methods = Arrays.asList(type.getDeclaredMethods());
    for (final Method m : methods) {
        Object o = values.get(m.getName());
        if (o == null) {
            o = m.getDefaultValue();
        }
        if (o == null) {
            throw new IncompleteAnnotationException(type, m.getName());
        }
        this.values.put(m.getName(), o);
    }
}
IncompleteAnnotationExceptionTest.java 文件源码 项目:freeVM 阅读 32 收藏 0 点赞 0 评论 0
public void testNullType() {
    try {
        new IncompleteAnnotationException(null, "str");
        fail("NullPointerException must be thrown");
    } catch (NullPointerException e) {
        // Expected
    }
}
IncompleteAnnotationExceptionTest.java 文件源码 项目:freeVM 阅读 33 收藏 0 点赞 0 评论 0
/**
 * @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 instanciate IncompleteAnnotationException", e);
    assertSame("wrong annotation type", clazz, e.annotationType());
    assertSame("wrong element name", elementName, e.elementName());
}
AnnotationFactory.java 文件源码 项目:freeVM 阅读 38 收藏 0 点赞 0 评论 0
/**
   * Processes a method invocation request to this annotation instance.
   * Recognizes the methods declared in the 
   * {@link java.lang.annotation.Annotation java.lang.annotation.Annotation}
   * interface, and member-defining methods of the implemented annotation type.
   * @throws IllegalArgumentException If the specified method is none of the above
   * @return the invocation result 
   */
  public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
  {
      String name = method.getName();
      Class[] params = method.getParameterTypes();
      if (params.length == 0) {
          if ("annotationType".equals(name)) {
              return klazz;
          } else if ("toString".equals(name)) {
              return toString();
          } else if ("hashCode".equals(name)) {
              return hashCode();
          }

          // this must be element value request
          AnnotationMember element = null;
          for (AnnotationMember el : elements) {
              if (name.equals(el.name)) {
                  element = el;
                  break;
              }                
          }
          if (element == null || !method.equals(element.definingMethod)) {
              throw new IllegalArgumentException(method.toString());
          } else {
              Object value = element.validateValue();
              if (value == null) {
                  throw new IncompleteAnnotationException(klazz, name);
              }
              return value;
          }
} else if (params.length == 1 && params[0] == Object.class && "equals".equals(name)){
    return Boolean.valueOf(equals(args[0]));
      }
      throw new IllegalArgumentException(
              "Invalid method for annotation type: " + method);
  }
IncompleteAnnotationExceptionTest.java 文件源码 项目:freeVM 阅读 28 收藏 0 点赞 0 评论 0
public void testNullType() {
    try {
        new IncompleteAnnotationException(null, "str");
        fail("NullPointerException must be thrown");
    } catch (NullPointerException e) {
        // Expected
    }
}
IncompleteAnnotationExceptionTest.java 文件源码 项目:freeVM 阅读 29 收藏 0 点赞 0 评论 0
/**
 * @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());
}
AnnotationDescriptionAnnotationInvocationHandlerTest.java 文件源码 项目:byte-buddy 阅读 30 收藏 0 点赞 0 评论 0
@Test(expected = IncompleteAnnotationException.class)
@SuppressWarnings("unchecked")
public void testIncompleteAnnotationException() throws Throwable {
    when(freeAnnotationValue.load(getClass().getClassLoader())).thenReturn((AnnotationValue.Loaded)
            new AnnotationDescription.AnnotationInvocationHandler.MissingValue(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]);
}
CoreMetaDataCompatibility.java 文件源码 项目:TA-Lib 阅读 32 收藏 0 点赞 0 评论 0
RetCode taGetFuncInfo(FuncInfo retFuncInfo) {
    try {
        retFuncInfo = super.getFuncInfo();
        return RetCode.Success;
    } catch (IncompleteAnnotationException e) {
        return RetCode.InternalError;
    }
}
AnnotationInvocationHandler.java 文件源码 项目:javify 阅读 39 收藏 0 点赞 0 评论 0
public Object invoke(Object proxy, Method method, Object[] args)
   throws Throwable
 {
   String methodName = method.getName().intern();

   if (args == null || args.length == 0)
     {
if (methodName == "toString")
  {
    return toString();
  }
else if (methodName == "hashCode")
  {
    return Integer.valueOf(hashCode());
  }
else if (methodName == "annotationType")
  {
    return type;
  }
else
  {
    Object val = memberValues.get(methodName);
    if (val == null)
      {
    throw new IncompleteAnnotationException(type, methodName);
      }
    try
      {
    if (val.getClass().isArray())
      val = coerce((Object[])val, method.getReturnType());
      }
    catch (ArrayStoreException _)
      {
    throw new AnnotationTypeMismatchException
      (method, val.getClass().getName());
      }
    if (! getBoxedReturnType(method).isInstance(val))
      throw (new AnnotationTypeMismatchException
         (method, val.getClass().getName()));
    return val;
  }
     }
   else if (args.length == 1)
     {
if (methodName == "equals")
  {
    return Boolean.valueOf(equals(proxy, args[0]));
  }
     }
   throw new InternalError("Invalid annotation proxy");
 }
AnnotationInvocationHandler.java 文件源码 项目:javify 阅读 24 收藏 0 点赞 0 评论 0
public Object invoke(Object proxy, Method method, Object[] args)
  throws Throwable
{
    String methodName = method.getName().intern();
    if (args == null || args.length == 0)
    {
        if (methodName == "toString")
        {
            return toString(type, memberValues);
        }
        else if (methodName == "hashCode")
        {
            return Integer.valueOf(hashCode(type, memberValues));
        }
        else if (methodName == "annotationType")
        {
            return type;
        }
        else
        {
            Object val = memberValues.get(methodName);
            if (val == null)
            {
                throw new IncompleteAnnotationException(type, methodName);
            }
            if (! getBoxedReturnType(method).isInstance(val))
            {
                throw new AnnotationTypeMismatchException(method,
                    val.getClass().getName());
            }
            if (val.getClass().isArray())
            {
                val = arrayClone(val);
            }
            return val;
        }
    }
    else if (args.length == 1)
    {
        if (methodName == "equals")
        {
            return Boolean.valueOf(equals(type, memberValues, args[0]));
        }
    }
    throw new InternalError("Invalid annotation proxy");
}
AnnotationInvocationHandler.java 文件源码 项目:jvm-stm 阅读 28 收藏 0 点赞 0 评论 0
public Object invoke(Object proxy, Method method, Object[] args)
    throws Throwable
  {
      String methodName = method.getName().intern();
      if (args == null || args.length == 0)
      {
          if (methodName == "toString")
          {
              return toString(type, memberValues);
          }
          else if (methodName == "hashCode")
          {
              return Integer.valueOf(hashCode(type, memberValues));
          }
          else if (methodName == "annotationType")
          {
              return type;
          }
          else
          {
              Object val = memberValues.get(methodName);
              if (val == null)
              {
                  throw new IncompleteAnnotationException(type, methodName);
              }
              if (! getBoxedReturnType(method).isInstance(val))
              {
                  throw new AnnotationTypeMismatchException(method,
                      val.getClass().getName());
              }
if (val.getClass().isArray())
{
    val = arrayClone(val);
}
              return val;
          }
      }
      else if (args.length == 1)
      {
          if (methodName == "equals")
          {
              return Boolean.valueOf(equals(type, memberValues, args[0]));
          }
      }
      throw new InternalError("Invalid annotation proxy");
  }
AnnotationInvocationHandler.java 文件源码 项目:jvm-stm 阅读 32 收藏 0 点赞 0 评论 0
public Object invoke(Object proxy, Method method, Object[] args)
   throws Throwable
 {
   String methodName = method.getName().intern();

   if (args == null || args.length == 0)
     {
if (methodName == "toString")
  {
    return toString();
  }
else if (methodName == "hashCode")
  {
    return Integer.valueOf(hashCode());
  }
else if (methodName == "annotationType")
  {
    return type;
  }
else
  {
    Object val = memberValues.get(methodName);
    if (val == null)
      {
    throw new IncompleteAnnotationException(type, methodName);
      }
    try
      {
    if (val.getClass().isArray())
      val = coerce((Object[])val, method.getReturnType());
      }
    catch (ArrayStoreException _)
      {
    throw new AnnotationTypeMismatchException
      (method, val.getClass().getName());
      }
    if (! getBoxedReturnType(method).isInstance(val))
      throw (new AnnotationTypeMismatchException
         (method, val.getClass().getName()));
    return val;
  }
     }
   else if (args.length == 1)
     {
if (methodName == "equals")
  {
    return Boolean.valueOf(equals(proxy, args[0]));
  }
     }
   throw new InternalError("Invalid annotation proxy");
 }
CoreMetaData.java 文件源码 项目:TA-Lib 阅读 29 收藏 0 点赞 0 评论 0
static private FuncInfo getFuncInfo(Method method) throws IncompleteAnnotationException {
    FuncInfo annotation = method.getAnnotation(FuncInfo.class);
    if (annotation != null) return annotation;
    throw new IncompleteAnnotationException(FuncInfo.class, "Method " + method.getName());
}
AnnotationInvocationHandler.java 文件源码 项目:JamVM-PH 阅读 35 收藏 0 点赞 0 评论 0
public Object invoke(Object proxy, Method method, Object[] args)
   throws Throwable
 {
   String methodName = method.getName().intern();

   if (args == null || args.length == 0)
     {
if (methodName == "toString")
  {
    return toString();
  }
else if (methodName == "hashCode")
  {
    return Integer.valueOf(hashCode());
  }
else if (methodName == "annotationType")
  {
    return type;
  }
else
  {
    Object val = memberValues.get(methodName);
    if (val == null)
      {
    throw new IncompleteAnnotationException(type, methodName);
      }
    try
      {
    if (val.getClass().isArray())
      val = coerce((Object[])val, method.getReturnType());
      }
    catch (ArrayStoreException _)
      {
    throw new AnnotationTypeMismatchException
      (method, val.getClass().getName());
      }
    if (! getBoxedReturnType(method).isInstance(val))
      throw (new AnnotationTypeMismatchException
         (method, val.getClass().getName()));
    return val;
  }
     }
   else if (args.length == 1)
     {
if (methodName == "equals")
  {
    return Boolean.valueOf(equals(proxy, args[0]));
  }
     }
   throw new InternalError("Invalid annotation proxy");
 }
AnnotationInvocationHandler.java 文件源码 项目:JamVM-PH 阅读 34 收藏 0 点赞 0 评论 0
public Object invoke(Object proxy, Method method, Object[] args)
    throws Throwable
  {
      String methodName = method.getName().intern();
      if (args == null || args.length == 0)
      {
          if (methodName == "toString")
          {
              return toString(type, memberValues);
          }
          else if (methodName == "hashCode")
          {
              return Integer.valueOf(hashCode(type, memberValues));
          }
          else if (methodName == "annotationType")
          {
              return type;
          }
          else
          {
              Object val = memberValues.get(methodName);
              if (val == null)
              {
                  throw new IncompleteAnnotationException(type, methodName);
              }
              if (! getBoxedReturnType(method).isInstance(val))
              {
                  throw new AnnotationTypeMismatchException(method,
                      val.getClass().getName());
              }
if (val.getClass().isArray())
{
    val = arrayClone(val);
}
              return val;
          }
      }
      else if (args.length == 1)
      {
          if (methodName == "equals")
          {
              return Boolean.valueOf(equals(type, memberValues, args[0]));
          }
      }
      throw new InternalError("Invalid annotation proxy");
  }


问题


面经


文章

微信
公众号

扫码关注公众号