protected AnnotationDefinition createAnnotationDefinition( Class<?> clazz ) { return DriverUtils.buildAnnotationDefinition( clazz ); }
public JavaSourceVisitor(JavaSource javaSource, ClassLoader classLoader, Resource resParts) { this.javaSource = javaSource; this.classTypeResolver = DriverUtils.createClassTypeResolver(javaSource, classLoader); this.resParts = resParts; }
public static boolean equalsType(Type type, String fullClassName, boolean multiple, String fullBagClassName, ClassTypeResolver classTypeResolver) throws Exception { String currentClassName; String currentBag; if (type.isArray()) { return false; } if (type.isPrimitive()) { return !multiple && fullClassName.equals(type.getName()); } if (isSimpleClass(type)) { currentClassName = classTypeResolver.getFullTypeName(type.getName()); return !multiple && fullClassName.equals(currentClassName); } Object[] simpleGenerics = isSimpleGeneric(type, classTypeResolver); if (multiple && Boolean.TRUE.equals(simpleGenerics[0]) && isManagedType(type, classTypeResolver)) { currentBag = (String) simpleGenerics[1]; currentBag = classTypeResolver.getFullTypeName(currentBag); currentClassName = (String) simpleGenerics[2]; currentClassName = classTypeResolver.getFullTypeName(currentClassName); return fullBagClassName.equals(currentBag) && fullClassName.equals(currentClassName); } return false; }
DriverUtils.copyAnnotationRetention(cls, annotationDefinition); DriverUtils.copyAnnotationTarget(cls, annotationDefinition); if (DriverUtils.isAnnotationMember(cls, method)) { returnType = method.getReturnType(); if ((isArray = returnType.isArray())) returnType = returnType.getComponentType(); valuePairDefinition = new AnnotationValuePairDefinitionImpl(method.getName(), NamingUtils.normalizeClassName(returnType.getName()), DriverUtils.buildValuePairType(returnType), isArray, valuePairDefinition.setAnnotationDefinition(buildAnnotationDefinition(returnType));
private boolean hasChangedToCollectionType(FieldSource<JavaClassSource> field, ObjectProperty property, ClassTypeResolver classTypeResolver) throws Exception { return DriverUtils.isManagedType(field.getType(), classTypeResolver) && !DriverUtils.equalsType(field.getType(), property.getClassName(), property.isMultiple(), property.getBag(), classTypeResolver) && property.isMultiple(); }
classTypeResolver = DriverUtils.createClassTypeResolver(javaClassSource, classLoader); Visibility visibility = DriverUtils.buildVisibility(javaClassSource.getVisibility()); JavaClassImpl nestedJavaClass = new JavaClassImpl("", nestedType.getName(), DriverUtils.buildVisibility(nestedType.getVisibility())); dataObject.addNestedClass(nestedJavaClass); if (javaClassSource.getInterfaces() != null) { if (fields != null) { for (FieldSource<JavaClassSource> field : fields) { if (DriverUtils.isManagedType(field.getType(), classTypeResolver)) { addProperty(dataObject, field.getType().toString(), false, DriverUtils.buildVisibility(field.getVisibility()), field.isStatic(), field.isFinal()));
if (DriverUtils.isManagedType(fieldType, classTypeResolver)) { if (fieldType.isPrimitive()) { fieldClassName = fieldType.getName(); } else if (DriverUtils.isSimpleClass(fieldType)) { fieldClassName = classTypeResolver.getFullTypeName(fieldType.getName()); } else {
ObjectProperty property; Visibility visibility = DriverUtils.buildVisibility(field.getVisibility()); className = type.getName(); } else { if (DriverUtils.isSimpleClass(type)) { className = resolveTypeName(classTypeResolver, type.getName());
public boolean isManagedField(FieldSource<JavaClassSource> field, ClassTypeResolver classTypeResolver) throws Exception { if (!field.isFinal() && !field.isStatic()) { //finally we can check if the field type is a managed type. //if not, the field should remain untouched return DriverUtils.isManagedType(field.getType(), classTypeResolver); } return false; }
return isSimpleClass(((List<Type>) type.getTypeArguments()).get(0));
public static int buildModifierRepresentation(Member<?> member) { int result = 0x0; result = addModifierRepresentation(result, member); result = addModifierRepresentation(result, (VisibilityScoped) member); return result; }
public static void copyAnnotationRetention(Class annotationClass, AnnotationDefinition annotationDefinition) { if (annotationClass.isAnnotationPresent(Retention.class)) { Retention retentionAnnotation = (Retention) annotationClass.getAnnotation(Retention.class); annotationDefinition.setRetention(DriverUtils.buildRetention(retentionAnnotation.value())); } }
public static void copyAnnotationTarget(Class annotationClass, AnnotationDefinition annotationDefinition) { if (annotationClass.isAnnotationPresent(Target.class)) { Target targetAnnotation = (Target) annotationClass.getAnnotation(Target.class); java.lang.annotation.ElementType[] targets = targetAnnotation.value(); if (targets != null && targets.length > 0) { for (int i = 0; i < targets.length; i++) { annotationDefinition.addTarget(buildElementType(targets[i])); } } else { //added to avoid an errai unmarshalling error in broser side, when an annotation has no targets, e.g. //javax.persistence.UniqueConstraint annotationDefinition.addTarget(ElementType.UNDEFINED); } } }
if (DriverUtils.isManagedType(field.getType(), classTypeResolver) && !DriverUtils.equalsType(field.getType(), property.getClassName(), property.isMultiple(),
public List<ObjectProperty> parseManagedTypesProperties(JavaClassSource javaClassSource, ClassTypeResolver classTypeResolver) throws ModelDriverException { List<FieldSource<JavaClassSource>> fields = javaClassSource.getFields(); List<ObjectProperty> properties = new ArrayList<ObjectProperty>(); ObjectProperty property; for (FieldSource<JavaClassSource> field : fields) { if (DriverUtils.isManagedType(field.getType(), classTypeResolver)) { property = parseProperty(field, classTypeResolver); properties.add(property); } else { logger.debug("field: " + field + "with fieldName: " + field.getName() + " won't be loaded by the diver because type: " + field.getType().getName() + " isn't a managed type."); } } return properties; }
public static Object[] isSimpleGeneric(Type type, ClassTypeResolver classTypeResolver) throws ModelDriverException { Object[] result = new Object[3]; result[0] = false; result[1] = null; result[2] = null; if (type.isArray() || type.isPrimitive() || !type.isParameterized() || (type.isParameterized() && type.getTypeArguments().size() != 1)) { return result; } Type<?> argument = ((List<Type>) type.getTypeArguments()).get(0); if (!isSimpleClass(argument)) { return result; } try { String outerClass = classTypeResolver.getFullTypeName(type.getName()); String argumentClass = classTypeResolver.getFullTypeName(argument.getName()); result[0] = true; result[1] = outerClass; result[2] = argumentClass; return result; } catch (ClassNotFoundException e) { throw new ModelDriverException("Class could not be resolved for name: " + type.getName() + ". " + e.getMessage(), e); } }
public static int buildModifierRepresentation(JavaClassSource classSource) { return addModifierRepresentation(0x0, classSource); }
protected Map<String, AnnotationDefinition> createTestAnnotations() { Map<String, AnnotationDefinition> annotationsDef = new HashMap<String, AnnotationDefinition>(); AnnotationDefinition annotationDefinition = DriverUtils.buildAnnotationDefinition(Label.class); annotationsDef.put(annotationDefinition.getClassName(), annotationDefinition); annotationDefinition = DriverUtils.buildAnnotationDefinition(Description.class); annotationsDef.put(annotationDefinition.getClassName(), annotationDefinition); return annotationsDef; }
} else { JavaClassSource javaClassSource = (JavaClassSource) javaType; classTypeResolver = DriverUtils.createClassTypeResolver(javaClassSource, classLoader); updateJavaClassSource(dataObject,
@Before public void initTest() { annotationDefinition = DriverUtils.buildAnnotationDefinition( StringParamsAnnotation.class ); }