INRIA / INRIA/spoon

[Bug]: ctType contains extra empty classes.

Open
#5,211 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
Java
Stars
2k
Forks
392
Avg merge
11h 24m
Merged PRs (30d)
36

Description

### Describe the bug

I import static member variables in the constant class to the current Java file. If Constants.java is not in the parsing path, the generated ctType contains an empty Constants.java. If the Constants.java is in the current parsing path, the actual class is overwritten by an empty Constants.java.

Only the ConfigQueryRequestHandlerTest.java file exists in the current project. The Constants.java file is in another project.

### Source code you are trying to analyze/transform

```Java
import org.apache.commons.io.FileUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockedStatic;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;

import java.io.File;

import static p13.Constants.ENCODE;

@RunWith(MockitoJUnitRunner.class)
public class ConfigQueryRequestHandlerTest {
@Mock
private File file;

@Test
public void testHandle() {
final MockedStatic fileUtilsMockedStatic = Mockito.mockStatic(FileUtils.class);
fileUtilsMockedStatic.when(() -> FileUtils.readFileToString(file, ENCODE)).thenReturn("content");
}
}
```

### Source code for your Spoon processing

```Java
Launcher launcher = new Launcher();
launcher.getEnvironment().setComplianceLevel(11);
launcher.getEnvironment().setAutoImports(true);
launcher.getEnvironment().setIgnoreDuplicateDeclarations(true);
launcher.addInputResource("D:\\git-code\\test");
CtModel model = launcher.buildModel();
Collection> allTypes = model.getAllTypes();
System.out.println(allTypes.size());
for (CtType ctType : allTypes) {
System.out.println(ctType.getSimpleName());
}
```

### Actual output

```Java
2
ConfigQueryRequestHandlerTest
Constants
```

### Expected output

```Java
1
ConfigQueryRequestHandlerTest
```

### Spoon Version

10.3.0

### JVM Version

11

### What operating system are you using?

win10

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.