Converter: use ide resolve through a dedicated interface
Eliminate direct usages of ResolveSession
This commit is contained in:
@@ -38,9 +38,9 @@ import org.jetbrains.jet.plugin.j2k.J2kPostProcessor
|
||||
import com.intellij.openapi.vfs.CharsetToolkit
|
||||
import org.jetbrains.jet.lang.psi.JetFile
|
||||
import org.jetbrains.jet.utils.addIfNotNull
|
||||
import org.jetbrains.jet.plugin.caches.resolve.getLazyResolveSession
|
||||
import com.intellij.openapi.vfs.VfsUtilCore
|
||||
import com.intellij.openapi.vfs.VirtualFileVisitor
|
||||
import org.jetbrains.jet.plugin.j2k.IdeaResolverForConverter
|
||||
|
||||
public class JavaToKotlinAction : AnAction() {
|
||||
override fun actionPerformed(e: AnActionEvent) {
|
||||
@@ -104,7 +104,7 @@ public class JavaToKotlinAction : AnAction() {
|
||||
}
|
||||
|
||||
private fun convertFiles(javaFiles: List<PsiJavaFile>, project: Project): List<VirtualFile> {
|
||||
val converter = JavaToKotlinConverter(project, ConverterSettings.defaultSettings, FilesConversionScope(javaFiles), IdeaReferenceSearcher, { it.getLazyResolveSession() })
|
||||
val converter = JavaToKotlinConverter(project, ConverterSettings.defaultSettings, FilesConversionScope(javaFiles), IdeaReferenceSearcher, IdeaResolverForConverter)
|
||||
|
||||
val convertedTexts = converter.elementsToKotlin(javaFiles.map { it to J2kPostProcessor(it) })
|
||||
|
||||
|
||||
+8
-6
@@ -34,7 +34,7 @@ import com.intellij.openapi.util.TextRange
|
||||
import com.intellij.psi.codeStyle.CodeStyleManager
|
||||
import com.intellij.lang.java.JavaLanguage
|
||||
import org.jetbrains.jet.plugin.j2k.J2kPostProcessor
|
||||
import org.jetbrains.jet.plugin.caches.resolve.getLazyResolveSession
|
||||
import org.jetbrains.jet.plugin.j2k.IdeaResolverForConverter
|
||||
|
||||
public class ConvertJavaCopyPastePostProcessor() : CopyPastePostProcessor<TextBlockTransferableData>() {
|
||||
|
||||
@@ -87,11 +87,13 @@ public class ConvertJavaCopyPastePostProcessor() : CopyPastePostProcessor<TextBl
|
||||
}
|
||||
|
||||
private fun convertCopiedCodeToKotlin(code: CopiedCode, fileCopiedFrom: PsiJavaFile, fileCopiedTo: JetFile): String {
|
||||
val converter = JavaToKotlinConverter(fileCopiedFrom.getProject(),
|
||||
ConverterSettings.defaultSettings,
|
||||
FilesConversionScope(listOf(fileCopiedFrom)),
|
||||
IdeaReferenceSearcher,
|
||||
{ it.getLazyResolveSession() })
|
||||
val converter = JavaToKotlinConverter(
|
||||
fileCopiedFrom.getProject(),
|
||||
ConverterSettings.defaultSettings,
|
||||
FilesConversionScope(listOf(fileCopiedFrom)),
|
||||
IdeaReferenceSearcher,
|
||||
IdeaResolverForConverter
|
||||
)
|
||||
val startOffsets = code.startOffsets
|
||||
val endOffsets = code.endOffsets
|
||||
assert(startOffsets.size == endOffsets.size) { "Must have the same size" }
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* 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.j2k
|
||||
|
||||
import org.jetbrains.jet.j2k.ResolverForConverter
|
||||
import org.jetbrains.jet.plugin.caches.resolve.getLazyResolveSession
|
||||
import org.jetbrains.jet.lang.psi.JetDeclaration
|
||||
|
||||
public object IdeaResolverForConverter: ResolverForConverter {
|
||||
override fun resolveToDescriptor(declaration: JetDeclaration) = declaration.getLazyResolveSession().resolveToDescriptor(declaration)
|
||||
}
|
||||
Reference in New Issue
Block a user