Skip to content

Commit

Permalink
add test to avoid shadowing
Browse files Browse the repository at this point in the history
  • Loading branch information
Luro02 committed Apr 18, 2024
1 parent cc2ccc3 commit ebd6f60
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ public void process(CtVariable<?> ctVariable) {
Collection<CtFieldReference<?>> visibleFields = getAllVisibleFields(parent);

List<CtFieldReference<?>> hiddenFields = visibleFields.stream()
// ignore fields that are allowed to be hidden
.filter(ctFieldReference -> !ALLOWED_FIELDS.contains(ctFieldReference.getSimpleName()))
// only keep fields that have the same name as the variable, but are not the same field
.filter(ctFieldReference -> ctFieldReference.getSimpleName().equals(ctVariable.getSimpleName())
&& !ctFieldReference.equals(ctVariable.getReference()))
.toList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,4 +401,30 @@ public String toString() {

problems.assertExhausted();
}


@Test
void testArrayParamHidesAttribute() throws LinterException, IOException {
ProblemIterator problems = this.checkIterator(StringSourceInfo.fromSourceStrings(
JavaVersion.JAVA_17,
Map.ofEntries(
Map.entry(
"Main",
"""
class Main {
private String ais;
public void doSomething(String[] ais) {
System.out.println(ais);
}
}
"""
)
)
), PROBLEM_TYPES);

// not reported, because only the array is used in the method

problems.assertExhausted();
}
}

0 comments on commit ebd6f60

Please sign in to comment.