From 81e863bdfd2779d483d8e21a1b9c27697025372a Mon Sep 17 00:00:00 2001 From: peter Date: Mon, 26 Oct 2009 17:08:43 +0000 Subject: [PATCH] WordCompletionTest->community --- .../codeInsight/completion/word/1.properties | 1 + .../codeInsight/completion/word/1.txt | 1 + .../codeInsight/completion/word/1.xml | 1 + .../completion/word/1_after.properties | 1 + .../codeInsight/completion/word/1_after.txt | 1 + .../codeInsight/completion/word/1_after.xml | 1 + .../codeInsight/completion/word/2.xml | 4 + .../codeInsight/completion/word/2_after.xml | 4 + .../codeInsight/completion/word/3.java | 3 + .../codeInsight/completion/word/3_after.java | 3 + .../codeInsight/completion/word/4.java | 4 + .../codeInsight/completion/word/4_after.java | 4 + .../completion/word/DollarsInPrefix.txt | 2 + .../completion/word/DollarsInPrefix_after.txt | 2 + .../completion/word/SpaceInComment.java | 4 + .../completion/word/TextInComment.java | 4 + .../completion/word/TextInComment_after.java | 4 + .../completion/WordCompletionTest.java | 106 ++++++++++++++++++ 18 files changed, 150 insertions(+) create mode 100644 java/java-tests/testData/codeInsight/completion/word/1.properties create mode 100644 java/java-tests/testData/codeInsight/completion/word/1.txt create mode 100644 java/java-tests/testData/codeInsight/completion/word/1.xml create mode 100644 java/java-tests/testData/codeInsight/completion/word/1_after.properties create mode 100644 java/java-tests/testData/codeInsight/completion/word/1_after.txt create mode 100644 java/java-tests/testData/codeInsight/completion/word/1_after.xml create mode 100644 java/java-tests/testData/codeInsight/completion/word/2.xml create mode 100644 java/java-tests/testData/codeInsight/completion/word/2_after.xml create mode 100644 java/java-tests/testData/codeInsight/completion/word/3.java create mode 100644 java/java-tests/testData/codeInsight/completion/word/3_after.java create mode 100644 java/java-tests/testData/codeInsight/completion/word/4.java create mode 100644 java/java-tests/testData/codeInsight/completion/word/4_after.java create mode 100644 java/java-tests/testData/codeInsight/completion/word/DollarsInPrefix.txt create mode 100644 java/java-tests/testData/codeInsight/completion/word/DollarsInPrefix_after.txt create mode 100644 java/java-tests/testData/codeInsight/completion/word/SpaceInComment.java create mode 100644 java/java-tests/testData/codeInsight/completion/word/TextInComment.java create mode 100644 java/java-tests/testData/codeInsight/completion/word/TextInComment_after.java create mode 100644 java/java-tests/testSrc/com/intellij/codeInsight/completion/WordCompletionTest.java diff --git a/java/java-tests/testData/codeInsight/completion/word/1.properties b/java/java-tests/testData/codeInsight/completion/word/1.properties new file mode 100644 index 000000000000..07ff18946dda --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/word/1.properties @@ -0,0 +1 @@ +Settings Sett other \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/completion/word/1.txt b/java/java-tests/testData/codeInsight/completion/word/1.txt new file mode 100644 index 000000000000..07ff18946dda --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/word/1.txt @@ -0,0 +1 @@ +Settings Sett other \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/completion/word/1.xml b/java/java-tests/testData/codeInsight/completion/word/1.xml new file mode 100644 index 000000000000..59ce61709e23 --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/word/1.xml @@ -0,0 +1 @@ +Settings Sett other \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/completion/word/1_after.properties b/java/java-tests/testData/codeInsight/completion/word/1_after.properties new file mode 100644 index 000000000000..d541cbaae542 --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/word/1_after.properties @@ -0,0 +1 @@ +Settings Settings other \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/completion/word/1_after.txt b/java/java-tests/testData/codeInsight/completion/word/1_after.txt new file mode 100644 index 000000000000..d541cbaae542 --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/word/1_after.txt @@ -0,0 +1 @@ +Settings Settings other \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/completion/word/1_after.xml b/java/java-tests/testData/codeInsight/completion/word/1_after.xml new file mode 100644 index 000000000000..0e55fb64166c --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/word/1_after.xml @@ -0,0 +1 @@ +Settings Settings other \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/completion/word/2.xml b/java/java-tests/testData/codeInsight/completion/word/2.xml new file mode 100644 index 000000000000..827ff426a45e --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/word/2.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/completion/word/2_after.xml b/java/java-tests/testData/codeInsight/completion/word/2_after.xml new file mode 100644 index 000000000000..2b4fb1785afa --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/word/2_after.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/completion/word/3.java b/java/java-tests/testData/codeInsight/completion/word/3.java new file mode 100644 index 000000000000..6b5f498d02b1 --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/word/3.java @@ -0,0 +1,3 @@ +public class MyClass { + String b = "My"; +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/completion/word/3_after.java b/java/java-tests/testData/codeInsight/completion/word/3_after.java new file mode 100644 index 000000000000..362513c90f15 --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/word/3_after.java @@ -0,0 +1,3 @@ +public class MyClass { + String b = "MyHardVariant"; +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/completion/word/4.java b/java/java-tests/testData/codeInsight/completion/word/4.java new file mode 100644 index 000000000000..ee67efda680b --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/word/4.java @@ -0,0 +1,4 @@ +public class MyClass { + String b = "My"; + // pu +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/completion/word/4_after.java b/java/java-tests/testData/codeInsight/completion/word/4_after.java new file mode 100644 index 000000000000..aad7a3fa2af9 --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/word/4_after.java @@ -0,0 +1,4 @@ +public class MyClass { + String b = "My"; + // public +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/completion/word/DollarsInPrefix.txt b/java/java-tests/testData/codeInsight/completion/word/DollarsInPrefix.txt new file mode 100644 index 000000000000..d20aabb4aa61 --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/word/DollarsInPrefix.txt @@ -0,0 +1,2 @@ +$test +$te \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/completion/word/DollarsInPrefix_after.txt b/java/java-tests/testData/codeInsight/completion/word/DollarsInPrefix_after.txt new file mode 100644 index 000000000000..eb7accf1a552 --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/word/DollarsInPrefix_after.txt @@ -0,0 +1,2 @@ +$test +$test \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/completion/word/SpaceInComment.java b/java/java-tests/testData/codeInsight/completion/word/SpaceInComment.java new file mode 100644 index 000000000000..aecf20aec235 --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/word/SpaceInComment.java @@ -0,0 +1,4 @@ +public class MyClass { + + // comment +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/completion/word/TextInComment.java b/java/java-tests/testData/codeInsight/completion/word/TextInComment.java new file mode 100644 index 000000000000..13285eca3293 --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/word/TextInComment.java @@ -0,0 +1,4 @@ +public class MyClass { + + /** comment My */ +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/completion/word/TextInComment_after.java b/java/java-tests/testData/codeInsight/completion/word/TextInComment_after.java new file mode 100644 index 000000000000..5e0022979846 --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/word/TextInComment_after.java @@ -0,0 +1,4 @@ +public class MyClass { + + /** comment MyClass */ +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/WordCompletionTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/completion/WordCompletionTest.java new file mode 100644 index 000000000000..22613915de80 --- /dev/null +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/WordCompletionTest.java @@ -0,0 +1,106 @@ +package com.intellij.codeInsight.completion; + +import com.intellij.JavaTestUtil; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiLiteralExpression; +import com.intellij.psi.PsiReference; +import com.intellij.psi.PsiReferenceBase; +import com.intellij.psi.impl.source.resolve.reference.PsiReferenceProviderBase; +import com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistry; +import com.intellij.util.ProcessingContext; +import org.jetbrains.annotations.NotNull; + +/** + * Created by IntelliJ IDEA. + * User: Maxim.Mossienko + * Date: Oct 14, 2004 + * Time: 4:39:37 PM + * To change this template use File | Settings | File Templates. + */ +public class WordCompletionTest extends CompletionTestCase { + private static final String BASE_PATH = "/codeInsight/completion/word/"; + + @Override + protected String getTestDataPath() { + return JavaTestUtil.getJavaTestDataPath(); + } + + public void testKeyWordCompletion() throws Exception { + configureByFile(BASE_PATH + "1.txt"); + checkResultByFile(BASE_PATH + "1_after.txt"); + + configureByFile(BASE_PATH + "1.properties"); + checkResultByFile(BASE_PATH + "1_after.properties"); + + configureByFile(BASE_PATH + "1.xml"); + checkResultByFile(BASE_PATH + "1_after.xml"); + + configureByFile(BASE_PATH + "2.xml"); + configureByFile(BASE_PATH + "2_after.xml"); + } + + public void testNoWordCompletionForNonSoftReference() throws Throwable { + final PsiReferenceProviderBase softProvider = new PsiReferenceProviderBase() { + @NotNull + public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull final ProcessingContext context) { + return new PsiReference[]{new PsiReferenceBase(element) { + public PsiElement resolve() { + return null; + } + + public boolean isSoft() { + return true; + } + + public Object[] getVariants() { + return new Object[]{"MySoftVariant"}; + } + }}; + } + }; + final PsiReferenceProviderBase hardProvider = new PsiReferenceProviderBase() { + @NotNull + public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull final ProcessingContext context) { + return new PsiReference[]{new PsiReferenceBase(element) { + public PsiElement resolve() { + return null; + } + + public boolean isSoft() { + return false; + } + + public Object[] getVariants() { + return new Object[]{"MyHardVariant"}; + } + }}; + } + }; + ReferenceProvidersRegistry.getInstance(getProject()).registerReferenceProvider(PsiLiteralExpression.class, softProvider); + ReferenceProvidersRegistry.getInstance(getProject()).registerReferenceProvider(PsiLiteralExpression.class, hardProvider); + + configureByFile(BASE_PATH + "3.java"); + checkResultByFile(BASE_PATH + "3_after.java"); + } + + public void testComments() throws Throwable { + configureByFile(BASE_PATH + "4.java"); + checkResultByFile(BASE_PATH + "4_after.java"); + } + + public void testSpaceInComment() throws Throwable { + configureByFile(BASE_PATH + "SpaceInComment.java"); + checkResultByFile(BASE_PATH + "SpaceInComment.java"); + } + + public void testTextInComment() throws Throwable { + configureByFile(BASE_PATH + "TextInComment.java"); + checkResultByFile(BASE_PATH + "TextInComment_after.java"); + } + + public void testDollarsInPrefix() throws Throwable { + configureByFile(BASE_PATH + getTestName(false) + ".txt"); + checkResultByFile(BASE_PATH + getTestName(false) + "_after.txt"); + } + +}