| Jean-Baptiste Queru | b56ea2a | 2013-01-08 11:11:20 -0800 | [diff] [blame] | 1 | /* |
| Tor Norbye | ec3fb1e | 2013-05-31 07:45:51 -0700 | [diff] [blame] | 2 | * Copyright 2000-2013 JetBrains s.r.o. |
| Jean-Baptiste Queru | b56ea2a | 2013-01-08 11:11:20 -0800 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.jetbrains.idea.devkit.codeInsight |
| 17 | import com.intellij.codeInsight.TargetElementUtilBase |
| 18 | import com.intellij.codeInsight.completion.CompletionType |
| 19 | import com.intellij.codeInspection.LocalInspectionTool |
| Tor Norbye | ec3fb1e | 2013-05-31 07:45:51 -0700 | [diff] [blame] | 20 | import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection |
| Tor Norbye | 7675366 | 2013-10-15 19:49:27 -0700 | [diff] [blame^] | 21 | import com.intellij.codeInspection.htmlInspections.RequiredAttributesInspection |
| Tor Norbye | ec3fb1e | 2013-05-31 07:45:51 -0700 | [diff] [blame] | 22 | import com.intellij.codeInspection.unusedSymbol.UnusedSymbolLocalInspection |
| Jean-Baptiste Queru | b56ea2a | 2013-01-08 11:11:20 -0800 | [diff] [blame] | 23 | import com.intellij.openapi.application.ApplicationManager |
| 24 | import com.intellij.openapi.application.PluginPathManager |
| 25 | import com.intellij.psi.ElementDescriptionUtil |
| 26 | import com.intellij.psi.PsiElement |
| 27 | import com.intellij.testFramework.PsiTestUtil |
| 28 | import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory |
| 29 | import com.intellij.testFramework.fixtures.JavaCodeInsightFixtureTestCase |
| 30 | import com.intellij.testFramework.fixtures.TempDirTestFixture |
| 31 | import com.intellij.usageView.UsageViewNodeTextLocation |
| 32 | import com.intellij.usageView.UsageViewTypeLocation |
| 33 | import com.intellij.util.xml.DeprecatedClassUsageInspection |
| 34 | import org.jetbrains.idea.devkit.inspections.* |
| Tor Norbye | 6739a8f | 2013-08-07 11:11:08 -0700 | [diff] [blame] | 35 | |
| Jean-Baptiste Queru | b56ea2a | 2013-01-08 11:11:20 -0800 | [diff] [blame] | 36 | /** |
| 37 | * @author peter |
| 38 | */ |
| 39 | public class PluginXmlFunctionalTest extends JavaCodeInsightFixtureTestCase { |
| 40 | private TempDirTestFixture myTempDirFixture; |
| 41 | |
| 42 | @Override |
| 43 | protected void setUp() throws Exception { |
| 44 | super.setUp(); |
| 45 | myTempDirFixture = IdeaTestFixtureFactory.getFixtureFactory().createTempDirTestFixture(); |
| 46 | myFixture.enableInspections(getInspectionClasses()); |
| 47 | } |
| 48 | |
| 49 | @Override |
| 50 | protected String getBasePath() { |
| 51 | return PluginPathManager.getPluginHomePathRelative("devkit") + "/testData/codeInsight"; |
| 52 | } |
| 53 | |
| 54 | public void testExtensionsHighlighting() throws Throwable { |
| 55 | final String root = "idea_core"; |
| 56 | addPluginXml(root, "<idea-plugin>\n" + |
| 57 | " <id>com.intellij</id>\n" + |
| 58 | " <extensionPoints>\n" + |
| 59 | " <extensionPoint name=\"completion.contributor\"/>\n" + |
| 60 | " </extensionPoints>\n" + |
| 61 | "</idea-plugin>"); |
| 62 | addPluginXml("indirect", "<idea-plugin>\n" + |
| 63 | " <id>com.intellij.indirect</id>\n" + |
| 64 | " <extensionPoints>\n" + |
| 65 | " <extensionPoint name=\"indirect\"/>\n" + |
| 66 | " </extensionPoints>\n" + |
| 67 | "</idea-plugin>"); |
| 68 | addPluginXml("custom", "<idea-plugin>\n" + |
| 69 | " <id>com.intellij.custom</id>\n" + |
| 70 | " <depends>com.intellij.indirect</depends>\n" + |
| 71 | " <extensionPoints>\n" + |
| 72 | " <extensionPoint name=\"custom\"/>\n" + |
| 73 | " </extensionPoints>\n" + |
| 74 | "</idea-plugin>"); |
| Tor Norbye | c7f983b | 2013-09-05 16:07:26 -0700 | [diff] [blame] | 75 | myFixture.addClass("package foo; public class MyRunnable implements java.lang.Runnable {}"); |
| 76 | myFixture.addClass("package foo; @Deprecated public abstract class MyDeprecatedEP {}"); |
| 77 | myFixture.addClass("package foo; public class MyDeprecatedEPImpl extends foo.MyDeprecatedEP {}"); |
| Jean-Baptiste Queru | b56ea2a | 2013-01-08 11:11:20 -0800 | [diff] [blame] | 78 | |
| 79 | configureByFile(); |
| Tor Norbye | c7f983b | 2013-09-05 16:07:26 -0700 | [diff] [blame] | 80 | myFixture.checkHighlighting(true, false, false); |
| Jean-Baptiste Queru | b56ea2a | 2013-01-08 11:11:20 -0800 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | public void testDependsHighlighting() throws Throwable { |
| 84 | final String root = "idea_core"; |
| 85 | addPluginXml(root, "<idea-plugin>\n" + |
| 86 | " <id>com.intellij</id>\n" + |
| 87 | " <module value=\"com.intellij.modules.vcs\"/>\n" + |
| 88 | "</idea-plugin>"); |
| 89 | addPluginXml("custom", "<idea-plugin>\n" + |
| 90 | " <id>com.intellij.custom</id>\n" + |
| 91 | "</idea-plugin>"); |
| 92 | |
| 93 | configureByFile(); |
| 94 | myFixture.checkHighlighting(false, false, false); |
| 95 | } |
| 96 | |
| Tor Norbye | 6739a8f | 2013-08-07 11:11:08 -0700 | [diff] [blame] | 97 | public void testDependsCompletion() throws Throwable { |
| 98 | addPluginXml("platform", "<idea-plugin>\n" + |
| 99 | " <id>com.intellij</id>\n" + |
| 100 | " <module value=\"com.intellij.modules.vcs\"/>\n" + |
| 101 | "</idea-plugin>"); |
| 102 | addPluginXml("lang", "<idea-plugin>\n" + |
| 103 | " <id>com.intellij</id>\n" + |
| 104 | " <module value=\"com.intellij.modules.lang\"/>\n" + |
| 105 | " <module value=\"com.intellij.modules.lang.another\"/>\n" + |
| 106 | "</idea-plugin>"); |
| 107 | addPluginXml("custom", "<idea-plugin>\n" + |
| 108 | " <id>com.intellij.custom</id>\n" + |
| 109 | "</idea-plugin>"); |
| 110 | configureByFile(); |
| 111 | |
| 112 | myFixture.completeBasic() |
| 113 | assertSameElements(myFixture.lookupElementStrings, |
| 114 | 'com.intellij.modules.vcs', |
| 115 | 'com.intellij.modules.lang', 'com.intellij.modules.lang.another', |
| 116 | 'com.intellij.custom') |
| 117 | } |
| 118 | |
| Jean-Baptiste Queru | b56ea2a | 2013-01-08 11:11:20 -0800 | [diff] [blame] | 119 | private void configureByFile() { |
| 120 | myFixture.configureFromExistingVirtualFile(myFixture.copyFileToProject(getTestName(false) + ".xml", "META-INF/plugin.xml")); |
| 121 | } |
| 122 | |
| 123 | public void testExtensionQualifiedName() throws Throwable { |
| Tor Norbye | 9322595 | 2013-08-29 10:40:28 -0700 | [diff] [blame] | 124 | myFixture.addClass("package foo; public class MyRunnable implements java.lang.Runnable {}"); |
| Jean-Baptiste Queru | b56ea2a | 2013-01-08 11:11:20 -0800 | [diff] [blame] | 125 | configureByFile(); |
| 126 | myFixture.checkHighlighting(false, false, false); |
| 127 | } |
| 128 | |
| 129 | public void testInnerClassCompletion() throws Throwable { |
| 130 | myFixture.addClass("package foo; public class Foo { public static class Fubar {} }"); |
| 131 | myFixture.configureByFile(getTestName(false) + ".xml"); |
| 132 | myFixture.completeBasic(); |
| 133 | myFixture.type('\n'); |
| 134 | myFixture.checkResultByFile(getTestName(false) + "_after.xml"); |
| 135 | } |
| 136 | |
| 137 | public void testResolveExtensionsFromDependentDescriptor() throws Throwable { |
| 138 | addPluginXml("xxx", "<idea-plugin>\n" + |
| 139 | " <id>com.intellij.xxx</id>\n" + |
| 140 | " <extensionPoints>\n" + |
| 141 | " <extensionPoint name=\"completion.contributor\"/>\n" + |
| 142 | " </extensionPoints>\n" + |
| 143 | "</idea-plugin>"); |
| 144 | |
| 145 | myFixture.copyFileToProject(getTestName(false) + "_main.xml", "META-INF/plugin.xml"); |
| 146 | myFixture.configureFromExistingVirtualFile(myFixture.copyFileToProject(getTestName(false) + "_dependent.xml", "META-INF/dep.xml")); |
| 147 | myFixture.checkHighlighting(false, false, false); |
| 148 | } |
| 149 | |
| 150 | private void addPluginXml(final String root, final String text) throws IOException { |
| 151 | myTempDirFixture.createFile(root + "/META-INF/plugin.xml", text); |
| 152 | ApplicationManager.application.runWriteAction { PsiTestUtil.addSourceContentToRoots(myModule, myTempDirFixture.getFile(root)) } |
| 153 | } |
| 154 | |
| 155 | public void testNoWordCompletionInClassPlaces() throws Throwable { |
| 156 | myFixture.addClass("package foo; public class FooFooFooFooFoo { }"); |
| 157 | myFixture.addClass("package foo; public interface ExtIntf { }"); |
| 158 | |
| 159 | myFixture.configureByFile(getTestName(false) + ".xml"); |
| 160 | myFixture.completeBasic(); |
| 161 | myFixture.type('\''); |
| 162 | myFixture.checkResultByFile(getTestName(false) + "_after.xml"); |
| 163 | } |
| 164 | |
| 165 | public void testNoClassCompletionOutsideJavaReferences() throws Throwable { |
| 166 | myFixture.addClass("package foo; public class FooFooFooFooFoo { }"); |
| 167 | |
| 168 | myFixture.configureByFile(getTestName(false) + ".xml"); |
| 169 | myFixture.completeBasic(); |
| 170 | myFixture.checkResultByFile(getTestName(false) + "_after.xml"); |
| 171 | } |
| 172 | |
| 173 | public void testShowPackagesInActionClass() { |
| 174 | myFixture.addClass("package com.intellij.openapi.actionSystem; public class AnAction { }"); |
| 175 | myFixture.addClass("package foo.bar; public class BarAction extends com.intellij.openapi.actionSystem.AnAction { }"); |
| 176 | myFixture.addClass("package foo.goo; public class GooAction extends com.intellij.openapi.actionSystem.AnAction { }"); |
| 177 | myFixture.configureByFile(getTestName(false) + ".xml"); |
| 178 | myFixture.completeBasic(); |
| 179 | assert myFixture.lookupElementStrings == ['bar', 'goo'] |
| 180 | assert myFixture.lookup.advertisements.find { it.contains('to see inheritors of com.intellij.openapi.actionSystem.AnAction') } |
| 181 | } |
| 182 | |
| 183 | public void testShowAnActionInheritorsOnSmartCompletion() { |
| 184 | myFixture.addClass("package com.intellij.openapi.actionSystem; public class AnAction { }"); |
| 185 | myFixture.addClass("package foo.bar; public class BarAction extends com.intellij.openapi.actionSystem.AnAction { }"); |
| 186 | myFixture.addClass("package foo.goo; public class GooAction extends com.intellij.openapi.actionSystem.AnAction { }"); |
| 187 | myFixture.addClass("package another.goo; public class AnotherAction extends com.intellij.openapi.actionSystem.AnAction { }"); |
| 188 | myFixture.configureByFile(getTestName(false) + ".xml"); |
| 189 | myFixture.complete(CompletionType.SMART); |
| 190 | assert myFixture.lookupElementStrings == ['foo.bar.BarAction', 'foo.goo.GooAction'] |
| 191 | assert !myFixture.lookup.advertisements.find { it.contains('to see inheritors of com.intellij.openapi.actionSystem.AnAction') } |
| 192 | } |
| 193 | |
| 194 | public void testDeprecatedExtensionAttribute() { |
| 195 | myFixture.enableInspections(DeprecatedClassUsageInspection.class); |
| 196 | myFixture.testHighlighting("deprecatedExtensionAttribute.xml", "MyExtBean.java"); |
| 197 | } |
| 198 | |
| 199 | public void testExtensionAttributeDeclaredUsingAccessors() { |
| 200 | myFixture.testHighlighting("extensionAttributeWithAccessors.xml", "ExtBeanWithAccessors.java"); |
| 201 | } |
| 202 | |
| 203 | public void testPluginModule() throws Throwable { |
| 204 | myFixture.testHighlighting("pluginWithModules.xml"); |
| 205 | } |
| 206 | |
| 207 | public void testPluginWithModules() throws Throwable { |
| 208 | myFixture.testHighlighting("pluginWithModules.xml"); |
| 209 | } |
| 210 | |
| 211 | public void testPluginWithXInclude() throws Throwable { |
| 212 | myFixture.testHighlighting("pluginWithXInclude.xml", "extensionPoints.xml"); |
| 213 | } |
| 214 | |
| 215 | public void testExtensionPointPresentation() { |
| 216 | myFixture.configureByFile(getTestName(true) + ".xml"); |
| 217 | final PsiElement element = |
| 218 | TargetElementUtilBase.findTargetElement(myFixture.getEditor(), TargetElementUtilBase.REFERENCED_ELEMENT_ACCEPTED); |
| 219 | assert element != null; |
| 220 | assertEquals("Extension Point", ElementDescriptionUtil.getElementDescription(element, UsageViewTypeLocation.INSTANCE)); |
| 221 | assertEquals("Extension Point bar", ElementDescriptionUtil.getElementDescription(element, UsageViewNodeTextLocation.INSTANCE)); |
| 222 | } |
| 223 | |
| 224 | public void testLoadForDefaultProject() throws Exception { |
| 225 | configureByFile(); |
| 226 | myFixture.testHighlighting(true, true, true); |
| 227 | } |
| 228 | |
| Tor Norbye | ec3fb1e | 2013-05-31 07:45:51 -0700 | [diff] [blame] | 229 | public void testImplicitUsagesDomElement() { |
| 230 | myFixture.addClass("package com.intellij.util.xml; public interface DomElement {}") |
| 231 | myFixture.addClass("package com.intellij.util.xml; public interface GenericAttributeValue<T> extends DomElement {}") |
| 232 | |
| 233 | myFixture.enableInspections(new UnusedSymbolLocalInspection(), new UnusedDeclarationInspection()) |
| 234 | myFixture.configureByFile("ImplicitUsagesDomElement.java") |
| 235 | myFixture.testHighlighting() |
| 236 | } |
| 237 | |
| 238 | public void testImplicitUsagesDomElementVisitor() { |
| 239 | myFixture.addClass("package com.intellij.util.xml; public interface DomElement {}") |
| 240 | myFixture.addClass("package com.intellij.util.xml; public interface DomElementVisitor {}") |
| 241 | |
| 242 | myFixture.enableInspections(new UnusedSymbolLocalInspection(), new UnusedDeclarationInspection()) |
| 243 | myFixture.configureByFile("ImplicitUsagesDomElementVisitor.java") |
| 244 | myFixture.testHighlighting() |
| 245 | } |
| 246 | |
| Jean-Baptiste Queru | b56ea2a | 2013-01-08 11:11:20 -0800 | [diff] [blame] | 247 | static Collection<Class<? extends LocalInspectionTool>> getInspectionClasses() { |
| 248 | return Arrays.asList( |
| 249 | //RegistrationProblemsInspection.class, |
| 250 | PluginXmlDomInspection.class, |
| 251 | ComponentNotRegisteredInspection.class, |
| 252 | InspectionDescriptionNotFoundInspection.class, |
| 253 | IntentionDescriptionNotFoundInspection.class, |
| Tor Norbye | 7675366 | 2013-10-15 19:49:27 -0700 | [diff] [blame^] | 254 | InspectionMappingConsistencyInspection.class, |
| 255 | RequiredAttributesInspection.class |
| Jean-Baptiste Queru | b56ea2a | 2013-01-08 11:11:20 -0800 | [diff] [blame] | 256 | ); |
| 257 | } |
| 258 | } |