@Override public void visitNode(AstNode astNode) { inlineHTMLCounter++; isOnlyClosingTag = "?>".equals(astNode.getTokenOriginalValue().trim()); lastInlineHTMLNode = astNode; }
private static Set<String> getImplicitAnonymousFunctionParameters(AstNode node) { ImmutableSet.Builder<String> builder = ImmutableSet.builder(); for (AstNode identifier : node.getDescendants(GenericTokenType.IDENTIFIER)) { builder.add(identifier.getTokenOriginalValue()); } return builder.build(); }
/** * Returns "::$field" for static field and "->field" for others. * * @param identifierNode node that correspond to the name of the class member. */ protected String getCalledName(AstNode identifierNode, List<AstNode> modifiers) { if (CheckUtils.isStaticClassMember(modifiers)) { return "::" + identifierNode.getTokenOriginalValue(); } else { return "->" + StringUtils.remove(identifierNode.getTokenOriginalValue(), "$"); } }
private String getCategoryFromStringLiteralParameter(AstNode parameterList) { String firstParam = parameterList.getFirstChild(PHPPunctuator.LPARENTHESIS).getNextAstNode().getTokenOriginalValue(); if (firstParam.startsWith("\"") && firstParam.endsWith("\"") || firstParam.startsWith("'") && firstParam.endsWith("'")) { String category = firstParam.substring(1, firstParam.length() - 1); if (LOCALE_CATEGORY_CONSTANTS.contains(category)) { return category; } } return null; }
private static Set<String> getOperatorParameters(AstNode node) { ImmutableSet.Builder<String> builder = ImmutableSet.builder(); List<AstNode> identifiers = node .getFirstChild(CSharpGrammar.OPERATOR_DECLARATOR) .getFirstChild(CSharpGrammar.UNARY_OPERATOR_DECLARATOR, CSharpGrammar.BINARY_OPERATOR_DECLARATOR, CSharpGrammar.CONVERSION_OPERATOR_DECLARATOR) .getChildren(GenericTokenType.IDENTIFIER); for (AstNode identifier : identifiers) { builder.add(identifier.getTokenOriginalValue()); } return builder.build(); }
@Override public void visitFile(AstNode astNode) { if (astNode == null) { // file wasn't parsed return; } actualArity = ""; actualModule = astNode.getFirstDescendant(ErlangGrammarImpl.moduleAttr) .getFirstChild(ErlangGrammarImpl.atom).getTokenOriginalValue(); }
@Override public void visitNode(AstNode node) { AstNode identifier = node.getFirstChild(GenericTokenType.IDENTIFIER); if (!pattern.matcher(identifier.getTokenOriginalValue()).matches()) { getContext().createLineViolation(this, "Rename this class to match the regular expression: " + format, identifier); } }
@Override public void visitNode(AstNode astNode) { String className = astNode.getFirstChild(PHPGrammar.IDENTIFIER).getTokenOriginalValue(); if (!pattern.matcher(className).matches()) { getContext().createLineViolation(this, "Rename class \"{0}\" to match the regular expression {1}.", astNode, className, format); } }
private boolean isTrueFalseOrNull(AstNode node) { AstNode scalar = node.getFirstChild(); return node.is(PHPGrammar.COMMON_SCALAR) && ("null".equalsIgnoreCase(scalar.getTokenOriginalValue()) || scalar.is(PHPGrammar.BOOLEAN_LITERAL)); }
@Override public void visitNode(AstNode astNode) { AstNode caller = astNode.getPreviousAstNode(); if ("self".equals(caller.getTokenOriginalValue())) { getContext().createLineViolation(this, "Use \"static\" keyword instead of \"self\".", caller); } }
@Override public void visitNode(AstNode astNode) { String varName = astNode.getTokenOriginalValue(); if (CheckUtils.PREDEFINED_VARIABLES.values().contains(varName)) { getContext().createLineViolation(this, "Do not access \"{0}\" directly.", astNode, varName); } }
/** * Returns variable name from node VARIABLE_WITHOUT_OBJECTS. */ public static String getVariableName(AstNode variableWithoutObject) { Preconditions.checkArgument(variableWithoutObject.is(PHPGrammar.VARIABLE_WITHOUT_OBJECTS)); return variableWithoutObject .getFirstChild(PHPGrammar.REFERENCE_VARIABLE) .getFirstChild(PHPGrammar.COMPOUND_VARIABLE).getTokenOriginalValue(); }
private boolean isConstructor(AstNode methodNode, String methodName) { AstNode grandParent = methodNode.getParent().getParent(); boolean isConstructorBeforePHP5_3_3 = false; if (grandParent.is(PHPGrammar.CLASS_DECLARATION)) { isConstructorBeforePHP5_3_3 = methodName.equals(grandParent.getFirstChild(PHPGrammar.IDENTIFIER).getTokenOriginalValue()); } return isConstructorBeforePHP5_3_3 || "__construct".equals(methodName); }
private void checkParameters(AstNode functionDec) { for (AstNode parameter : FunctionUtils.getFunctionParameters(functionDec)) { String name = parameter.getTokenOriginalValue(); if (classState.hasFieldNamed(name)) { reportIssue(parameter, name); } } }
private static AstNode getDeprecatedConstructor(AstNode astNode) { String className = astNode.getFirstChild(PHPGrammar.IDENTIFIER).getTokenOriginalValue(); for (AstNode classStmt : astNode.getChildren(PHPGrammar.CLASS_STATEMENT)) { AstNode stmt = classStmt.getFirstChild(); if (stmt.is(PHPGrammar.METHOD_DECLARATION) && className.equals(getMethodName(stmt))) { return stmt; } } return null; }
private void reportUnusedVariable() { for (Variable localVar : getCurrentScope().getLocalVariables().values()) { if (localVar.getUsage() == 1) { getContext().createLineViolation(this, "Remove this unused \"{0}\" local variable.", localVar.getDeclaration(), localVar.getDeclaration().getTokenOriginalValue()); } } }
@Override public void visitNode(AstNode astNode) { getContext().createLineViolation(this, "Replace \"{0}\" with \"{1}\".", astNode, astNode.getTokenOriginalValue(), astNode.is(PHPKeyword.INCLUDE) ? PHPKeyword.INCLUDE_ONCE.getValue() : PHPKeyword.REQUIRE_ONCE.getValue()); } }
@Override public void visitNode(AstNode astNode) { String punctuator = astNode.is(PHPKeyword.AND) ? PHPPunctuator.ANDAND.getValue() : PHPPunctuator.OROR.getValue(); getContext().createLineViolation(this, "Replace \"{0}\" with \"{1}\".", astNode, astNode.getTokenOriginalValue(), punctuator); }
private void checkExtendsAndImplementsLine(FormattingStandardCheck formattingCheck, AstNode node) { AstNode identifier = node.getFirstChild(PHPGrammar.IDENTIFIER); String className = identifier.getTokenOriginalValue(); int classNameLine = identifier.getTokenLine(); boolean isExtendsOnClassNameLine = isExtendsOnClassNameLine(node, classNameLine); boolean isImplementsOnClassNameLine = isImplementsOnClassNameLine(node, classNameLine); String msg = getIssueMessage(isExtendsOnClassNameLine, isImplementsOnClassNameLine); if (msg != null) { formattingCheck.reportIssue("Move " + msg + " to the same line as the declaration of its class name, \"" + className + "\".", node); } }
@Override public void leaveNode(AstNode node) { SourceClass sourceClass = (SourceClass) getContext().peekSourceCode(); int complexity = ChecksHelper.getRecursiveMeasureInt(sourceClass, PHPMetric.COMPLEXITY); if (complexity > max) { getContext().createLineViolation(this, "The Cyclomatic Complexity of this class \"{0}\" is {1} which is greater than {2} authorized, split this class.", node, node.getFirstChild(PHPGrammar.IDENTIFIER).getTokenOriginalValue(), complexity, max); } }