use of java.lang.annotation.Annotation in project orientdb by orientechnologies.
the class OConsoleApplication method formatCommandSpecs.
protected String formatCommandSpecs(final String iCommand, final Method m) {
final StringBuilder buffer = new StringBuilder();
final StringBuilder signature = new StringBuilder();
signature.append(iCommand);
String paramName = null;
String paramDescription = null;
boolean paramOptional = false;
buffer.append("\n\nWHERE:\n\n");
for (Annotation[] annotations : m.getParameterAnnotations()) {
for (Annotation ann : annotations) {
if (ann instanceof com.orientechnologies.common.console.annotation.ConsoleParameter) {
paramName = ((com.orientechnologies.common.console.annotation.ConsoleParameter) ann).name();
paramDescription = ((com.orientechnologies.common.console.annotation.ConsoleParameter) ann).description();
paramOptional = ((com.orientechnologies.common.console.annotation.ConsoleParameter) ann).optional();
break;
}
}
if (paramName == null)
paramName = "?";
if (paramOptional)
signature.append(" [<" + paramName + ">]");
else
signature.append(" <" + paramName + ">");
buffer.append("* ");
buffer.append(String.format("%-18s", paramName));
if (paramDescription != null)
buffer.append(paramDescription);
if (paramOptional)
buffer.append(" (optional)");
buffer.append("\n");
}
signature.append(buffer);
return signature.toString();
}
use of java.lang.annotation.Annotation in project orientdb by orientechnologies.
the class OObjectSerializerHelper method analyzeClass.
protected static List<Field> analyzeClass(final Class<?> iClass) {
final List<Field> properties = new ArrayList<Field>();
classes.put(iClass.getName(), properties);
String fieldName;
Class<?> fieldType;
int fieldModifier;
boolean autoBinding;
for (Class<?> currentClass = iClass; currentClass != Object.class; ) {
for (Field f : currentClass.getDeclaredFields()) {
fieldModifier = f.getModifiers();
if (Modifier.isStatic(fieldModifier) || Modifier.isNative(fieldModifier) || Modifier.isTransient(fieldModifier))
continue;
if (f.getName().equals("this$0"))
continue;
if (jpaTransientClass != null) {
Annotation ann = f.getAnnotation(jpaTransientClass);
if (ann != null)
// @Transient DEFINED, JUMP IT
continue;
}
fieldName = f.getName();
fieldType = f.getType();
properties.add(f);
// CHECK FOR AUTO-BINDING
autoBinding = true;
if (f.getAnnotation(OAccess.class) == null || f.getAnnotation(OAccess.class).value() == OAccess.OAccessType.PROPERTY)
autoBinding = true;
else // JPA 2+ AVAILABLE?
if (jpaAccessClass != null) {
Annotation ann = f.getAnnotation(jpaAccessClass);
if (ann != null) {
// TODO: CHECK IF CONTAINS VALUE=FIELD
autoBinding = true;
}
}
if (f.getAnnotation(ODocumentInstance.class) != null)
// BOUND DOCUMENT ON IT
boundDocumentFields.put(iClass, f);
boolean idFound = false;
if (f.getAnnotation(OId.class) != null) {
// RECORD ID
fieldIds.put(iClass, f);
idFound = true;
} else // JPA 1+ AVAILABLE?
if (jpaIdClass != null && f.getAnnotation(jpaIdClass) != null) {
// RECORD ID
fieldIds.put(iClass, f);
idFound = true;
}
if (idFound) {
// CHECK FOR TYPE
if (fieldType.isPrimitive())
OLogManager.instance().warn(OObjectSerializerHelper.class, "Field '%s' cannot be a literal to manage the Record Id", f.toString());
else if (!ORID.class.isAssignableFrom(fieldType) && fieldType != String.class && fieldType != Object.class && !Number.class.isAssignableFrom(fieldType))
OLogManager.instance().warn(OObjectSerializerHelper.class, "Field '%s' cannot be managed as type: %s", f.toString(), fieldType);
}
boolean vFound = false;
if (f.getAnnotation(OVersion.class) != null) {
// RECORD ID
fieldVersions.put(iClass, f);
vFound = true;
} else // JPA 1+ AVAILABLE?
if (jpaVersionClass != null && f.getAnnotation(jpaVersionClass) != null) {
// RECORD ID
fieldVersions.put(iClass, f);
vFound = true;
}
if (vFound) {
// CHECK FOR TYPE
if (fieldType.isPrimitive())
OLogManager.instance().warn(OObjectSerializerHelper.class, "Field '%s' cannot be a literal to manage the Version", f.toString());
else if (fieldType != String.class && fieldType != Object.class && !Number.class.isAssignableFrom(fieldType))
OLogManager.instance().warn(OObjectSerializerHelper.class, "Field '%s' cannot be managed as type: %s", f.toString(), fieldType);
}
// JPA 1+ AVAILABLE?
if (jpaEmbeddedClass != null && f.getAnnotation(jpaEmbeddedClass) != null) {
if (embeddedFields.get(iClass) == null)
embeddedFields.put(iClass, new ArrayList<String>());
embeddedFields.get(iClass).add(fieldName);
}
if (autoBinding)
// TRY TO GET THE VALUE BY THE GETTER (IF ANY)
try {
String getterName = "get" + OUtils.camelCase(fieldName);
Method m = currentClass.getMethod(getterName, NO_ARGS);
getters.put(iClass.getName() + "." + fieldName, m);
} catch (Exception e) {
registerFieldGetter(iClass, fieldName, f);
}
else
registerFieldGetter(iClass, fieldName, f);
if (autoBinding)
// TRY TO GET THE VALUE BY THE SETTER (IF ANY)
try {
String getterName = "set" + OUtils.camelCase(fieldName);
Method m = currentClass.getMethod(getterName, f.getType());
setters.put(iClass.getName() + "." + fieldName, m);
} catch (Exception e) {
registerFieldSetter(iClass, fieldName, f);
}
else
registerFieldSetter(iClass, fieldName, f);
}
registerCallbacks(iClass, currentClass);
currentClass = currentClass.getSuperclass();
if (currentClass.equals(ODocument.class))
// POJO EXTENDS ODOCUMENT: SPECIAL CASE: AVOID TO CONSIDER
// ODOCUMENT FIELDS
currentClass = Object.class;
}
return properties;
}
use of java.lang.annotation.Annotation in project powermock by powermock.
the class TestClassTransformer method forTestClass.
public static ForTestClass forTestClass(final Class<?> testClass) {
return new ForTestClass() {
@Override
public RemovesTestMethodAnnotation removesTestMethodAnnotation(final Class<? extends Annotation> testMethodAnnotation) {
return new RemovesTestMethodAnnotation() {
@Override
public TestClassTransformer fromMethods(final Collection<Method> testMethodsThatRunOnOtherClassLoaders) {
return new TestClassTransformer(testClass, testMethodAnnotation) {
/**
* Is lazily initilized because of
* AbstractTestSuiteChunkerImpl#chunkClass(Class)
*/
Collection<String> methodsThatRunOnOtherClassLoaders;
@Override
boolean mustHaveTestAnnotationRemoved(CtMethod method) throws NotFoundException {
if (null == methodsThatRunOnOtherClassLoaders) {
/* This lazy initialization is necessary - see above */
methodsThatRunOnOtherClassLoaders = new HashSet<String>();
for (Method m : testMethodsThatRunOnOtherClassLoaders) {
methodsThatRunOnOtherClassLoaders.add(signatureOf(m));
}
testMethodsThatRunOnOtherClassLoaders.clear();
}
return methodsThatRunOnOtherClassLoaders.contains(signatureOf(method));
}
};
}
@Override
public TestClassTransformer fromAllMethodsExcept(Method singleMethodToRunOnTargetClassLoader) {
final String targetMethodSignature = signatureOf(singleMethodToRunOnTargetClassLoader);
return new TestClassTransformer(testClass, testMethodAnnotation) {
@Override
boolean mustHaveTestAnnotationRemoved(CtMethod method) throws Exception {
return !signatureOf(method).equals(targetMethodSignature);
}
};
}
};
}
};
}
use of java.lang.annotation.Annotation in project powermock by powermock.
the class PowerMockStatement method clearMockFields.
private void clearMockFields(Object target, Object annotationEnabler) throws Exception {
if (annotationEnabler != null) {
Class<? extends Annotation>[] mockAnnotations = Whitebox.invokeMethod(annotationEnabler, "getMockAnnotations");
Set<Field> mockFields = Whitebox.getFieldsAnnotatedWith(target, mockAnnotations);
for (Field field : mockFields) {
field.set(target, null);
}
}
}
use of java.lang.annotation.Annotation in project powermock by powermock.
the class PowerMockTestCase method clearMockFields.
private void clearMockFields() throws Exception, IllegalAccessException {
if (annotationEnabler != null) {
final Class<? extends Annotation>[] mockAnnotations = Whitebox.invokeMethod(annotationEnabler, "getMockAnnotations");
Set<Field> mockFields = Whitebox.getFieldsAnnotatedWith(this, mockAnnotations);
for (Field field : mockFields) {
field.set(this, null);
}
}
}
Aggregations