mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
EA-222766 support cases when PsiDeclaredTarget#getNavigationElement differs from element which was used to obtain target
GitOrigin-RevId: 7a48175b460115d7bf1862b017d3e89727333e99
This commit is contained in:
committed by
intellij-monorepo-bot
parent
b277b98e36
commit
504b4e9b9a
@@ -4,6 +4,7 @@ package com.intellij.model.psi.impl;
|
||||
import com.intellij.model.Symbol;
|
||||
import com.intellij.model.psi.PsiSymbolDeclaration;
|
||||
import com.intellij.model.psi.PsiSymbolService;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.pom.PomTarget;
|
||||
import com.intellij.pom.PsiDeclaredTarget;
|
||||
@@ -15,6 +16,8 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
class PsiElement2Declaration implements PsiSymbolDeclaration {
|
||||
|
||||
private static final Logger LOG = Logger.getInstance(PsiElement2Declaration.class);
|
||||
|
||||
private final PsiElement myTargetElement;
|
||||
private final PsiElement myDeclaringElement;
|
||||
private final TextRange myDeclarationRange;
|
||||
@@ -82,10 +85,18 @@ class PsiElement2Declaration implements PsiSymbolDeclaration {
|
||||
@NotNull
|
||||
private static TextRange getDeclarationRangeFromPom(@NotNull PomTarget target, @NotNull PsiElement declaringElement) {
|
||||
if (target instanceof PsiDeclaredTarget) {
|
||||
assert ((PsiDeclaredTarget)target).getNavigationElement() == declaringElement;
|
||||
TextRange nameIdentifierRange = ((PsiDeclaredTarget)target).getNameIdentifierRange();
|
||||
PsiDeclaredTarget declaredTarget = (PsiDeclaredTarget)target;
|
||||
TextRange nameIdentifierRange = declaredTarget.getNameIdentifierRange();
|
||||
if (nameIdentifierRange != null) {
|
||||
return nameIdentifierRange;
|
||||
PsiElement navigationElement = declaredTarget.getNavigationElement();
|
||||
if (navigationElement == declaringElement) {
|
||||
return nameIdentifierRange;
|
||||
}
|
||||
else {
|
||||
LOG.assertTrue(navigationElement.getContainingFile() == declaringElement.getContainingFile());
|
||||
int delta = declaringElement.getTextRange().getStartOffset() - navigationElement.getTextRange().getStartOffset();
|
||||
return nameIdentifierRange.shiftLeft(delta);
|
||||
}
|
||||
}
|
||||
}
|
||||
return rangeOf(declaringElement);
|
||||
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
// 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.codeInsight
|
||||
|
||||
import com.intellij.codeInsight.daemon.impl.HighlightInfoType
|
||||
import com.intellij.codeInsight.daemon.impl.IdentifierHighlighterPassFactory
|
||||
import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase
|
||||
import groovy.transform.CompileStatic
|
||||
|
||||
@CompileStatic
|
||||
class PluginXmlIdentifierHighlightingTest extends LightJavaCodeInsightFixtureTestCase {
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp()
|
||||
myFixture.readEditorMarkupModel = true
|
||||
}
|
||||
|
||||
void 'test ep references'() {
|
||||
myFixture.configureByText 'plugin.xml', '''\
|
||||
<idea-plugin>
|
||||
<extensionPoints>
|
||||
<extensionPoint name="foo<caret>.bar"/>
|
||||
</extensionPoints>
|
||||
<extensions>
|
||||
<foo.bar/>
|
||||
</extensions>
|
||||
</idea-plugin>
|
||||
'''
|
||||
IdentifierHighlighterPassFactory.doWithHighlightingEnabled {
|
||||
def infos = myFixture.doHighlighting()
|
||||
assert infos.findAll {
|
||||
it.severity == HighlightInfoType.ELEMENT_UNDER_CARET_SEVERITY
|
||||
}.size() == 2
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user