[Bug] Spoon metamodel does not consider certain model classes when getting the concept name for a class
- Dominant language
- Java
- Stars
- 2k
- Forks
- 392
- Avg merge
- 11h 24m
- Merged PRs (30d)
- 36
Description
**Describe the bug**
The spoon metamodel does not seem to consider the `CtUnnamedModule` , `CtRootPackage` and `CtUnresolvedImport` classes at the moment, which gave me some trouble when doing some metamodel queries (to do processor filtering).
**To Reproduce**
Just try giving `Metamodel.getConceptName()` an instance of one of these types:
```java
Metamodel.getConceptName(factory.getModel().getRootPackage().getClass());
```
This call will fail with an exception because CtRootPackage does not directly inherit from CtPackage; it inherits from CtPackageImpl.
I have a fork where I've implemented a fix for this, but it essentially just involves special casing the names of these specific types within `Metamodel.getConceptName()`. I also ended up removing the (deprecated) `CompilationUnit` and `CompilationUnitImpl` classes when I did this, but those changes can probably be isolated from this.
```java
private static String getConceptName(String simpleName) {
if (simpleName.endsWith(CLASS_SUFFIX)) {
simpleName = simpleName.substring(0, simpleName.length() - CLASS_SUFFIX.length());
// The unnamed module and certain other classes are a special case due to their names
} else if (simpleName.equals("CtUnnamedModule")) {
simpleName = "CtModule";
} else if (simpleName.equals("CtRootPackage")) {
simpleName = "CtPackage";
} else if (simpleName.equals("CtUnresolvedImport")) {
simpleName = "CtImport";
}
return simpleName;
}
```
**Operating system, JDK and Spoon version used**
* OS: MacOS Monterey (M1)
* JDK: 11
* Spoon version: 10.1.0
Contributor guide
Assessment
This issue has not been assessed yet.