Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,10 @@
import com.sun.tools.javac.api.JavacTrees;
import com.sun.tools.javac.code.Symbol.MethodSymbol;
import com.sun.tools.javac.tree.DCTree.DCDocComment;
import com.sun.tools.javac.tree.DocCommentTable;
import com.sun.tools.javac.tree.JCTree;
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
import com.sun.tools.javac.util.Position;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
Expand All @@ -69,26 +67,9 @@ static Optional<String> getBestMatch(String to, int maxEditDistance, Iterable<St
}

static DCDocComment getDocComment(VisitorState state, Tree tree) {
return getCommentTree(
((JCCompilationUnit) state.getPath().getCompilationUnit()).docComments, (JCTree) tree);
}

private static final Method COMMENT_TREE_METHOD = getCommentTreeMethod();

private static Method getCommentTreeMethod() {
try {
return DocCommentTable.class.getMethod("getCommentTree", JCTree.class);
} catch (ReflectiveOperationException e) {
throw new LinkageError(e.getMessage(), e);
}
}

private static DCDocComment getCommentTree(DocCommentTable docCommentTable, JCTree tree) {
try {
return (DCDocComment) COMMENT_TREE_METHOD.invoke(docCommentTable, tree);
} catch (ReflectiveOperationException e) {
throw new LinkageError(e.getMessage(), e);
}
return (DCDocComment)
((JCCompilationUnit) state.getPath().getCompilationUnit())
.docComments.getCommentTree((JCTree) tree);
}

static SuggestedFix replace(DocTree docTree, String replacement, VisitorState state) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
import com.sun.tools.javac.code.Type;
import com.sun.tools.javac.tree.DCTree;
import com.sun.tools.javac.tree.DCTree.DCDocComment;
import com.sun.tools.javac.tree.DocCommentTable;
import com.sun.tools.javac.tree.JCTree;
import java.io.IOException;
import java.lang.annotation.Retention;
Expand Down Expand Up @@ -1130,9 +1129,9 @@ public static class JavadocQualifier extends BugChecker implements BugChecker.Cl
@Override
public Description matchClass(ClassTree tree, VisitorState state) {
DCTree.DCDocComment comment =
getCommentTree(
((JCTree.JCCompilationUnit) state.getPath().getCompilationUnit()).docComments,
(JCTree) tree);
(DCDocComment)
((JCTree.JCCompilationUnit) state.getPath().getCompilationUnit())
.docComments.getCommentTree((JCTree) tree);
if (comment == null) {
return Description.NO_MATCH;
}
Expand All @@ -1152,17 +1151,6 @@ public Void visitLink(LinkTree node, Void unused) {
}
}

private static DCDocComment getCommentTree(DocCommentTable docCommentTable, JCTree tree) {
try {
return (DCDocComment)
DocCommentTable.class
.getMethod("getCommentTree", JCTree.class)
.invoke(docCommentTable, tree);
} catch (ReflectiveOperationException e) {
throw new LinkageError(e.getMessage(), e);
}
}

@Test
public void qualifyJavadocTest() {
BugCheckerRefactoringTestHelper.newInstance(JavadocQualifier.class, getClass())
Expand Down
Loading