I18NInspectionTest moved

This commit is contained in:
Dmitry Avdeev
2014-07-04 15:00:11 +04:00
parent c79345a684
commit 6ef3ea8577
38 changed files with 423 additions and 0 deletions
+1
View File
@@ -21,6 +21,7 @@
<orderEntry type="module" module-name="testFramework-java" scope="TEST" />
<orderEntry type="module" module-name="properties-psi-api" />
<orderEntry type="module" module-name="properties-psi-impl" />
<orderEntry type="module" module-name="ui-designer" scope="TEST" />
</component>
</module>
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
</problems>
@@ -0,0 +1,11 @@
@interface Language {
@org.jetbrains.annotations.NonNls
java.lang.String value();
}
class Foo {
void foo() {
@Language("abcdefgh")
String s;
}
}
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>Test.java</file>
<line>8</line>
<description>Hard coded string literal</description>
</problem>
</problems>
@@ -0,0 +1,14 @@
class Test {
private class InnerTest {
public InnerTest(String s) { }
public abstract void run();
}
public void foo(String s) {
bar(new InnerTest("Literal") { public void run() { } });
}
public void bar(InnerTest t) {
}
}
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
</problems>
@@ -0,0 +1,6 @@
class Test {
void foo() {
@org.jetbrains.annotations.NonNls StringBuffer buffer = new StringBuffer("text");
buffer = new StringBuffer("text");
}
}
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>Test.java</file>
<line>2</line>
<description>Hard coded string literal</description>
</problem>
<problem>
<file>Test.java</file>
<line>3</line>
<description>Hard coded string literal</description>
</problem>
</problems>
@@ -0,0 +1,21 @@
enum Test {
CHECKIN("Text1"),
ADD("Rext2");
Test(final String id) {
myId = id;
}
private final String myId;
}
enum Test2 {
CHECKIN("Text1"),
ADD("Rext2");
Test2(@org.jetbrains.annotations.NonNls final String id) {
myId = id;
}
private final String myId;
}
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
</problems>
@@ -0,0 +1,7 @@
class Foo {
@org.jetbrains.annotations.NonNls String field;
@org.jetbrains.annotations.NonNls String field2 = "text1";
void foo() {
field = "text2";
}
}
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>Test.form</file>
<line>1</line>
<description>Hard coded string literal</description>
</problem>
</problems>
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1">
<tabbedpane id="de448" class="com.intellij.ui.components.JBTabbedPane">
<constraints>
<xy x="84" y="134" width="200" height="200"/>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200"/>
</grid>
</constraints>
<properties/>
<border type="none"/>
<children>
<scrollpane id="38bd0">
<constraints>
<tabbedpane title="Literal"/>
</constraints>
<properties/>
<border type="none"/>
<children/>
</scrollpane>
</children>
</tabbedpane>
</form>
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>Foo.java</file>
<line>3</line>
<description>Hard coded string literal</description>
</problem>
</problems>
@@ -0,0 +1,5 @@
class Foo {
void foo(String s) {
foo("text");
}
}
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>Test.java</file>
<line>7</line>
<description>Hard coded string literal</description>
</problem>
</problems>
@@ -0,0 +1,14 @@
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class Test {
public static void main(String[] args){
ActionListener listener = new ActionListener(){
{
final String test = "problem reported twice";
}
public void actionPerformed(final ActionEvent e) {
}
};
}
}
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>Test.java</file>
<line>3</line>
<description>Hard coded string literal</description>
</problem>
<problem>
<file>Test.java</file>
<line>8</line>
<description>Hard coded string literal</description>
</problem>
</problems>
@@ -0,0 +1,11 @@
class Foo {
void foo() {
String v1 = "text";
@org.jetbrains.annotations.NonNls String v2 = "text";
String v3;
@org.jetbrains.annotations.NonNls String v4;
v3 = "text";
v4 = "text";
}
}
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
</problems>
@@ -0,0 +1,9 @@
class Foo {
@org.jetbrains.annotations.NonNls String[] myArray = new String[] {"text1", "text2"};
@org.jetbrains.annotations.NonNls Stirng[] foo() {
myArray = new String[] {"text3", "text4"};
myArray[0] = "text5";
return new String[] {"text6"};
}
}
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>Foo.java</file>
<line>4</line>
<problem_class>Hard coded strings</problem_class>
<description>Hard coded string literal: 'xxxxx'</description>
</problem>
<problem>
<file>Foo.java</file>
<line>9</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Hard coded strings</problem_class>
<description>Hard coded string literal: 'MYNON-NLS'</description>
</problem>
</problems>
@@ -0,0 +1,12 @@
class Foo {
void foo(String... s) {
foo("literal", "literal"); // MYNON-NLS0
String d = "xxxxx"; // NON-NLS
String d0 = "xxxxx", d01="sssss"; //MYNON-NLS
String d1 = "xxxxx"; // MYNON-NLS?
String d2 = "xxxxx"; /* MYNON-NLS ??? */
String wtf="MYNON-NLS";
String dw2 = "xxxxx"; String wtw="MYNON-NLS"; /* MYNON-NLS ??? */
}
}
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
</problems>
@@ -0,0 +1,11 @@
class Test {
public static final Test TEST = new Test("text") {
public void foo() {}
};
public Test(@org.jetbrains.annotations.NonNls String p) {
}
public abstract void foo();
}
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
</problems>
@@ -0,0 +1,17 @@
class A {
void foo(@org.jetbrains.annotations.NonNls String p){
}
}
class B extends A{
void foo(String p){
}
}
class C extends B{
void foo(String p){
foo("text");
}
}
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>Test.java</file>
<line>2</line>
<description>Hard coded string literal</description>
</problem>
<problem>
<file>Test.java</file>
<line>6</line>
<description>Hard coded string literal</description>
</problem>
<problem>
<file>Test.java</file>
<line>11</line>
<description>Hard coded string literal</description>
</problem>
<problem>
<file>Test.java</file>
<line>12</line>
<description>Hard coded string literal</description>
</problem>
</problems>
@@ -0,0 +1,14 @@
class A extends C{
String foo(String p){ return "text";}
}
class B extends A{
String foo(String p){ return "text";}
}
class C extends A{
String foo(String p){
foo("text");
return "text";
}
}
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
</problems>
@@ -0,0 +1,17 @@
interface I {
@org.jetbrains.annotations.NonNls String foo();
}
class B implements I{
public String foo() {
return "text";
}
}
class A {
B inner = new B() {
public String foo() {
return "text";
}
};
}
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
</problems>
@@ -0,0 +1,12 @@
import java.util.Collection;
class SBTest {
void foo(@org.jetbrains.annotations.NonNls Collection coll) {
coll.add("aaa");
}
void foo(@org.jetbrains.annotations.NonNls StringBuffer buffer) {
buffer.append("aaa");
buffer.append("aaa").append("bbb").append("do not i18n this too");
}
}
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
</problems>
@@ -0,0 +1,8 @@
class Test {
void foo(@org.jetbrains.annotations.NonNls String s) {
switch (s) {
case "foooooo":
break;
}
}
}
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
</problems>
@@ -0,0 +1,5 @@
class Foo {
void foo(@org.jetbrains.annotations.NonNls String... s) {
foo("literal", "literal");
}
}
@@ -0,0 +1,62 @@
/*
* Copyright (c) 2005 JetBrains s.r.o. All Rights Reserved.
*/
package com.intellij.codeInspection.i18n;
import com.intellij.openapi.application.PluginPathManager;
import com.intellij.openapi.roots.LanguageLevelProjectExtension;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.psi.JavaPsiFacade;
import com.intellij.testFramework.InspectionTestCase;
/**
* @author lesya
*/
public class I18NInspectionTest extends InspectionTestCase {
private void doTest() throws Exception {
doTest(new I18nInspection());
}
private void doTest(I18nInspection tool) throws Exception {
doTest("i18n/" + getTestName(true), tool);
}
public void testHardCodedStringLiteralAsParameter() throws Exception{ doTest(); }
public void testReturnTypeInheritsNonNlsAnnotationFromParent() throws Exception{ doTest(); }
public void testRecursiveInheritance() throws Exception { doTest(); }
public void testParameterInheritsNonNlsAnnotationFromSuper() throws Exception { doTest(); }
public void testLocalVariables() throws Exception { doTest(); }
public void testFields() throws Exception{ doTest(); }
public void testAnonymousClassConstructorParameter() throws Exception { doTest(); }
public void testStringBufferNonNls() throws Exception { doTest(); }
public void testEnum() throws Exception {
final JavaPsiFacade facade = getJavaFacade();
final LanguageLevel effectiveLanguageLevel = LanguageLevelProjectExtension.getInstance(facade.getProject()).getLanguageLevel();
LanguageLevelProjectExtension.getInstance(facade.getProject()).setLanguageLevel(LanguageLevel.JDK_1_5);
try {
doTest();
}
finally {
LanguageLevelProjectExtension.getInstance(facade.getProject()).setLanguageLevel(effectiveLanguageLevel);
}
}
public void testFormTabbedPaneTitle() throws Exception { doTest(); }
public void testVarargNonNlsParameter() throws Exception { doTest(); }
public void testInitializerInAnonymousClass() throws Exception{ doTest(); }
public void testNonNlsArray() throws Exception{ doTest(); }
public void testParameterInNewAnonymousClass() throws Exception{ doTest(); }
public void testConstructorCallOfNonNlsVariable() throws Exception{ doTest(); }
public void testSwitchOnNonNlsString() throws Exception{ doTest(); }
public void testNonNlsComment() throws Exception{
I18nInspection inspection = new I18nInspection();
inspection.nonNlsCommentPattern = "MYNON-NLS";
inspection.cacheNonNlsCommentPattern();
doTest(inspection);
}
public void testAnnotationArgument() throws Exception{ doTest(); }
@Override
protected String getTestDataPath() {
return PluginPathManager.getPluginHomePath("java-i18n") + "/testData/inspections";
}
}