INRIA / INRIA/spoon

Investigate different methods of generating simple names for anonymous entities

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

Description

When processing an anonymous entity (such as an anonymous class), Spoon seems to rely on the following code:
```java
// ... other code
if ((type instanceof CtClass || type instanceof CtInterface)
&& typeDeclaration.binding != null
&& (typeDeclaration.binding.isAnonymousType() || typeDeclaration.binding instanceof LocalTypeBinding && typeDeclaration.binding.enclosingMethod() != null)) {
type.setSimpleName(computeAnonymousName(typeDeclaration.binding.constantPoolName()));
}
// ... other code
```

(present [here](https://github.com/INRIA/spoon/blob/master/src/main/java/spoon/support/compiler/jdt/JDTTreeBuilderHelper.java#L856))

This results in a **numeric "simple name"** being generated and given to the anonymous entity (implementation [here](https://github.com/INRIA/spoon/blob/master/src/main/java/spoon/support/compiler/jdt/JDTTreeBuilderHelper.java#L104) but is also present in snippet below).
```java
static String computeAnonymousName(char[] anonymousQualifiedName) {
final String poolName = CharOperation.charToString(anonymousQualifiedName);
return poolName.substring(poolName.lastIndexOf(CtType.INNERTTYPE_SEPARATOR) + 1);
}

```

This could result in some issues when we'd like to have simple names that are more _representative_ of the anonymous entities. For instance, using just numeric names for anonymous entities seems to have caused the following issue: https://github.com/SpoonLabs/gumtree-spoon-ast-diff/issues/347 (see the discussion for more).

We can probably improve this anonymous naming convention. One idea could be to use the parent/super-class in generating the simple-name, among others.

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.