Start of port of javadoc check for types.
This commit is contained in:
parent
b881f65b1a
commit
4d9e56e2b3
|
|
@ -38,7 +38,7 @@ public class MyCommonAST
|
|||
/** the column number **/
|
||||
private int mColumnNo = 0;
|
||||
|
||||
/** @see antlr.CommonAST **/
|
||||
/** @see antlr.CommonAST */
|
||||
public void initialize(Token aTok)
|
||||
{
|
||||
super.initialize(aTok);
|
||||
|
|
@ -46,13 +46,13 @@ public class MyCommonAST
|
|||
mColumnNo = aTok.getColumn() - 1; // expect columns to start @ 0
|
||||
}
|
||||
|
||||
/** @return the line number **/
|
||||
/** @return the line number */
|
||||
public int getLineNo()
|
||||
{
|
||||
return mLineNo;
|
||||
}
|
||||
|
||||
/** @return the column number **/
|
||||
/** @return the column number */
|
||||
public int getColumnNo()
|
||||
{
|
||||
return mColumnNo;
|
||||
|
|
|
|||
|
|
@ -271,7 +271,7 @@ class Verifier
|
|||
|
||||
final String[] jd = getJavadocBefore(lineNo - 1);
|
||||
if (jd == null) {
|
||||
mMessages.add(lineNo, "javadoc.missing");
|
||||
// mMessages.add(lineNo, "javadoc.missing");
|
||||
}
|
||||
else if (mInScope.size() == 0) {
|
||||
// don't check author/version for inner classes
|
||||
|
|
|
|||
|
|
@ -0,0 +1,58 @@
|
|||
package com.puppycrawl.tools.checkstyle.checks;
|
||||
|
||||
import com.puppycrawl.tools.checkstyle.Scope;
|
||||
import com.puppycrawl.tools.checkstyle.api.Check;
|
||||
import com.puppycrawl.tools.checkstyle.api.DetailAST;
|
||||
import com.puppycrawl.tools.checkstyle.api.FileContents;
|
||||
import com.puppycrawl.tools.checkstyle.api.ScopeUtils;
|
||||
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
|
||||
import com.puppycrawl.tools.checkstyle.api.Utils;
|
||||
|
||||
public class JavadocTypeCheck
|
||||
extends Check
|
||||
{
|
||||
private Scope mScope = Scope.PRIVATE;
|
||||
|
||||
public void setScope(String aFrom)
|
||||
{
|
||||
mScope = Scope.getInstance(aFrom);
|
||||
}
|
||||
|
||||
/** @see com.puppycrawl.tools.checkstyle.api.Check */
|
||||
public int[] getDefaultTokens()
|
||||
{
|
||||
return new int[] {TokenTypes.INTERFACE_DEF, TokenTypes.CLASS_DEF};
|
||||
}
|
||||
|
||||
/** @see com.puppycrawl.tools.checkstyle.api.Check */
|
||||
public void visitToken(DetailAST aAST)
|
||||
{
|
||||
final DetailAST mods =
|
||||
Utils.findFirstToken(aAST.getFirstChild(), TokenTypes.MODIFIERS);
|
||||
final Scope declaredScope = ScopeUtils.getScopeFromMods(mods);
|
||||
final Scope typeScope =
|
||||
ScopeUtils.inInterfaceBlock(aAST) ? Scope.PUBLIC : declaredScope;
|
||||
if (typeScope.isIn(mScope)) {
|
||||
final Scope surroundingScope = ScopeUtils.getSurroundingScope(aAST);
|
||||
if ((surroundingScope == null) || surroundingScope.isIn(mScope)) {
|
||||
final FileContents contents = getFileContents();
|
||||
final String[] cmt =
|
||||
contents.getJavadocBefore(aAST.getLineNo());
|
||||
if (cmt == null) {
|
||||
log(aAST.getLineNo(), "javadoc.missing");
|
||||
}
|
||||
// else if (mInScope.size() == 0) {
|
||||
// // don't check author/version for inner classes
|
||||
// if (!mConfig.isAllowNoAuthor()
|
||||
// && (MATCH_JAVADOC_AUTHOR.grep(cmt).length == 0)) {
|
||||
// mMessages.add(lineNo, "type.missingTag", "@author");
|
||||
// }
|
||||
// if (mConfig.isRequireVersion()
|
||||
// && (MATCH_JAVADOC_VERSION.grep(cmt).length == 0)) {
|
||||
// mMessages.add(lineNo, "type.missingTag", "@version");
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -224,7 +224,6 @@ public class CheckerTest
|
|||
final String filepath = getPath("InputTags.java");
|
||||
assertNotNull(c);
|
||||
final String[] expected = {
|
||||
filepath + ":8: Missing a Javadoc comment.",
|
||||
filepath + ":14:5: Missing a Javadoc comment.",
|
||||
filepath + ":18: Unused @param tag for 'unused'.",
|
||||
filepath + ":24: Expected an @return tag.",
|
||||
|
|
@ -260,7 +259,6 @@ public class CheckerTest
|
|||
final String filepath = getPath("InputTags.java");
|
||||
assertNotNull(c);
|
||||
final String[] expected = {
|
||||
filepath + ":8: Missing a Javadoc comment.",
|
||||
filepath + ":14:5: Missing a Javadoc comment.",
|
||||
filepath + ":18: Unused @param tag for 'unused'.",
|
||||
filepath + ":24: Expected an @return tag.",
|
||||
|
|
@ -294,10 +292,7 @@ public class CheckerTest
|
|||
final String filepath = getPath("InputInner.java");
|
||||
assertNotNull(c);
|
||||
final String[] expected = {
|
||||
filepath + ":14: Missing a Javadoc comment.",
|
||||
filepath + ":21: Missing a Javadoc comment.",
|
||||
filepath + ":24:16: Name 'data' must match pattern '^[A-Z](_?[A-Z0-9]+)*$'.",
|
||||
filepath + ":27: Missing a Javadoc comment.",
|
||||
};
|
||||
verify(c, filepath, expected);
|
||||
}
|
||||
|
|
@ -311,10 +306,7 @@ public class CheckerTest
|
|||
final String filepath = getPath("InputInner.java");
|
||||
assertNotNull(c);
|
||||
final String[] expected = {
|
||||
filepath + ":14: Missing a Javadoc comment.",
|
||||
filepath + ":21: Missing a Javadoc comment.",
|
||||
filepath + ":24:16: Name 'data' must match pattern '^[A-Z](_?[A-Z0-9]+)*$'.",
|
||||
filepath + ":27: Missing a Javadoc comment.",
|
||||
};
|
||||
verify(c, filepath, expected);
|
||||
}
|
||||
|
|
@ -359,13 +351,9 @@ public class CheckerTest
|
|||
final String filepath = getPath("InputPublicOnly.java");
|
||||
assertNotNull(c);
|
||||
final String[] expected = {
|
||||
filepath + ":7: Missing a Javadoc comment.",
|
||||
filepath + ":9: Missing a Javadoc comment.",
|
||||
filepath + ":12:9: Missing a Javadoc comment.",
|
||||
filepath + ":14: Missing a Javadoc comment.",
|
||||
filepath + ":18:13: Missing a Javadoc comment.",
|
||||
filepath + ":25:13: Missing a Javadoc comment.",
|
||||
filepath + ":34: Missing a Javadoc comment.",
|
||||
filepath + ":38:9: Missing a Javadoc comment.",
|
||||
filepath + ":49:5: Missing a Javadoc comment.",
|
||||
filepath + ":54:5: Missing a Javadoc comment.",
|
||||
|
|
@ -405,7 +393,6 @@ public class CheckerTest
|
|||
final String filepath = getPath("InputPublicOnly.java");
|
||||
assertNotNull(c);
|
||||
final String[] expected = {
|
||||
filepath + ":7: Missing a Javadoc comment.",
|
||||
filepath + ":59:5: Missing a Javadoc comment.",
|
||||
filepath + ":64:5: Missing a Javadoc comment.",
|
||||
filepath + ":79:5: Missing a Javadoc comment.",
|
||||
|
|
@ -423,43 +410,12 @@ public class CheckerTest
|
|||
final String filepath = getPath("InputScopeInnerInterfaces.java");
|
||||
assertNotNull(c);
|
||||
final String[] expected = {
|
||||
filepath + ":7: Missing a Javadoc comment.",
|
||||
filepath + ":38: Missing a Javadoc comment.",
|
||||
filepath + ":43:9: Missing a Javadoc comment.",
|
||||
filepath + ":44:9: Missing a Javadoc comment."
|
||||
};
|
||||
verify(c, filepath, expected);
|
||||
}
|
||||
|
||||
public void testScopeInnerClassesPackage()
|
||||
throws Exception
|
||||
{
|
||||
mProps.setProperty(Defn.JAVADOC_CHECKSCOPE_PROP,
|
||||
Scope.getInstance("package").getName());
|
||||
final Checker c = createChecker();
|
||||
final String filepath = getPath("InputScopeInnerClasses.java");
|
||||
assertNotNull(c);
|
||||
final String[] expected = {
|
||||
filepath + ":18: Missing a Javadoc comment.",
|
||||
filepath + ":20: Missing a Javadoc comment.",
|
||||
filepath + ":22: Missing a Javadoc comment."
|
||||
};
|
||||
verify(c, filepath, expected);
|
||||
}
|
||||
|
||||
public void testScopeInnerClassesPublic()
|
||||
throws Exception
|
||||
{
|
||||
mProps.setProperty(Defn.JAVADOC_CHECKSCOPE_PROP, Scope.PUBLIC.getName());
|
||||
final Checker c = createChecker();
|
||||
final String filepath = getPath("InputScopeInnerClasses.java");
|
||||
assertNotNull(c);
|
||||
final String[] expected = {
|
||||
filepath + ":18: Missing a Javadoc comment.",
|
||||
};
|
||||
verify(c, filepath, expected);
|
||||
}
|
||||
|
||||
public void testScopeAnonInnerPrivate()
|
||||
throws Exception
|
||||
{
|
||||
|
|
|
|||
|
|
@ -0,0 +1,144 @@
|
|||
package com.puppycrawl.tools.checkstyle;
|
||||
|
||||
import com.puppycrawl.tools.checkstyle.checks.JavadocTypeCheck;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* @author Oliver.Burn
|
||||
*
|
||||
* To change this generated comment edit the template variable "typecomment":
|
||||
* Window>Preferences>Java>Templates.
|
||||
* To enable and disable the creation of type comments go to
|
||||
* Window>Preferences>Java>Code Generation.
|
||||
*/
|
||||
public class JavadocTypeCheckTest extends BaseCheckTestCase
|
||||
{
|
||||
public JavadocTypeCheckTest(String arg0)
|
||||
{
|
||||
super(arg0);
|
||||
}
|
||||
|
||||
public void testTags() throws Exception
|
||||
{
|
||||
final CheckConfiguration checkConfig = new CheckConfiguration();
|
||||
checkConfig.setClassname(JavadocTypeCheck.class.getName());
|
||||
final Checker c = createChecker(checkConfig);
|
||||
final String fname = getPath("InputTags.java");
|
||||
final String[] expected =
|
||||
{
|
||||
"8: Missing a Javadoc comment.",
|
||||
};
|
||||
verify(c, fname, expected);
|
||||
}
|
||||
|
||||
public void testInner() throws Exception
|
||||
{
|
||||
final CheckConfiguration checkConfig = new CheckConfiguration();
|
||||
checkConfig.setClassname(JavadocTypeCheck.class.getName());
|
||||
final Checker c = createChecker(checkConfig);
|
||||
final String fname = getPath("InputInner.java");
|
||||
final String[] expected =
|
||||
{
|
||||
"14: Missing a Javadoc comment.",
|
||||
"21: Missing a Javadoc comment.",
|
||||
"27: Missing a Javadoc comment.",
|
||||
};
|
||||
verify(c, fname, expected);
|
||||
}
|
||||
|
||||
public void testStrict() throws Exception
|
||||
{
|
||||
final CheckConfiguration checkConfig = new CheckConfiguration();
|
||||
checkConfig.setClassname(JavadocTypeCheck.class.getName());
|
||||
final Checker c = createChecker(checkConfig);
|
||||
final String fname = getPath("InputPublicOnly.java");
|
||||
final String[] expected =
|
||||
{
|
||||
"7: Missing a Javadoc comment.",
|
||||
"9: Missing a Javadoc comment.",
|
||||
"14: Missing a Javadoc comment.",
|
||||
"34: Missing a Javadoc comment.",
|
||||
};
|
||||
verify(c, fname, expected);
|
||||
}
|
||||
|
||||
public void testProtected() throws Exception
|
||||
{
|
||||
final CheckConfiguration checkConfig = new CheckConfiguration();
|
||||
checkConfig.setClassname(JavadocTypeCheck.class.getName());
|
||||
checkConfig.addProperty("scope", Scope.PROTECTED.getName());
|
||||
final Checker c = createChecker(checkConfig);
|
||||
final String fname = getPath("InputPublicOnly.java");
|
||||
final String[] expected =
|
||||
{
|
||||
"7: Missing a Javadoc comment.",
|
||||
};
|
||||
verify(c, fname, expected);
|
||||
}
|
||||
|
||||
public void testPublic() throws Exception
|
||||
{
|
||||
final CheckConfiguration checkConfig = new CheckConfiguration();
|
||||
checkConfig.setClassname(JavadocTypeCheck.class.getName());
|
||||
checkConfig.addProperty("scope", Scope.PUBLIC.getName());
|
||||
final Checker c = createChecker(checkConfig);
|
||||
final String fname = getPath("InputScopeInnerInterfaces.java");
|
||||
final String[] expected =
|
||||
{
|
||||
"7: Missing a Javadoc comment.",
|
||||
"38: Missing a Javadoc comment.",
|
||||
};
|
||||
verify(c, fname, expected);
|
||||
}
|
||||
|
||||
public void testProtest() throws Exception
|
||||
{
|
||||
final CheckConfiguration checkConfig = new CheckConfiguration();
|
||||
checkConfig.setClassname(JavadocTypeCheck.class.getName());
|
||||
checkConfig.addProperty("scope", Scope.PROTECTED.getName());
|
||||
final Checker c = createChecker(checkConfig);
|
||||
final String fname = getPath("InputScopeInnerInterfaces.java");
|
||||
final String[] expected =
|
||||
{
|
||||
"7: Missing a Javadoc comment.",
|
||||
"29: Missing a Javadoc comment.",
|
||||
"38: Missing a Javadoc comment.",
|
||||
};
|
||||
verify(c, fname, expected);
|
||||
}
|
||||
|
||||
public void testPkg() throws Exception
|
||||
{
|
||||
final CheckConfiguration checkConfig = new CheckConfiguration();
|
||||
checkConfig.setClassname(JavadocTypeCheck.class.getName());
|
||||
checkConfig.addProperty(
|
||||
"scope",
|
||||
Scope.getInstance("package").getName());
|
||||
final Checker c = createChecker(checkConfig);
|
||||
final String fname = getPath("InputScopeInnerClasses.java");
|
||||
final String[] expected =
|
||||
{
|
||||
"18: Missing a Javadoc comment.",
|
||||
"20: Missing a Javadoc comment.",
|
||||
"22: Missing a Javadoc comment.",
|
||||
};
|
||||
verify(c, fname, expected);
|
||||
}
|
||||
|
||||
public void testEclipse() throws Exception
|
||||
{
|
||||
final CheckConfiguration checkConfig = new CheckConfiguration();
|
||||
checkConfig.setClassname(JavadocTypeCheck.class.getName());
|
||||
checkConfig.addProperty(
|
||||
"scope",
|
||||
Scope.getInstance("public").getName());
|
||||
final Checker c = createChecker(checkConfig);
|
||||
final String fname = getPath("InputScopeInnerClasses.java");
|
||||
final String[] expected =
|
||||
{
|
||||
"18: Missing a Javadoc comment.",
|
||||
};
|
||||
verify(c, fname, expected);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue