1 package com.intellij.codeInsight.completion;
3 import com.intellij.JavaTestUtil;
4 import com.intellij.codeInsight.CodeInsightSettings;
5 import com.intellij.codeInsight.lookup.LookupElement;
6 import com.intellij.codeInspection.javaDoc.JavaDocLocalInspection;
7 import com.intellij.lang.StdLanguages;
8 import com.intellij.psi.PsiElement;
9 import com.intellij.psi.PsiReference;
10 import com.intellij.psi.PsiReferenceBase;
11 import com.intellij.psi.PsiReferenceProvider;
12 import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
13 import com.intellij.psi.impl.source.resolve.reference.PsiReferenceRegistrarImpl;
14 import com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistry;
15 import com.intellij.psi.javadoc.PsiDocTag;
16 import com.intellij.util.ObjectUtils;
17 import com.intellij.util.ProcessingContext;
18 import org.jetbrains.annotations.NotNull;
20 import java.util.Arrays;
21 import java.util.List;
27 public class JavadocCompletionTest extends LightFixtureCompletionTestCase {
30 protected String getBasePath() {
31 return JavaTestUtil.getRelativeJavaTestDataPath() + "/codeInsight/completion/javadoc/";
35 protected void setUp() throws Exception {
37 myFixture.enableInspections(new JavaDocLocalInspection());
40 public void testNamesInClass() throws Exception {
41 configureByFile("ClassTagName.java");
42 assertStringItems("author", "deprecated", "param", "see", "serial", "since", "version");
45 public void testNamesInField() throws Exception {
46 configureByFile("FieldTagName.java");
47 assertStringItems("deprecated", "see", "serial", "serialField", "since");
50 public void testNamesInMethod0() throws Exception {
51 configureByFile("MethodTagName0.java");
52 assertStringItems("deprecated", "exception", "param", "return", "see", "serialData", "since", "throws");
55 public void testNamesInMethod1() throws Exception {
56 configureByFile("MethodTagName1.java");
57 assertStringItems("see", "serialData", "since");
60 public void testParamValueCompletion() throws Exception {
61 configureByFile("ParamValue0.java");
62 assertStringItems("a", "b", "c");
65 public void testParamValueWithPrefixCompletion() throws Exception {
66 configureByFile("ParamValue1.java");
67 assertStringItems("a1", "a2", "a3");
70 public void testDescribedParameters() throws Exception {
71 configureByFile("ParamValue2.java");
72 assertStringItems("a2", "a3");
75 public void testSee0() throws Exception {
76 configureByFile("See0.java");
77 assertStringItems("foo", "clone", "equals", "getClass", "hashCode", "notify", "notifyAll", "Object", "toString", "wait", "wait", "wait", "finalize", "registerNatives");
80 public void testSee1() throws Exception {
81 configureByFile("See1.java");
82 assertStringItems("notify", "notifyAll");
85 public void testSee2() throws Exception {
86 configureByFile("See2.java");
87 assertStringItems("notify", "notifyAll");
90 public void testSee3() throws Exception {
91 configureByFile("See3.java");
93 assertTrue(getLookupElementStrings().containsAll(Arrays.asList("foo", "myField")));
97 private List<String> getLookupElementStrings() {
98 return ObjectUtils.assertNotNull(myFixture.getLookupElementStrings());
101 public void testSee4() throws Exception {
102 configureByFile("See4.java");
104 assertTrue(getLookupElementStrings().containsAll(Arrays.asList("A", "B", "C")));
107 public void testSee5() throws Exception {
108 configureByFile("See5.java");
110 assertTrue(getLookupElementStrings().containsAll(Arrays.asList("foo", "myName")));
113 public void testIDEADEV10620() throws Exception {
114 configureByFile("IDEADEV10620.java");
116 checkResultByFile("IDEADEV10620-after.java");
119 public void testException0() throws Exception {
120 configureByFile("Exception0.java");
121 assertStringItems("deprecated", "exception", "param", "see", "serialData", "since", "throws");
124 public void testException1() throws Exception {
125 configureByFile("Exception1.java");
126 assertTrue(myItems.length > 18);
129 public void testException2() throws Exception {
130 myFixture.configureByFile("Exception2.java");
131 myFixture.complete(CompletionType.SMART);
132 assertStringItems("IllegalStateException", "IOException");
135 public void testInlineLookup() throws Exception {
136 configureByFile("InlineTagName.java");
137 assertStringItems("code", "docRoot", "inheritDoc", "link", "linkplain", "literal", "value");
140 public void testFinishWithSharp() throws Throwable {
141 boolean old = CodeInsightSettings.getInstance().AUTOCOMPLETE_ON_CODE_COMPLETION;
142 CodeInsightSettings.getInstance().AUTOCOMPLETE_ON_CODE_COMPLETION = false;
144 checkFinishWithSharp(CompletionType.BASIC);
147 CodeInsightSettings.getInstance().AUTOCOMPLETE_ON_CODE_COMPLETION = old;
151 public void testFinishWithSharpClassName() throws Throwable {
152 checkFinishWithSharp(CompletionType.CLASS_NAME);
155 private void checkFinishWithSharp(CompletionType completionType) throws Exception {
156 myFixture.configureByFile("FinishWithSharp.java");
157 myFixture.complete(completionType);
159 checkResultByFile("FinishWithSharp_after.java");
160 final List<LookupElement> items = getLookup().getItems();
161 assertEquals("bar", items.get(0).getLookupString());
162 assertEquals("foo", items.get(1).getLookupString());
165 public void testShortenClassName() throws Throwable {
166 CodeStyleSettingsManager.getSettings(getProject()).USE_FQ_CLASS_NAMES_IN_JAVADOC = false;
171 CodeStyleSettingsManager.getSettings(getProject()).USE_FQ_CLASS_NAMES_IN_JAVADOC = true;
175 public void testMethodBeforeSharp() throws Throwable {
179 public void testShortenClassReference() throws Throwable { doTest(); }
180 public void testQualifiedClassReference() throws Throwable {
181 configureByFile(getTestName(false) + ".java");
182 myFixture.complete(CompletionType.BASIC, 2);
183 checkResultByFile(getTestName(false) + "_after.java");
185 public void testThrowsNonImported() throws Throwable {
186 configureByFile(getTestName(false) + ".java");
187 myFixture.complete(CompletionType.BASIC, 2);
188 checkResultByFile(getTestName(false) + "_after.java");
191 private void doTest() throws Exception {
192 configureByFile(getTestName(false) + ".java");
193 checkResultByFile(getTestName(false) + "_after.java");
196 public void testInlinePackageReferenceCompletion() throws Exception {
197 configureByFile("InlineReference.java");
198 assertTrue(getLookupElementStrings().containsAll(Arrays.asList("io", "lang", "util")));
201 public void testCustomReferenceProvider() throws Exception {
202 PsiReferenceRegistrarImpl registrar =
203 (PsiReferenceRegistrarImpl) ReferenceProvidersRegistry.getInstance().getRegistrar(StdLanguages.JAVA);
204 PsiReferenceProvider provider = new PsiReferenceProvider() {
207 public PsiReference[] getReferencesByElement(@NotNull final PsiElement element, @NotNull final ProcessingContext context) {
208 return new PsiReference[]{new PsiReferenceBase<PsiElement>(element) {
211 public PsiElement resolve() {
217 public Object[] getVariants() {
218 return new Object[]{"1", "2", "3"};
224 registrar.registerReferenceProvider(PsiDocTag.class, provider);
225 configureByFile("ReferenceProvider.java");
226 assertStringItems("1", "2", "3");
229 registrar.unregisterReferenceProvider(PsiDocTag.class, provider);