use of java.lang.annotation.Annotation in project jodd by oblac.
the class ValidationContext method collectPropertyAnnotationChecks.
/**
* Process all annotations of provided properties.
*/
protected void collectPropertyAnnotationChecks(List<Check> annChecks, PropertyDescriptor propertyDescriptor) {
FieldDescriptor fd = propertyDescriptor.getFieldDescriptor();
if (fd != null) {
Annotation[] annotations = fd.getField().getAnnotations();
collectAnnotationChecks(annChecks, propertyDescriptor.getType(), propertyDescriptor.getName(), annotations);
}
MethodDescriptor md = propertyDescriptor.getReadMethodDescriptor();
if (md != null) {
Annotation[] annotations = md.getMethod().getAnnotations();
collectAnnotationChecks(annChecks, propertyDescriptor.getType(), propertyDescriptor.getName(), annotations);
}
md = propertyDescriptor.getWriteMethodDescriptor();
if (md != null) {
Annotation[] annotations = md.getMethod().getAnnotations();
collectAnnotationChecks(annChecks, propertyDescriptor.getType(), propertyDescriptor.getName(), annotations);
}
}
use of java.lang.annotation.Annotation in project jodd by oblac.
the class ScopeDataResolver method inspectMethodParameterScopeData.
// ---------------------------------------------------------------- inspect method
/**
* Inspects all method parameters for scope type.
*/
protected ScopeData inspectMethodParameterScopeData(String name, Class type, Annotation[] annotations, ScopeType scopeType) {
ScopeData sd = new ScopeData();
int count = 0;
for (Annotation annotation : annotations) {
if (annotation instanceof In) {
ScopeData.In scopeDataIn = inspectIn((In) annotation, scopeType, name, type);
if (scopeDataIn != null) {
count++;
sd.in = new ScopeData.In[] { scopeDataIn };
}
} else if (annotation instanceof Out) {
ScopeData.Out scopeDataOut = inspectOut((Out) annotation, scopeType, name, type);
if (scopeDataOut != null) {
count++;
sd.out = new ScopeData.Out[] { scopeDataOut };
}
} else if (annotation instanceof InOut) {
ScopeData.In scopeDataIn = inspectIn((InOut) annotation, scopeType, name, type);
if (scopeDataIn != null) {
count++;
sd.in = new ScopeData.In[] { scopeDataIn };
}
ScopeData.Out scopeDataOut = inspectOut((InOut) annotation, scopeType, name, type);
if (scopeDataOut != null) {
count++;
sd.out = new ScopeData.Out[] { scopeDataOut };
}
}
}
if (count == 0) {
return null;
}
return sd;
}
use of java.lang.annotation.Annotation in project jodd by oblac.
the class AnnotatedPropertyInterceptor method lookupAnnotatedProperties.
/**
* Lookups for annotated properties. Caches all annotated properties on the first
* action class scan.
*/
protected PropertyDescriptor[] lookupAnnotatedProperties(Class type) {
PropertyDescriptor[] properties = annotatedProperties.get(type);
if (properties != null) {
return properties;
}
ClassDescriptor cd = ClassIntrospector.lookup(type);
PropertyDescriptor[] allProperties = cd.getAllPropertyDescriptors();
List<PropertyDescriptor> list = new ArrayList<>();
for (PropertyDescriptor propertyDescriptor : allProperties) {
Annotation ann = null;
if (propertyDescriptor.getFieldDescriptor() != null) {
ann = propertyDescriptor.getFieldDescriptor().getField().getAnnotation(annotations);
}
if (ann == null && propertyDescriptor.getWriteMethodDescriptor() != null) {
ann = propertyDescriptor.getWriteMethodDescriptor().getMethod().getAnnotation(annotations);
}
if (ann == null && propertyDescriptor.getReadMethodDescriptor() != null) {
ann = propertyDescriptor.getReadMethodDescriptor().getMethod().getAnnotation(annotations);
}
if (ann != null) {
list.add(propertyDescriptor);
}
}
if (list.isEmpty()) {
properties = EMPTY;
} else {
properties = list.toArray(new PropertyDescriptor[list.size()]);
}
annotatedProperties.put(type, properties);
return properties;
}
use of java.lang.annotation.Annotation in project jodd by oblac.
the class InvReplTest method testReplacement.
@Test
public void testReplacement() throws IllegalAccessException, InstantiationException, NoSuchMethodException, IOException {
InvokeProxetta proxetta = initProxetta();
String className = One.class.getCanonicalName();
byte[] klazz = proxetta.builder(One.class).create();
//FileUtil.writeBytes("/Users/igor/OneClone.class", klazz);
FastByteArrayOutputStream fbaos = new FastByteArrayOutputStream();
// PrintStream out = System.out;
System.setOut(new PrintStream(fbaos));
One one = (One) ClassLoaderUtil.defineClass((new StringBuilder()).append(className).append(JoddProxetta.invokeProxyClassNameSuffix).toString(), klazz).newInstance();
// clone ctor calls super ctor,
assertEquals("one ctor!one ctor!", fbaos.toString());
fbaos.reset();
one.example1();
assertEquals("REPLACED VIRTUAL! jodd.proxetta.inv.Two * one!173>overriden sub", fbaos.toString());
fbaos.reset();
one.example2();
assertEquals("REPLACED STATIC! one * jodd/proxetta/inv/Two * example2 * void example2() * jodd.proxetta.inv.One * jodd.proxetta.inv.One$$Clonetou!15013static: 4", fbaos.toString());
fbaos.reset();
one.example3();
assertEquals("state = REPLACED ctor!", fbaos.toString());
fbaos.reset();
assertEquals("jodd.proxetta.inv.One$$Clonetou", one.getClass().getName());
assertTrue(one instanceof Serializable);
Annotation[] anns = one.getClass().getAnnotations();
assertEquals(3, anns.length);
Method ms = one.getClass().getMethod("example1");
anns = ms.getAnnotations();
assertEquals(1, anns.length);
}
use of java.lang.annotation.Annotation in project openhab1-addons by openhab.
the class MetadataHandler method generate.
/**
* Scans the class and generates metadata.
*/
public void generate(Class<?> clazz) throws IllegalAccessException {
if (clazz == null) {
return;
}
for (Field field : clazz.getDeclaredFields()) {
if (field.getType().getName().startsWith(PACKAGE_TO_SCAN) && !field.isEnumConstant()) {
generate(field.getType());
} else {
for (Annotation annotation : field.getAnnotations()) {
if (annotation.annotationType().equals(ProviderMappings.class)) {
ProviderMappings providerAnnotations = (ProviderMappings) annotation;
for (Provider provider : providerAnnotations.value()) {
Map<String, ProviderMappingInfo> mappings = providerMappings.get(provider.name());
if (mappings == null) {
mappings = new HashMap<String, ProviderMappingInfo>();
providerMappings.put(provider.name(), mappings);
}
Converter<?> converter = getConverter(field, provider.converter());
String target = clazz.getSimpleName().toLowerCase() + "." + field.getName();
ProviderMappingInfo pm = new ProviderMappingInfo(provider.property(), target, converter);
mappings.put(pm.getSource(), pm);
logger.trace("Added provider mapping {}: {}", provider.name(), pm);
}
} else if (annotation.annotationType().equals(ForecastMappings.class)) {
ForecastMappings forecastsAnnotations = (ForecastMappings) annotation;
for (Forecast forecast : forecastsAnnotations.value()) {
List<String> forecastProperties = forecastMappings.get(forecast.provider());
if (forecastProperties == null) {
forecastProperties = new ArrayList<String>();
forecastMappings.put(forecast.provider(), forecastProperties);
}
forecastProperties.add(forecast.property());
logger.trace("Added forecast mapping {}: {}", forecast.provider(), forecast.property());
}
}
}
}
}
}
Aggregations