Fix to ignore LT,GT,BAND,QUESTION tokens if part of generic declaration. Partially based on patch 1097339.

This commit is contained in:
Michael Studman 2005-04-04 21:55:40 +00:00
parent c4d4b6139c
commit f3fe388937
2 changed files with 38 additions and 1 deletions

View File

@ -178,6 +178,30 @@ public class OperatorWrapCheck
final int colNo = aAST.getColumnNo();
final int lineNo = aAST.getLineNo();
final String currentLine = getLines()[lineNo - 1];
// GT/LT aren't operators if they're part of type arguments or parameters
if ((aAST.getType() == TokenTypes.GT || aAST.getType() == TokenTypes.LT) &&
(aAST.getParent().getType() == TokenTypes.TYPE_ARGUMENTS
|| aAST.getParent().getType() == TokenTypes.TYPE_PARAMETERS))
{
return;
}
//QUESTION is not an operator if it's part of a type argument
if (aAST.getType() == TokenTypes.QUESTION &&
aAST.getParent().getType() == TokenTypes.TYPE_ARGUMENT)
{
return;
}
//BAND is not an operator if it's part of a type argument
if (aAST.getType() == TokenTypes.BAND &&
(aAST.getParent().getType() == TokenTypes.TYPE_UPPER_BOUNDS
|| aAST.getParent().getType() == TokenTypes.TYPE_LOWER_BOUNDS))
{
return;
}
// TODO: Handle comments before and after operator
// Check if rest of line is whitespace, and not just the operator
// by itself. This last bit is to handle the operator on a line by

View File

@ -6,7 +6,7 @@ package com.puppycrawl.tools.checkstyle;
/**
* Test case for detecting operator wrapping.
* @author Lars Kühne
* @author Lars K<EFBFBD>hne
**/
class InputOpWrap
{
@ -34,4 +34,17 @@ class InputOpWrap
int y =
0;
}
<
T extends Comparable &
java.io.Serializable
>
void testGenerics1()
{
Comparable
<
String
>
c = new String();
}
}