Two more annotation-related problems (module Indentation, bug 1109214 and module UnnecessaryParentheses, bug 1109238)
This commit is contained in:
parent
2c8f014f31
commit
7dd31794bc
|
|
@ -128,6 +128,14 @@ public class UnnecessaryParenthesesCheck extends Check
|
|||
{
|
||||
final int type = aAST.getType();
|
||||
final boolean surrounded = isSurrounded(aAST);
|
||||
final DetailAST parent = aAST.getParent();
|
||||
|
||||
if (type == TokenTypes.ASSIGN
|
||||
&& parent.getType() == TokenTypes.ANNOTATION_MEMBER_VALUE_PAIR)
|
||||
{
|
||||
// shouldn't process assign in annotation pairs
|
||||
return;
|
||||
}
|
||||
|
||||
// An identifier surrounded by parentheses.
|
||||
if (surrounded && type == TokenTypes.IDENT) {
|
||||
|
|
@ -163,6 +171,14 @@ public class UnnecessaryParenthesesCheck extends Check
|
|||
public void leaveToken(DetailAST aAST)
|
||||
{
|
||||
final int type = aAST.getType();
|
||||
final DetailAST parent = aAST.getParent();
|
||||
|
||||
if (type == TokenTypes.ASSIGN
|
||||
&& parent.getType() == TokenTypes.ANNOTATION_MEMBER_VALUE_PAIR)
|
||||
{
|
||||
// shouldn't process assign in annotation pairs
|
||||
return;
|
||||
}
|
||||
|
||||
// An expression is surrounded by parentheses.
|
||||
if (type == TokenTypes.EXPR) {
|
||||
|
|
|
|||
|
|
@ -62,11 +62,16 @@ public class AssignHandler extends BlockParentHandler
|
|||
|
||||
// if this is assign in expression then skip first child,
|
||||
// because it's lvalue.
|
||||
if (assign.getParent() != null
|
||||
&& assign.getParent().getType() == TokenTypes.EXPR)
|
||||
{
|
||||
final DetailAST parent = assign.getParent();
|
||||
if (parent != null && parent.getType() == TokenTypes.EXPR) {
|
||||
child = (DetailAST) child.getNextSibling();
|
||||
}
|
||||
if (parent != null
|
||||
&& parent.getType() == TokenTypes.ANNOTATION_MEMBER_VALUE_PAIR)
|
||||
{
|
||||
child = (DetailAST) assign.getNextSibling();
|
||||
}
|
||||
|
||||
checkExpressionSubtree(child, expectedLevel, false, true);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -453,7 +453,7 @@ annotationMemberValuePair!
|
|||
|
||||
annotationMemberValueInitializer
|
||||
:
|
||||
conditionalExpression | annotation | annotationMemberArrayInitializer
|
||||
annotationExpression | annotation | annotationMemberArrayInitializer
|
||||
;
|
||||
|
||||
// This is an initializer used to set up an annotation member array.
|
||||
|
|
@ -479,10 +479,15 @@ annotationMemberArrayInitializer
|
|||
// The two things that can initialize an annotation array element are a conditional expression
|
||||
// and an annotation (nested annotation array initialisers are not valid)
|
||||
annotationMemberArrayValueInitializer
|
||||
: conditionalExpression
|
||||
: annotationExpression
|
||||
| annotation
|
||||
;
|
||||
|
||||
annotationExpression
|
||||
: conditionalExpression
|
||||
{#annotationExpression = #(#[EXPR,"EXPR"],#annotationExpression);}
|
||||
;
|
||||
|
||||
// Definition of a Java class
|
||||
classDefinition![AST modifiers]
|
||||
: c:"class" IDENT
|
||||
|
|
@ -1786,4 +1791,4 @@ EXPONENT
|
|||
protected
|
||||
FLOAT_SUFFIX
|
||||
: 'f'|'F'|'d'|'D'
|
||||
;
|
||||
;
|
||||
|
|
|
|||
|
|
@ -2,9 +2,10 @@
|
|||
|
||||
@interface MyAnnotation {
|
||||
String name();
|
||||
int version();
|
||||
}
|
||||
|
||||
@MyAnnotation(name = "ABC")
|
||||
@MyAnnotation(name = "ABC", version = 1)
|
||||
public class Input15Extensions
|
||||
{
|
||||
|
||||
|
|
|
|||
|
|
@ -6,18 +6,18 @@ import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
|
|||
|
||||
/**
|
||||
* Test fixture for the UnnecessaryParenthesesCheck.
|
||||
*
|
||||
*
|
||||
* @author Eric K. Roe
|
||||
*/
|
||||
public class UnnecessaryParenthesesCheckTest extends BaseCheckTestCase {
|
||||
private static final String TEST_FILE = "coding" + File.separator +
|
||||
"InputUnnecessaryParentheses.java";
|
||||
|
||||
|
||||
public void testDefault() throws Exception
|
||||
{
|
||||
final DefaultConfiguration checkConfig =
|
||||
createCheckConfig(UnnecessaryParenthesesCheck.class);
|
||||
|
||||
|
||||
final String[] expected = {
|
||||
"4:22: Unnecessary parentheses around assignment right-hand side.",
|
||||
"4:29: Unnecessary parentheses around expression.",
|
||||
|
|
@ -66,4 +66,11 @@ public class UnnecessaryParenthesesCheckTest extends BaseCheckTestCase {
|
|||
|
||||
verify(checkConfig, getPath(TEST_FILE), expected);
|
||||
}
|
||||
|
||||
public void test15Extensions() throws Exception
|
||||
{
|
||||
final DefaultConfiguration checkConfig = createCheckConfig(UnnecessaryParenthesesCheck.class);
|
||||
final String[] expected = {};
|
||||
verify(checkConfig, getPath("Input15Extensions.java"), expected);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,8 +9,6 @@ import com.puppycrawl.tools.checkstyle.Checker;
|
|||
* @author jrichard
|
||||
*/
|
||||
public class IndentationCheckTest extends BaseCheckTestCase {
|
||||
|
||||
|
||||
public void testInvalidLabel()
|
||||
throws Exception
|
||||
{
|
||||
|
|
@ -29,8 +27,6 @@ public class IndentationCheckTest extends BaseCheckTestCase {
|
|||
verify(checkConfig, getPath("indentation/InputInvalidLabelIndent.java"), expected);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void testValidLabel()
|
||||
throws Exception
|
||||
{
|
||||
|
|
@ -40,7 +36,6 @@ public class IndentationCheckTest extends BaseCheckTestCase {
|
|||
verify(checkConfig, getPath("indentation/InputValidLabelIndent.java"), expected);
|
||||
}
|
||||
|
||||
|
||||
public void testValidIfWithChecker()
|
||||
throws Exception
|
||||
{
|
||||
|
|
@ -52,7 +47,6 @@ public class IndentationCheckTest extends BaseCheckTestCase {
|
|||
verify(c, fname, expected);
|
||||
}
|
||||
|
||||
|
||||
public void testValidDotWithChecker()
|
||||
throws Exception
|
||||
{
|
||||
|
|
@ -64,7 +58,6 @@ public class IndentationCheckTest extends BaseCheckTestCase {
|
|||
verify(c, fname, expected);
|
||||
}
|
||||
|
||||
|
||||
public void testValidMethodWithChecker()
|
||||
throws Exception
|
||||
{
|
||||
|
|
@ -76,7 +69,6 @@ public class IndentationCheckTest extends BaseCheckTestCase {
|
|||
verify(c, fname, expected);
|
||||
}
|
||||
|
||||
|
||||
public void testInvalidMethodWithChecker()
|
||||
throws Exception
|
||||
{
|
||||
|
|
@ -122,9 +114,6 @@ public class IndentationCheckTest extends BaseCheckTestCase {
|
|||
verify(c, fname, expected);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void testInvalidSwitchWithChecker()
|
||||
throws Exception
|
||||
{
|
||||
|
|
@ -173,8 +162,6 @@ public class IndentationCheckTest extends BaseCheckTestCase {
|
|||
verify(c, fname, expected);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void testValidArrayInitWithChecker()
|
||||
throws Exception
|
||||
{
|
||||
|
|
@ -228,9 +215,6 @@ public class IndentationCheckTest extends BaseCheckTestCase {
|
|||
verify(c, fname, expected);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void testValidTryWithChecker()
|
||||
throws Exception
|
||||
{
|
||||
|
|
@ -279,7 +263,6 @@ public class IndentationCheckTest extends BaseCheckTestCase {
|
|||
verify(c, fname, expected);
|
||||
}
|
||||
|
||||
|
||||
// TODO: needs to be finished
|
||||
public void testInvalidClassDefWithChecker()
|
||||
throws Exception
|
||||
|
|
@ -333,7 +316,6 @@ public class IndentationCheckTest extends BaseCheckTestCase {
|
|||
verify(c, fname, expected);
|
||||
}
|
||||
|
||||
|
||||
public void testInvalidBlockWithChecker()
|
||||
throws Exception
|
||||
{
|
||||
|
|
@ -694,4 +676,11 @@ public class IndentationCheckTest extends BaseCheckTestCase {
|
|||
final String[] expected = {};
|
||||
verify(checkConfig, getPath("indentation/InputValidAssignIndent.java"), expected);
|
||||
}
|
||||
|
||||
public void test15Extensions() throws Exception
|
||||
{
|
||||
final DefaultConfiguration checkConfig = createCheckConfig(IndentationCheck.class);
|
||||
final String[] expected = {};
|
||||
verify(checkConfig, getPath("Input15Extensions.java"), expected);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,6 +72,9 @@
|
|||
<li>Annotations and enums are classes too and should be treated so by
|
||||
ClassFanOutComplexity checks (bug 1109205)</li>
|
||||
|
||||
<li>Two more annotation-related problems (module Indentation, bug
|
||||
1109214 and module UnnecessaryParentheses, bug 1109238)</li>
|
||||
|
||||
</ul>
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue