diff --git a/idea/idea-analysis/src/org/jetbrains/jet/plugin/codeInsight/DescriptorToDeclarationUtil.java b/idea/idea-analysis/src/org/jetbrains/jet/plugin/codeInsight/DescriptorToDeclarationUtil.java deleted file mode 100644 index 24878e803d2..00000000000 --- a/idea/idea-analysis/src/org/jetbrains/jet/plugin/codeInsight/DescriptorToDeclarationUtil.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright 2010-2013 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.openapi.project.Project; -import com.intellij.psi.PsiElement; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor; -import org.jetbrains.jet.lang.psi.JetDeclaration; -import org.jetbrains.jet.lang.psi.JetFile; -import org.jetbrains.jet.lang.resolve.DescriptorToSourceUtils; -import org.jetbrains.jet.plugin.libraries.DecompiledNavigationUtils; -import org.jetbrains.jet.plugin.references.BuiltInsReferenceResolver; - -import java.util.Collection; -import java.util.Collections; - -public final class DescriptorToDeclarationUtil { - private DescriptorToDeclarationUtil() { - } - - @Nullable - public static PsiElement getDeclaration(@NotNull JetFile file, @NotNull DeclarationDescriptor descriptor) { - return getDeclaration(file.getProject(), descriptor); - } - - @Nullable - public static PsiElement getDeclaration(@NotNull Project project, @NotNull DeclarationDescriptor descriptor) { - Collection elements = DescriptorToSourceUtils.descriptorToDeclarations(descriptor); - if (elements.isEmpty()) { - elements = findDecompiledAndBuiltInDeclarations(project, descriptor); - } - if (!elements.isEmpty()) { - return elements.iterator().next(); - } - return null; - } - - @NotNull - public static Collection findDecompiledAndBuiltInDeclarations( - @NotNull Project project, - @NotNull DeclarationDescriptor descriptor - ) { - BuiltInsReferenceResolver libraryReferenceResolver = project.getComponent(BuiltInsReferenceResolver.class); - Collection elements = libraryReferenceResolver.resolveBuiltInSymbol(descriptor); - if (!elements.isEmpty()) { - return elements; - } - - JetDeclaration decompiledDeclaration = DecompiledNavigationUtils.findDeclarationForReference(project, descriptor); - if (decompiledDeclaration != null) { - return Collections.singleton(decompiledDeclaration); - } - return Collections.emptySet(); - } -} diff --git a/idea/idea-analysis/src/org/jetbrains/jet/plugin/codeInsight/DescriptorToDeclarationUtil.kt b/idea/idea-analysis/src/org/jetbrains/jet/plugin/codeInsight/DescriptorToDeclarationUtil.kt new file mode 100644 index 00000000000..5649327ca30 --- /dev/null +++ b/idea/idea-analysis/src/org/jetbrains/jet/plugin/codeInsight/DescriptorToDeclarationUtil.kt @@ -0,0 +1,54 @@ +/* + * Copyright 2010-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. + */ + +package org.jetbrains.jet.plugin.codeInsight + +import org.jetbrains.jet.lang.psi.JetFile +import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor +import com.intellij.psi.PsiElement +import com.intellij.openapi.project.Project +import org.jetbrains.jet.lang.resolve.DescriptorToSourceUtils +import org.jetbrains.jet.plugin.references.BuiltInsReferenceResolver +import org.jetbrains.jet.plugin.libraries.DecompiledNavigationUtils + +object DescriptorToDeclarationUtil { + public fun getDeclaration(file: JetFile, descriptor: DeclarationDescriptor): PsiElement? { + return getDeclaration(file.getProject(), descriptor) + } + + public fun getDeclaration(project: Project, descriptor: DeclarationDescriptor): PsiElement? { + var elements: Collection = DescriptorToSourceUtils.descriptorToDeclarations(descriptor) + if (elements.isEmpty()) { + elements = findDecompiledAndBuiltInDeclarations(project, descriptor) + } + + return elements.firstOrNull() + } + + public fun findDecompiledAndBuiltInDeclarations(project: Project, descriptor: DeclarationDescriptor): Collection { + val libraryReferenceResolver = project.getComponent(javaClass()) + val elements = libraryReferenceResolver!!.resolveBuiltInSymbol(descriptor) + if (!elements.isEmpty()) { + return elements + } + + val decompiledDeclaration = DecompiledNavigationUtils.findDeclarationForReference(project, descriptor) + if (decompiledDeclaration != null) { + return setOf(decompiledDeclaration) + } + return setOf() + } +} \ No newline at end of file diff --git a/idea/src/org/jetbrains/jet/plugin/actions/JetAddFunctionToClassifierAction.java b/idea/src/org/jetbrains/jet/plugin/actions/JetAddFunctionToClassifierAction.java index 368fceabe8a..8bf6a14bd32 100644 --- a/idea/src/org/jetbrains/jet/plugin/actions/JetAddFunctionToClassifierAction.java +++ b/idea/src/org/jetbrains/jet/plugin/actions/JetAddFunctionToClassifierAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2013 JetBrains s.r.o. + * Copyright 2010-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. @@ -80,7 +80,7 @@ public class JetAddFunctionToClassifierAction implements QuestionAction { PsiDocumentManager.getInstance(project).commitAllDocuments(); - final JetClass classifierDeclaration = (JetClass) DescriptorToDeclarationUtil.getDeclaration(project, typeDescriptor); + final JetClass classifierDeclaration = (JetClass) DescriptorToDeclarationUtil.INSTANCE$.getDeclaration(project, typeDescriptor); CommandProcessor.getInstance().executeCommand(project, new Runnable() { @Override public void run() { diff --git a/idea/src/org/jetbrains/jet/plugin/codeInsight/OverrideImplementMethodsHandler.java b/idea/src/org/jetbrains/jet/plugin/codeInsight/OverrideImplementMethodsHandler.java index 142103d0ba2..fd7e64f74f3 100644 --- a/idea/src/org/jetbrains/jet/plugin/codeInsight/OverrideImplementMethodsHandler.java +++ b/idea/src/org/jetbrains/jet/plugin/codeInsight/OverrideImplementMethodsHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2013 JetBrains s.r.o. + * Copyright 2010-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. @@ -63,7 +63,7 @@ public abstract class OverrideImplementMethodsHandler implements LanguageCodeIns ) { List members = new ArrayList(); for (CallableMemberDescriptor memberDescriptor : missingImplementations) { - PsiElement declaration = DescriptorToDeclarationUtil.getDeclaration(file, memberDescriptor); + PsiElement declaration = DescriptorToDeclarationUtil.INSTANCE$.getDeclaration(file, memberDescriptor); if (declaration == null) { LOG.error("Can not find declaration for descriptor " + memberDescriptor); } diff --git a/idea/src/org/jetbrains/jet/plugin/refactoring/JetRefactoringUtil.java b/idea/src/org/jetbrains/jet/plugin/refactoring/JetRefactoringUtil.java index 7756a46e73c..72f2e17a697 100644 --- a/idea/src/org/jetbrains/jet/plugin/refactoring/JetRefactoringUtil.java +++ b/idea/src/org/jetbrains/jet/plugin/refactoring/JetRefactoringUtil.java @@ -137,7 +137,7 @@ public class JetRefactoringUtil { Project project = declaration.getProject(); Map overriddenElementsToDescriptor = new HashMap(); for (CallableDescriptor overriddenDescriptor : OverrideResolver.getAllOverriddenDescriptors(declarationDescriptor)) { - PsiElement overriddenDeclaration = DescriptorToDeclarationUtil.getDeclaration(project, overriddenDescriptor); + PsiElement overriddenDeclaration = DescriptorToDeclarationUtil.INSTANCE$.getDeclaration(project, overriddenDescriptor); if (PsiTreeUtil.instanceOf(overriddenDeclaration, JetNamedFunction.class, JetProperty.class, PsiMethod.class)) { overriddenElementsToDescriptor.put(overriddenDeclaration, overriddenDescriptor); } diff --git a/idea/src/org/jetbrains/jet/plugin/refactoring/changeSignature/JetChangeSignatureData.java b/idea/src/org/jetbrains/jet/plugin/refactoring/changeSignature/JetChangeSignatureData.java index 86545e47663..50ff6f7a3ed 100644 --- a/idea/src/org/jetbrains/jet/plugin/refactoring/changeSignature/JetChangeSignatureData.java +++ b/idea/src/org/jetbrains/jet/plugin/refactoring/changeSignature/JetChangeSignatureData.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2013 JetBrains s.r.o. + * Copyright 2010-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. @@ -105,7 +105,7 @@ public final class JetChangeSignatureData implements JetMethodDescriptor { @NotNull private Collection computeHierarchyFrom(@NotNull FunctionDescriptor baseDescriptor) { - PsiElement declaration = DescriptorToDeclarationUtil.getDeclaration(baseDeclaration.getProject(), baseDescriptor); + PsiElement declaration = DescriptorToDeclarationUtil.INSTANCE$.getDeclaration(baseDeclaration.getProject(), baseDescriptor); Set result = Sets.newHashSet(); result.add(declaration); if (!(declaration instanceof JetNamedFunction)) {