Skip to content

Commit

Permalink
Issue #3721: enforced no abbreviations in checkstyle
Browse files Browse the repository at this point in the history
  • Loading branch information
rnveach committed Feb 15, 2017
1 parent 4c1f698 commit 0d087b2
Show file tree
Hide file tree
Showing 44 changed files with 172 additions and 163 deletions.
2 changes: 1 addition & 1 deletion config/checkstyle_checks.xml
Expand Up @@ -371,7 +371,7 @@
<!-- Naming Conventions -->
<module name="AbbreviationAsWordInName">
<property name="ignoreFinal" value="false"/>
<property name="allowedAbbreviationLength" value="1"/>
<property name="allowedAbbreviationLength" value="0"/>
<property name="allowedAbbreviations" value="AST"/>
</module>
<module name="AbstractClassName"/>
Expand Down
2 changes: 1 addition & 1 deletion config/findbugs-exclude.xml
Expand Up @@ -108,7 +108,7 @@
<Match>
<!-- Temporary disabled. Have to deal with Javadoc nodes as well
See https://github.com/checkstyle/checkstyle/issues/3432-->
<Class name="com.puppycrawl.tools.checkstyle.gui.JTreeTable" />
<Class name="com.puppycrawl.tools.checkstyle.gui.TreeTable" />
<Method name="makeCodeSelection"/>
<Bug pattern="RV_RETURN_VALUE_IGNORED_NO_SIDE_EFFECT"/>
</Match>
Expand Down
8 changes: 4 additions & 4 deletions config/suppressions.xml
Expand Up @@ -28,7 +28,7 @@
files="AbstractCheckTest.java|AbstractClassNameCheckTest.java|AbstractTypeAwareCheckTest.java|AbstractJavadocCheckTest.java|AbstractViolationReporterTest.java"/>

<!-- Tone down the checking for test code -->
<suppress checks="CyclomaticComplexity" files="[\\/]XDocsPagesTest\.java"/>
<suppress checks="CyclomaticComplexity" files="[\\/]XdocsPagesTest\.java"/>
<suppress checks="IllegalCatch" files="[\\/]internal[\\/]\w+Util\.java"/>
<suppress checks="EmptyBlock" files=".*[\\/]src[\\/]test[\\/]"/>
<suppress checks="ImportControl" files=".*[\\/]src[\\/](test|it)[\\/]"/>
Expand All @@ -42,7 +42,7 @@
<suppress checks="MethodCount" files=".*[\\/]src[\\/](test|it)[\\/]"/>

<!--The Check generates too many violations, fixing them will make code unmanageable.-->
<suppress checks="MagicNumber" files="(ParseTreeTablePModel|MainFrame)\.java"/>
<suppress checks="MagicNumber" files="(ParseTreeTablePresentation|MainFrame)\.java"/>

<!-- Methods that build fake AST are very long-->
<suppress checks="MethodLength" files="src[\\/]test[\\/]java[\\/]com[\\/]puppycrawl[\\/]tools[\\/]checkstyle[\\/]grammars[\\/]comments[\\/]CommentsTest\.java"/>
Expand Down Expand Up @@ -75,11 +75,11 @@
<suppress checks="ClassDataAbstractionCoupling" files="AutomaticBean\.java"/>
<!-- they are aggregators of logic, usage a several of classes are ok -->
<suppress checks="ClassDataAbstractionCoupling" files="(Checker|TreeWalker|Main|CheckstyleAntTask|JavadocDetailNodeParser)\.java"/>
<suppress checks="ClassDataAbstractionCoupling" files="(CheckerTest|TreeWalkerTest|BaseCheckTestSupport|XDocsPagesTest|CheckstyleAntTaskTest)\.java"/>
<suppress checks="ClassDataAbstractionCoupling" files="(CheckerTest|TreeWalkerTest|BaseCheckTestSupport|XdocsPagesTest|CheckstyleAntTaskTest)\.java"/>
<suppress checks="ClassDataAbstractionCoupling" files="PropertyCacheFile\.java"/>
<suppress checks="ClassFanOutComplexity" files="[\\/]Main\.java"/>
<!-- a lot of GUI elements is OK -->
<suppress checks="ClassDataAbstractionCoupling" files="(JTreeTable|MainFrame)\.java"/>
<suppress checks="ClassDataAbstractionCoupling" files="(TreeTable|MainFrame)\.java"/>

<!-- Should be fixed after moving https://github.com/sevntu-checkstyle/sevntu.checkstyle/blob/master/sevntu-checks/src/main/java/com/github/sevntu/checkstyle/checks/coding/ReturnCountExtendedCheck.java into the main repo -->
<suppress checks="ReturnCount" files="(ClassResolver|ConfigurationLoader|IndentationCheckTest)\.java"/>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -1445,7 +1445,7 @@
<!-- Swing related classes -->
<exclude>com/puppycrawl/tools/checkstyle/gui/BaseCellEditor*.class</exclude>
<exclude>com/puppycrawl/tools/checkstyle/gui/CodeSelector.class</exclude>
<exclude>com/puppycrawl/tools/checkstyle/gui/JTreeTable*.class</exclude>
<exclude>com/puppycrawl/tools/checkstyle/gui/TreeTable*.class</exclude>
<exclude>com/puppycrawl/tools/checkstyle/gui/ListToTreeSelectionModelWrapper*.class</exclude>
<exclude>com/puppycrawl/tools/checkstyle/gui/Main*.class</exclude>
<exclude>com/puppycrawl/tools/checkstyle/gui/MainFrame*.class</exclude>
Expand Down
65 changes: 33 additions & 32 deletions src/main/java/com/puppycrawl/tools/checkstyle/api/FileContents.java
Expand Up @@ -92,35 +92,13 @@ public FileContents(FileText text) {
@Override
public void reportSingleLineComment(String type, int startLineNo,
int startColNo) {
reportCppComment(startLineNo, startColNo);
reportSinglelineComment(startLineNo, startColNo);
}

@Override
public void reportBlockComment(String type, int startLineNo,
int startColNo, int endLineNo, int endColNo) {
reportCComment(startLineNo, startColNo, endLineNo, endColNo);
}

/**
* Report the location of a C++ style comment.
* @param startLineNo the starting line number
* @param startColNo the starting column number
**/
public void reportCppComment(int startLineNo, int startColNo) {
final String line = line(startLineNo - 1);
final String[] txt = {line.substring(startColNo)};
final Comment comment = new Comment(txt, startColNo, startLineNo,
line.length() - 1);
cppComments.put(startLineNo, comment);
}

/**
* Returns a map of all the C++ style comments. The key is a line number,
* the value is the comment {@link TextBlock} at the line.
* @return the Map of comments
*/
public ImmutableMap<Integer, TextBlock> getCppComments() {
return ImmutableMap.copyOf(cppComments);
reportBlockComment(startLineNo, startColNo, endLineNo, endColNo);
}

/**
Expand All @@ -130,9 +108,9 @@ public ImmutableMap<Integer, TextBlock> getCppComments() {
* @param endLineNo the ending line number
* @param endColNo the ending column number
**/
public void reportCComment(int startLineNo, int startColNo,
public void reportBlockComment(int startLineNo, int startColNo,
int endLineNo, int endColNo) {
final String[] cComment = extractCComment(startLineNo, startColNo,
final String[] cComment = extractBlockComment(startLineNo, startColNo,
endLineNo, endColNo);
final Comment comment = new Comment(cComment, startColNo, endLineNo,
endColNo);
Expand All @@ -155,13 +133,35 @@ public void reportCComment(int startLineNo, int startColNo,
}
}

/**
* Report the location of a C++ style comment.
* @param startLineNo the starting line number
* @param startColNo the starting column number
**/
public void reportSinglelineComment(int startLineNo, int startColNo) {
final String line = line(startLineNo - 1);
final String[] txt = {line.substring(startColNo)};
final Comment comment = new Comment(txt, startColNo, startLineNo,
line.length() - 1);
cppComments.put(startLineNo, comment);
}

/**
* Returns a map of all the C++ style comments. The key is a line number,
* the value is the comment {@link TextBlock} at the line.
* @return the Map of comments
*/
public ImmutableMap<Integer, TextBlock> getSinglelineComments() {
return ImmutableMap.copyOf(cppComments);
}

/**
* Returns a map of all C style comments. The key is the line number, the
* value is a {@link List} of C style comment {@link TextBlock}s
* that start at that line.
* @return the map of comments
*/
public ImmutableMap<Integer, List<TextBlock>> getCComments() {
public ImmutableMap<Integer, List<TextBlock>> getBlockComments() {
return ImmutableMap.copyOf(clangComments);
}

Expand All @@ -173,7 +173,7 @@ public ImmutableMap<Integer, List<TextBlock>> getCComments() {
* @param endColNo the ending column number
* @return C comment as a array
**/
private String[] extractCComment(int startLineNo, int startColNo,
private String[] extractBlockComment(int startLineNo, int startColNo,
int endLineNo, int endColNo) {
final String[] returnValue;
if (startLineNo == endLineNo) {
Expand Down Expand Up @@ -296,8 +296,9 @@ public boolean lineIsComment(int lineNo) {
**/
public boolean hasIntersectionWithComment(int startLineNo,
int startColNo, int endLineNo, int endColNo) {
return hasIntersectionWithCComment(startLineNo, startColNo, endLineNo, endColNo)
|| hasIntersectionWithCppComment(startLineNo, startColNo, endLineNo, endColNo);
return hasIntersectionWithBlockComment(startLineNo, startColNo, endLineNo, endColNo)
|| hasIntersectionWithSinglelineComment(startLineNo, startColNo, endLineNo,
endColNo);
}

/**
Expand All @@ -316,7 +317,7 @@ public boolean inPackageInfo() {
* @param endColNo the ending column number
* @return true if the positions intersects with a C comment.
*/
private boolean hasIntersectionWithCComment(int startLineNo, int startColNo,
private boolean hasIntersectionWithBlockComment(int startLineNo, int startColNo,
int endLineNo, int endColNo) {
// Check C comments (all comments should be checked)
final Collection<List<TextBlock>> values = clangComments.values();
Expand All @@ -338,7 +339,7 @@ private boolean hasIntersectionWithCComment(int startLineNo, int startColNo,
* @param endColNo the ending column number
* @return true if the positions intersects with a CPP comment.
*/
private boolean hasIntersectionWithCppComment(int startLineNo, int startColNo,
private boolean hasIntersectionWithSinglelineComment(int startLineNo, int startColNo,
int endLineNo, int endColNo) {
// Check CPP comments (line searching is possible)
for (int lineNumber = startLineNo; lineNumber <= endLineNo;
Expand Down
Expand Up @@ -220,8 +220,8 @@ public int[] getRequiredTokens() {

@Override
public void beginTree(DetailAST rootAST) {
singlelineComments = getFileContents().getCppComments();
blockComments = getFileContents().getCComments();
singlelineComments = getFileContents().getSinglelineComments();
blockComments = getFileContents().getBlockComments();
}

@Override
Expand Down Expand Up @@ -280,7 +280,7 @@ private boolean hasTrailComment(DetailAST ast) {
final List<TextBlock> commentList = blockComments.get(lineNo);
if (commentList != null) {
final TextBlock comment = commentList.get(commentList.size() - 1);
result = isTrailingCComent(comment, line);
result = isTrailingBlockComment(comment, line);
}
}
return result;
Expand All @@ -292,7 +292,7 @@ private boolean hasTrailComment(DetailAST ast) {
* @param line the line where the comment starts.
* @return true if the comment is trailing.
*/
private static boolean isTrailingCComent(TextBlock comment, String line) {
private static boolean isTrailingBlockComment(TextBlock comment, String line) {
return comment.getText().length != 1
|| line.substring(comment.getEndColNo() + 1).trim().isEmpty();
}
Expand Down
Expand Up @@ -150,9 +150,9 @@ public void visitToken(DetailAST ast) {
@Override
public void beginTree(DetailAST rootAST) {
final Map<Integer, TextBlock> cppComments = getFileContents()
.getCppComments();
.getSinglelineComments();
final Map<Integer, List<TextBlock>> cComments = getFileContents()
.getCComments();
.getBlockComments();
final Set<Integer> lines = new HashSet<>();
lines.addAll(cppComments.keySet());
lines.addAll(cComments.keySet());
Expand Down
Expand Up @@ -617,7 +617,7 @@ private String getImportGroup(boolean isStatic, String importPath) {
}
else if (customImportOrderRules.contains(SAME_PACKAGE_RULE_GROUP)) {
final String importPathTrimmedToSamePackageDepth =
getFirstNDomainsFromIdent(samePackageMatchingDepth, importPath);
getFirstDomainsFromIdent(samePackageMatchingDepth, importPath);
if (samePackageDomainsRegExp.equals(importPathTrimmedToSamePackageDepth)) {
bestMatch.group = SAME_PACKAGE_RULE_GROUP;
bestMatch.matchLength = importPath.length();
Expand Down Expand Up @@ -772,7 +772,7 @@ else if (ruleStr.startsWith(SAME_PACKAGE_RULE_GROUP)) {
private static String createSamePackageRegexp(int firstPackageDomainsCount,
DetailAST packageNode) {
final String packageFullPath = getFullImportIdent(packageNode);
return getFirstNDomainsFromIdent(firstPackageDomainsCount, packageFullPath);
return getFirstDomainsFromIdent(firstPackageDomainsCount, packageFullPath);
}

/**
Expand All @@ -784,7 +784,7 @@ private static String createSamePackageRegexp(int firstPackageDomainsCount,
* @return String with defined amount of domains or full identifier
* (if full identifier had less domain then specified)
*/
private static String getFirstNDomainsFromIdent(
private static String getFirstDomainsFromIdent(
final int firstPackageDomainsCount, final String packageFullPath) {
final StringBuilder builder = new StringBuilder();
final StringTokenizer tokens = new StringTokenizer(packageFullPath, ".");
Expand Down
Expand Up @@ -541,7 +541,7 @@ protected final int getBraceAdjustment() {
* @param rparen parenthesis to check
* @param lparen left parenthesis associated with aRparen
*/
protected final void checkRParen(DetailAST lparen, DetailAST rparen) {
protected final void checkRightParen(DetailAST lparen, DetailAST rparen) {
if (rparen != null) {
// the rcurly can either be at the correct indentation,
// or not first on the line
Expand All @@ -561,7 +561,7 @@ && isOnStartOfLine(rparen)) {
* Check the indentation of the left parenthesis.
* @param lparen parenthesis to check
*/
protected final void checkLParen(final DetailAST lparen) {
protected final void checkLeftParen(final DetailAST lparen) {
// the rcurly can either be at the correct indentation, or on the
// same line as the lcurly
if (lparen != null
Expand Down
Expand Up @@ -61,7 +61,7 @@ protected DetailAST getTopLevelAst() {
}

@Override
protected DetailAST getLCurly() {
protected DetailAST getLeftCurly() {
return getMainAst();
}

Expand All @@ -73,7 +73,7 @@ protected IndentLevel curlyIndent() {
}

@Override
protected DetailAST getRCurly() {
protected DetailAST getRightCurly() {
return getMainAst().findFirstToken(TokenTypes.RCURLY);
}

Expand All @@ -94,7 +94,7 @@ protected IndentLevel getChildrenExpectedIndent() {
getIndentCheck().getLineWrappingIndentation());

final int firstLine = getFirstLine(Integer.MAX_VALUE, getListChild());
final int lcurlyPos = expandedTabsColumnNo(getLCurly());
final int lcurlyPos = expandedTabsColumnNo(getLeftCurly());
final int firstChildPos =
getNextFirstNonBlankOnLineAfter(firstLine, lcurlyPos);
if (firstChildPos >= 0) {
Expand Down

0 comments on commit 0d087b2

Please sign in to comment.