/** * @deprecated in 1.17, use {@link #getPreviousAstNode()} instead */ @Deprecated public AstNode previousAstNode() { return getPreviousAstNode(); }
private boolean isFirstOnline(AstNode curlyBrace) { Token previousToken = curlyBrace.getPreviousAstNode().getLastToken(); // In one case, clonsing parenthesis can be on the same line as the opening curly brace if (previousToken.getType().equals(PHPPunctuator.RPARENTHESIS)) { previousToken = curlyBrace.getPreviousAstNode().getPreviousAstNode().getLastToken(); } return previousToken.getLine() != curlyBrace.getTokenLine(); }
private void searchEventInPreviousTag(AstNode metadata) { AstNode previousDirective = metadata.getParent().getParent().getPreviousAstNode(); while (previousDirective != null && MetadataTag.isMetadataTag(previousDirective)) { checkEventTag(previousDirective); previousDirective = previousDirective.getPreviousAstNode(); } }
private static int getNumberOfNonPublicFields(List<AstNode> fields) { int nbNonPublicFields = 0; for (AstNode field : fields) { if (Modifiers.isNonPublic(Modifiers.getModifiers(field.getPreviousAstNode()))) { nbNonPublicFields++; } } return nbNonPublicFields; }
private boolean hasVisibility(AstNode functionDef) { Set<AstNodeType> modifiers = Modifiers.getModifiers(functionDef.getPreviousAstNode()); for (AstNodeType modifier : modifiers) { if (isVisibility(modifier)) { return true; } } return false; }
private static boolean isNotVariableVariables(AstNode compoundNode) { AstNode compoundParentPreviousNode = compoundNode.getParent().getPreviousAstNode(); return compoundParentPreviousNode != null && compoundParentPreviousNode.isNot(PHPGrammar.SIMPLE_INDIRECT_REFERENCE); } }
private static boolean hasArrayTypeTag(AstNode directive) { AstNode previousDirective = directive.getPreviousAstNode(); while (previousDirective != null && MetadataTag.isMetadataTag(previousDirective)) { if (MetadataTag.isTag(previousDirective.getFirstChild().getFirstChild(FlexGrammar.METADATA_STATEMENT), "ArrayElementType")) { return true; } previousDirective = previousDirective.getPreviousAstNode(); } return false; } }
@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); } }
private static Token getPreviousToken(AstNode node) { AstNode result = node.getPreviousAstNode(); while (result != null && !result.hasToken()) { while (result != null && !result.hasToken()) { result = result.getPreviousAstNode(); } while (result != null && result.getLastChild() != null) { result = result.getLastChild(); } } return result == null ? null : result.getToken(); }
private static String getModifiedVarByPostfixOp(AstNode unaryOperator) { AstNode parentPreviousNode = unaryOperator.getParent().getPreviousAstNode(); if (parentPreviousNode.is(CSharpGrammar.SIMPLE_NAME)) { return parentPreviousNode.getTokenValue(); } return null; }
private static AstNode getLiteralFromLogicalOrEqualityComparison(AstNode operator) { AstNode leftExpr = operator.getPreviousAstNode(); AstNode rightExpr = operator.getNextAstNode(); if (isBooleanLiteral(leftExpr)) { return leftExpr; } else if (isBooleanLiteral(rightExpr)) { return rightExpr; } else { return null; } }
@Override public void visitNode(AstNode node) { if (!isExcluded(node) && node.getPreviousAstNode().getLastToken() != null && node.getPreviousAstNode().getLastToken().getLine() != node.getTokenLine()) { getContext().createLineViolation(this, "Move this left curly brace to the end of previous line of code.", node); } }
private void retrieveAllPrivateFields(AstNode classDef) { for (AstNode varDeclaration : Clazz.getFields(classDef)) { if (Modifiers.getModifiers(varDeclaration.getParent().getPreviousAstNode()).contains(FlexKeyword.PRIVATE)) { for (AstNode identifier : Variable.getDeclaredIdentifiers(varDeclaration)) { privateFields.put(identifier.getTokenValue(), new PrivateField(identifier, 0)); } } } }
private static boolean isSimpleVariable(AstNode compoundNode) { AstNode compoundChild = compoundNode.getFirstChild(); if (compoundChild.isNot(PHPGrammar.VAR_IDENTIFIER)) { return false; } return isNotVariableVariables(compoundNode) && compoundChild.getPreviousAstNode().isNot(PHPPunctuator.ARROW, PHPPunctuator.DOUBLECOLON, PHPPunctuator.DOLAR_LCURLY); }
private boolean isEmptyMethod(AstNode methodDeclaration) { AstNode block = methodDeclaration.getFirstChild(CSharpGrammar.METHOD_BODY).getFirstChild(CSharpGrammar.BLOCK); if (block == null) { return false; } AstNode rightCurlyBrace = block.getFirstChild(CSharpPunctuator.RCURLYBRACE); return rightCurlyBrace.getPreviousAstNode().is(CSharpPunctuator.LCURLYBRACE) && !hasComment(rightCurlyBrace); }
private void retrieveAllPrivateFunctions(AstNode classDef) { for (AstNode functionDef : Clazz.getFunctions(classDef)) { if (!Function.isAccessor(functionDef) && Modifiers.getModifiers(functionDef.getPreviousAstNode()).contains(FlexKeyword.PRIVATE) && !Function.isEmptyConstructor(functionDef, Clazz.getName(classDef))) { AstNode identifierNode = functionDef .getFirstChild(FlexGrammar.FUNCTION_NAME) .getFirstChild(FlexGrammar.IDENTIFIER); functions.put(identifierNode.getTokenValue(), new PrivateFunction(identifierNode, 0)); } } }
@Override public void visitNode(AstNode node) { if (!isExcluded(node) && node.getPreviousAstNode().getLastToken().getLine() == node.getTokenLine()) { getContext().createLineViolation(this, "Move this left curly brace to the beginning of next line of code.", node); } }
@Override public void visitNode(AstNode node) { AstNode parent = node.getParent(); if (parentIsNotExpression(parent) && node.getNumberOfChildren() == 3) { AstNode foundCandidate = node.getLastChild(); AstNode percentCandidate = foundCandidate.getPreviousAstNode(); if (percentCandidate.is(PlSqlPunctuator.MOD) && "FOUND".equals(foundCandidate.getTokenValue())) { addLineIssue(getLocalizedMessage(CHECK_KEY), node.getTokenLine()); } } }
/** * Check the number of space before and after the given node. */ protected boolean isSpaceAround(AstNode node, int before, int after) { int spaceBefore = getNbSpaceBetween(node.getPreviousAstNode().getLastToken(), node.getToken()); int spaceAfter = getNbSpaceBetween(node.getToken(), node.getNextAstNode().getToken()); return spaceBefore == before && spaceAfter == after; }
private int getLineStartingColumn(AstNode node) { int line = node.getTokenLine(); AstNode previousNode = node.getPreviousAstNode(); int column = node.getToken().getColumn(); while (previousNode != null && previousNode.getToken().getLine() == line) { column = previousNode.getToken().getColumn(); previousNode = previousNode.getParent(); } return column; }