code review
This commit is contained in:
@@ -35,6 +35,7 @@ import org.jetbrains.annotations.TestOnly
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import org.jetbrains.jet.lang.psi.JetFunctionLiteralExpression
|
||||
import com.intellij.psi.PsiElement
|
||||
import java.util.LinkedHashSet
|
||||
|
||||
public class KotlinCoverageExtension(): JavaCoverageEngineExtension() {
|
||||
override fun isApplicableTo(conf: RunConfigurationBase?): Boolean = conf is JetRunConfiguration
|
||||
@@ -70,9 +71,9 @@ public class KotlinCoverageExtension(): JavaCoverageEngineExtension() {
|
||||
}
|
||||
|
||||
class object {
|
||||
TestOnly public fun collectOutputClassNames(srcFile: JetFile): Set<String> {
|
||||
public fun collectOutputClassNames(srcFile: JetFile): Set<String> {
|
||||
val typeMapper = JetPositionManager.createTypeMapper(srcFile, srcFile.getModuleInfo())
|
||||
val classNames = HashSet<String>()
|
||||
val classNames = LinkedHashSet<String>()
|
||||
srcFile.acceptChildren(object: JetTreeVisitorVoid() {
|
||||
override fun visitDeclaration(dcl: JetDeclaration) {
|
||||
super.visitDeclaration(dcl)
|
||||
|
||||
@@ -69,6 +69,7 @@ import org.jetbrains.jet.codegen.binding.CodegenBinding.asmTypeForAnonymousClass
|
||||
import org.jetbrains.jet.plugin.stubindex.PackageIndexUtil
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor
|
||||
import com.intellij.psi.stubs.StubElement
|
||||
import org.jetbrains.jet.plugin.util.application.runReadAction
|
||||
|
||||
public class JetPositionManager(private val myDebugProcess: DebugProcess) : PositionManager {
|
||||
private val myTypeMappers = WeakHashMap<Pair<FqName, IdeaModuleInfo>, CachedValue<JetTypeMapper>>()
|
||||
@@ -82,12 +83,11 @@ public class JetPositionManager(private val myDebugProcess: DebugProcess) : Posi
|
||||
throw NoDataException()
|
||||
}
|
||||
|
||||
val lineNumber: Int
|
||||
try {
|
||||
lineNumber = location.lineNumber() - 1
|
||||
val lineNumber = try {
|
||||
location.lineNumber() - 1
|
||||
}
|
||||
catch (e: InternalError) {
|
||||
lineNumber = -1
|
||||
-1
|
||||
}
|
||||
|
||||
|
||||
@@ -170,16 +170,12 @@ public class JetPositionManager(private val myDebugProcess: DebugProcess) : Posi
|
||||
}
|
||||
|
||||
private fun classNameForPosition(sourcePosition: SourcePosition): String? {
|
||||
val result = Ref.create<String>()
|
||||
|
||||
ApplicationManager.getApplication().runReadAction {
|
||||
return runReadAction {
|
||||
val file = sourcePosition.getFile() as JetFile
|
||||
val isInLibrary = LibraryUtil.findLibraryEntry(file.getVirtualFile(), file.getProject()) != null
|
||||
val typeMapper = if (!isInLibrary) prepareTypeMapper(file) else createTypeMapperForLibraryFile(sourcePosition.getElementAt(), file)
|
||||
result.set(getClassNameForElement(sourcePosition.getElementAt(), typeMapper, file, isInLibrary))
|
||||
getClassNameForElement(sourcePosition.getElementAt(), typeMapper, file, isInLibrary)
|
||||
}
|
||||
|
||||
return result.get()
|
||||
}
|
||||
|
||||
private fun prepareTypeMapper(file: JetFile): JetTypeMapper {
|
||||
@@ -187,12 +183,11 @@ public class JetPositionManager(private val myDebugProcess: DebugProcess) : Posi
|
||||
|
||||
var value: CachedValue<JetTypeMapper>? = myTypeMappers.get(key)
|
||||
if (value == null) {
|
||||
value = CachedValuesManager.getManager(file.getProject()).createCachedValue<JetTypeMapper>(object : CachedValueProvider<JetTypeMapper> {
|
||||
override fun compute(): CachedValueProvider.Result<JetTypeMapper>? {
|
||||
val typeMapper = createTypeMapper(file, key.second)
|
||||
return CachedValueProvider.Result<JetTypeMapper>(typeMapper, PsiModificationTracker.MODIFICATION_COUNT)
|
||||
}
|
||||
}, false)
|
||||
value = CachedValuesManager.getManager(file.getProject()).createCachedValue<JetTypeMapper>(
|
||||
{() ->
|
||||
val typeMapper = createTypeMapper(file, key.second)
|
||||
CachedValueProvider.Result<JetTypeMapper>(typeMapper, PsiModificationTracker.MODIFICATION_COUNT)
|
||||
}, false)
|
||||
|
||||
myTypeMappers.put(key, value)
|
||||
}
|
||||
@@ -231,10 +226,8 @@ public class JetPositionManager(private val myDebugProcess: DebugProcess) : Posi
|
||||
|
||||
TestOnly
|
||||
public fun addTypeMapper(file: JetFile, typeMapper: JetTypeMapper) {
|
||||
val value = CachedValuesManager.getManager(file.getProject()).createCachedValue<JetTypeMapper>(object : CachedValueProvider<JetTypeMapper> {
|
||||
override fun compute() = CachedValueProvider.Result<JetTypeMapper>(typeMapper, PsiModificationTracker.MODIFICATION_COUNT)
|
||||
}, false)
|
||||
|
||||
val value = CachedValuesManager.getManager(file.getProject()).createCachedValue<JetTypeMapper>(
|
||||
{ () -> CachedValueProvider.Result<JetTypeMapper>(typeMapper, PsiModificationTracker.MODIFICATION_COUNT) }, false)
|
||||
val key = createKeyForTypeMapper(file)
|
||||
myTypeMappers.put(key, value)
|
||||
}
|
||||
@@ -249,10 +242,9 @@ public class JetPositionManager(private val myDebugProcess: DebugProcess) : Posi
|
||||
analysisResult.throwIfError()
|
||||
|
||||
val state = GenerationState(project, ClassBuilderFactories.THROW_EXCEPTION, analysisResult.moduleDescriptor,
|
||||
analysisResult.bindingContext, ArrayList(packageFiles))
|
||||
analysisResult.bindingContext, packageFiles.toList())
|
||||
state.beforeCompile()
|
||||
val typeMapper = state.getTypeMapper()
|
||||
return typeMapper
|
||||
return state.getTypeMapper()
|
||||
}
|
||||
|
||||
public fun getClassNameForElement(notPositionedElement: PsiElement?, typeMapper: JetTypeMapper, file: JetFile, isInLibrary: Boolean): String? {
|
||||
@@ -383,10 +375,7 @@ public class JetPositionManager(private val myDebugProcess: DebugProcess) : Posi
|
||||
val inlineType = InlineUtil.getInlineType(call.getResultingDescriptor())
|
||||
if (!inlineType.isInline()) return false
|
||||
|
||||
for (entry in call.getValueArguments().entrySet()) {
|
||||
val valueParameterDescriptor = entry.getKey()
|
||||
val resolvedValueArgument = entry.getValue()
|
||||
|
||||
for ((valueParameterDescriptor, resolvedValueArgument) in call.getValueArguments()) {
|
||||
for (next in resolvedValueArgument.getArguments()) {
|
||||
val expression = next.getArgumentExpression()
|
||||
if (valueArgument == expression) {
|
||||
|
||||
+3
-3
@@ -25,6 +25,7 @@ import com.intellij.openapi.fileEditor.impl.LoadTextUtil
|
||||
import kotlin.test.assertEquals
|
||||
import java.io.File
|
||||
import com.intellij.testFramework.UsefulTestCase
|
||||
import org.jetbrains.jet.JetTestUtils
|
||||
|
||||
public abstract class AbstractKotlinCoverageOutputFilesTest(): JetLightCodeInsightFixtureTestCase() {
|
||||
private val TEST_DATA_PATH = PluginTestCaseBase.getTestDataPathBase() + "/coverage/outputFiles"
|
||||
@@ -32,9 +33,8 @@ public abstract class AbstractKotlinCoverageOutputFilesTest(): JetLightCodeInsig
|
||||
override fun getTestDataPath(): String? = TEST_DATA_PATH
|
||||
|
||||
public fun doTest(path: String) {
|
||||
var kotlinFile = myFixture.configureByFile(path) as JetFile
|
||||
val kotlinFile = myFixture.configureByFile(path) as JetFile
|
||||
val actualClasses = KotlinCoverageExtension.collectOutputClassNames(kotlinFile)
|
||||
val expectedClasses = FileUtil.loadLines(path.replace(".kt", ".expected.txt"))
|
||||
UsefulTestCase.assertSameElements(actualClasses, expectedClasses)
|
||||
JetTestUtils.assertEqualsToFile(File(path.replace(".kt", ".expected.txt")), actualClasses.join("\n"))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user