@Override public Object visit(final ASTCompilationUnit node, final Object data) { interestingLineNumberComments.clear(); final List<Comment> comments = node.getComments(); for (final Comment comment : comments) { if (getProperty(REGEX_DESCRIPTOR).matcher(comment.getImage()).matches()) { interestingLineNumberComments.add(comment.getBeginLine()); } } return super.visit(node, data); }
return; for (Comment comment : node.getComments()) { if (!(comment instanceof FormalComment)) { continue;
@Override public Object call(Context context, List args) throws FunctionCallException { if (!args.isEmpty()) { return Boolean.FALSE; } Node n = (Node) context.getNodeSet().get(0); if (n instanceof AbstractNode) { int codeBeginLine = ((AbstractNode) n).getBeginLine(); int codeEndLine = ((AbstractNode) n).getEndLine(); List<Comment> commentList = ((AbstractNode) n).getFirstParentOfType(ASTCompilationUnit.class).getComments(); for (Comment comment : commentList) { if (comment.getBeginLine() == codeBeginLine || comment.getEndLine() == codeEndLine) { return comment.getImage(); } } } return Boolean.FALSE; } }
@Override public Object visit(ASTCompilationUnit cUnit, Object data) { // NPE patch: Eclipse plugin doesn't call start() at onset? if (currentBadWords == null) { start(null); } for (Comment comment : cUnit.getComments()) { List<String> badWords = illegalTermsIn(comment); if (badWords.isEmpty()) { continue; } addViolationWithMessage(data, cUnit, errorMsgFor(badWords), comment.getBeginLine(), comment.getEndLine()); } return super.visit(cUnit, data); }
@Override public Object visit(ASTCompilationUnit cUnit, Object data) { for (Comment comment : cUnit.getComments()) { if (hasTooManyLines(comment)) { addViolationWithMessage(data, cUnit, this.getMessage() + ": Too many lines", comment.getBeginLine(), comment.getEndLine()); } List<Integer> lineNumbers = overLengthLineIndicesIn(comment); if (lineNumbers.isEmpty()) { continue; } for (Integer lineNum : lineNumbers) { addViolationWithMessage(data, cUnit, this.getMessage() + ": Line too long", lineNum, lineNum); } } return super.visit(cUnit, data); } }
protected SortedMap<Integer, Node> orderedCommentsAndDeclarations(ASTCompilationUnit cUnit) { SortedMap<Integer, Node> itemsByLineNumber = new TreeMap<>(); addDeclarations(itemsByLineNumber, cUnit.findDescendantsOfType(ASTClassOrInterfaceDeclaration.class, true)); addDeclarations(itemsByLineNumber, cUnit.getComments()); addDeclarations(itemsByLineNumber, cUnit.findDescendantsOfType(ASTFieldDeclaration.class, true)); addDeclarations(itemsByLineNumber, cUnit.findDescendantsOfType(ASTMethodDeclaration.class, true)); addDeclarations(itemsByLineNumber, cUnit.findDescendantsOfType(ASTConstructorDeclaration.class, true)); addDeclarations(itemsByLineNumber, cUnit.findDescendantsOfType(ASTEnumDeclaration.class, true)); return itemsByLineNumber; }
@Override public Object visit(final ASTCompilationUnit node, final Object data) { interestingLineNumberComments.clear(); final List<Comment> comments = node.getComments(); for (final Comment comment : comments) { if (getProperty(REGEX_DESCRIPTOR).matcher(comment.getImage()).matches()) { interestingLineNumberComments.add(comment.getBeginLine()); } } return super.visit(node, data); }
return; for (Comment comment : node.getComments()) { if (!(comment instanceof FormalComment)) { continue;
private SortedMap<Integer, Node> orderedCommentsAndEnumDeclarations(ASTCompilationUnit cUnit) { SortedMap<Integer, Node> itemsByLineNumber = new TreeMap<>(); List<ASTEnumDeclaration> enumDecl = cUnit.findDescendantsOfType(ASTEnumDeclaration.class); NodeSortUtils.addNodesToSortedMap(itemsByLineNumber, enumDecl); List<ASTEnumConstant> contantDecl = cUnit.findDescendantsOfType(ASTEnumConstant.class); NodeSortUtils.addNodesToSortedMap(itemsByLineNumber, contantDecl); NodeSortUtils.addNodesToSortedMap(itemsByLineNumber, cUnit.getComments()); return itemsByLineNumber; }
@Override public Object call(Context context, List args) throws FunctionCallException { if (!args.isEmpty()) { return Boolean.FALSE; } Node n = (Node) context.getNodeSet().get(0); if (n instanceof AbstractNode) { int codeBeginLine = ((AbstractNode) n).getBeginLine(); int codeEndLine = ((AbstractNode) n).getEndLine(); List<Comment> commentList = ((AbstractNode) n).getFirstParentOfType(ASTCompilationUnit.class).getComments(); for (Comment comment : commentList) { if (comment.getBeginLine() == codeBeginLine || comment.getEndLine() == codeEndLine) { return comment.getImage(); } } } return Boolean.FALSE; } }
@Override public Object visit(ASTCompilationUnit cUnit, Object data) { // NPE patch: Eclipse plugin doesn't call start() at onset? if (currentBadWords == null) { start(null); } for (Comment comment : cUnit.getComments()) { List<String> badWords = illegalTermsIn(comment); if (badWords.isEmpty()) { continue; } addViolationWithMessage(data, cUnit, errorMsgFor(badWords), comment.getBeginLine(), comment.getEndLine()); } return super.visit(cUnit, data); }
/** * Check comments behind nodes. * * @param cUnit compilation unit * @return sorted comments and expressions */ protected SortedMap<Integer, Node> orderedCommentsAndExpressions(ASTCompilationUnit cUnit) { SortedMap<Integer, Node> itemsByLineNumber = new TreeMap<>(); // expression nodes List<ASTExpression> expressionNodes = cUnit.findDescendantsOfType(ASTExpression.class); NodeSortUtils.addNodesToSortedMap(itemsByLineNumber, expressionNodes); // filed declaration nodes List<ASTFieldDeclaration> fieldNodes = cUnit.findDescendantsOfType(ASTFieldDeclaration.class); NodeSortUtils.addNodesToSortedMap(itemsByLineNumber, fieldNodes); // enum constant nodes List<ASTEnumConstant> enumConstantNodes = cUnit.findDescendantsOfType(ASTEnumConstant.class); NodeSortUtils.addNodesToSortedMap(itemsByLineNumber, enumConstantNodes); NodeSortUtils.addNodesToSortedMap(itemsByLineNumber, cUnit.getComments()); return itemsByLineNumber; }
protected SortedMap<Integer, Node> orderedCommentsAndDeclarations(ASTCompilationUnit cUnit) { SortedMap<Integer, Node> itemsByLineNumber = new TreeMap<>(); addDeclarations(itemsByLineNumber, cUnit.findDescendantsOfType(ASTClassOrInterfaceDeclaration.class, true)); addDeclarations(itemsByLineNumber, cUnit.getComments()); addDeclarations(itemsByLineNumber, cUnit.findDescendantsOfType(ASTFieldDeclaration.class, true)); addDeclarations(itemsByLineNumber, cUnit.findDescendantsOfType(ASTMethodDeclaration.class, true)); addDeclarations(itemsByLineNumber, cUnit.findDescendantsOfType(ASTConstructorDeclaration.class, true)); addDeclarations(itemsByLineNumber, cUnit.findDescendantsOfType(ASTEnumDeclaration.class, true)); return itemsByLineNumber; }
@Override public Object visit(ASTCompilationUnit cUnit, Object data) { for (Comment comment : cUnit.getComments()) { if (hasTooManyLines(comment)) { addViolationWithMessage(data, cUnit, this.getMessage() + ": Too many lines", comment.getBeginLine(), comment.getEndLine()); } List<Integer> lineNumbers = overLengthLineIndicesIn(comment); if (lineNumbers.isEmpty()) { continue; } for (Integer lineNum : lineNumbers) { addViolationWithMessage(data, cUnit, this.getMessage() + ": Line too long", lineNum, lineNum); } } return super.visit(cUnit, data); } }
protected SortedMap<Integer, Node> orderedComments(ASTCompilationUnit cUnit) { SortedMap<Integer, Node> itemsByLineNumber = new TreeMap<>(); NodeSortUtils.addNodesToSortedMap(itemsByLineNumber, cUnit.getComments()); List<ASTAnnotation> annotations = cUnit.findDescendantsOfType(ASTAnnotation.class); NodeSortUtils.addNodesToSortedMap(itemsByLineNumber, annotations); List<ASTClassOrInterfaceDeclaration> classDecl = cUnit.findDescendantsOfType(ASTClassOrInterfaceDeclaration.class); NodeSortUtils.addNodesToSortedMap(itemsByLineNumber, classDecl); List<ASTFieldDeclaration> fields = cUnit.findDescendantsOfType(ASTFieldDeclaration.class); NodeSortUtils.addNodesToSortedMap(itemsByLineNumber, fields); List<ASTMethodDeclaration> methods = cUnit.findDescendantsOfType(ASTMethodDeclaration.class); NodeSortUtils.addNodesToSortedMap(itemsByLineNumber, methods); List<ASTConstructorDeclaration> constructors = cUnit.findDescendantsOfType(ASTConstructorDeclaration.class); NodeSortUtils.addNodesToSortedMap(itemsByLineNumber, constructors); List<ASTEnumDeclaration> enumDecl = cUnit.findDescendantsOfType(ASTEnumDeclaration.class); NodeSortUtils.addNodesToSortedMap(itemsByLineNumber, enumDecl); return itemsByLineNumber; }
@Override protected SortedMap<Integer, Node> orderedCommentsAndDeclarations(ASTCompilationUnit cUnit) { SortedMap<Integer, Node> itemsByLineNumber = new TreeMap<>(); List<ASTImportDeclaration> importDecl = cUnit .findDescendantsOfType(ASTImportDeclaration.class); NodeSortUtils.addNodesToSortedMap(itemsByLineNumber, importDecl); List<ASTClassOrInterfaceDeclaration> classDecl = cUnit .findDescendantsOfType(ASTClassOrInterfaceDeclaration.class); NodeSortUtils.addNodesToSortedMap(itemsByLineNumber, classDecl); List<ASTFieldDeclaration> fields = cUnit.findDescendantsOfType(ASTFieldDeclaration.class); NodeSortUtils.addNodesToSortedMap(itemsByLineNumber, fields); List<ASTMethodDeclaration> methods = cUnit.findDescendantsOfType(ASTMethodDeclaration.class); NodeSortUtils.addNodesToSortedMap(itemsByLineNumber, methods); List<ASTConstructorDeclaration> constructors = cUnit.findDescendantsOfType(ASTConstructorDeclaration.class); NodeSortUtils.addNodesToSortedMap(itemsByLineNumber, constructors); List<ASTBlockStatement> blockStatements = cUnit.findDescendantsOfType(ASTBlockStatement.class); NodeSortUtils.addNodesToSortedMap(itemsByLineNumber, blockStatements); NodeSortUtils.addNodesToSortedMap(itemsByLineNumber, cUnit.getComments()); return itemsByLineNumber; }