use of net.sourceforge.pmd.lang.java.ast.Comment in project pmd by pmd.
the class CommentContentRule method visit.
@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);
}
use of net.sourceforge.pmd.lang.java.ast.Comment in project pmd by pmd.
the class CommentDefaultAccessModifierRule method visit.
@Override
public Object visit(final ASTCompilationUnit node, final Object data) {
interestingLineNumberComments.clear();
final List<Comment> comments = node.getComments();
for (final Comment comment : comments) {
if (comment.getImage().matches(getProperty(REGEX_DESCRIPTOR).trim())) {
interestingLineNumberComments.add(comment.getBeginLine());
}
}
return super.visit(node, data);
}
use of net.sourceforge.pmd.lang.java.ast.Comment in project pmd-eclipse-plugin by pmd.
the class NodeImageDeriver method dumpComments.
private static void dumpComments(ASTCompilationUnit node) {
for (Comment comment : node.getComments()) {
System.out.println(comment.getClass().getName());
System.out.println(comment.getImage());
}
}
use of net.sourceforge.pmd.lang.java.ast.Comment in project pmd by pmd.
the class GetCommentOnFunction method call.
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;
}
use of net.sourceforge.pmd.lang.java.ast.Comment in project pmd by pmd.
the class UnusedImportsRule method visitComments.
private void visitComments(ASTCompilationUnit node) {
if (imports.isEmpty()) {
return;
}
for (Comment comment : node.getComments()) {
if (!(comment instanceof FormalComment)) {
continue;
}
for (Pattern p : PATTERNS) {
Matcher m = p.matcher(comment.getImage());
while (m.find()) {
String s = m.group(1);
imports.remove(new ImportWrapper(s, s, new DummyJavaNode(-1)));
if (m.groupCount() > 1) {
s = m.group(2);
if (s != null) {
String[] params = s.split("\\s*,\\s*");
for (String param : params) {
final int firstDot = param.indexOf('.');
final String expectedImportName;
if (firstDot == -1) {
expectedImportName = param;
} else {
expectedImportName = param.substring(0, firstDot);
}
imports.remove(new ImportWrapper(param, expectedImportName, new DummyJavaNode(-1)));
}
}
}
if (imports.isEmpty()) {
return;
}
}
}
}
}
Aggregations