@@ -82,34 +82,41 @@ public Schema resolve(AnnotatedType annotatedType, ModelConverterContext modelCo
82
82
}
83
83
84
84
private Class <?> getClassFromPredicate (QuerydslPredicate predicate ) throws CannotCompileException {
85
- ClassTypeInformation <?> classTypeInformation = ClassTypeInformation .from (predicate .root ());
86
- TypeInformation <?> domainType = classTypeInformation .getRequiredActualType ();
87
- Optional <Class <? extends QuerydslBinderCustomizer <?>>> bindingsAnnotation = Optional .of (predicate )
88
- .map (QuerydslPredicate ::bindings )
89
- .map (CastUtils ::cast );
90
- QuerydslBindings bindings = bindingsAnnotation
91
- .map (it -> querydslBindingsFactory .createBindingsFor (domainType , it ))
92
- .orElseGet (() -> querydslBindingsFactory .createBindingsFor (domainType ));
85
+ Class <?> tClass = null ;
93
86
String generatedClassName = "com.springdoc.core." + predicate .bindings ().getSimpleName () + "G" ;
94
- ClassPool classPool = ClassPool .getDefault ();
95
- CtClass classPoolOrNull = classPool .getOrNull (generatedClassName );
96
- if (classPoolOrNull == null ) {
97
- classPoolOrNull = classPool .makeClass (generatedClassName );
98
- Set <String > fieldsToAdd = Arrays .stream (predicate .root ().getDeclaredFields ()).map (Field ::getName ).collect (Collectors .toSet ());
99
- //remove blacklisted fields
100
- Set <String > blacklist = getBindingFieldValues (bindings , "blackList" );
101
- fieldsToAdd .removeIf (blacklist ::contains );
102
- Set <String > whiteList = getBindingFieldValues (bindings , "whiteList" );
103
- Set <String > aliases = getBindingFieldValues (bindings , "aliases" );
104
- fieldsToAdd .addAll (aliases );
105
- fieldsToAdd .addAll (whiteList );
106
- for (String fieldName : fieldsToAdd ) {
107
- CtField f = new CtField (CtClass .charType , fieldName , classPoolOrNull );
108
- f .setModifiers (Modifier .PUBLIC );
109
- classPoolOrNull .addField (f );
87
+ try {
88
+ tClass = Class .forName (generatedClassName );
89
+ }
90
+ catch (ClassNotFoundException cnfe ) {
91
+ ClassTypeInformation <?> classTypeInformation = ClassTypeInformation .from (predicate .root ());
92
+ TypeInformation <?> domainType = classTypeInformation .getRequiredActualType ();
93
+ Optional <Class <? extends QuerydslBinderCustomizer <?>>> bindingsAnnotation = Optional .of (predicate )
94
+ .map (QuerydslPredicate ::bindings )
95
+ .map (CastUtils ::cast );
96
+ QuerydslBindings bindings = bindingsAnnotation
97
+ .map (it -> querydslBindingsFactory .createBindingsFor (domainType , it ))
98
+ .orElseGet (() -> querydslBindingsFactory .createBindingsFor (domainType ));
99
+ ClassPool classPool = ClassPool .getDefault ();
100
+ CtClass classPoolOrNull = classPool .getOrNull (generatedClassName );
101
+ if (classPoolOrNull == null ) {
102
+ classPoolOrNull = classPool .makeClass (generatedClassName );
103
+ Set <String > fieldsToAdd = Arrays .stream (predicate .root ().getDeclaredFields ()).map (Field ::getName ).collect (Collectors .toSet ());
104
+ //remove blacklisted fields
105
+ Set <String > blacklist = getBindingFieldValues (bindings , "blackList" );
106
+ fieldsToAdd .removeIf (blacklist ::contains );
107
+ Set <String > whiteList = getBindingFieldValues (bindings , "whiteList" );
108
+ Set <String > aliases = getBindingFieldValues (bindings , "aliases" );
109
+ fieldsToAdd .addAll (aliases );
110
+ fieldsToAdd .addAll (whiteList );
111
+ for (String fieldName : fieldsToAdd ) {
112
+ CtField f = new CtField (CtClass .charType , fieldName , classPoolOrNull );
113
+ f .setModifiers (Modifier .PUBLIC );
114
+ classPoolOrNull .addField (f );
115
+ }
110
116
}
117
+ tClass = classPoolOrNull .toClass (this .getClass ().getClassLoader (), this .getClass ().getProtectionDomain ());
111
118
}
112
- return classPoolOrNull . toClass ( this . getClass (). getClassLoader (), this . getClass (). getProtectionDomain ()) ;
119
+ return tClass ;
113
120
}
114
121
115
122
private Set <String > getBindingFieldValues (QuerydslBindings instance , String fieldName ) {
0 commit comments