konveyor / konveyor/java-analyzer-bundle

Searching about a java package name fails

Open
#191 4 comments 0 reactions 0 assignees View on GitHub
kind/bug priority/important-soon stale triage/accepted
Dominant language
Java
Stars
2
Forks
21
PR merge metrics
No merged PRs in 30d

Description

## Issue

Searching about a java package name fails using as location `11` and query `com.todo.app.controller` when the java project to be analyzed contains a java file `TaskController` where there is a line with `package `com.todo.app.controller`

The problem is related to the code of the existing `ReferenceSymbolProvider` class as we got a class cast exception

```
// Code
public class ReferenceSymbolProvider implements SymbolProvider, WithQuery {
private String query;

@Override
public List get(SearchMatch match) {
SymbolKind k = convertSymbolKind((IJavaElement) match.getElement());
List symbols = new ArrayList<>();
// For Method Calls we will need to do the local variable trick
try {
ReferenceMatch m = (ReferenceMatch) match; // We got a Class cast exception

// Error
!MESSAGE unable to convert for variable: java.lang.ClassCastException: class org.eclipse.jdt.core.search.PackageDeclarationMatch cannot be cast to class org.eclipse.jdt.core.search.ReferenceMatch (org.eclipse.jdt.core.search.PackageDeclarationMatch and org.eclipse.jdt.core.search.ReferenceMatch are in unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @536856f1)
```

The class cast exception can be fixed using this code
```
PackageDeclarationMatch m = (PackageDeclarationMatch)match;
```
but then the code should be reviewed in order to:
- Handle properly the class type: `PackageDeclarationMatch`, `ReferencenMatch` ?, etc
- Manage the `IPackageFragment` part of the class `SymbolProvider` and method `default Location getLocation(IJavaElement element, SearchMatch match)` to return the location, range for a package discovered

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in the existing ReferenceSymbolProvider implementation and reproduce the search for location 11 with query com.todo.app.controller. Trace get(SearchMatch), the PackageDeclarationMatch and ReferenceMatch handling, and SymbolProvider.getLocation(IJavaElement, SearchMatch), including IPackageFragment. Done means package searches avoid the class-cast exception and return the package location and range correctly.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
search
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.