下面列出了org.eclipse.jdt.core.dom.ASTNode#JAVADOC 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void preVisit(final ASTNode node) {
// If node is a foldableType add node to foldableStack and
// add fold to allFolds
if (foldableTypes.contains(node.getNodeType())) {
final FoldableNode fn = tree.new FoldableNode(node);
// If node is also a javadoc, add its range to javadocFolds
// along with first line of javadoc comment
if (node.getNodeType() == ASTNode.JAVADOC) {
final Javadoc jdoc = (Javadoc) node;
String firstTagLine = "";
if (!jdoc.tags().isEmpty()) { // Handle empty comment
final String firstTag = ((TagElement) jdoc.tags().get(0)).toString();
firstTagLine = firstTag.split("\n")[1].substring(2);
// If tokenizing comments add javadoc tokens to tree
if (tokenizeComments)
fn.addTerms(tokenizeCommentString(firstTag));
}
javadocFolds.put(fn.getRange(), firstTagLine);
}
foldableStack.push(fn);
allFolds.add(fn.getRange());
}
}
public static boolean isInsideJavadoc(ASTNode node) {
do {
if (node.getNodeType() == ASTNode.JAVADOC)
return true;
node= node.getParent();
} while (node != null);
return false;
}
@Override
protected FoldableNode getBestNode(final HashMap<FoldableNode, Option> options, final double budget,
final boolean debug) {
int maxScore = Integer.MIN_VALUE;
FoldableNode bestNode = null;
// For every *folded* FoldableNode
for (final FoldableNode fn : options.keySet()) {
if (!fn.isUnfolded()) {
// Get cost
final int cost = options.get(fn).cost;
// Get parent node
final ASTNode parentNode = fn.node.getParent();
// Get score (2 - javadoc, 0 - method, 1 - o/w)
int score = Integer.MIN_VALUE;
if (cost <= budget) {
if (fn.node.getNodeType() == ASTNode.JAVADOC)
score = 2;
else if (parentNode == null) // parent is root node
score = 1;
else if (parentNode.getNodeType() == ASTNode.METHOD_DECLARATION)
score = 0;
else
score = 1;
}
// Set profit (for counting ties)
// options.get(fn).profit = score;
// Print node cost stats
if (debug)
System.out.println(
"\n+++++ Node: " + fn + "Cost: " + cost + " Budget: " + budget + " score: " + score);
// Set bestNode as node with max score
if (score > maxScore) {
maxScore = score;
bestNode = fn;
}
}
}
// countRandomlyBrokenTies(options, bestNode, maxScore);
// Print out bestNode and stats
if (debug && bestNode != null)
System.out.println("\n+=+=+ bestNode " + bestNode.printRange() + ", cost: " + options.get(bestNode).cost
+ " score: " + maxScore);
return bestNode;
}