private void reportIssuesOnVariable() { issuableVariables.removeAll(excludedVariables); for (VariableTree variable : issuableVariables) { reportIssue(variable.simpleName(), "Remove this misleading mutable servlet instance field or make it \"static\" and/or \"final\""); } issuableVariables.clear(); excludedVariables.clear(); }
private void checkName(VariableTree variableTree) { if (!SerializableContract.SERIAL_VERSION_UID_FIELD.equals(variableTree.simpleName().name()) && !pattern.matcher(variableTree.simpleName().name()).matches()) { reportIssue(variableTree.simpleName(), "Rename this constant name to match the regular expression '" + format + "'."); } }
private void checkVariable(VariableTree varTree) { int line = varTree.simpleName().identifierToken().line(); if (varSameDeclaration || lastVarLine == line) { reportIssue(varTree.simpleName(), String.format("Declare \"%s\" on a separate line.", varTree.simpleName().name())); } varSameDeclaration = ",".equals(varTree.endToken().text()); lastVarLine = line; } }
private void checkVariableUsages() { for (VariableTree variableTree : variables) { Symbol symbol = variableTree.symbol(); if (symbol.usages().size() == assignments.get(symbol).size()) { IdentifierTree simpleName = variableTree.simpleName(); reportIssue(simpleName, "Remove this unused \"" + simpleName + "\" local variable."); } } }
@Override public void visitNode(Tree tree) { ClassTree classTree = (ClassTree) tree; for (Tree member : classTree.members()) { if (member.is(Tree.Kind.VARIABLE)) { VariableTree field = (VariableTree) member; if (isFieldModifierConcernedByRule(field.modifiers()) && !pattern.matcher(field.simpleName().name()).matches()) { reportIssue(field.simpleName(), String.format("Rename this field \"%s\" to match the regular expression '%s'.", field.simpleName().name(), getFormat())); } } } }
@Override public void leaveNode(Tree tree) { if(tree.is(Tree.Kind.CATCH)) { CatchTree catchTree = (CatchTree) tree; caughtVariables.remove(catchTree.parameter().simpleName().name()); } }
private void handleVariable(VariableTree tree) { IdentifierTree variable = tree.simpleName(); isPasswordVariableName(variable) .filter(passwordVariableName -> isNotEmptyStringOrCharArrayFromString(tree.initializer())) .ifPresent(passwordVariableName -> report(variable, passwordVariableName)); }
@Override public void leaveFile(JavaFileScannerContext context) { unsecuredCookies.forEach(v -> reportIssue(v.declaration().simpleName(), MESSAGE)); unsecuredReturns.forEach(r -> reportIssue(r, MESSAGE)); unsecuredSetters.forEach(m -> reportIssue(m.arguments(), MESSAGE)); }
private static boolean isSerialVersionUID(Tree tree) { Tree parent = tree.parent(); while (parent != null && !parent.is(Tree.Kind.VARIABLE)) { parent = parent.parent(); } return parent != null && "serialVersionUID".equals(((VariableTree) parent).simpleName().name()); }
@Override public void visitVariable(VariableTree tree) { if (tree.initializer() == null) { name = tree.simpleName().name(); } else { super.visitVariable(tree); } } }
private void checkVariable(VariableTree tree) { if (isFileNameVariable(tree.simpleName())) { checkExpression(tree.initializer()); } }
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."); } } }
@Override public void visitClass(ClassTree tree) { if (tree.is(Tree.Kind.CLASS) || tree.is(Tree.Kind.ENUM)) { for (Tree member : tree.members()) { if (member.is(Tree.Kind.VARIABLE) && isPublicStaticNotFinal((VariableTree) member)) { context.reportIssue(this, ((VariableTree) member).simpleName(), "Make this \"public static " + ((VariableTree) member).simpleName() + "\" field final"); } } } super.visitClass(tree); }
private void checkPrivateField(Symbol privateFieldSymbol, TypeSymbol classSymbol) { MethodTree methodWhereUsed = usedInOneMethodOnly(privateFieldSymbol, classSymbol); if (methodWhereUsed != null && !isLiveInMethodEntry(privateFieldSymbol, methodWhereUsed)) { IdentifierTree declarationIdentifier = ((VariableTree) privateFieldSymbol.declaration()).simpleName(); String message = String.format(MESSAGE, privateFieldSymbol.name()); reportIssue(declarationIdentifier, message); } }
private static boolean referencePrivateProperty(String variableName, ClassTree classTree) { for (Tree member : classTree.members()) { if (member.is(Tree.Kind.VARIABLE)) { VariableTree variableTree = (VariableTree) member; if (ModifiersUtils.hasModifier(variableTree.modifiers(), Modifier.PRIVATE) && variableTree.simpleName().name().equals(variableName)) { return true; } } } return false; }
@Override public void visitVariable(VariableTree tree) { declareVariable(computeFlags(tree.modifiers(), tree), tree.simpleName(), (VariableTreeImpl) tree); super.visitVariable(tree); }
@Override public void visitVariable(VariableTree tree) { super.visitVariable(tree); if (isPublic(tree.modifiers())) { checkIfAllowed(tree.type(), "The type of the \"" + tree.simpleName() + "\" object "); } }
@Override public void visitVariable(VariableTree tree) { scan(tree.modifiers()); scan(tree.type()); scan(tree.simpleName()); scan(tree.initializer()); }
protected static Tree getReportTree(Tree tree) { Tree reportTree = tree; if(reportTree.is(PublicApiChecker.classKinds())) { reportTree = ExpressionsHelper.reportOnClassTree((ClassTree) reportTree); } else if(reportTree.is(PublicApiChecker.methodKinds())) { reportTree = ((MethodTree) reportTree).simpleName(); } else if(reportTree.is(Tree.Kind.VARIABLE)) { reportTree = ((VariableTree) reportTree).simpleName(); } return reportTree; }
@Override public void visitNode(Tree tree) { VariableTree variableTree = (VariableTree) tree; Type type = variableTree.type().symbolType(); if (ModifiersUtils.hasModifier(variableTree.modifiers(), Modifier.STATIC) && isForbiddenType(variableTree)) { if (type.isSubtypeOf(JAVA_TEXT_SIMPLE_DATE_FORMAT) && onlySynchronizedUsages((Symbol.VariableSymbol) variableTree.symbol())) { return; } IdentifierTree identifierTree = variableTree.simpleName(); reportIssue(identifierTree, String.format("Make \"%s\" an instance variable.", identifierTree.name())); } }