FMLModContainer.java 文件源码

java
阅读 32 收藏 0 点赞 0 评论 0

项目:TRHS_Club_Mod_2016 作者:
@SuppressWarnings("unchecked")
private Method gatherAnnotations(Class<?> clazz) throws Exception
{
    Method factoryMethod = null;
    for (Method m : clazz.getDeclaredMethods())
    {
        for (Annotation a : m.getAnnotations())
        {
            if (a.annotationType().equals(Mod.EventHandler.class))
            {
                if (m.getParameterTypes().length == 1 && FMLEvent.class.isAssignableFrom(m.getParameterTypes()[0]))
                {
                    m.setAccessible(true);
                    eventMethods.put((Class<? extends FMLEvent>) m.getParameterTypes()[0],m);
                }
                else
                {
                    FMLLog.log(getModId(), Level.ERROR,"The mod %s appears to have an invalid event annotation %s. This annotation can only apply to methods with recognized event arguments - it will not be called", getModId(), a.annotationType().getSimpleName());
                }
            }
            else if (a.annotationType().equals(Mod.InstanceFactory.class))
            {
                if (Modifier.isStatic(m.getModifiers()) && m.getParameterTypes().length == 0 && factoryMethod == null)
                {
                    m.setAccessible(true);
                    factoryMethod = m;
                }
                else if (!(Modifier.isStatic(m.getModifiers()) && m.getParameterTypes().length == 0))
                {
                    FMLLog.log(getModId(),  Level.ERROR, "The InstanceFactory annotation can only apply to a static method, taking zero arguments - it will be ignored on %s(%s)", m.getName(), Arrays.asList(m.getParameterTypes()));
                }
                else if (factoryMethod != null)
                {
                    FMLLog.log(getModId(), Level.ERROR, "The InstanceFactory annotation can only be used once, the application to %s(%s) will be ignored", m.getName(), Arrays.asList(m.getParameterTypes()));
                }
            }
        }
    }
    return factoryMethod;
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号