Fix parameter annotation accessing

This commit is contained in:
Juan Martín Sotuyo Dodero committed 2022-11-28 18:32:55 -03:00
1 parent 648729a980
commit b783443835
2 files changed
+11 -1

No files matched your search

@@ -134,6 +134,12 @@ abstract class ExecutableStub extends MemberStubBase implements JExecutableSymbo
public TypeSystem getTypeSystem() {
return ExecutableStub.this.getTypeSystem();
}
@Override
public List<SymAnnot> getDeclaredAnnotations() {
int paramIndex = ExecutableStub.this.getFormalParameters().indexOf(this);
return ExecutableStub.this.getFormalParameterAnnotations(paramIndex);
}
}
/**
@@ -7,6 +7,7 @@ package net.sourceforge.pmd.lang.java.symbols.internal.asm;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@@ -194,7 +195,7 @@ abstract class GenericSigBase<T extends JTypeParameterOwnerSymbol & AsmStub> {
private final @NonNull String signature;
private Map<Integer, List<SymAnnot>> parameterAnnotations;
private Map<Integer, List<SymAnnot>> parameterAnnotations = Collections.emptyMap();
private List<JTypeMirror> parameterTypes;
private List<JTypeMirror> exceptionTypes;
private JTypeMirror returnType;
@@ -256,6 +257,9 @@ abstract class GenericSigBase<T extends JTypeParameterOwnerSymbol & AsmStub> {
}
void addParameterAnnotation(int paramIndex, SymAnnot annot) {
if (parameterAnnotations.isEmpty()) {
parameterAnnotations = new HashMap<>(); // Make writable
}
parameterAnnotations.computeIfAbsent(paramIndex, ArrayList::new).add(annot);
}