annoscan

A reflection based annotation scanner.

Лицензия

Лицензия

Группа

Группа

com.siirush
Идентификатор

Идентификатор

annoscan
Последняя версия

Последняя версия

0.1.5
Дата

Дата

Тип

Тип

jar
Описание

Описание

annoscan
A reflection based annotation scanner.
Ссылка на сайт

Ссылка на сайт

http://github.com/mrdanpsmith/annoscan
Система контроля версий

Система контроля версий

https://github.com/mrdanpsmith/annoscan

Скачать annoscan

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/com.siirush/annoscan/ -->
<dependency>
    <groupId>com.siirush</groupId>
    <artifactId>annoscan</artifactId>
    <version>0.1.5</version>
</dependency>
// https://jarcasting.com/artifacts/com.siirush/annoscan/
implementation 'com.siirush:annoscan:0.1.5'
// https://jarcasting.com/artifacts/com.siirush/annoscan/
implementation ("com.siirush:annoscan:0.1.5")
'com.siirush:annoscan:jar:0.1.5'
<dependency org="com.siirush" name="annoscan" rev="0.1.5">
  <artifact name="annoscan" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.siirush', module='annoscan', version='0.1.5')
)
libraryDependencies += "com.siirush" % "annoscan" % "0.1.5"
[com.siirush/annoscan "0.1.5"]

Зависимости

compile (1)

Идентификатор библиотеки Тип Версия
javax.inject : javax.inject jar 1

test (1)

Идентификатор библиотеки Тип Версия
junit : junit jar 4.11

Модули Проекта

Данный проект не имеет модулей.

Annoscan

Reflective annotation scanner for Java.

Why another annotation scanner?

After scouring the web a few times, I could not find an easy way to do a simple task: take a class and scan for annotated properties.

As part of my development efforts on another project, I wrote such an annotation scanner.

I often found myself needing to do this same task; so, I decided to publish the code to make it accessible to others.

Installation

Annoscan is in maven central. Simply add the following dependency:

<dependency>
    <groupId>com.siirush</groupId>
    <artifactId>annoscan</artifactId>
    <version>0.1.5</version>
</dependency>

Configuration

AnnoScan can be configured using a variety of methods.

It relies on constructor injection and is annotated in compliance with JSR-330 containers (Guice, Spring 3, etc).

In addition, it can be handwired manually or obtained using the provider singleton.

Handwired:

AnnoScan annoScan = new AnnoScanImpl(new GetterLocatorImpl());

Provider:

AnnoScan annoScan = AnnoScanProvider.instance.get();

Usage

To scan a class for annotated properties, simply call one of the methods with your class and annotation class.

In unspecified order:

properties = annoScan.getAnnotatedProperties(TestClass.class,TestAnnotation.class);

In sorted order:

sortedProperties = annoScan.getAnnotatedPropertiesSorted(TestClassWithSort.class, TestAnnotation.class, new TestAnnotationComparator());

Then iterate through all of the properties and get the annotation or the value of the field:

for (AnnotatedProperty<TestAnnotation> property: properties) {
	TestAnnotation annotation = property.getAnnotation();
	Object fieldValue = property.getPropertyAccessor().getValue(annotatedObject);
}

Additional Notes

The default AnnoScan and GetterLocator implementations are stateless and can be instantiated prototypically with minimal overhead, or as singletons.

The default provider instance get method call demonstrated above returns a singleton.

Версии библиотеки

Версия
0.1.5
0.1.4