@Test public void is_false_value() throws Exception { assertThat(createLiterals(Tree.Kind.BOOLEAN_LITERAL, "false", "False", "FALSE") .allMatch(CheckUtils::isFalseValue)).isTrue(); assertThat(createLiterals(Tree.Kind.NUMERIC_LITERAL, "0", "0.0") .allMatch(CheckUtils::isFalseValue)).isTrue(); assertThat(createLiterals(Tree.Kind.REGULAR_STRING_LITERAL, "\"0\"", "'0'", "''") .allMatch(CheckUtils::isFalseValue)).isTrue(); assertThat((createLiterals(Tree.Kind.NULL_LITERAL, "NULL")) .allMatch(CheckUtils::isFalseValue)).isTrue(); VariableIdentifierTreeImpl variableIdentifierTree = new VariableIdentifierTreeImpl( new InternalSyntaxToken(1, 1, "var", Collections.emptyList(), 1, false)); assertThat(CheckUtils.isFalseValue(variableIdentifierTree)).isFalse(); }
public static boolean isFalseValue(ExpressionTree tree) { if (tree.is(Tree.Kind.BOOLEAN_LITERAL, Kind.NUMERIC_LITERAL)) { String value = ((LiteralTree) tree).value(); return value.equalsIgnoreCase("false") || value.equals("0") || value.equals("0.0"); } if (tree.is(Kind.REGULAR_STRING_LITERAL)) { String value = trimQuotes(((LiteralTree) tree).value()); return value.isEmpty() || value.equals("0"); } return tree.is(Kind.NULL_LITERAL); }
CheckUtils { public static boolean isFalseValue(ExpressionTree tree) { if (tree.is(Tree.Kind.BOOLEAN_LITERAL, Kind.NUMERIC_LITERAL)) { String value = ((LiteralTree) tree).value(); return value.equalsIgnoreCase("false") || value.equals("0") || value.equals("0.0"); } if (tree.is(Kind.REGULAR_STRING_LITERAL)) { String value = trimQuotes(((LiteralTree) tree).value()); return value.isEmpty() || value.equals("0"); } return tree.is(Kind.NULL_LITERAL); } }
CheckUtils { public static boolean isFalseValue(ExpressionTree tree) { if (tree.is(Tree.Kind.BOOLEAN_LITERAL, Kind.NUMERIC_LITERAL)) { String value = ((LiteralTree) tree).value(); return value.equalsIgnoreCase("false") || value.equals("0") || value.equals("0.0"); } if (tree.is(Kind.REGULAR_STRING_LITERAL)) { String value = trimQuotes(((LiteralTree) tree).value()); return value.isEmpty() || value.equals("0"); } return tree.is(Kind.NULL_LITERAL); } private  CheckUtils(); }
CheckUtils { public static boolean isFalseValue(ExpressionTree tree) { if (tree.is(Tree.Kind.BOOLEAN_LITERAL, Kind.NUMERIC_LITERAL)) { String value = ((LiteralTree) tree).value(); return value.equalsIgnoreCase("false") || value.equals("0") || value.equals("0.0"); } if (tree.is(Kind.REGULAR_STRING_LITERAL)) { String value = trimQuotes(((LiteralTree) tree).value()); return value.isEmpty() || value.equals("0"); } return tree.is(Kind.NULL_LITERAL); } private  CheckUtils(); static boolean isFunction(Tree tree); static String getFunctionName(FunctionTree functionDec); @Nullable static String getFunctionName(FunctionCallTree functionCall); @Nullable static String getLowerCaseFunctionName(FunctionCallTree functionCall); @Nullable static String functionName(FunctionCallTree functionCall); @Nullable static String lowerCaseFunctionName(FunctionCallTree functionCall); static Set<String> lowerCaseSet(String... names); static String getClassName(ClassDeclarationTree classDeclaration); static String getLowerCaseClassName(ClassDeclarationTree classDeclarationTree); @Nullable static String nameOf(Tree tree); static boolean isOverriding(MethodDeclarationTree declaration); static boolean isExitExpression(FunctionCallTree functionCallTree); static boolean hasModifier(ClassMemberTree tree, String toFind); static boolean hasModifier(List<SyntaxToken> modifiers, String toFind); static boolean isClosingTag(SyntaxToken token); static boolean isClosingTag(Tree tree); static Stream<String> lines(PhpFile file); static ExpressionTree skipParenthesis(ExpressionTree expr); @Nullable static ExpressionTree getForCondition(ForStatementTree tree); static String trimQuotes(String value); static String trimQuotes(LiteralTree literalTree); static boolean isFalseValue(ExpressionTree tree); static boolean isTrueValue(ExpressionTree tree); static boolean isStringLiteralWithValue(@Nullable Tree tree, String s); static boolean isNullOrEmptyString(ExpressionTree tree); static boolean hasAnnotation(Tree declaration, String annotation); static boolean isPublic(ClassMemberTree tree); static boolean isAbstract(ClassDeclarationTree tree); }
CheckUtils { public static boolean isFalseValue(ExpressionTree tree) { if (tree.is(Tree.Kind.BOOLEAN_LITERAL, Kind.NUMERIC_LITERAL)) { String value = ((LiteralTree) tree).value(); return value.equalsIgnoreCase("false") || value.equals("0") || value.equals("0.0"); } if (tree.is(Kind.REGULAR_STRING_LITERAL)) { String value = trimQuotes(((LiteralTree) tree).value()); return value.isEmpty() || value.equals("0"); } return tree.is(Kind.NULL_LITERAL); } private  CheckUtils(); static boolean isFunction(Tree tree); static String getFunctionName(FunctionTree functionDec); @Nullable static String getFunctionName(FunctionCallTree functionCall); @Nullable static String getLowerCaseFunctionName(FunctionCallTree functionCall); @Nullable static String functionName(FunctionCallTree functionCall); @Nullable static String lowerCaseFunctionName(FunctionCallTree functionCall); static Set<String> lowerCaseSet(String... names); static String getClassName(ClassDeclarationTree classDeclaration); static String getLowerCaseClassName(ClassDeclarationTree classDeclarationTree); @Nullable static String nameOf(Tree tree); static boolean isOverriding(MethodDeclarationTree declaration); static boolean isExitExpression(FunctionCallTree functionCallTree); static boolean hasModifier(ClassMemberTree tree, String toFind); static boolean hasModifier(List<SyntaxToken> modifiers, String toFind); static boolean isClosingTag(SyntaxToken token); static boolean isClosingTag(Tree tree); static Stream<String> lines(PhpFile file); static ExpressionTree skipParenthesis(ExpressionTree expr); @Nullable static ExpressionTree getForCondition(ForStatementTree tree); static String trimQuotes(String value); static String trimQuotes(LiteralTree literalTree); static boolean isFalseValue(ExpressionTree tree); static boolean isTrueValue(ExpressionTree tree); static boolean isStringLiteralWithValue(@Nullable Tree tree, String s); static boolean isNullOrEmptyString(ExpressionTree tree); static boolean hasAnnotation(Tree declaration, String annotation); static boolean isPublic(ClassMemberTree tree); static boolean isAbstract(ClassDeclarationTree tree); static final ImmutableList<Kind> FUNCTION_KINDS; static final ImmutableMap<String, String> SUPERGLOBALS_BY_OLD_NAME; static final ImmutableSet<String> SUPERGLOBALS; }