Clean up return types of `HasAnnotations` implementations
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 18/100
Research direction
Start with the default getAnnotationOfType and getAnnotations in HasAnnotations.java, then compare them with the overrides in JavaCodeUnit.java and the casts in AccessTarget.java. The open question is whether JavaMember and JavaCodeUnit should become self-typed generics, which is a breaking API change that needs maintainer agreement before any code changes. Done means a chosen approach, agreed in the thread, with the redundant overrides and casts removed.
Written by the indexing model from the issue text.
Description
Problem
HasAnnotations.java has default implementations for most of its methods, e.g.:
default JavaAnnotation<? extends SELF> getAnnotationOfType(String typeName) {
Optional<? extends JavaAnnotation<? extends SELF>> annotation = tryGetAnnotationOfType(typeName);
if (!annotation.isPresent()) {
throw new IllegalArgumentException(String.format("%s is not annotated with @%s", getDescription(), typeName));
}
return annotation.get();
}
A lot classes also inherit the implementations of JavaMember, e.g.:
public Set<? extends JavaAnnotation<? extends JavaMember>> getAnnotations() {
return ImmutableSet.copyOf(annotations.values());
}
However, some existing implementations have formally incompatible return types although the behaviour is entirely identical to the default implementation (e.g. JavaCodeUnit.java):
@Override
@SuppressWarnings("unchecked") // we know the 'owning' member is this code unit
public JavaAnnotation<? extends JavaCodeUnit> getAnnotationOfType(String typeName) {
return (JavaAnnotation<? extends JavaCodeUnit>) super.getAnnotationOfType(typeName);
}
We should consider cleaning up the types here so we can get rid of redundant overrides and typecasts as much as possible.
However, this is a breaking change since this changes return types of external parameters.
Ideas
I am not yet sure what the best approach is. Some thoughts (feel free to edit this post):
- Just remove all typecasting overrides
- Quite easy (regex search for
^\s*return \(.*super, also check instances of@SuppressWarnings("unchecked")to be sure)
- Quite easy (regex search for
- ❓ Is it a problem that e.g.
JavaFieldonly implementsHasAnnotations<JavaMember>and notHasAnnotations<JavaField>?- If that is the case,
JavaMemberwill also need to be generic (JavaMember<SELF extends JavaMember<SELF>>) and the same forJavaCodeUnit->JavaCodeUnit<SELF extends JavaCodeUnit<SELF>> - This also applies to a bunch of casts in
AccessTarget.java, e.g.return (Optional<JavaField>) super.resolveMember(); - Making
JavaMemberandJavaCodeUnitself-aware comes with a significant number of code changes, and I am not yet 100 % convinced that it will work out.
- If that is the case,
- Dominant language
- Java
- Stars
- 3.9k
- Forks
- 350
- Avg merge
- 3d 2m
- Merged PRs (30d)
- 13
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from TNG/ArchUnit
-
PackageMatcher wildcards don't match package names with non-ASCII lettersPossibly taken @StefanPenndorf claimed this 6 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 25/100
Maintainers usually reply within 1 day
-
beFreeOfCycles() misses cycles: TarjanComponentFinder does not return the component with the lowest node indexPossibly taken @StefanPenndorf claimed this 6 days ago. Open
Difficulty 4/5 3-5 days Newbie friendliness 30/100
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 52/100
TNG/ArchUnit#1773 · 1 comment ·
Maintainers usually reply within 1 day
-
Constructor parameters added by the compiler (inner classes, enums) make `getParameters()` / `getParameterTypes()` inconsistent and misplace parameter annotationsPossibly taken @SamuelAdigos claimed this 8 days ago. Open
Difficulty 5/5 Over a week Newbie friendliness 48/100
TNG/ArchUnit#1772 · 3 comments ·
Maintainers usually reply within 1 day
-
breaking change
Difficulty 4/5 3-5 days Newbie friendliness 30/100
Maintainers usually reply within 1 day
Similar issues
-
hermes-queue
Difficulty 1/5 Under an hour Newbie friendliness 85/100
chrisalunlloyd2-sudo/mindpalace#337 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 79/100
flutter/flutter-intellij#9221 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
ucsb-cs156/proj-frontiers#844 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 74/100
AllTheMods/ATM10-Aeronautics#159 ·
Maintainers usually reply within 6 days
-
type: dependency-upgrade
Difficulty 1/5 Under an hour Newbie friendliness 76/100
spring-projects/spring-security#20057 ·
Maintainers usually reply within 1 day