Skip to content

Commit

Permalink
Fix generics with arrays handling in NoWhitespaceAfter, issue checkst…
Browse files Browse the repository at this point in the history
  • Loading branch information
mkordas committed Apr 18, 2015
1 parent aebf3b3 commit 1ece7ba
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
Expand Up @@ -204,7 +204,12 @@ else if (isMultiDimensionalArray(arrayDeclarator)) {
typeOrIdent = getArrayIdentifier(arrayDeclarator);
}
else {
typeOrIdent = arrayDeclarator.getFirstChild();
if (isArrayUsedAsTypeForGenericBoundedWildcard(arrayDeclarator)) {
typeOrIdent = arrayDeclarator.getParent();
}
else {
typeOrIdent = arrayDeclarator.getFirstChild();
}
}
}
return typeOrIdent;
Expand Down Expand Up @@ -249,6 +254,21 @@ private static boolean isArrayInstantiation(DetailAST arrayDeclaration)
return arrayDeclaration.getParent().getType() == TokenTypes.LITERAL_NEW;
}

/**
* Checks if current array is used as type for generic bounded wildcard.
* <p>
* E.g. {@code <? extends String[]>} or {@code <? super Object[]>}.
* </p>
* @param arrayDeclarator {@link TokenTypes#ARRAY_DECLARATOR ARRAY_DECLARATOR}
* @return true if current array is used as type for generic bounded wildcard.
*/
private static boolean isArrayUsedAsTypeForGenericBoundedWildcard(DetailAST arrayDeclarator)
{
final int firstChildType = arrayDeclarator.getFirstChild().getType();
return firstChildType == TokenTypes.TYPE_UPPER_BOUNDS
|| firstChildType == TokenTypes.TYPE_LOWER_BOUNDS;
}

/**
* Control whether whitespace is flagged at linebreaks.
* @param allowLineBreaks whether whitespace should be
Expand Down
Expand Up @@ -83,6 +83,8 @@ public void testSpace()
"225:14: " + getCheckMessage(WS_NOT_FOLLOWED, "("),
"235:14: " + getCheckMessage(WS_NOT_FOLLOWED, "("),
"235:39: " + getCheckMessage(WS_NOT_PRECEDED, ")"),
"252:21: " + getCheckMessage(WS_NOT_FOLLOWED, "("),
"252:93: " + getCheckMessage(WS_NOT_PRECEDED, ")"),
};
verify(checkConfig, getPath("InputWhitespace.java"), expected);
}
Expand Down
Expand Up @@ -180,7 +180,7 @@ void rfe521323()
}
}


/** bug 806243 (NoWhitespaceBeforeCheck error for anonymous inner class) */
private int i ;
// ^ whitespace
Expand Down Expand Up @@ -248,4 +248,6 @@ public void run() {
}
}.start();
}

public void foo(java.util.List<? extends String[]> bar, Comparable<? super Object[]> baz) { }
}

0 comments on commit 1ece7ba

Please sign in to comment.