Updated version of the "comparingReference" sample plugin.
authorAlexey <Alexey.Chursin@jetbrains.com>
Fri, 17 Sep 2010 08:08:53 +0000 (12:08 +0400)
committerAlexey <Alexey.Chursin@jetbrains.com>
Fri, 17 Sep 2010 08:23:15 +0000 (12:23 +0400)
samples/comparingReferences/comparingReferences.iml
samples/comparingReferences/comparingReferences.ipr
samples/comparingReferences/source/com/intellij/codeInspection/ComparingReferencesInspection.java
samples/comparingReferences/testData/before.after.java [new file with mode: 0644]
samples/comparingReferences/testData/before.java [new file with mode: 0644]
samples/comparingReferences/testData/before1.after.java [new file with mode: 0644]
samples/comparingReferences/testData/before1.java [new file with mode: 0644]
samples/comparingReferences/testSource/testPlugin/TestThisPlugin.java [new file with mode: 0644]

index 5000ad3ec83d39a6d3bac9ca04ee97cac68d3bb6..f38326667e0067ef3ab1b0b92df36ef2c48382ac 100644 (file)
@@ -6,8 +6,9 @@
     <exclude-output />
     <content url="file://$MODULE_DIR$">
       <sourceFolder url="file://$MODULE_DIR$/source" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/testSource" isTestSource="true" />
     </content>
-    <orderEntry type="inheritedJdk" />
+    <orderEntry type="jdk" jdkName="IDEA IC-96.1124" jdkType="IDEA JDK" />
     <orderEntry type="sourceFolder" forTests="false" />
   </component>
 </module>
index dacd55a8c87b6cfaed8d44b12489d97bcb9caea9..001dcf91c3c514667a3d39f53d2858ff7b8209ac 100644 (file)
       <module fileurl="file://$PROJECT_DIR$/comparingReferences.iml" filepath="$PROJECT_DIR$/comparingReferences.iml" />
     </modules>
   </component>
-  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_6" assert-keyword="true" jdk-15="true" project-jdk-name="IDEA IC-96.1068" project-jdk-type="IDEA JDK" />
+  <component name="ProjectResources">
+    <default-html-doctype>http://www.w3.org/1999/xhtml</default-html-doctype>
+  </component>
+  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_6" assert-keyword="true" jdk-15="true" project-jdk-name="IDEA IC-96.1097" project-jdk-type="IDEA JDK" />
   <component name="VcsDirectoryMappings">
     <mapping directory="" vcs="" />
     <mapping directory="$PROJECT_DIR$/../../.." vcs="Git" />
index d900809cfb4fa448d8b9e019a7859e74779faa0a..6410db394eed00df86762123adc2e8493ee0c36a 100644 (file)
@@ -31,7 +31,7 @@ public class ComparingReferencesInspection extends BaseJavaLocalInspectionTool {
 
   @NotNull
   public String getDisplayName() {
-   // return InspectionsBundle.message("inspection.comparing.references.display.name");
+
       return "'==' or '!=' instead of 'equals()'";
   }
 
@@ -94,9 +94,11 @@ public class ComparingReferencesInspection extends BaseJavaLocalInspectionTool {
   private static class MyQuickFix implements LocalQuickFix {
     @NotNull
     public String getName() {
+        // The test (see the TestThisPlugin class) uses this string to identify the quick fix action.
       return InspectionsBundle.message("inspection.comparing.references.use.quickfix");
     }
 
+
     public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
       try {
         PsiBinaryExpression binaryExpression = (PsiBinaryExpression)descriptor.getPsiElement();
diff --git a/samples/comparingReferences/testData/before.after.java b/samples/comparingReferences/testData/before.after.java
new file mode 100644 (file)
index 0000000..a3058ef
--- /dev/null
@@ -0,0 +1,6 @@
+public class X {
+    public boolean compare2Strings(java.lang.String s1, java.lang.String s2) {
+        return (s1.equals(s2));
+    }
+
+}
\ No newline at end of file
diff --git a/samples/comparingReferences/testData/before.java b/samples/comparingReferences/testData/before.java
new file mode 100644 (file)
index 0000000..23095bc
--- /dev/null
@@ -0,0 +1,6 @@
+public class X {
+    public boolean compare2Strings(java.lang.String s1, java.lang.String s2) {
+        return (<caret>s1 == s2);
+    }
+
+}
\ No newline at end of file
diff --git a/samples/comparingReferences/testData/before1.after.java b/samples/comparingReferences/testData/before1.after.java
new file mode 100644 (file)
index 0000000..acedf90
--- /dev/null
@@ -0,0 +1,6 @@
+public class X {
+public boolean compare2Dates(java.util.Date dt1, java.util.Date dt2){
+        return (!dt1.equals(dt2));
+    }
+
+}
\ No newline at end of file
diff --git a/samples/comparingReferences/testData/before1.java b/samples/comparingReferences/testData/before1.java
new file mode 100644 (file)
index 0000000..325c4eb
--- /dev/null
@@ -0,0 +1,6 @@
+public class X {
+public boolean compare2Dates(java.util.Date dt1, java.util.Date dt2){
+        return (dt1 <caret>!= dt2);
+    }
+
+}
\ No newline at end of file
diff --git a/samples/comparingReferences/testSource/testPlugin/TestThisPlugin.java b/samples/comparingReferences/testSource/testPlugin/TestThisPlugin.java
new file mode 100644 (file)
index 0000000..06216ce
--- /dev/null
@@ -0,0 +1,75 @@
+package testPlugin;
+
+
+import com.intellij.codeInsight.daemon.impl.HighlightInfo;
+import com.intellij.codeInsight.intention.IntentionAction;
+import com.intellij.codeInspection.ComparingReferencesInspection;
+import com.intellij.testFramework.builders.JavaModuleFixtureBuilder;
+import com.intellij.testFramework.fixtures.*;
+import junit.framework.Assert;
+import com.intellij.openapi.ui.Messages;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.List;
+
+public class TestThisPlugin {
+
+    protected CodeInsightTestFixture myFixture;
+    // Specify path to your test data directory
+    // e.g.  final String dataPath = "c:\\users\\john.doe\\idea\\community\\samples\\ComparingReferences/testData";
+    final String dataPath = "c:\\users\\John.Doe\\idea\\community\\samples\\comparingReferences/testData";
+
+
+    @Before
+
+    public void setUp() throws Exception {
+
+        final IdeaTestFixtureFactory fixtureFactory = IdeaTestFixtureFactory.getFixtureFactory();
+        final TestFixtureBuilder<IdeaProjectTestFixture> testFixtureBuilder = fixtureFactory.createFixtureBuilder();
+        myFixture = JavaTestFixtureFactory.getFixtureFactory().createCodeInsightFixture(testFixtureBuilder.getFixture());
+        myFixture.setTestDataPath(dataPath);
+        final JavaModuleFixtureBuilder builder = testFixtureBuilder.addModule(JavaModuleFixtureBuilder.class);
+
+        builder.addContentRoot(myFixture.getTempDirPath()).addSourceRoot("");
+        builder.setMockJdkLevel(JavaModuleFixtureBuilder.MockJdkLevel.jdk15);
+        myFixture.setUp();
+
+
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        myFixture.tearDown();
+        myFixture = null;
+    }
+
+    protected void doTest(String testName, String hint) throws Throwable {
+        myFixture.configureByFile(testName + ".java");
+        myFixture.enableInspections(ComparingReferencesInspection.class);
+        List<HighlightInfo> highlightInfos = myFixture.doHighlighting();
+        Assert.assertTrue(!highlightInfos.isEmpty());
+
+        final IntentionAction action = myFixture.findSingleIntention(hint);
+
+        Assert.assertNotNull(action);
+        myFixture.launchAction(action);
+        myFixture.checkResultByFile(testName + ".after.java");
+
+    }
+
+    @Test
+    // Test the "==" case
+    public void test() throws Throwable {
+        doTest("before", "Use equals()");
+
+    }
+     @Test
+     // Test the "!=" case
+    public void test1() throws Throwable {
+        doTest("before1", "Use equals()");
+
+    }
+
+}