Skip to content

Commit

Permalink
Issue checkstyle#7977: Resolve Pitest Issues - JavadocMethodCheck (5)
Browse files Browse the repository at this point in the history
  • Loading branch information
HuGanghui committed Apr 17, 2020
1 parent 729d735 commit 20ad567
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 92 deletions.
3 changes: 0 additions & 3 deletions .ci/pitest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,9 @@ 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>"
"JavadocMethodCheck.java.html:<td class='covered'><pre><span class='survived'> if (classInfo == null) {</span></pre></td></tr>"
"JavadocMethodCheck.java.html:<td class='covered'><pre><span class='survived'> child != null;</span></pre></td></tr>"
"JavadocMethodCheck.java.html:<td class='covered'><pre><span class='survived'> if (child.getType() == TokenTypes.TYPE_PARAMETER) {</span></pre></td></tr>"
"JavadocMethodCheck.java.html:<td class='covered'><pre><span class='survived'> if (classInfo != null) {</span></pre></td></tr>"
"JavadocMethodCheck.java.html:<td class='covered'><pre><span class='survived'> currentTypeParams.clear();</span></pre></td></tr>"
"JavadocMethodCheck.java.html:<td class='covered'><pre><span class='survived'> while (iterator.hasNext()) {</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>"
"TagParser.java.html:<td class='covered'><pre><span class='survived'> while (column &#60; currentLine.length()</span></pre></td></tr>"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1056,37 +1056,10 @@ private void processClass(DetailAST ast) {
private ClassInfo createClassInfo(final Token name,
final String surroundingClass) {
final ClassInfo result;
final ClassInfo classInfo = findClassAlias(name.getText());
if (classInfo == null) {
result = new RegularClass(name, surroundingClass, this);
}
else {
result = new ClassAlias(name, classInfo);
}
result = new RegularClass(name, surroundingClass, this);
return result;
}

/**
* Looking if a given name is alias.
*
* @param name given name
* @return ClassInfo for alias if it exists, null otherwise
* @noinspection WeakerAccess
*/
private ClassInfo findClassAlias(final String name) {
ClassInfo classInfo = null;
final Iterator<Map<String, ClassInfo>> iterator = currentTypeParams
.descendingIterator();
while (iterator.hasNext()) {
final Map<String, ClassInfo> paramMap = iterator.next();
classInfo = paramMap.get(name);
if (classInfo != null) {
break;
}
}
return classInfo;
}

/**
* Contains class's {@code Token}.
*/
Expand Down Expand Up @@ -1153,30 +1126,6 @@ public String toString() {

}

/** Represents type param which is "alias" for real type. */
private static class ClassAlias extends ClassInfo {

/** Class information associated with the alias. */
private final ClassInfo classInfo;

/**
* Creates new instance of the class.
*
* @param name token which represents name of class alias.
* @param classInfo class information associated with the alias.
*/
/* package */ ClassAlias(final Token name, ClassInfo classInfo) {
super(name);
this.classInfo = classInfo;
}

@Override
public String toString() {
return "ClassAlias[alias " + getName() + " for " + classInfo.getName() + "]";
}

}

/**
* Represents text element with location in the text.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -537,43 +537,6 @@ public void testClassRegularClass() throws Exception {
assertEquals(expected, result, "Invalid toString result");
}

@Test
public void testClassAliasToString() throws Exception {
final Class<?> tokenType = Class.forName("com.puppycrawl.tools.checkstyle.checks.javadoc."
+ "JavadocMethodCheck$Token");

final Class<?> regularClassType = Class
.forName("com.puppycrawl.tools.checkstyle.checks.javadoc."
+ "JavadocMethodCheck$RegularClass");
final Constructor<?> regularClassConstructor = regularClassType.getDeclaredConstructor(
tokenType, String.class, JavadocMethodCheck.class);
regularClassConstructor.setAccessible(true);

final Constructor<?> tokenConstructor = tokenType.getDeclaredConstructor(String.class,
int.class, int.class);
final Object token = tokenConstructor.newInstance("blablabla", 1, 1);

final Object regularClass = regularClassConstructor.newInstance(token, "sur",
new JavadocMethodCheck());

final Class<?> classAliasType = Class.forName(
"com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocMethodCheck$ClassAlias");
final Class<?> abstractTypeInfoType = Class
.forName("com.puppycrawl.tools.checkstyle.checks.javadoc."
+ "JavadocMethodCheck$ClassInfo");

final Constructor<?> classAliasConstructor = classAliasType
.getDeclaredConstructor(tokenType, abstractTypeInfoType);
classAliasConstructor.setAccessible(true);

final Object classAlias = classAliasConstructor.newInstance(token, regularClass);
final Method toString = classAlias.getClass().getDeclaredMethod("toString");
toString.setAccessible(true);
final String result = (String) toString.invoke(classAlias);
assertEquals("ClassAlias[alias Token[blablabla(1x1)] for Token[blablabla(1x1)]]", result,
"Invalid toString result");
}

@Test
public void testWithoutLogErrors() throws Exception {
final DefaultConfiguration config = createModuleConfig(JavadocMethodCheck.class);
Expand Down

0 comments on commit 20ad567

Please sign in to comment.