1
1
package nl .jrdie .idea .springql .svc ;
2
2
3
+ import com .intellij .ide .projectView .ProjectView ;
3
4
import com .intellij .lang .java .JavaLanguage ;
4
5
import com .intellij .lang .jsgraphql .schema .GraphQLSchemaInfo ;
5
6
import com .intellij .lang .jsgraphql .schema .GraphQLSchemaProvider ;
25
26
import com .intellij .psi .stubs .StubIndexKey ;
26
27
import com .intellij .psi .util .PsiModificationTracker ;
27
28
import com .intellij .util .messages .Topic ;
29
+ import java .text .NumberFormat ;
30
+ import java .time .Duration ;
31
+ import java .util .Arrays ;
32
+ import java .util .Collections ;
33
+ import java .util .List ;
34
+ import java .util .Locale ;
35
+ import java .util .Objects ;
36
+ import java .util .Set ;
37
+ import java .util .concurrent .atomic .AtomicLong ;
38
+ import java .util .concurrent .atomic .AtomicReference ;
39
+ import java .util .stream .Collectors ;
40
+ import kotlin .collections .CollectionsKt ;
28
41
import nl .jrdie .idea .springql .GraphQLSchemaEventListener ;
29
42
import nl .jrdie .idea .springql .index .MutableQLIdeIndex ;
30
43
import nl .jrdie .idea .springql .index .QLIdeIndex ;
31
44
import nl .jrdie .idea .springql .index .entry .QLClassSchemaMappingIndexEntry ;
45
+ import nl .jrdie .idea .springql .index .entry .QLMethodBatchMappingIndexEntry ;
32
46
import nl .jrdie .idea .springql .index .entry .QLMethodSchemaMappingIndexEntry ;
47
+ import nl .jrdie .idea .springql .index .entry .SchemaMappingIndexEntry ;
33
48
import nl .jrdie .idea .springql .index .processor .QLAnnotationIndexProcessor ;
34
49
import nl .jrdie .idea .springql .types .SchemaMappingSummary ;
50
+ import nl .jrdie .idea .springql .types .SchemaMappingType ;
35
51
import nl .jrdie .idea .springql .utils .JSGraphQLPlugin ;
36
52
import nl .jrdie .idea .springql .utils .JSGraphQLVersionBypassUtils ;
37
53
import nl .jrdie .idea .springql .utils .QLIdeUtil ;
47
63
import org .jetbrains .uast .UMethod ;
48
64
import org .jetbrains .uast .UastContextKt ;
49
65
50
- import java .text .NumberFormat ;
51
- import java .time .Duration ;
52
- import java .util .Collections ;
53
- import java .util .List ;
54
- import java .util .Locale ;
55
- import java .util .Objects ;
56
- import java .util .Set ;
57
- import java .util .concurrent .atomic .AtomicLong ;
58
- import java .util .concurrent .atomic .AtomicReference ;
59
- import java .util .stream .Collectors ;
60
-
61
66
public class QLIdeServiceImpl implements QLIdeService , Disposable {
62
67
63
68
private static final Logger LOGGER = Logger .getInstance (QLIdeServiceImpl .class );
@@ -138,7 +143,7 @@ private void tryRegisterGraphQLSchemaChangeListener() {
138
143
(GraphQLSchemaEventListener )
139
144
schemaVersion -> {
140
145
// Force reloading of the index when a schema file changes
141
- QLIdeServiceImpl . this . getIndex (true );
146
+ getIndex (true );
142
147
});
143
148
} catch (Exception e ) {
144
149
throw new IllegalStateException (
@@ -234,6 +239,10 @@ public QLIdeIndex getIndex(boolean forceReload) {
234
239
+ ENGLISH_NUMBER_FORMAT .format (indexTime .toNanos ())
235
240
+ " ns)" );
236
241
242
+ // Necessary to refresh nodes in project window;
243
+ // see 'nl.jrdie.idea.springql.ide.tree.QLProjectTreeStructureProvider'.
244
+ ProjectView .getInstance (this .project ).refresh ();
245
+
237
246
return this .cachedIdeIndex = indexBuilder .get ().build ();
238
247
}
239
248
@@ -311,13 +320,16 @@ public boolean isMethodUsed(UMethod uMethod) {
311
320
public boolean needsControllerAnnotation (@ NotNull UClass uClass ) {
312
321
Objects .requireNonNull (uClass , "uClass" );
313
322
323
+ // TODO Meta-annotations
314
324
if (UExtKt .hasUAnnotation (uClass , SPRING_CONTROLLER_FQN )) {
315
325
return false ;
316
326
}
317
327
318
328
//noinspection UnnecessaryLocalVariable
319
329
final boolean containsAnnotations =
320
- uClass .getUAnnotations ().stream ()
330
+ Arrays .stream (uClass .getMethods ())
331
+ .map (UMethod ::getUAnnotations )
332
+ .flatMap (List ::stream )
321
333
.anyMatch (
322
334
uAnnotation ->
323
335
isSchemaMappingAnnotation (uAnnotation )
@@ -368,7 +380,7 @@ public SchemaMappingSummary getSummaryForMethod(@NotNull UMethod uMethod) {
368
380
Objects .requireNonNull (uMethod , "uMethod" );
369
381
370
382
QLIdeIndex index = getIndex ();
371
- List <QLMethodSchemaMappingIndexEntry > a = index .methodSchemaMappingByMethod (uMethod );
383
+ List <SchemaMappingIndexEntry > a = index .schemaMappingByMethod (uMethod );
372
384
373
385
if (a .isEmpty ()) {
374
386
return null ;
@@ -378,13 +390,13 @@ public SchemaMappingSummary getSummaryForMethod(@NotNull UMethod uMethod) {
378
390
throw new IllegalStateException ("Should not happen" );
379
391
}
380
392
381
- QLMethodSchemaMappingIndexEntry b = a .get (0 );
393
+ SchemaMappingIndexEntry b = a .get (0 );
382
394
383
395
String typeName = b .getParentType ();
384
396
if (typeName == null || typeName .isEmpty ()) {
385
397
UClass uClass = UastContextKt .getUastParentOfType (uMethod .getSourcePsi (), UClass .class );
386
398
if (uClass != null ) {
387
- Set <QLClassSchemaMappingIndexEntry > c = index .schemaMappingByClass (uClass );
399
+ List <QLClassSchemaMappingIndexEntry > c = index .schemaMappingByClass (uClass );
388
400
389
401
if (c .size () > 1 ) {
390
402
throw new IllegalStateException (
@@ -418,7 +430,12 @@ public SchemaMappingSummary getSummaryForMethod(@NotNull UMethod uMethod) {
418
430
b .getAnnotationPsi (),
419
431
schemaPsi ,
420
432
b .getUAnnotation (),
421
- QLIdeUtil .INSTANCE .reduceSchemaMappingAnnotationName (b .getUAnnotation ()));
433
+ QLIdeUtil .INSTANCE .reduceSchemaMappingAnnotationName (b .getUAnnotation ()),
434
+ uMethod ,
435
+ b instanceof QLMethodBatchMappingIndexEntry
436
+ ? SchemaMappingType .BATCH_MAPPING
437
+ : SchemaMappingType .SCHEMA_MAPPING ,
438
+ Objects .requireNonNull (uMethod .getSourcePsi ()));
422
439
}
423
440
424
441
@ Override
@@ -514,6 +531,34 @@ public List<UAnnotation> findNearestSchemaMappingAnnotations(UElement uElement)
514
531
return null ;
515
532
}
516
533
534
+ @ NotNull
535
+ @ Override
536
+ public List <SchemaMappingSummary > getThoroughSchemaMappingSummaryView () {
537
+ return getIndex ().allMethodSchemaMappingEntries ().stream ()
538
+ .map (QLMethodSchemaMappingIndexEntry ::getUMethod )
539
+ .map (this ::getSummaryForMethod )
540
+ .filter (Objects ::nonNull )
541
+ .collect (Collectors .toList ());
542
+ }
543
+
544
+ @ NotNull
545
+ @ Override
546
+ public List <SchemaMappingSummary > getThoroughSummaryView () {
547
+ return List .copyOf (
548
+ CollectionsKt .union (
549
+ getThoroughSchemaMappingSummaryView (), getThoroughBatchMappingSummaryView ()));
550
+ }
551
+
552
+ @ NotNull
553
+ @ Override
554
+ public List <SchemaMappingSummary > getThoroughBatchMappingSummaryView () {
555
+ return getIndex ().allMethodBatchMappingEntries ().stream ()
556
+ .map (QLMethodBatchMappingIndexEntry ::getUMethod )
557
+ .map (this ::getSummaryForMethod )
558
+ .filter (Objects ::nonNull )
559
+ .collect (Collectors .toList ());
560
+ }
561
+
517
562
@ NotNull
518
563
@ Override
519
564
public QLSchemaRegistry getSchemaRegistry () {
@@ -586,7 +631,7 @@ private boolean updateAndCheckModified() {
586
631
.invoke (schemaTracker );
587
632
long graphQLModificationCount =
588
633
(long )
589
- schemaTracker
634
+ modificationTracker
590
635
.getClass ()
591
636
.getMethod ("getModificationCount" )
592
637
.invoke (modificationTracker );
0 commit comments