diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/whitespace/OperatorWrapCheck.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/whitespace/OperatorWrapCheck.java index 5cdaa64b8..86fda0b68 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/whitespace/OperatorWrapCheck.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/whitespace/OperatorWrapCheck.java @@ -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 diff --git a/src/testinputs/com/puppycrawl/tools/checkstyle/InputOpWrap.java b/src/testinputs/com/puppycrawl/tools/checkstyle/InputOpWrap.java index 35bb20afc..4c8b8fb3c 100644 --- a/src/testinputs/com/puppycrawl/tools/checkstyle/InputOpWrap.java +++ b/src/testinputs/com/puppycrawl/tools/checkstyle/InputOpWrap.java @@ -6,7 +6,7 @@ package com.puppycrawl.tools.checkstyle; /** * Test case for detecting operator wrapping. - * @author Lars Kühne + * @author Lars K�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(); + } }