org.sonar.plugins.java.api.semantic.Symbol Java Examples
The following examples show how to use
org.sonar.plugins.java.api.semantic.Symbol.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UnusedMethodParameterCheck.java From vjtools with Apache License 2.0 | 6 votes |
@Override public void visitNode(Tree tree) { if (!hasSemantic()) { return; } MethodTree methodTree = (MethodTree) tree; if (methodTree.block() == null || !isIncluded(methodTree)) { return; } List<IdentifierTree> unused = Lists.newArrayList(); for (VariableTree var : methodTree.parameters()) { Symbol symbol = var.symbol(); if (symbol.usages().isEmpty() && !symbol.metadata().isAnnotatedWith(AUTHORIZED_ANNOTATION) && !isStrutsActionParameter(var)) { unused.add(var.simpleName()); } } Set<String> unresolvedIdentifierNames = unresolvedIdentifierNames(methodTree.block()); // kill the noise regarding unresolved identifiers, and remove the one with matching names from the list of // unused unused = unused.stream().filter(id -> !unresolvedIdentifierNames.contains(id.name())) .collect(Collectors.toList()); if (!unused.isEmpty()) { reportUnusedParameters(unused); } }
Example #2
Source File: UnusedMethodParameterCheck.java From vjtools with Apache License 2.0 | 6 votes |
@Override public void visitNode(Tree tree) { if (!hasSemantic()) { return; } MethodTree methodTree = (MethodTree) tree; if (methodTree.block() == null || !isIncluded(methodTree)) { return; } List<IdentifierTree> unused = Lists.newArrayList(); for (VariableTree var : methodTree.parameters()) { Symbol symbol = var.symbol(); if (symbol.usages().isEmpty() && !symbol.metadata().isAnnotatedWith(AUTHORIZED_ANNOTATION) && !isStrutsActionParameter(var)) { unused.add(var.simpleName()); } } Set<String> unresolvedIdentifierNames = unresolvedIdentifierNames(methodTree.block()); // kill the noise regarding unresolved identifiers, and remove the one with matching names from the list of // unused unused = unused.stream().filter(id -> !unresolvedIdentifierNames.contains(id.name())) .collect(Collectors.toList()); if (!unused.isEmpty()) { reportUnusedParameters(unused); } }
Example #3
Source File: UnusedPrivateFieldCheck.java From vjtools with Apache License 2.0 | 5 votes |
public void checkIfUnused(VariableTree tree) { if (hasNoAnnotation(tree)) { Symbol symbol = tree.symbol(); String name = symbol.name(); if (symbol.isPrivate() && onlyUsedInVariableAssignment(symbol) && !"serialVersionUID".equals(name) && !unknownIdentifiers.contains(name)) { reportIssue(tree.simpleName(), "Remove this unused \"" + name + "\" private field."); } } }
Example #4
Source File: UnusedPrivateFieldCheck.java From vjtools with Apache License 2.0 | 5 votes |
public void checkIfUnused(VariableTree tree) { if (hasNoAnnotation(tree)) { Symbol symbol = tree.symbol(); String name = symbol.name(); if (symbol.isPrivate() && onlyUsedInVariableAssignment(symbol) && !"serialVersionUID".equals(name) && !unknownIdentifiers.contains(name)) { reportIssue(tree.simpleName(), "Remove this unused \"" + name + "\" private field."); } } }
Example #5
Source File: UnusedPrivateFieldCheck.java From vjtools with Apache License 2.0 | 4 votes |
private boolean onlyUsedInVariableAssignment(Symbol symbol) { return symbol.usages().size() == assignments.get(symbol).size(); }
Example #6
Source File: UnusedPrivateFieldCheck.java From vjtools with Apache License 2.0 | 4 votes |
private void addAssignment(IdentifierTree identifier) { Symbol reference = identifier.symbol(); if (!reference.isUnknown()) { assignments.put(reference, identifier); } }
Example #7
Source File: UnusedPrivateFieldCheck.java From vjtools with Apache License 2.0 | 4 votes |
private boolean onlyUsedInVariableAssignment(Symbol symbol) { return symbol.usages().size() == assignments.get(symbol).size(); }
Example #8
Source File: UnusedPrivateFieldCheck.java From vjtools with Apache License 2.0 | 4 votes |
private void addAssignment(IdentifierTree identifier) { Symbol reference = identifier.symbol(); if (!reference.isUnknown()) { assignments.put(reference, identifier); } }
Example #9
Source File: MethodMatcher.java From AEM-Rules-for-SonarQube with Apache License 2.0 | 4 votes |
private boolean matches(Symbol symbol) { return symbol.isMethodSymbol() && isSearchedMethod((MethodSymbol) symbol); }