1717package org.jetbrains.kotlin.ui.editors.codeassist
1818
1919import com.intellij.psi.PsiElement
20+ import com.intellij.psi.PsiFile
2021import com.intellij.psi.util.PsiTreeUtil
2122import org.eclipse.jdt.core.IJavaProject
2223import org.eclipse.jdt.internal.ui.JavaPlugin
@@ -35,10 +36,8 @@ import org.eclipse.jface.text.contentassist.IContextInformation
3536import org.eclipse.jface.text.contentassist.IContextInformationValidator
3637import org.eclipse.jface.text.templates.TemplateContext
3738import org.eclipse.jface.text.templates.TemplateProposal
38- import org.jetbrains.kotlin.core.log.KotlinLogger
3939import org.jetbrains.kotlin.descriptors.ClassDescriptor
4040import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
41- import org.jetbrains.kotlin.eclipse.ui.utils.EditorUtil
4241import org.jetbrains.kotlin.eclipse.ui.utils.KotlinImageProvider
4342import org.jetbrains.kotlin.idea.util.CallTypeAndReceiver
4443import org.jetbrains.kotlin.name.Name
@@ -107,8 +106,8 @@ class KotlinCompletionProcessor(
107106 }
108107 if (psiElement != null ) {
109108 addAll(generateKeywordProposals(identifierPart, psiElement))
109+ addAll(generateTemplateProposals(psiElement.containingFile, viewer, offset, identifierPart))
110110 }
111- addAll(generateTemplateProposals(viewer, offset, identifierPart))
112111 }
113112 }
114113
@@ -163,14 +162,10 @@ class KotlinCompletionProcessor(
163162 }
164163 }
165164
166- private fun generateTemplateProposals (viewer : ITextViewer , offset : Int , identifierPart : String ): List <ICompletionProposal > {
167- val file = editor.eclipseFile
168- if (file == null ) {
169- KotlinLogger .logError(" Failed to retrieve IFile from editor $editor " , null )
170- return emptyList()
171- }
165+ private fun generateTemplateProposals (
166+ psiFile : PsiFile , viewer : ITextViewer , offset : Int , identifierPart : String ): List <ICompletionProposal > {
172167
173- val contextTypeIds = KotlinApplicableTemplateContext .getApplicableContextTypeIds(viewer, file , offset - identifierPart.length)
168+ val contextTypeIds = KotlinApplicableTemplateContext .getApplicableContextTypeIds(viewer, psiFile , offset - identifierPart.length)
174169 val region = Region (offset - identifierPart.length, identifierPart.length)
175170
176171 val templateIcon = JavaPluginImages .get(JavaPluginImages .IMG_OBJS_TEMPLATE )
0 commit comments