Skip to content

Commit

Permalink
improve code
Browse files Browse the repository at this point in the history
  • Loading branch information
erwan-serandour committed Dec 13, 2024
1 parent 2d1ee6b commit 960ae79
Showing 1 changed file with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,25 +104,26 @@ public void setContext(JavaFileScannerContext context) {
@Override
public void leaveFile(JavaFileScannerContext context) {
// now, we know all variable that are used in annotation so we can report issues
Set<String> idNames = identifiersUsedInAnnotations.stream()
.map(IdentifierData::identifier)
.collect(Collectors.toSet());
Set<Symbol> idSymbols = identifiersUsedInAnnotations.stream()
.map(IdentifierData::symbol)
.filter(s -> !s.isUnknown())
.collect(Collectors.toSet());
Set<String> idNamesWithSemantic = identifiersUsedInAnnotations.stream()
.filter(i -> !i.symbol().isUnknown())
.map(IdentifierData::identifier)
.collect(Collectors.toSet());
Set<String> idNamesWithoutSemantic = identifiersUsedInAnnotations.stream()
.filter(i -> i.symbol().isUnknown())
.map(IdentifierData::identifier)
.collect(Collectors.toSet());

hardCodedUri.stream()
.filter(v -> {
boolean insideAnnotation = idNames.contains(v.identifier())
&& (
// equals to an identifier with unknown semantic, we cannot compare their symbols
idNamesWithoutSemantic.contains(v.identifier())
|| idSymbols.contains(v.symbol()));
// equals to an identifier with unknown semantic, we cannot compare their symbols
boolean insideAnnotation = idNamesWithoutSemantic.contains(v.identifier()) ||
// idNamesWithSemantic is used to only compare the symbols when their string identifier are the same
// as comparing symbols is costly
(idNamesWithSemantic.contains(v.identifier()) && idSymbols.contains(v.symbol()));
return !insideAnnotation;
})
.forEach(v -> reportHardcodedURI(v.initializer()));
Expand Down

0 comments on commit 960ae79

Please sign in to comment.