Skip to content

Commit

Permalink
Issue #6295: changed code to remove javadoc profile mutations
Browse files Browse the repository at this point in the history
  • Loading branch information
rnveach authored and romani committed Dec 28, 2018
1 parent e1ad26b commit 9198b1f
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 46 deletions.
10 changes: 0 additions & 10 deletions .ci/pitest.sh
Expand Up @@ -99,23 +99,13 @@ pitest-javadoc)
"AbstractJavadocCheck.java.html:<td class='covered'><pre><span class='survived'> beginJavadocTree(root);</span></pre></td></tr>"
"AbstractJavadocCheck.java.html:<td class='covered'><pre><span class='survived'> finishJavadocTree(root);</span></pre></td></tr>"
"AbstractJavadocCheck.java.html:<td class='covered'><pre><span class='survived'> javadocTokens.clear();</span></pre></td></tr>"
"AbstractJavadocCheck.java.html:<td class='covered'><pre><span class='survived'> TREE_CACHE.get().clear();</span></pre></td></tr>"
"AbstractJavadocCheck.java.html:<td class='covered'><pre><span class='survived'> TREE_CACHE.get().clear();</span></pre></td></tr>"
"AbstractTypeAwareCheck.java.html:<td class='covered'><pre><span class='survived'> if (!currentClassName.isEmpty()) {</span></pre></td></tr>"
"AbstractTypeAwareCheck.java.html:<td class='covered'><pre><span class='survived'> if (dotIdx == -1) {</span></pre></td></tr>"
"AbstractTypeAwareCheck.java.html:<td class='covered'><pre><span class='survived'> imports.clear();</span></pre></td></tr>"
"AbstractTypeAwareCheck.java.html:<td class='covered'><pre><span class='survived'> typeParams.clear();</span></pre></td></tr>"
"JavadocMethodCheck.java.html:<td class='covered'><pre><span class='survived'> while (remIndex &#60; lines.length) {</span></pre></td></tr>"
"JavadocMethodCheck.java.html:<td class='covered'><pre><span class='survived'> while (remIndex &#60; lines.length) {</span></pre></td></tr>"
"JavadocPackageCheck.java.html:<td class='covered'><pre><span class='survived'> directoriesChecked.clear();</span></pre></td></tr>"
"JavadocPackageCheck.java.html:<td class='covered'><pre><span class='survived'> super.beginProcessing(charset);</span></pre></td></tr>"
"JavadocTagInfo.java.html:<td class='covered'><pre><span class='survived'> .collect(Collectors.toMap(JavadocTagInfo::getName, tagName -&#62; tagName)));</span></pre></td></tr>"
"JavadocTagInfo.java.html:<td class='covered'><pre><span class='survived'> .collect(Collectors.toMap(JavadocTagInfo::getText, tagText -&#62; tagText)));</span></pre></td></tr>"
"JavadocTypeCheck.java.html:<td class='covered'><pre><span class='survived'> tagCount++;</span></pre></td></tr>"
"SummaryJavadocCheck.java.html:<td class='covered'><pre><span class='survived'> for (int i = 0; !found &#38;&#38; i &#60; children.length - 1; i++) {</span></pre></td></tr>"
"SummaryJavadocCheck.java.html:<td class='covered'><pre><span class='survived'> if (child.getType() != JavadocTokenTypes.JAVADOC_INLINE_TAG</span></pre></td></tr>"
"TagParser.java.html:<td class='covered'><pre><span class='survived'> while (column &#60; currentLine.length()</span></pre></td></tr>"
"WriteTagCheck.java.html:<td class='covered'><pre><span class='survived'> tagCount += 1;</span></pre></td></tr>"
);
checkPitestReport "${ignoredItems[@]}"
;;
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -2178,7 +2178,7 @@
<param>*.Input*</param>
</excludedTestClasses>
<coverageThreshold>100</coverageThreshold>
<mutationThreshold>96</mutationThreshold>
<mutationThreshold>99</mutationThreshold>
<timeoutFactor>${pitest.plugin.timeout.factor}</timeoutFactor>
<timeoutConstant>${pitest.plugin.timeout.constant}</timeoutConstant>
<threads>${pitest.plugin.threads}</threads>
Expand Down
Expand Up @@ -274,7 +274,7 @@ public final void beginTree(DetailAST rootAST) {

@Override
public final void finishTree(DetailAST rootAST) {
TREE_CACHE.get().clear();
// No code by default
}

@Override
Expand Down
Expand Up @@ -602,19 +602,18 @@ private static List<JavadocTag> getMultilineArgTags(final Matcher argMultilineSt
final List<JavadocTag> tags = new ArrayList<>();
final String param1 = argMultilineStart.group(1);
final String param2 = argMultilineStart.group(2);
int remIndex = lineIndex + 1;
while (remIndex < lines.length) {
for (int remIndex = lineIndex + 1; remIndex < lines.length; remIndex++) {
final Matcher multilineCont = MATCH_JAVADOC_MULTILINE_CONT.matcher(lines[remIndex]);
if (multilineCont.find()) {
remIndex = lines.length;
final String lFin = multilineCont.group(1);
if (!lFin.equals(NEXT_TAG)
&& !lFin.equals(END_JAVADOC)) {
tags.add(new JavadocTag(tagLine, column, param1, param2));
}
break;
}
remIndex++;
}

return tags;
}

Expand All @@ -628,22 +627,22 @@ private static List<JavadocTag> getMultilineArgTags(final Matcher argMultilineSt
*/
private static List<JavadocTag> getMultilineNoArgTags(final Matcher noargMultilineStart,
final String[] lines, final int lineIndex, final int tagLine) {
final String param1 = noargMultilineStart.group(1);
final int col = noargMultilineStart.start(1) - 1;
final List<JavadocTag> tags = new ArrayList<>();
int remIndex = lineIndex + 1;
while (remIndex < lines.length) {
final Matcher multilineCont = MATCH_JAVADOC_MULTILINE_CONT
.matcher(lines[remIndex]);
if (multilineCont.find()) {
remIndex = lines.length;
final String lFin = multilineCont.group(1);
if (!lFin.equals(NEXT_TAG)
&& !lFin.equals(END_JAVADOC)) {
tags.add(new JavadocTag(tagLine, col, param1));
}
}
int remIndex = lineIndex;
Matcher multilineCont;

do {
remIndex++;
multilineCont = MATCH_JAVADOC_MULTILINE_CONT.matcher(lines[remIndex]);
} while (!multilineCont.find());

final List<JavadocTag> tags = new ArrayList<>();
final String lFin = multilineCont.group(1);
if (!lFin.equals(NEXT_TAG)
&& !lFin.equals(END_JAVADOC)) {
final String param1 = noargMultilineStart.group(1);
final int col = noargMultilineStart.start(1) - 1;

tags.add(new JavadocTag(tagLine, col, param1));
}

return tags;
Expand Down
Expand Up @@ -63,12 +63,6 @@ public JavadocPackageCheck() {
setFileExtensions("java");
}

@Override
public void beginProcessing(String charset) {
super.beginProcessing(charset);
directoriesChecked.clear();
}

@Override
protected void processFiltered(File file, FileText fileText) throws CheckstyleException {
// Check if already processed directory
Expand Down
Expand Up @@ -284,18 +284,18 @@ private List<JavadocTag> getJavadocTags(TextBlock textBlock) {
private void checkTag(int lineNo, List<JavadocTag> tags, String tagName,
Pattern formatPattern) {
if (formatPattern != null) {
int tagCount = 0;
boolean hasTag = false;
final String tagPrefix = "@";
for (int i = tags.size() - 1; i >= 0; i--) {
final JavadocTag tag = tags.get(i);
if (tag.getTagName().equals(tagName)) {
tagCount++;
hasTag = true;
if (!formatPattern.matcher(tag.getFirstArg()).find()) {
log(lineNo, MSG_TAG_FORMAT, tagPrefix + tagName, formatPattern.pattern());
}
}
}
if (tagCount == 0) {
if (!hasTag) {
log(lineNo, MSG_MISSING_TAG, tagPrefix + tagName);
}
}
Expand Down
Expand Up @@ -162,7 +162,7 @@ private static boolean startsWithInheritDoc(DetailNode root) {
boolean found = false;
final DetailNode[] children = root.getChildren();

for (int i = 0; !found && i < children.length - 1; i++) {
for (int i = 0; !found; i++) {
final DetailNode child = children[i];
if (child.getType() == JavadocTokenTypes.JAVADOC_INLINE_TAG
&& child.getChildren()[1].getType() == JavadocTokenTypes.INHERIT_DOC_LITERAL) {
Expand Down Expand Up @@ -239,8 +239,7 @@ private static String getFirstSentence(DetailNode ast) {
text = getFirstSentence(child);
}

if (child.getType() != JavadocTokenTypes.JAVADOC_INLINE_TAG
&& text.contains(periodSuffix)) {
if (text.contains(periodSuffix)) {
result.append(text, 0, text.indexOf(periodSuffix) + 1);
break;
}
Expand Down
Expand Up @@ -170,12 +170,12 @@ public void visitToken(DetailAST ast) {
*/
private void checkTag(int lineNo, String... comment) {
if (tagRegExp != null) {
int tagCount = 0;
boolean hasTag = false;
for (int i = 0; i < comment.length; i++) {
final String commentValue = comment[i];
final Matcher matcher = tagRegExp.matcher(commentValue);
if (matcher.find()) {
tagCount += 1;
hasTag = true;
final int contentStart = matcher.start(1);
final String content = commentValue.substring(contentStart);
if (tagFormat == null || tagFormat.matcher(content).find()) {
Expand All @@ -186,7 +186,7 @@ private void checkTag(int lineNo, String... comment) {
}
}
}
if (tagCount == 0) {
if (!hasTag) {
log(lineNo, MSG_MISSING_TAG, tag);
}
}
Expand Down
Expand Up @@ -141,6 +141,7 @@ public void testTags() throws Exception {
"337:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
"344:5: " + getCheckMessage(MSG_INVALID_INHERIT_DOC),
"383:8: " + getCheckMessage(MSG_DUPLICATE_TAG, "@return"),
"389:37: " + getCheckMessage(MSG_EXPECTED_TAG, "@param", "algorithm"),
};

verify(checkConfig, getPath("InputJavadocMethodTags.java"), expected);
Expand Down Expand Up @@ -181,6 +182,7 @@ public void testTagsWithResolver() throws Exception {
"337:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
"344:5: " + getCheckMessage(MSG_INVALID_INHERIT_DOC),
"383:8: " + getCheckMessage(MSG_DUPLICATE_TAG, "@return"),
"389:37: " + getCheckMessage(MSG_EXPECTED_TAG, "@param", "algorithm"),
};
verify(checkConfig, getPath("InputJavadocMethodTags.java"), expected);
}
Expand Down Expand Up @@ -301,6 +303,7 @@ public void testTagsWithSubclassesAllowed() throws Exception {
"337:5: " + getCheckMessage(MSG_JAVADOC_MISSING),
"344:5: " + getCheckMessage(MSG_INVALID_INHERIT_DOC),
"383:8: " + getCheckMessage(MSG_DUPLICATE_TAG, "@return"),
"389:37: " + getCheckMessage(MSG_EXPECTED_TAG, "@param", "algorithm"),
};
verify(checkConfig, getPath("InputJavadocMethodTags.java"), expected);
}
Expand Down
Expand Up @@ -384,3 +384,7 @@ class WrongException extends RuntimeException
* oops */
String[] results() default {};
}
class MoreExamples {
/** @param algorithm*/
public void setAlgorithm(String algorithm) {}
}

0 comments on commit 9198b1f

Please sign in to comment.