diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/codeInspection/confusing/GrPackageInspection.java b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/codeInspection/confusing/GrPackageInspection.java index 8a1a6007f314..476f40d0c72d 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/codeInspection/confusing/GrPackageInspection.java +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/codeInspection/confusing/GrPackageInspection.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,7 +38,7 @@ import org.jetbrains.plugins.groovy.lang.psi.GroovyFileBase; import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition; import org.jetbrains.plugins.groovy.lang.psi.api.toplevel.GrTopStatement; import org.jetbrains.plugins.groovy.lang.psi.api.toplevel.packaging.GrPackageDefinition; -import org.jetbrains.plugins.groovy.lang.resolve.ResolveUtil; +import org.jetbrains.plugins.groovy.lang.resolve.ExpectedPackageNameProviderKt; import javax.swing.*; @@ -89,7 +89,7 @@ public class GrPackageInspection extends BaseInspection { if (!myCheckScripts && file.isScript()) return; - String expectedPackage = ResolveUtil.inferExpectedPackageName(file); + String expectedPackage = ExpectedPackageNameProviderKt.inferExpectedPackageName((GroovyFile)file); String actual = file.getPackageName(); if (!expectedPackage.equals(actual)) { diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/ExpectedPackageNameProvider.kt b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/ExpectedPackageNameProvider.kt new file mode 100644 index 000000000000..af07f7c679ea --- /dev/null +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/ExpectedPackageNameProvider.kt @@ -0,0 +1,42 @@ +/* + * Copyright 2000-2016 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jetbrains.plugins.groovy.lang.resolve + +import com.intellij.openapi.extensions.ExtensionPointName +import com.intellij.psi.JavaDirectoryService +import org.jetbrains.plugins.groovy.lang.psi.GroovyFile + +interface ExpectedPackageNameProvider { + + fun inferPackageName(file: GroovyFile): String? +} + +class DefaultExpectedPackageNameProvider : ExpectedPackageNameProvider { + + override fun inferPackageName(file: GroovyFile) = file.containingDirectory?.let { + JavaDirectoryService.getInstance().getPackage(it)?.qualifiedName + } +} + +private val EP_NAME = ExtensionPointName.create("org.intellij.groovy.expectedPackageNameProvider") + +fun inferExpectedPackageName(file: GroovyFile): String { + for (ext in EP_NAME.extensions) { + val name = ext.inferPackageName(file) ?: continue + return name + } + return "" +} \ No newline at end of file diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/ResolveUtil.java b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/ResolveUtil.java index ee90d21b244e..02fca05c7f61 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/ResolveUtil.java +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/ResolveUtil.java @@ -925,19 +925,6 @@ public class ResolveUtil { return null; } - @NotNull - public static String inferExpectedPackageName(PsiElement place) { - PsiFile file = place.getContainingFile(); - PsiDirectory psiDirectory = file.getContainingDirectory(); - if (psiDirectory != null && file instanceof GroovyFile) { - PsiPackage aPackage = JavaDirectoryService.getInstance().getPackage(psiDirectory); - if (aPackage != null) { - return aPackage.getQualifiedName(); - } - } - return ""; - } - public static PsiNamedElement findDuplicate(@NotNull GrVariable variable) { if (isScriptField(variable)) { final String name = variable.getName(); diff --git a/plugins/groovy/src/META-INF/plugin.xml b/plugins/groovy/src/META-INF/plugin.xml index 75056aeb3f5b..0188b03d4c7e 100644 --- a/plugins/groovy/src/META-INF/plugin.xml +++ b/plugins/groovy/src/META-INF/plugin.xml @@ -84,6 +84,7 @@ + @@ -244,6 +245,8 @@ +