initial implementation of showing coverage data in IDE

This commit is contained in:
Dmitry Jemerov
2014-12-05 21:29:09 +01:00
parent 8f2092fe79
commit 052c0e60a4
5 changed files with 103 additions and 0 deletions
+11
View File
@@ -0,0 +1,11 @@
<component name="libraryTable">
<library name="coverage-plugin">
<CLASSES>
<root url="jar://$PROJECT_DIR$/ideaSDK/plugins/coverage/lib/coverage.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$PROJECT_DIR$/ideaSDK/sources/sources.zip!/plugins/coverage/src" />
</SOURCES>
</library>
</component>
+1
View File
@@ -44,5 +44,6 @@
<orderEntry type="module" module-name="idea-analysis" exported="" />
<orderEntry type="module" module-name="kotlin-android-plugin" />
<orderEntry type="module" module-name="js.frontend" />
<orderEntry type="library" scope="PROVIDED" name="coverage-plugin" level="project" />
</component>
</module>
+5
View File
@@ -0,0 +1,5 @@
<idea-plugin>
<extensions defaultExtensionNs="com.intellij">
<javaCoverageEngineExtension implementation="org.jetbrains.jet.plugin.coverage.KotlinCoverageExtension"/>
</extensions>
</idea-plugin>
+1
View File
@@ -15,6 +15,7 @@
<depends optional="true" config-file="kotlin-copyright.xml">com.intellij.copyright</depends>
<depends optional="true" config-file="javaScriptDebug.xml">JavaScriptDebugger</depends>
<depends optional="true" config-file="android.xml">org.jetbrains.android</depends>
<depends optional="true" config-file="coverage.xml">Coverage</depends>
<project-components>
<component>
@@ -0,0 +1,85 @@
/*
* 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.coverage
import com.intellij.coverage.JavaCoverageEngineExtension
import com.intellij.execution.configurations.RunConfigurationBase
import org.jetbrains.jet.plugin.run.JetRunConfiguration
import com.intellij.psi.PsiFile
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.coverage.CoverageSuitesBundle
import java.io.File
import org.jetbrains.jet.lang.psi.JetFile
import org.jetbrains.jet.plugin.debugger.JetPositionManager
import org.jetbrains.jet.plugin.caches.resolve.getModuleInfo
import java.util.HashSet
import org.jetbrains.jet.lang.psi.JetTreeVisitor
import org.jetbrains.jet.lang.psi.JetDeclaration
import com.intellij.openapi.roots.ProjectRootManager
import org.jetbrains.jet.lang.psi.JetTreeVisitorVoid
import org.jetbrains.annotations.TestOnly
import com.intellij.openapi.application.ApplicationManager
public class KotlinCoverageExtension(): JavaCoverageEngineExtension() {
override fun isApplicableTo(conf: RunConfigurationBase?): Boolean = conf is JetRunConfiguration
override fun collectOutputFiles(srcFile: PsiFile,
output: VirtualFile?,
testoutput: VirtualFile?,
suite: CoverageSuitesBundle,
classFiles: MutableSet<File>): Boolean {
if (srcFile is JetFile) {
val fileIndex = ProjectRootManager.getInstance(srcFile.getProject()).getFileIndex()
if (fileIndex.isInLibraryClasses(srcFile.getVirtualFile()) ||
fileIndex.isInLibrarySource(srcFile.getVirtualFile())) {
return false
}
val classNames = ApplicationManager.getApplication().runReadAction<Set<String>> { collectOutputClassNames(srcFile) }
fun findUnder(name: String, root: VirtualFile?): File? {
if (root != null) {
val outputFile = File(root.getPath(), name + ".class")
if (outputFile.exists()) {
return outputFile
}
}
return null
}
classNames.map { findUnder(it, output) ?: findUnder(it, testoutput) }.filterNotNullTo(classFiles)
return true
}
return false
}
class object {
TestOnly public fun collectOutputClassNames(srcFile: JetFile): Set<String> {
val typeMapper = JetPositionManager.createTypeMapper(srcFile, srcFile.getModuleInfo())
val classNames = HashSet<String>()
srcFile.acceptChildren(object: JetTreeVisitorVoid() {
override fun visitDeclaration(dcl: JetDeclaration) {
val className = JetPositionManager.getClassNameForElement(dcl.getFirstChild(), typeMapper, srcFile, false)
if (className != null) {
classNames.add(className)
}
}
})
return classNames
}
}
}