mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-04 17:20:55 +07:00
IDEA-238824 Support "Goto EP declaration in plugin.xml" for ProjectExtensionPointName
GitOrigin-RevId: 9b56bb54c76450f9070bfd5f7896b6e79391028f
This commit is contained in:
committed by
intellij-monorepo-bot
parent
69089e2860
commit
d997d95a2f
@@ -1,22 +1,9 @@
|
||||
/*
|
||||
* Copyright 2000-2014 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.
|
||||
*/
|
||||
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package org.jetbrains.idea.devkit.navigation;
|
||||
|
||||
import com.intellij.codeInsight.daemon.RelatedItemLineMarkerInfo;
|
||||
import com.intellij.openapi.extensions.ExtensionPointName;
|
||||
import com.intellij.openapi.extensions.ProjectExtensionPointName;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiTypesUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
@@ -30,6 +17,7 @@ import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class ExtensionPointDeclarationRelatedItemLineMarkerProvider extends DevkitRelatedLineMarkerProviderBase {
|
||||
|
||||
@Override
|
||||
protected void collectNavigationMarkers(@NotNull PsiElement element, @NotNull Collection<? super RelatedItemLineMarkerInfo<?>> result) {
|
||||
if (element instanceof PsiField) {
|
||||
@@ -38,9 +26,10 @@ public class ExtensionPointDeclarationRelatedItemLineMarkerProvider extends Devk
|
||||
}
|
||||
|
||||
private static void process(PsiField psiField, Collection<? super RelatedItemLineMarkerInfo<?>> result) {
|
||||
if (!isExtensionPointNameDeclarationField(psiField)) return;
|
||||
final ExtensionPointType epType = isExtensionPointNameDeclarationField(psiField);
|
||||
if (epType == ExtensionPointType.NONE) return;
|
||||
|
||||
final PsiClass epClass = resolveExtensionPointClass(psiField);
|
||||
final PsiClass epClass = resolveExtensionPointClass(psiField, epType);
|
||||
if (epClass == null) return;
|
||||
|
||||
final String epName = resolveEpName(psiField);
|
||||
@@ -60,9 +49,10 @@ public class ExtensionPointDeclarationRelatedItemLineMarkerProvider extends Devk
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static PsiClass resolveExtensionPointClass(PsiField psiField) {
|
||||
private static PsiClass resolveExtensionPointClass(PsiField psiField,
|
||||
ExtensionPointType epType) {
|
||||
final PsiType typeParameter = PsiUtil.substituteTypeParameter(psiField.getType(),
|
||||
ExtensionPointName.class.getName(),
|
||||
epType.qualifiedClassName,
|
||||
0, false);
|
||||
return PsiUtil.resolveClassInClassTypeOnly(typeParameter);
|
||||
}
|
||||
@@ -88,29 +78,49 @@ public class ExtensionPointDeclarationRelatedItemLineMarkerProvider extends Devk
|
||||
return o instanceof String ? (String)o : null;
|
||||
}
|
||||
|
||||
private static boolean isExtensionPointNameDeclarationField(PsiField psiField) {
|
||||
|
||||
enum ExtensionPointType {
|
||||
NONE(""),
|
||||
APPLICATION(ExtensionPointName.class.getName()),
|
||||
PROJECT(ProjectExtensionPointName.class.getName());
|
||||
|
||||
private final String qualifiedClassName;
|
||||
|
||||
ExtensionPointType(String qualifiedClassName) {
|
||||
this.qualifiedClassName = qualifiedClassName;
|
||||
}
|
||||
|
||||
static ExtensionPointType find(String qualifiedClassName) {
|
||||
if (APPLICATION.qualifiedClassName.equals(qualifiedClassName)) return APPLICATION;
|
||||
if (PROJECT.qualifiedClassName.equals(qualifiedClassName)) return PROJECT;
|
||||
return NONE;
|
||||
}
|
||||
}
|
||||
|
||||
private static ExtensionPointType isExtensionPointNameDeclarationField(PsiField psiField) {
|
||||
// *do* allow non-public
|
||||
if (!psiField.hasModifierProperty(PsiModifier.FINAL) ||
|
||||
!psiField.hasModifierProperty(PsiModifier.STATIC) ||
|
||||
psiField.hasModifierProperty(PsiModifier.ABSTRACT)) {
|
||||
return false;
|
||||
return ExtensionPointType.NONE;
|
||||
}
|
||||
|
||||
if (!psiField.hasInitializer()) {
|
||||
return false;
|
||||
return ExtensionPointType.NONE;
|
||||
}
|
||||
|
||||
final PsiExpression initializer = psiField.getInitializer();
|
||||
if (!(initializer instanceof PsiMethodCallExpression) &&
|
||||
!(initializer instanceof PsiNewExpression)) {
|
||||
return false;
|
||||
return ExtensionPointType.NONE;
|
||||
}
|
||||
|
||||
final PsiClass fieldClass = PsiTypesUtil.getPsiClass(psiField.getType());
|
||||
if (fieldClass == null) {
|
||||
return false;
|
||||
return ExtensionPointType.NONE;
|
||||
}
|
||||
|
||||
return ExtensionPointName.class.getName().equals(fieldClass.getQualifiedName());
|
||||
final String qualifiedClassName = fieldClass.getQualifiedName();
|
||||
return ExtensionPointType.find(qualifiedClassName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
import com.intellij.openapi.extensions.ProjectExtensionPointName;
|
||||
|
||||
import java.lang.String;
|
||||
|
||||
public class MyStringEP {
|
||||
|
||||
public static final ProjectExtensionPointName<String> EP_<caret>NAME =
|
||||
new ProjectExtensionPointName<>("com.intellij.myStringEP");
|
||||
|
||||
}
|
||||
@@ -58,6 +58,10 @@ public class ExtensionPointDeclarationRelatedItemLineMarkerProviderTest extends
|
||||
assertSingleEPDeclaration("MyStringEPConstructor.java");
|
||||
}
|
||||
|
||||
public void testMyStringProjectEP() {
|
||||
assertSingleEPDeclaration("MyStringProjectEP.java");
|
||||
}
|
||||
|
||||
private void assertSingleEPDeclaration(String filePath) {
|
||||
PsiFile file = myFixture.configureByFile("plugin.xml");
|
||||
String path = file.getVirtualFile().getPath();
|
||||
|
||||
Reference in New Issue
Block a user