|
| 1 | +package io.konveyor.tackle.core.internal.symbol; |
| 2 | + |
| 3 | +import static org.junit.Assert.assertTrue; |
| 4 | + |
| 5 | +import java.util.List; |
| 6 | + |
| 7 | +import org.eclipse.lsp4j.SymbolInformation; |
| 8 | +import org.junit.Test; |
| 9 | + |
| 10 | +import io.konveyor.tackle.core.internal.testing.AbstractSymbolProviderTest; |
| 11 | + |
| 12 | + |
| 13 | +public class MethodDeclarationSymbolProviderIntegrationTest extends AbstractSymbolProviderTest { |
| 14 | + |
| 15 | + @Test |
| 16 | + public void testFullyQualifiedMethodDeclarations() { |
| 17 | + // Test fully qualified method declaration search for SampleApplication.merge |
| 18 | + List<SymbolInformation> sampleAppResults = searchMethodDeclarations("io.konveyor.demo.SampleApplication.merge"); |
| 19 | + printResults(sampleAppResults); |
| 20 | + assertTrue("[1] Should find merge() declaration in SampleApplication.java", |
| 21 | + sampleAppResults.size() == 1); |
| 22 | + assertTrue("[1b] Result should be in SampleApplication.java", |
| 23 | + sampleAppResults.get(0).getLocation().getUri().contains("SampleApplication.java")); |
| 24 | + |
| 25 | + // Test fully qualified method declaration search for PackageUsageExample.merge |
| 26 | + List<SymbolInformation> packageExampleResults = searchMethodDeclarations("io.konveyor.demo.PackageUsageExample.merge"); |
| 27 | + printResults(packageExampleResults); |
| 28 | + assertTrue("[2] Should find merge() declaration in PackageUsageExample.java", |
| 29 | + packageExampleResults.size() == 1); |
| 30 | + assertTrue("[2b] Result should be in PackageUsageExample.java", |
| 31 | + packageExampleResults.get(0).getLocation().getUri().contains("PackageUsageExample.java")); |
| 32 | + |
| 33 | + // Test fully qualified method declaration search for ServletExample.merge |
| 34 | + List<SymbolInformation> servletResults = searchMethodDeclarations("io.konveyor.demo.ServletExample.merge"); |
| 35 | + printResults(servletResults); |
| 36 | + assertTrue("[3] Should find merge() declaration in ServletExample.java", |
| 37 | + servletResults.size() == 1); |
| 38 | + assertTrue("[3b] Result should be in ServletExample.java", |
| 39 | + servletResults.get(0).getLocation().getUri().contains("ServletExample.java")); |
| 40 | + |
| 41 | + // Half qualified method declaration DOES work (different from method calls) |
| 42 | + // This is because method declarations are matched by class name + method name |
| 43 | + List<SymbolInformation> halfQualifiedResults = searchMethodDeclarations("SampleApplication.merge"); |
| 44 | + printResults(halfQualifiedResults); |
| 45 | + assertTrue("[4] Should find 1 result matching SampleApplication.merge (half-qualified works for declarations)", |
| 46 | + halfQualifiedResults.size() == 1); |
| 47 | + assertTrue("[4b] Result should be in SampleApplication.java", |
| 48 | + halfQualifiedResults.get(0).getLocation().getUri().contains("SampleApplication.java")); |
| 49 | + |
| 50 | + // Test pattern matching with wildcard on class name |
| 51 | + List<SymbolInformation> patternResults = searchMethodDeclarations("io.konveyor.demo.*.merge"); |
| 52 | + printResults(patternResults); |
| 53 | + assertTrue("[5] Should find all 3 merge() declarations matching io.konveyor.demo.*.merge", |
| 54 | + patternResults.size() == 3); |
| 55 | + } |
| 56 | + |
| 57 | + |
| 58 | + @Test |
| 59 | + public void testNonQualifiedMethodDeclarations() { |
| 60 | + // Search for all "merge" method declarations |
| 61 | + List<SymbolInformation> allResults = searchMethodDeclarations("merge"); |
| 62 | + printResults(allResults); |
| 63 | + |
| 64 | + // Should find all 3 merge() declarations in the project |
| 65 | + assertTrue("[1] Should find all 3 merge() declarations in the project", |
| 66 | + allResults.size() == 3); |
| 67 | + |
| 68 | + // Verify each file has exactly one merge() declaration |
| 69 | + List<SymbolInformation> sampleAppResults = inFile(allResults, "SampleApplication.java"); |
| 70 | + assertTrue("[2] Should find exactly 1 merge() declaration in SampleApplication.java", |
| 71 | + sampleAppResults.size() == 1); |
| 72 | + |
| 73 | + List<SymbolInformation> packageExampleResults = inFile(allResults, "PackageUsageExample.java"); |
| 74 | + assertTrue("[3] Should find exactly 1 merge() declaration in PackageUsageExample.java", |
| 75 | + packageExampleResults.size() == 1); |
| 76 | + |
| 77 | + List<SymbolInformation> servletResults = inFile(allResults, "ServletExample.java"); |
| 78 | + assertTrue("[4] Should find exactly 1 merge() declaration in ServletExample.java", |
| 79 | + servletResults.size() == 1); |
| 80 | + |
| 81 | + // Test pattern matching with wildcard |
| 82 | + List<SymbolInformation> mergeStarResults = searchMethodDeclarations("merg*"); |
| 83 | + printResults(mergeStarResults); |
| 84 | + assertTrue("[5] Should find all 3 merge() declarations matching merg*", |
| 85 | + mergeStarResults.size() == 3); |
| 86 | + } |
| 87 | + |
| 88 | + |
| 89 | + @Test |
| 90 | + public void testMethodDeclarationPatterns() { |
| 91 | + // Test various pattern combinations |
| 92 | + |
| 93 | + // Pattern: method name ending with 'e' |
| 94 | + List<SymbolInformation> mergeResults = searchMethodDeclarations("*merge"); |
| 95 | + printResults(mergeResults); |
| 96 | + assertTrue("[1] Should find all 3 merge() declarations matching *merge", |
| 97 | + mergeResults.size() == 3); |
| 98 | + |
| 99 | + // Test fully qualified pattern with class wildcard |
| 100 | + List<SymbolInformation> demoPackageResults = searchMethodDeclarations("io.konveyor.demo.Sample*.merge"); |
| 101 | + printResults(demoPackageResults); |
| 102 | + assertTrue("[2] Should find merge() in SampleApplication matching io.konveyor.demo.Sample*.merge", |
| 103 | + demoPackageResults.size() == 1); |
| 104 | + |
| 105 | + // Test fully qualified pattern with method wildcard |
| 106 | + List<SymbolInformation> sampleAllMethods = searchMethodDeclarations("io.konveyor.demo.SampleApplication.*"); |
| 107 | + printResults(sampleAllMethods); |
| 108 | + assertTrue("[3] Should find multiple method declarations in SampleApplication matching io.konveyor.demo.SampleApplication.*", |
| 109 | + sampleAllMethods.size() > 1); |
| 110 | + } |
| 111 | +} |
0 commit comments