类org.apache.velocity.tools.config.DefaultKey源码实例Demo

下面列出了怎么用org.apache.velocity.tools.config.DefaultKey的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: velocity-tools   文件: ClassToolTests.java
public @Test void methodGetAnnotations() throws Exception
{
    ClassTool classTool = new ClassTool();
    // default type is java.lang.Object
    assertTrue(classTool.getAnnotations().isEmpty());
    classTool.setType(MyDeprecated.class);
    assertEquals(1, classTool.getAnnotations().size());
    classTool.setType(ValueParser.class);
    List<Annotation> annotations = classTool.getAnnotations();
    assertEquals(3, annotations.size());
    Collections.sort(annotations, new Comparator<Annotation>()
    {
        @Override
        public int compare(Annotation o1, Annotation o2)
        {
            return o1.toString().compareTo(o2.toString());
        }
    });
    assertTrue(annotations.get(0).annotationType() == DefaultKey.class);
    assertTrue(annotations.get(1).annotationType() == InvalidScope.class);
    assertTrue(annotations.get(2).annotationType() == SkipSetters.class);
}
 
public AnnotatedVelocityToolsScanner() {
    provider.addIncludeFilter(new AnnotationTypeFilter(DefaultKey.class));
}
 
@Override
protected void scan(String[] sources, Map<String, VelocityTool> velocityToolsMap) {

    for (String basePackage : sources) {

        Set<BeanDefinition> candidates = provider.findCandidateComponents(basePackage);

        for (BeanDefinition beanDefinition : candidates) {

            Class<?> toolClass = resolveToolClass(beanDefinition);

            DefaultKey defaultKey = findAnnotation(toolClass, DefaultKey.class);

            String key = defaultKey.value();

            String scope = getScope(toolClass);

            VelocityTool velocityTool = new VelocityTool(new ToolInfo(key, toolClass), scope);

            velocityToolsMap.put(key, velocityTool);

        }

    }
}
 
 类所在包
 类方法
 同包方法