ed9b1ac151
Spring Support: Implement Spring-specific references
62 lines
2.4 KiB
Java
62 lines
2.4 KiB
Java
/*
|
|
* Copyright 2010-2015 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.kotlin.test;
|
|
|
|
import com.intellij.navigation.ItemPresentation;
|
|
import com.intellij.navigation.NavigationItem;
|
|
import com.intellij.psi.PsiAnonymousClass;
|
|
import com.intellij.psi.PsiElement;
|
|
import com.intellij.psi.PsiPackage;
|
|
import com.intellij.psi.util.PsiTreeUtil;
|
|
import org.jetbrains.annotations.NotNull;
|
|
import org.jetbrains.kotlin.psi.KtClass;
|
|
import org.jetbrains.kotlin.psi.KtObjectDeclaration;
|
|
import org.junit.Assert;
|
|
|
|
public final class ReferenceUtils {
|
|
private ReferenceUtils() {
|
|
}
|
|
|
|
public static String renderAsGotoImplementation(@NotNull PsiElement element) {
|
|
PsiElement navigationElement = element.getNavigationElement();
|
|
|
|
if (navigationElement instanceof KtObjectDeclaration && ((KtObjectDeclaration) navigationElement).isCompanion()) {
|
|
//default presenter return null for companion object
|
|
KtClass containingClass = PsiTreeUtil.getParentOfType(navigationElement, KtClass.class);
|
|
assert containingClass != null;
|
|
return "companion object of " + renderAsGotoImplementation(containingClass);
|
|
}
|
|
|
|
Assert.assertTrue(navigationElement instanceof NavigationItem);
|
|
ItemPresentation presentation = ((NavigationItem) navigationElement).getPresentation();
|
|
|
|
if (presentation == null) {
|
|
return element.getText();
|
|
}
|
|
|
|
String presentableText = presentation.getPresentableText();
|
|
String locationString = presentation.getLocationString();
|
|
if (locationString == null && element.getParent() instanceof PsiAnonymousClass) {
|
|
locationString = "<anonymous>";
|
|
}
|
|
return locationString == null || navigationElement instanceof PsiPackage
|
|
// for PsiPackage, presentableText is FQ name of current package
|
|
? presentableText
|
|
: locationString + "." + presentableText;
|
|
}
|
|
}
|