Giter Club home page Giter Club logo

at's Introduction

AT

Java 获取注解(Annotation)的工具类

基于Fluent API设计,用于获取包、类、构造函数、字段和方法上的注解,以及方法和构造函数中参数上的注解;

该工具类的灵感来源于JOOR

使用例子

静态导入

import static z.cube.utils.AT.at;

获取包上注解

 PackageAnnotationTest pat = at(Person.class)
                .package_()
                .annotation(PackageAnnotationTest.class).get();
                

获取类上注解

XmlRootElement x = at(Person.class)
            .annotation(XmlRootElement.class)
            .get();

获取构造函数上的注解

Deprecated deprecated = at(Person.class)
            .constructor(String.class, Integer.class)
            .annotation(Deprecated.class).get();

List<Annotation> anns = at(Person.class)
            .constructor(String.class, Integer.class)
            .annotation().list();

获取字段上的注解

XmlAttribute att = at(Person.class)
            .field("name")
            .annotation(XmlAttribute.class)
            .get();

获取方法上的注解

NotNull nn = at(Person.class)
        .method("setName", String.class)
        .annotation(NotNull.class)
        .get();

获取参数上的注解

// 通过参数名称的方式
// 获取方法参数名称为name上的注解
NotNull nn = at(Person.class)
        .method("setName", String.class)
        .param("name")
        .annotation(NotNull.class)
        .get();
                
// 获取构造函数参数名称为name上的注解
List<Annotation> anns = at(Person.class)
                .constructor(String.class, Integer.class)
                .param("name")
                .annotation().list();

// 通过参数索引的方式
NotNull nn2 = at(Person.class)
        .method("setName", String.class)
        .arg(0)
        .annotation(NotNull.class)
        .get();

Max max = at(Person.class)
        .constructor(String.class, Integer.class)
        .arg(1)
        .annotation(Max.class).get();

at's People

Contributors

boqodo avatar

Watchers

生安小胜 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.