@@ -150,16 +150,13 @@ public void visitElement(PsiElement element) {
150150 } else {
151151 interfaces = Collections .emptyList ();
152152 }
153- ObjectTypeDefinition definition = withSourceLocation (new ObjectTypeDefinition (endpointType .getName (), interfaces , Collections .emptyList (), fieldDefinitions ), typeDefinition );
154153
155- if (typeDefinition .getNamedTypeDef () instanceof JSGraphQLEndpointDocumentationAware ) {
156- final String documentation = ((JSGraphQLEndpointDocumentationAware ) typeDefinition .getNamedTypeDef ()).getDocumentation (false );
157- if (StringUtils .isNotBlank (documentation )) {
158- definition .setDescription (new Description (documentation , definition .getSourceLocation (), true ));
159- }
160- }
154+ final ObjectTypeDefinition .Builder builder = ObjectTypeDefinition .newObjectTypeDefinition ();
155+ final SourceLocation sourceLocation = getSourceLocation (typeDefinition );
156+ final Description description = getDescription (typeDefinition , sourceLocation );
157+ builder .name (endpointType .getName ()).implementz (interfaces ).fieldDefinitions (fieldDefinitions ).sourceLocation (sourceLocation ).description (description );
161158
162- registry .add (definition );
159+ registry .add (builder . build () );
163160
164161 } else if (psiDefinition instanceof JSGraphQLEndpointInterfaceTypeDefinition ) {
165162
@@ -173,16 +170,12 @@ public void visitElement(PsiElement element) {
173170 addFieldDefinition (fieldDefinitions , addedFieldNames , endpointFieldDefinition , errors );
174171 }
175172 }
176- final InterfaceTypeDefinition definition = withSourceLocation (new InterfaceTypeDefinition (psiInterfaceDefinition .getNamedTypeDef ().getName (), fieldDefinitions , Collections .emptyList ()), psiDefinition );
177-
178- if (psiInterfaceDefinition .getNamedTypeDef () instanceof JSGraphQLEndpointDocumentationAware ) {
179- final String documentation = ((JSGraphQLEndpointDocumentationAware ) psiInterfaceDefinition .getNamedTypeDef ()).getDocumentation (false );
180- if (StringUtils .isNotBlank (documentation )) {
181- definition .setDescription (new Description (documentation , definition .getSourceLocation (), true ));
182- }
183- }
184173
185- registry .add (definition );
174+ final InterfaceTypeDefinition .Builder builder = InterfaceTypeDefinition .newInterfaceTypeDefinition ();
175+ final SourceLocation sourceLocation = getSourceLocation (psiDefinition );
176+ final Description description = getDescription (psiInterfaceDefinition , sourceLocation );
177+ builder .name (psiInterfaceDefinition .getNamedTypeDef ().getName ()).definitions (fieldDefinitions ).sourceLocation (sourceLocation ).description (description );
178+ registry .add (builder .build ());
186179 }
187180
188181 } else if (psiDefinition instanceof JSGraphQLEndpointInputObjectTypeDefinition ) {
@@ -193,11 +186,18 @@ public void visitElement(PsiElement element) {
193186 if (psiInputObjectDefinition .getFieldDefinitionSet () != null ) {
194187 for (JSGraphQLEndpointFieldDefinition fieldDefinition : psiInputObjectDefinition .getFieldDefinitionSet ().getFieldDefinitionList ()) {
195188 if (fieldDefinition .getCompositeType () != null ) {
196- inputValueDefinitions .add (new InputValueDefinition (fieldDefinition .getProperty ().getName (), createType (fieldDefinition .getCompositeType ())));
189+ final InputValueDefinition inputValueDefinition = InputValueDefinition .newInputValueDefinition ()
190+ .name (fieldDefinition .getProperty ().getName ())
191+ .type (createType (fieldDefinition .getCompositeType ()))
192+ .build ();
193+ inputValueDefinitions .add (inputValueDefinition );
197194 }
198195 }
199196 }
200- registry .add (withSourceLocation (new InputObjectTypeDefinition (psiInputObjectDefinition .getNamedTypeDef ().getName (), Collections .emptyList (), inputValueDefinitions ), psiDefinition ));
197+ final InputObjectTypeDefinition .Builder builder = InputObjectTypeDefinition .newInputObjectDefinition ();
198+ final SourceLocation sourceLocation = getSourceLocation (psiDefinition );
199+ builder .name (psiInputObjectDefinition .getNamedTypeDef ().getName ()).inputValueDefinitions (inputValueDefinitions ).sourceLocation (sourceLocation );
200+ registry .add (builder .build ());
201201
202202 }
203203 } else if (psiDefinition instanceof JSGraphQLEndpointEnumTypeDefinition ) {
@@ -210,7 +210,11 @@ public void visitElement(PsiElement element) {
210210 enumValueDefinitions .add (new EnumValueDefinition (psiEnumValueDefinition .getIdentifier ().getText ()));
211211 }
212212 }
213- registry .add (withSourceLocation (new EnumTypeDefinition (psiEnumTypeDefinition .getNamedTypeDef ().getName (), enumValueDefinitions , Collections .emptyList ()), psiDefinition ));
213+ final EnumTypeDefinition .Builder enumTypeDefinition = EnumTypeDefinition .newEnumTypeDefinition ()
214+ .name (psiEnumTypeDefinition .getNamedTypeDef ().getName ())
215+ .enumValueDefinitions (enumValueDefinitions )
216+ .sourceLocation (getSourceLocation (psiDefinition ));
217+ registry .add (enumTypeDefinition .build ());
214218 }
215219
216220 } else if (psiDefinition instanceof JSGraphQLEndpointUnionTypeDefinition ) {
@@ -224,7 +228,11 @@ public void visitElement(PsiElement element) {
224228 memberTypes .add (new TypeName (psiUnionMember .getIdentifier ().getText ()));
225229 }
226230 }
227- registry .add (withSourceLocation (new UnionTypeDefinition (psiUnionTypeDefinition .getNamedTypeDef ().getName (), Collections .emptyList (), memberTypes ), psiDefinition ));
231+ final UnionTypeDefinition .Builder builder = UnionTypeDefinition .newUnionTypeDefinition ()
232+ .name (psiUnionTypeDefinition .getNamedTypeDef ().getName ())
233+ .memberTypes (memberTypes )
234+ .sourceLocation (getSourceLocation (psiDefinition ));
235+ registry .add (builder .build ());
228236
229237 }
230238
@@ -238,7 +246,12 @@ public void visitElement(PsiElement element) {
238246 for (Introspection .DirectiveLocation directiveLocation : Introspection .DirectiveLocation .values ()) {
239247 directiveLocations .add (new DirectiveLocation (directiveLocation .name ()));
240248 }
241- registry .add (new DirectiveDefinition (psiAnnotationDefinition .getNamedTypeDef ().getName (), inputValueDefinitions , directiveLocations ));
249+ final DirectiveDefinition .Builder builder = DirectiveDefinition .newDirectiveDefinition ()
250+ .name (psiAnnotationDefinition .getNamedTypeDef ().getName ())
251+ .inputValueDefinitions (inputValueDefinitions )
252+ .directiveLocations (directiveLocations )
253+ .sourceLocation (getSourceLocation (psiDefinition ));
254+ registry .add (builder .build ());
242255 }
243256
244257 }
@@ -247,22 +260,36 @@ public void visitElement(PsiElement element) {
247260 return registryWithErrors ;
248261 }
249262
263+ private Description getDescription (JSGraphQLEndpointNamedTypeDefinition typeDefinition , SourceLocation sourceLocation ) {
264+ if (typeDefinition .getNamedTypeDef () instanceof JSGraphQLEndpointDocumentationAware ) {
265+ final String documentation = ((JSGraphQLEndpointDocumentationAware ) typeDefinition .getNamedTypeDef ()).getDocumentation (false );
266+ if (StringUtils .isNotBlank (documentation )) {
267+ return new Description (documentation , sourceLocation , true );
268+ }
269+ }
270+ return null ;
271+ }
272+
250273 private void addFieldDefinition (List <FieldDefinition > fieldDefinitions , Set <String > addedFieldNames , JSGraphQLEndpointFieldDefinition endpointFieldDefinition , List <GraphQLException > errors ) {
251274 final JSGraphQLEndpointProperty property = endpointFieldDefinition .getProperty ();
252275 final String fieldName = property .getName ();
253276 if (endpointFieldDefinition .getCompositeType () != null ) {
254277 final Type fieldType = createType (endpointFieldDefinition .getCompositeType ());
255278 if (fieldType != null ) {
256279 if (addedFieldNames .add (fieldName )) {
257- FieldDefinition fieldDefinition = new FieldDefinition (fieldName , fieldType , createInputValueDefinitions (endpointFieldDefinition .getArgumentsDefinition (), errors ), Collections .emptyList ());
258- withSourceLocation (fieldDefinition , endpointFieldDefinition );
280+ final SourceLocation sourceLocation = getSourceLocation (endpointFieldDefinition );
281+ final FieldDefinition .Builder builder = FieldDefinition .newFieldDefinition ()
282+ .name (fieldName )
283+ .type (fieldType )
284+ .inputValueDefinitions (createInputValueDefinitions (endpointFieldDefinition .getArgumentsDefinition (), errors ))
285+ .sourceLocation (sourceLocation );
259286 if (property instanceof JSGraphQLEndpointDocumentationAware ) {
260287 final String documentation = ((JSGraphQLEndpointDocumentationAware ) property ).getDocumentation (false );
261288 if (StringUtils .isNotBlank (documentation )) {
262- fieldDefinition . setDescription (new Description (documentation , fieldDefinition . getSourceLocation () , true ));
289+ builder . description (new Description (documentation , sourceLocation , true ));
263290 }
264291 }
265- fieldDefinitions .add (fieldDefinition );
292+ fieldDefinitions .add (builder . build () );
266293 }
267294 } else {
268295 errors .add (new JSGraphQLEndpointSchemaError ("Field '" + fieldName + "' has no valid output type" , endpointFieldDefinition ));
@@ -295,38 +322,35 @@ private List<InputValueDefinition> createInputValueDefinitions(JSGraphQLEndpoint
295322 }
296323
297324 private Type createType (JSGraphQLEndpointCompositeType endpointCompositeType ) {
298- final boolean isNomNull = endpointCompositeType .getText ().contains ("!" );
325+ final boolean isNonNull = endpointCompositeType .getText ().contains ("!" );
299326 if (endpointCompositeType .getListType () != null ) {
300327 final JSGraphQLEndpointNamedType listElementType = endpointCompositeType .getListType ().getNamedType ();
301328 if (listElementType != null ) {
302329 final String name = listElementType .getName ();
303330 if (name != null ) {
304- Type type = withSourceLocation ( new TypeName (name ), listElementType );
305- type = withSourceLocation ( new ListType (type ), endpointCompositeType );
306- if (isNomNull ) {
307- type = withSourceLocation ( new NonNullType (type ), endpointCompositeType );
331+ Type type = TypeName . newTypeName (name ). sourceLocation ( getSourceLocation ( listElementType )). build ( );
332+ type = ListType . newListType (type ). sourceLocation ( getSourceLocation ( endpointCompositeType )). build ( );
333+ if (isNonNull ) {
334+ type = NonNullType . newNonNullType (type ). sourceLocation ( getSourceLocation ( endpointCompositeType )). build ( );
308335 }
309336 return type ;
310337 }
311338 }
312339 } else if (endpointCompositeType .getNamedType () != null ) {
313340 final String name = endpointCompositeType .getNamedType ().getName ();
314341 if (name != null ) {
315- Type type = withSourceLocation ( new TypeName (name ), endpointCompositeType .getNamedType ());
316- if (isNomNull ) {
317- type = withSourceLocation ( new NonNullType (type ), endpointCompositeType );
342+ Type type = TypeName . newTypeName (name ). sourceLocation ( getSourceLocation ( endpointCompositeType .getNamedType ())). build ( );
343+ if (isNonNull ) {
344+ type = NonNullType . newNonNullType (type ). sourceLocation ( getSourceLocation ( endpointCompositeType )). build ( );
318345 }
319346 return type ;
320347 }
321348 }
322349 return null ;
323350 }
324351
325- private <T extends Node <?>> T withSourceLocation (T node , PsiElement psiSourceElement ) {
326- if (node instanceof AbstractNode ) {
327- ((AbstractNode <?>) node ).setSourceLocation (new SourceLocation (-1 , -1 , psiSourceElement .getContainingFile ().getName ()));
328- }
329- return node ;
352+ private SourceLocation getSourceLocation (PsiElement psiSourceElement ) {
353+ return new SourceLocation (-1 , -1 , psiSourceElement .getContainingFile ().getName ());
330354 }
331355
332356 private Map <String , JSGraphQLNamedType > computeNamedTypes () {
0 commit comments