Skip to content

Commit c0c5efe

Browse files
committed
Move the scan references into ScanDictionary
Moves Reference and its subclasses next to DictionaryEntry, which stores them and prints them in the "Two different classes" error. TypeClassMatcher and the field resolvers no longer name SchemaClassScanner. Edits to compile: - InterfaceReference and InputObjectReference are private again. - private dropped on DictionaryReference, UnusedTypeReference, UnionMemberReference and SealedSubclassReference, which the scanner creates. - SchemaClassScanner.XReference becomes ScanDictionary.XReference in TypeClassMatcher, MethodFieldResolver, PropertyFieldResolver, MapFieldResolver and NestedGenericWrapperTest. - Imports.
1 parent 7522a46 commit c0c5efe

7 files changed

Lines changed: 59 additions & 58 deletions

File tree

‎src/main/kotlin/graphql/kickstart/tools/ScanDictionary.kt‎

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
package graphql.kickstart.tools
22

33
import com.fasterxml.jackson.databind.JsonNode
4-
import graphql.kickstart.tools.SchemaClassScanner.InputObjectReference
5-
import graphql.kickstart.tools.SchemaClassScanner.InterfaceReference
6-
import graphql.kickstart.tools.SchemaClassScanner.Reference
7-
import graphql.kickstart.tools.SchemaClassScanner.ReturnValueReference
84
import graphql.kickstart.tools.util.JavaType
95
import graphql.kickstart.tools.util.unwrap
106
import graphql.kickstart.tools.util.withExtensions
117
import graphql.language.*
128
import graphql.schema.idl.ScalarInfo
139
import org.slf4j.Logger
1410
import java.lang.reflect.Member
11+
import java.lang.reflect.Method
1512

1613
internal class ScanDictionary(
1714
private val options: SchemaParserOptions,
@@ -227,4 +224,46 @@ internal class ScanDictionary(
227224
return clazz
228225
}
229226
}
227+
228+
abstract class Reference {
229+
abstract fun getDescription(): String
230+
override fun toString() = getDescription()
231+
}
232+
233+
class DictionaryReference : Reference() {
234+
override fun getDescription() = "provided dictionary"
235+
}
236+
237+
class UnusedTypeReference : Reference() {
238+
override fun getDescription() = "unused type"
239+
}
240+
241+
private class InterfaceReference(private val type: ObjectTypeDefinition) : Reference() {
242+
override fun getDescription() = "interface declarations of ${type.name}"
243+
}
244+
245+
class UnionMemberReference(private val union: UnionTypeDefinition) : Reference() {
246+
override fun getDescription() = "member of union ${union.name}"
247+
}
248+
249+
class SealedSubclassReference(private val sealedType: JavaType) : Reference() {
250+
override fun getDescription() = "subclass of sealed type ${sealedType.typeName}"
251+
}
252+
253+
private class InputObjectReference(private val type: InputValueDefinition) : Reference() {
254+
override fun getDescription() = "input object $type"
255+
}
256+
257+
internal class ReturnValueReference(private val method: Method) : Reference() {
258+
fun getMethod() = method
259+
override fun getDescription() = "return type of method $method"
260+
}
261+
262+
internal class MethodParameterReference(private val method: Method, private val index: Int) : Reference() {
263+
override fun getDescription() = "parameter $index of method $method"
264+
}
265+
266+
internal class FieldTypeReference(private val field: String) : Reference() {
267+
override fun getDescription() = "type of field $field"
268+
}
230269
}

‎src/main/kotlin/graphql/kickstart/tools/SchemaClassScanner.kt‎

Lines changed: 5 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
package graphql.kickstart.tools
22

3+
import graphql.kickstart.tools.ScanDictionary.DictionaryReference
4+
import graphql.kickstart.tools.ScanDictionary.FieldTypeReference
35
import graphql.kickstart.tools.ScanDictionary.InitialDictionaryEntry
6+
import graphql.kickstart.tools.ScanDictionary.SealedSubclassReference
7+
import graphql.kickstart.tools.ScanDictionary.UnionMemberReference
8+
import graphql.kickstart.tools.ScanDictionary.UnusedTypeReference
49
import graphql.kickstart.tools.resolver.FieldResolver
510
import graphql.kickstart.tools.resolver.FieldResolverScanner
611
import graphql.kickstart.tools.resolver.MethodFieldResolver
@@ -14,7 +19,6 @@ import org.apache.commons.lang3.reflect.TypeUtils
1419
import org.slf4j.LoggerFactory
1520
import java.lang.reflect.Field
1621
import java.lang.reflect.Member
17-
import java.lang.reflect.Method
1822
import java.lang.reflect.Modifier
1923
import java.lang.reflect.ParameterizedType
2024

@@ -582,48 +586,6 @@ internal class SchemaClassScanner(
582586

583587
private data class QueueItem(val type: ObjectTypeDefinition, val clazz: JavaType)
584588

585-
abstract class Reference {
586-
abstract fun getDescription(): String
587-
override fun toString() = getDescription()
588-
}
589-
590-
private class DictionaryReference : Reference() {
591-
override fun getDescription() = "provided dictionary"
592-
}
593-
594-
private class UnusedTypeReference : Reference() {
595-
override fun getDescription() = "unused type"
596-
}
597-
598-
class InterfaceReference(private val type: ObjectTypeDefinition) : Reference() {
599-
override fun getDescription() = "interface declarations of ${type.name}"
600-
}
601-
602-
private class UnionMemberReference(private val union: UnionTypeDefinition) : Reference() {
603-
override fun getDescription() = "member of union ${union.name}"
604-
}
605-
606-
private class SealedSubclassReference(private val sealedType: JavaType) : Reference() {
607-
override fun getDescription() = "subclass of sealed type ${sealedType.typeName}"
608-
}
609-
610-
class InputObjectReference(private val type: InputValueDefinition) : Reference() {
611-
override fun getDescription() = "input object $type"
612-
}
613-
614-
internal class ReturnValueReference(private val method: Method) : Reference() {
615-
fun getMethod() = method
616-
override fun getDescription() = "return type of method $method"
617-
}
618-
619-
internal class MethodParameterReference(private val method: Method, private val index: Int) : Reference() {
620-
override fun getDescription() = "parameter $index of method $method"
621-
}
622-
623-
internal class FieldTypeReference(private val field: String) : Reference() {
624-
override fun getDescription() = "type of field $field"
625-
}
626-
627589
private class RootTypesHolder(
628590
options: SchemaParserOptions,
629591
rootInfo: RootTypeInfo,

‎src/main/kotlin/graphql/kickstart/tools/TypeClassMatcher.kt‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ internal class TypeClassMatcher(private val definitionsByName: Map<String, TypeD
9595

9696
internal data class ScalarMatch(val type: ScalarTypeDefinition) : Match
9797

98-
internal data class ValidMatch(val type: TypeDefinition<*>, val javaType: JavaType, val reference: SchemaClassScanner.Reference) : Match
98+
internal data class ValidMatch(val type: TypeDefinition<*>, val javaType: JavaType, val reference: ScanDictionary.Reference) : Match
9999

100100
internal enum class Location(val prettyName: String) {
101101
RETURN_TYPE("return type"),
@@ -106,14 +106,14 @@ internal class TypeClassMatcher(private val definitionsByName: Map<String, TypeD
106106
val graphQLType: GraphQLLangType,
107107
val javaType: JavaType,
108108
val typeResolver: GenericTypeResolver,
109-
val reference: SchemaClassScanner.Reference,
109+
val reference: ScanDictionary.Reference,
110110
val location: Location
111111
) {
112112
companion object {
113-
fun returnValue(graphQLType: GraphQLLangType, javaType: JavaType, typeResolver: GenericTypeResolver, reference: SchemaClassScanner.Reference) =
113+
fun returnValue(graphQLType: GraphQLLangType, javaType: JavaType, typeResolver: GenericTypeResolver, reference: ScanDictionary.Reference) =
114114
PotentialMatch(graphQLType, javaType, typeResolver, reference, Location.RETURN_TYPE)
115115

116-
fun parameterType(graphQLType: GraphQLLangType, javaType: JavaType, typeResolver: GenericTypeResolver, reference: SchemaClassScanner.Reference) =
116+
fun parameterType(graphQLType: GraphQLLangType, javaType: JavaType, typeResolver: GenericTypeResolver, reference: ScanDictionary.Reference) =
117117
PotentialMatch(graphQLType, javaType, typeResolver, reference, Location.PARAMETER_TYPE)
118118
}
119119
}

‎src/main/kotlin/graphql/kickstart/tools/resolver/MapFieldResolver.kt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package graphql.kickstart.tools.resolver
22

33
import com.fasterxml.classmate.TypeResolver
4-
import graphql.kickstart.tools.SchemaClassScanner
4+
import graphql.kickstart.tools.ScanDictionary
55
import graphql.kickstart.tools.SchemaParserOptions
66
import graphql.kickstart.tools.TypeClassMatcher
77
import graphql.kickstart.tools.util.JavaType
@@ -44,7 +44,7 @@ internal class MapFieldResolver(
4444
}
4545

4646
override fun scanForMatches(): List<TypeClassMatcher.PotentialMatch> {
47-
return listOf(TypeClassMatcher.PotentialMatch.returnValue(field.type, mapGenericValue, typeResolver, SchemaClassScanner.FieldTypeReference(field.name)))
47+
return listOf(TypeClassMatcher.PotentialMatch.returnValue(field.type, mapGenericValue, typeResolver, ScanDictionary.FieldTypeReference(field.name)))
4848
}
4949

5050
override fun toString() = "MapFieldResolver{key=${field.name}}"

‎src/main/kotlin/graphql/kickstart/tools/resolver/MethodFieldResolver.kt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,10 @@ internal class MethodFieldResolver(
160160
}
161161

162162
override fun scanForMatches(): List<TypeClassMatcher.PotentialMatch> {
163-
val returnValueMatch = TypeClassMatcher.PotentialMatch.returnValue(field.type, getResolvedReturnType(), typeResolver, SchemaClassScanner.ReturnValueReference(method))
163+
val returnValueMatch = TypeClassMatcher.PotentialMatch.returnValue(field.type, getResolvedReturnType(), typeResolver, ScanDictionary.ReturnValueReference(method))
164164

165165
return field.inputValueDefinitions.mapIndexed { i, inputDefinition ->
166-
TypeClassMatcher.PotentialMatch.parameterType(inputDefinition.type, getMethodParameterType(i)!!, typeResolver, SchemaClassScanner.MethodParameterReference(method, i))
166+
TypeClassMatcher.PotentialMatch.parameterType(inputDefinition.type, getMethodParameterType(i)!!, typeResolver, ScanDictionary.MethodParameterReference(method, i))
167167
} + listOf(returnValueMatch)
168168
}
169169

‎src/main/kotlin/graphql/kickstart/tools/resolver/PropertyFieldResolver.kt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package graphql.kickstart.tools.resolver
22

3-
import graphql.kickstart.tools.SchemaClassScanner
3+
import graphql.kickstart.tools.ScanDictionary
44
import graphql.kickstart.tools.SchemaParserOptions
55
import graphql.kickstart.tools.TypeClassMatcher
66
import graphql.language.FieldDefinition
@@ -31,7 +31,7 @@ internal class PropertyFieldResolver(
3131
field.type,
3232
property.genericType,
3333
typeResolver,
34-
SchemaClassScanner.FieldTypeReference(property.toString())
34+
ScanDictionary.FieldTypeReference(property.toString())
3535
)
3636
)
3737
}

‎src/test/kotlin/graphql/kickstart/tools/NestedGenericWrapperTest.kt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ class NestedGenericWrapperTest {
181181

182182
val accepted = javaTypes.flatMap { (shape, javaType) -> graphQLTypes.map { Triple(shape, javaType, it) } }.filter { (_, javaType, graphQLType) ->
183183
val match = try {
184-
matcher.match(TypeClassMatcher.PotentialMatch.returnValue(graphQLType, typeResolver.resolve(javaType), typeResolver, SchemaClassScanner.ReturnValueReference(method)))
184+
matcher.match(TypeClassMatcher.PotentialMatch.returnValue(graphQLType, typeResolver.resolve(javaType), typeResolver, ScanDictionary.ReturnValueReference(method)))
185185
} catch (e: SchemaClassScannerError) {
186186
null
187187
}

0 commit comments

Comments
 (0)