From 6d489a50cb2ea45650e1b7ba49f1ac56ccd54169 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Mon, 7 May 2012 23:01:01 +0400 Subject: [PATCH] Implemented "Go to type declaration" for Kotlin entities. #KT-1318 fixed --- idea/src/META-INF/plugin.xml | 1 + .../JetTypeDeclarationProvider.java | 57 +++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 idea/src/org/jetbrains/jet/plugin/codeInsight/JetTypeDeclarationProvider.java diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml index fefdb5730f5..c04ae767ba5 100644 --- a/idea/src/META-INF/plugin.xml +++ b/idea/src/META-INF/plugin.xml @@ -92,6 +92,7 @@ + diff --git a/idea/src/org/jetbrains/jet/plugin/codeInsight/JetTypeDeclarationProvider.java b/idea/src/org/jetbrains/jet/plugin/codeInsight/JetTypeDeclarationProvider.java new file mode 100644 index 00000000000..ee4636819d1 --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/codeInsight/JetTypeDeclarationProvider.java @@ -0,0 +1,57 @@ +/* + * Copyright 2010-2012 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.jet.plugin.codeInsight; + +import com.intellij.codeInsight.navigation.actions.TypeDeclarationProvider; +import com.intellij.psi.PsiElement; +import org.jetbrains.jet.lang.descriptors.CallableDescriptor; +import org.jetbrains.jet.lang.descriptors.ClassifierDescriptor; +import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor; +import org.jetbrains.jet.lang.psi.JetElement; +import org.jetbrains.jet.lang.psi.JetFile; +import org.jetbrains.jet.lang.resolve.BindingContext; +import org.jetbrains.jet.lang.resolve.BindingContextUtils; +import org.jetbrains.jet.lang.types.JetType; +import org.jetbrains.jet.plugin.project.WholeProjectAnalyzerFacade; + +/** + * @author Evgeny Gerashchenko + * @since 07.05.12 + */ +public class JetTypeDeclarationProvider implements TypeDeclarationProvider { + @Override + public PsiElement[] getSymbolTypeDeclarations(PsiElement symbol) { + if (symbol instanceof JetElement && symbol.getContainingFile() instanceof JetFile) { + BindingContext bindingContext = + WholeProjectAnalyzerFacade.analyzeProjectWithCacheOnAFile((JetFile) symbol.getContainingFile()).getBindingContext(); + DeclarationDescriptor descriptor = bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, symbol); + if (descriptor instanceof CallableDescriptor) { + JetType type = ((CallableDescriptor) descriptor).getReturnType(); + if (type != null) { + ClassifierDescriptor classifierDescriptor = type.getConstructor().getDeclarationDescriptor(); + if (classifierDescriptor != null) { + PsiElement typeElement = BindingContextUtils.descriptorToDeclaration(bindingContext, classifierDescriptor); + if (typeElement != null) { + return new PsiElement[] {typeElement}; + } + } + } + } + } + return new PsiElement[0]; + } +}