Fix exception in SuppressWarningsHolder on annotation with dot. #1148

This commit is contained in:
Michal Kordas 2015-05-31 17:41:43 +02:00 committed by Roman Ivanov
parent b930ba24be
commit e3c089a4cd
3 changed files with 56 additions and 0 deletions

View File

@ -398,6 +398,8 @@ public class SuppressWarningsHolder
return quotedText.substring(1, quotedText.length() - 1);
case TokenTypes.IDENT:
return firstChild.getText();
case TokenTypes.DOT:
return firstChild.getLastChild().getText();
default:
throw new IllegalArgumentException("String literal AST expected: "
+ firstChild);

View File

@ -0,0 +1,36 @@
////////////////////////////////////////////////////////////////////////////////
// checkstyle: Checks Java source code for adherence to a set of rules.
// Copyright (C) 2001-2015 the original author or authors.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
////////////////////////////////////////////////////////////////////////////////
package com.puppycrawl.tools.checkstyle.checks;
import com.puppycrawl.tools.checkstyle.BaseCheckTestSupport;
import com.puppycrawl.tools.checkstyle.api.Configuration;
import org.junit.Test;
public class SuppressWarningsHolderTest extends BaseCheckTestSupport {
@Test
public void testOnComplexAnnotations() throws Exception {
Configuration checkConfig = createCheckConfig(SuppressWarningsHolder.class);
String[] expected = {
};
verify(checkConfig, getPath("InputSuppressWarningsHolder.java"), expected);
}
}

View File

@ -0,0 +1,18 @@
package com.puppycrawl.tools.checkstyle;
public class InputSuppressWarningsHolder {
static final String UNUSED = "unused";
@SuppressWarnings(UNUSED)
int a;
@SuppressWarnings(InputSuppressWarningsHolder.UNUSED)
int b;
@SuppressWarnings(com.puppycrawl.tools.checkstyle.InputSuppressWarningsHolder.UNUSED)
int c;
@SuppressWarnings(value = UNUSED)
int d;
@SuppressWarnings(value = InputSuppressWarningsHolder.UNUSED)
int e;
@SuppressWarnings(value = com.puppycrawl.tools.checkstyle.InputSuppressWarningsHolder.UNUSED)
int f;
}