mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[groovy] allow to plug into package name detection
This commit is contained in:
+3
-3
@@ -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)) {
|
||||
|
||||
|
||||
+42
@@ -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<ExpectedPackageNameProvider>("org.intellij.groovy.expectedPackageNameProvider")
|
||||
|
||||
fun inferExpectedPackageName(file: GroovyFile): String {
|
||||
for (ext in EP_NAME.extensions) {
|
||||
val name = ext.inferPackageName(file) ?: continue
|
||||
return name
|
||||
}
|
||||
return ""
|
||||
}
|
||||
-13
@@ -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();
|
||||
|
||||
@@ -84,6 +84,7 @@
|
||||
<extensionPoint name="signatureHintProcessor" interface="org.jetbrains.plugins.groovy.lang.psi.typeEnhancers.SignatureHintProcessor"/>
|
||||
<extensionPoint name="mvc.runCommandHandler" interface="org.jetbrains.plugins.groovy.mvc.actions.MvcRunCommandActionHandler"/>
|
||||
<extensionPoint name="gdslScriptProvider" interface="org.jetbrains.plugins.groovy.dsl.GdslScriptProvider"/>
|
||||
<extensionPoint name="expectedPackageNameProvider" interface="org.jetbrains.plugins.groovy.lang.resolve.ExpectedPackageNameProvider"/>
|
||||
</extensionPoints>
|
||||
|
||||
<extensions defaultExtensionNs="org.intellij.groovy">
|
||||
@@ -244,6 +245,8 @@
|
||||
<customAnnotationChecker implementation="org.jetbrains.plugins.groovy.annotator.checkers.TypeCheckedAnnotationChecker"/>
|
||||
<mvc.runCommandHandler implementation="org.jetbrains.plugins.groovy.mvc.actions.DefaultMvcRunCommandActionHandler" order="last"/>
|
||||
<methodComparator implementation="org.jetbrains.plugins.groovy.lang.resolve.GrDefaultMethodComparator" order="last"/>
|
||||
<expectedPackageNameProvider implementation="org.jetbrains.plugins.groovy.lang.resolve.DefaultExpectedPackageNameProvider"
|
||||
order="last"/>
|
||||
</extensions>
|
||||
|
||||
<extensions defaultExtensionNs="com.intellij.properties">
|
||||
|
||||
Reference in New Issue
Block a user