mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-03-12 00:21:27 +00:00
Compare commits
212 Commits
rr/faster_
...
master_as3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c44df5540e | ||
|
|
b9070b69f8 | ||
|
|
71e650513c | ||
|
|
e3a3624162 | ||
|
|
189076a5bb | ||
|
|
78aaa4dae6 | ||
|
|
29ad09088a | ||
|
|
6616febfa7 | ||
|
|
e26bd24e30 | ||
|
|
7eaec8a4b4 | ||
|
|
296c63d8ec | ||
|
|
f93e7739fd | ||
|
|
a5c8f8b5b3 | ||
|
|
848042a21e | ||
|
|
0d591f8607 | ||
|
|
0d75d096b6 | ||
|
|
951ffc124a | ||
|
|
64978a88dd | ||
|
|
729645ca78 | ||
|
|
ade37c16b6 | ||
|
|
1af8c9ba68 | ||
|
|
c5c70252af | ||
|
|
b48000fb45 | ||
|
|
14abbddab8 | ||
|
|
66e446973a | ||
|
|
fec652cf70 | ||
|
|
00b550fc81 | ||
|
|
d20f1e6652 | ||
|
|
144583dd63 | ||
|
|
45aeae2ab3 | ||
|
|
0563bf8586 | ||
|
|
df1cfe1494 | ||
|
|
17a70f0be6 | ||
|
|
22404acde3 | ||
|
|
80fa987c84 | ||
|
|
51f96b2534 | ||
|
|
567a9e6d3d | ||
|
|
0e1c2f75d6 | ||
|
|
7c1d17201f | ||
|
|
450ba36445 | ||
|
|
8f6e3499db | ||
|
|
3d3a7b9118 | ||
|
|
30cd5055e5 | ||
|
|
0bcf74885a | ||
|
|
21340b3121 | ||
|
|
cda0973a0a | ||
|
|
d90788ea73 | ||
|
|
65ce1fe992 | ||
|
|
b217a04268 | ||
|
|
695deb30b1 | ||
|
|
2bb3e4092e | ||
|
|
f2a0e97b1b | ||
|
|
76d41fb630 | ||
|
|
0baa79a090 | ||
|
|
bf07c37b95 | ||
|
|
5ed17d276b | ||
|
|
fabecf1848 | ||
|
|
b64f832149 | ||
|
|
f3209f5589 | ||
|
|
1ccdcd7cf5 | ||
|
|
66f18c7865 | ||
|
|
6e2a773222 | ||
|
|
cde4590e09 | ||
|
|
5035c9fa54 | ||
|
|
f56867fc3b | ||
|
|
8bcfcc4d78 | ||
|
|
cf6641693e | ||
|
|
39dbd25ea7 | ||
|
|
26bedccc28 | ||
|
|
0836fe199b | ||
|
|
5c236caef5 | ||
|
|
2c24e81aef | ||
|
|
46592f860f | ||
|
|
df7f9007c2 | ||
|
|
1916415ae1 | ||
|
|
53886f8eb8 | ||
|
|
f0c5a8aacf | ||
|
|
0047a8d0b8 | ||
|
|
2c72862eb5 | ||
|
|
97cb8d126c | ||
|
|
97d2430260 | ||
|
|
c89eeb579d | ||
|
|
e55bd30b75 | ||
|
|
3fae3132ef | ||
|
|
7ee8d49d6a | ||
|
|
69a623d596 | ||
|
|
5463e3531d | ||
|
|
c413c9bafb | ||
|
|
235963ea3f | ||
|
|
f57e70a3d2 | ||
|
|
ff9564685a | ||
|
|
52a738ac0f | ||
|
|
add5f0fdd3 | ||
|
|
68c6681cb8 | ||
|
|
b6544fbd53 | ||
|
|
b1c39f33aa | ||
|
|
a9a1696e35 | ||
|
|
2f35ad5f10 | ||
|
|
ad73d21c8b | ||
|
|
37acd0f9f4 | ||
|
|
f3ae8cdc2d | ||
|
|
599011cea6 | ||
|
|
4d917db729 | ||
|
|
5ef8849607 | ||
|
|
79ce15d9aa | ||
|
|
e74a7d93d9 | ||
|
|
58b18c5617 | ||
|
|
6189b60c9a | ||
|
|
1cf039e8bc | ||
|
|
968c857933 | ||
|
|
b8d1805b24 | ||
|
|
c10c23567a | ||
|
|
b3ad8dd9d9 | ||
|
|
5c27501c0c | ||
|
|
66a2538082 | ||
|
|
f157c2527f | ||
|
|
266fe49e18 | ||
|
|
4870d1d2de | ||
|
|
29fdbe53fe | ||
|
|
e5ef0ed62c | ||
|
|
06bf92e78c | ||
|
|
d529c253ed | ||
|
|
718e68ac77 | ||
|
|
889e27801f | ||
|
|
0a907f5ba4 | ||
|
|
3068461f90 | ||
|
|
1f7758cd74 | ||
|
|
3f1cbf8391 | ||
|
|
d52b4c9d17 | ||
|
|
9130222b5e | ||
|
|
ff6354fb2c | ||
|
|
5f76dcc45f | ||
|
|
e4a322a29b | ||
|
|
12592bb76d | ||
|
|
ba655ad59d | ||
|
|
a919601f9a | ||
|
|
1c3672cb88 | ||
|
|
0dd5df8163 | ||
|
|
40cfa186e0 | ||
|
|
2002449917 | ||
|
|
8ab85f3138 | ||
|
|
69250f4ef6 | ||
|
|
dfe77c0723 | ||
|
|
6c578275a9 | ||
|
|
c78da40bec | ||
|
|
df3977bf83 | ||
|
|
14c80a5e01 | ||
|
|
b54a476dc2 | ||
|
|
a715d666b7 | ||
|
|
fe33d8c1a7 | ||
|
|
45596b8260 | ||
|
|
e2010af17d | ||
|
|
e1893cc49b | ||
|
|
180822cb22 | ||
|
|
f1f5d64324 | ||
|
|
183277c585 | ||
|
|
7ee877f5b9 | ||
|
|
443a77db67 | ||
|
|
a1c84c0aae | ||
|
|
5bf610b933 | ||
|
|
544720953b | ||
|
|
7295035179 | ||
|
|
737a59749e | ||
|
|
fbf5b9518e | ||
|
|
41756d8887 | ||
|
|
2a5e50c137 | ||
|
|
8010b37be6 | ||
|
|
6e8960c1f1 | ||
|
|
60e703b44d | ||
|
|
2d463d3de6 | ||
|
|
2b8de185de | ||
|
|
3553ab13ac | ||
|
|
d0e40712f6 | ||
|
|
a4867f3c2b | ||
|
|
bfd9e9f51f | ||
|
|
2c998fb6a8 | ||
|
|
e13ccd4a23 | ||
|
|
d57c1ccc4b | ||
|
|
642bee1d37 | ||
|
|
5967d53b97 | ||
|
|
e3119a3eac | ||
|
|
dce6f728ab | ||
|
|
3d1b7080c8 | ||
|
|
50d9dd23cf | ||
|
|
c21ef998a8 | ||
|
|
cd07fce0e0 | ||
|
|
4b244f8b37 | ||
|
|
6afe378542 | ||
|
|
0a8bd2025a | ||
|
|
8cfa2c101e | ||
|
|
e4add32f5a | ||
|
|
1aa096bcea | ||
|
|
810c0fecdf | ||
|
|
c03f990b9c | ||
|
|
16778b2710 | ||
|
|
4341913fd8 | ||
|
|
3ea1541f8e | ||
|
|
7211a9277d | ||
|
|
176828d621 | ||
|
|
e7ee045ba2 | ||
|
|
8afd1ba794 | ||
|
|
333288c475 | ||
|
|
6504b7ee20 | ||
|
|
0f4ea105ab | ||
|
|
5ad86b7bfc | ||
|
|
8d7a07271f | ||
|
|
0a4efa54da | ||
|
|
d077d5add7 | ||
|
|
8a6db402d6 | ||
|
|
628ef645b4 | ||
|
|
5cac1e218f | ||
|
|
14fbe38a3e |
@@ -118,4 +118,27 @@
|
||||
<fail message="Either specify pre_build or post_build"/>
|
||||
</target>
|
||||
|
||||
<macrodef name="patch_plugin_xml">
|
||||
<attribute name="plugin.xml" />
|
||||
<sequential>
|
||||
<replace file="@{plugin.xml}" token="<!-- DEPENDS-ON-AS-PLACEHOLDER -->" value="<depends>com.intellij.modules.androidstudio</depends>"/>
|
||||
</sequential>
|
||||
</macrodef>
|
||||
|
||||
<target name="patchXmlForAndroidStudio">
|
||||
<unzip src="${artifact.output.path}/Kotlin/lib/kotlin-plugin.jar" dest="tmpAndroidStudio">
|
||||
<patternset>
|
||||
<include name="META-INF/plugin.xml"/>
|
||||
</patternset>
|
||||
</unzip>
|
||||
|
||||
<patch_plugin_xml plugin.xml="tmpAndroidStudio/META-INF/plugin.xml"/>
|
||||
|
||||
<jar destfile="${artifact.output.path}/Kotlin/lib/kotlin-plugin.jar" update="true">
|
||||
<fileset dir="tmpAndroidStudio"/>
|
||||
<file file="META-INF/plugin.xml"/>
|
||||
</jar>
|
||||
|
||||
<delete file="tmpAndroidStudio"/>
|
||||
</target>
|
||||
</project>
|
||||
|
||||
@@ -22,6 +22,7 @@ buildscript {
|
||||
"https://jcenter.bintray.com/",
|
||||
"https://plugins.gradle.org/m2",
|
||||
"http://dl.bintray.com/kotlin/kotlinx",
|
||||
"http://dl.bintray.com/kotlin/uast",
|
||||
"https://repo.gradle.org/gradle/libs-releases-local", // for native-platform
|
||||
"https://jetbrains.bintray.com/intellij-third-party-dependencies", // for jflex
|
||||
"https://dl.bintray.com/jetbrains/markdown" // for org.jetbrains:markdown
|
||||
@@ -142,6 +143,7 @@ extra["versions.robolectric"] = "3.1"
|
||||
extra["versions.org.springframework"] = "4.2.0.RELEASE"
|
||||
extra["versions.jflex"] = "1.7.0"
|
||||
extra["versions.markdown"] = "0.1.25"
|
||||
extra["versions.org.jetbrains.uast"] = "1.0.12"
|
||||
|
||||
val isTeamcityBuild = project.hasProperty("teamcity") || System.getenv("TEAMCITY_VERSION") != null
|
||||
val intellijUltimateEnabled = project.getBooleanProperty("intellijUltimateEnabled") ?: isTeamcityBuild
|
||||
@@ -156,7 +158,7 @@ extra["intellijSeparateSdks"] = intellijSeparateSdks
|
||||
extra["IntellijCoreDependencies"] =
|
||||
listOf("annotations",
|
||||
"asm-all",
|
||||
"guava-21.0",
|
||||
"guava-19.0",
|
||||
"jdom",
|
||||
"jna",
|
||||
"log4j",
|
||||
|
||||
@@ -5,3 +5,5 @@ org.gradle.jvmargs=-Duser.country=US -Dkotlin.daemon.jvm.options=-Xmx1600m
|
||||
|
||||
#buildSrc.kotlin.repo=https://jcenter.bintray.com
|
||||
#buildSrc.kotlin.version=1.1.50
|
||||
|
||||
intellijUltimateEnabled=false
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
package org.jetbrains.kotlin.android.tests;
|
||||
|
||||
import org.jetbrains.kotlin.jps.build.BaseKotlinJpsBuildTestCase;
|
||||
@@ -60,3 +60,4 @@ public class AndroidJpsBuildTestCase extends BaseKotlinJpsBuildTestCase {
|
||||
loadProject(workDir.getAbsolutePath() + File.separator + PROJECT_NAME + ".ipr");
|
||||
}
|
||||
}
|
||||
*/
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
package org.jetbrains.kotlin.android.tests;
|
||||
|
||||
import com.google.common.io.Files;
|
||||
@@ -74,3 +74,4 @@ public class AndroidRunner {
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
@@ -20,6 +20,7 @@ import com.intellij.openapi.vfs.StandardFileSystems
|
||||
import com.intellij.openapi.vfs.VfsUtilCore
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.psi.PsiJavaModule
|
||||
import com.intellij.openapi.vfs.VirtualFileManager
|
||||
import com.intellij.psi.PsiManager
|
||||
import com.intellij.psi.impl.light.LightJavaModule
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation
|
||||
@@ -91,22 +92,22 @@ class ClasspathRootsResolver(
|
||||
|
||||
for ((root, packagePrefix) in javaSourceRoots) {
|
||||
val modularRoot = modularSourceRoot(root, hasOutputDirectoryInClasspath)
|
||||
if (modularRoot != null) {
|
||||
modules += modularRoot
|
||||
}
|
||||
else {
|
||||
result += JavaRoot(root, JavaRoot.RootType.SOURCE, packagePrefix?.let { prefix ->
|
||||
if (isValidJavaFqName(prefix)) FqName(prefix)
|
||||
else null.also {
|
||||
report(STRONG_WARNING, "Invalid package prefix name is ignored: $prefix")
|
||||
if (modularRoot != null) {
|
||||
modules += modularRoot
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
else {
|
||||
result += JavaRoot(root, JavaRoot.RootType.SOURCE, packagePrefix?.let { prefix ->
|
||||
if (isValidJavaFqName(prefix)) FqName(prefix)
|
||||
else null.also {
|
||||
report(STRONG_WARNING, "Invalid package prefix name is ignored: $prefix")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
for (root in jvmClasspathRoots) {
|
||||
result += JavaRoot(root, JavaRoot.RootType.BINARY)
|
||||
}
|
||||
result += JavaRoot(root, JavaRoot.RootType.BINARY)
|
||||
}
|
||||
|
||||
val outputDirectoryAddedAsPartOfModule = modules.any { module -> module.moduleRoots.any { it.file == outputDirectory } }
|
||||
|
||||
@@ -116,16 +117,17 @@ class ClasspathRootsResolver(
|
||||
if (outputDirectoryAddedAsPartOfModule && root == outputDirectory) continue
|
||||
|
||||
val module = modularBinaryRoot(root)
|
||||
if (module != null) {
|
||||
modules += module
|
||||
}
|
||||
}
|
||||
if (module != null) {
|
||||
modules += module
|
||||
}
|
||||
}
|
||||
|
||||
addModularRoots(modules, result)
|
||||
|
||||
return RootsAndModules(result, modules)
|
||||
}
|
||||
|
||||
/*
|
||||
private fun findSourceModuleInfo(root: VirtualFile): Pair<VirtualFile, PsiJavaModule>? {
|
||||
val moduleInfoFile =
|
||||
when {
|
||||
@@ -139,8 +141,10 @@ class ClasspathRootsResolver(
|
||||
|
||||
return moduleInfoFile to psiJavaModule
|
||||
}
|
||||
*/
|
||||
|
||||
private fun modularSourceRoot(root: VirtualFile, hasOutputDirectoryInClasspath: Boolean): JavaModule.Explicit? {
|
||||
/*
|
||||
val (moduleInfoFile, psiJavaModule) = findSourceModuleInfo(root) ?: return null
|
||||
val sourceRoot = JavaModule.Root(root, isBinary = false)
|
||||
val roots =
|
||||
@@ -148,12 +152,15 @@ class ClasspathRootsResolver(
|
||||
listOf(sourceRoot, JavaModule.Root(outputDirectory!!, isBinary = true))
|
||||
else listOf(sourceRoot)
|
||||
return JavaModule.Explicit(JavaModuleInfo.create(psiJavaModule), roots, moduleInfoFile)
|
||||
*/
|
||||
return null
|
||||
}
|
||||
|
||||
private fun modularBinaryRoot(root: VirtualFile): JavaModule? {
|
||||
val isJar = root.fileSystem.protocol == StandardFileSystems.JAR_PROTOCOL
|
||||
val manifest: Attributes? by lazy(NONE) { readManifestAttributes(root) }
|
||||
|
||||
/*
|
||||
val moduleInfoFile =
|
||||
root.findChild(PsiJavaModule.MODULE_INFO_CLS_FILE)
|
||||
?: root.takeIf { isJar }?.findFileByRelativePath(MULTI_RELEASE_MODULE_INFO_CLS_FILE)?.takeIf {
|
||||
@@ -164,6 +171,7 @@ class ClasspathRootsResolver(
|
||||
val moduleInfo = JavaModuleInfo.read(moduleInfoFile) ?: return null
|
||||
return JavaModule.Explicit(moduleInfo, listOf(JavaModule.Root(root, isBinary = true)), moduleInfoFile)
|
||||
}
|
||||
*/
|
||||
|
||||
// Only .jar files can be automatic modules
|
||||
if (isJar) {
|
||||
|
||||
@@ -245,10 +245,12 @@ class KotlinCliJavaFileManagerImpl(private val myPsiManager: PsiManager) : CoreJ
|
||||
return result
|
||||
}
|
||||
|
||||
/*
|
||||
override fun findModules(moduleName: String, scope: GlobalSearchScope): Collection<PsiJavaModule> {
|
||||
// TODO
|
||||
return emptySet()
|
||||
}
|
||||
*/
|
||||
|
||||
override fun getNonTrivialPackagePrefixes(): Collection<String> = emptyList()
|
||||
|
||||
|
||||
@@ -28,7 +28,6 @@ import com.intellij.ide.highlighter.JavaFileType
|
||||
import com.intellij.ide.plugins.PluginManagerCore
|
||||
import com.intellij.lang.MetaLanguage
|
||||
import com.intellij.lang.java.JavaParserDefinition
|
||||
import com.intellij.lang.jvm.facade.JvmElementProvider
|
||||
import com.intellij.openapi.Disposable
|
||||
import com.intellij.openapi.application.TransactionGuard
|
||||
import com.intellij.openapi.application.TransactionGuardImpl
|
||||
@@ -44,7 +43,6 @@ import com.intellij.openapi.util.text.StringUtil
|
||||
import com.intellij.openapi.vfs.*
|
||||
import com.intellij.openapi.vfs.impl.ZipHandler
|
||||
import com.intellij.psi.FileContextProvider
|
||||
import com.intellij.psi.JavaModuleSystem
|
||||
import com.intellij.psi.PsiElementFinder
|
||||
import com.intellij.psi.PsiManager
|
||||
import com.intellij.psi.augment.PsiAugmentProvider
|
||||
@@ -386,7 +384,7 @@ class KotlinCoreEnvironment private constructor(
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val ideaCompatibleBuildNumber = "173.1"
|
||||
private val ideaCompatibleBuildNumber = "172.9999"
|
||||
|
||||
init {
|
||||
setCompatibleBuild()
|
||||
@@ -509,8 +507,6 @@ class KotlinCoreEnvironment private constructor(
|
||||
//
|
||||
CoreApplicationEnvironment.registerExtensionPoint(Extensions.getRootArea(), TypeAnnotationModifier.EP_NAME, TypeAnnotationModifier::class.java)
|
||||
CoreApplicationEnvironment.registerExtensionPoint(Extensions.getRootArea(), MetaLanguage.EP_NAME, MetaLanguage::class.java)
|
||||
//
|
||||
CoreApplicationEnvironment.registerExtensionPoint(Extensions.getRootArea(), JavaModuleSystem.EP_NAME, JavaModuleSystem::class.java)
|
||||
}
|
||||
|
||||
private fun registerApplicationExtensionPointsAndExtensionsFrom(configuration: CompilerConfiguration, configFilePath: String) {
|
||||
@@ -561,7 +557,6 @@ class KotlinCoreEnvironment private constructor(
|
||||
private fun registerProjectExtensionPoints(area: ExtensionsArea) {
|
||||
CoreApplicationEnvironment.registerExtensionPoint(area, PsiTreeChangePreprocessor.EP_NAME, PsiTreeChangePreprocessor::class.java)
|
||||
CoreApplicationEnvironment.registerExtensionPoint(area, PsiElementFinder.EP_NAME, PsiElementFinder::class.java)
|
||||
CoreApplicationEnvironment.registerExtensionPoint(area, JvmElementProvider.EP_NAME, JvmElementProvider::class.java)
|
||||
}
|
||||
|
||||
// made public for Upsource
|
||||
|
||||
@@ -19,7 +19,6 @@ package org.jetbrains.kotlin.cli.jvm.compiler
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.psi.PsiJavaModule
|
||||
import com.intellij.psi.PsiManager
|
||||
import com.intellij.psi.impl.PsiModificationTrackerImpl
|
||||
import com.intellij.psi.search.DelegatingGlobalSearchScope
|
||||
@@ -189,14 +188,14 @@ object KotlinToJVMBytecodeCompiler {
|
||||
}
|
||||
}
|
||||
|
||||
val isJava9Module = chunk.any { module ->
|
||||
val isJava9Module = false /*chunk.any { module ->
|
||||
module.getJavaSourceRoots().any { (path, packagePrefix) ->
|
||||
val file = File(path)
|
||||
packagePrefix == null &&
|
||||
(file.name == PsiJavaModule.MODULE_INFO_FILE ||
|
||||
(file.isDirectory && file.listFiles().any { it.name == PsiJavaModule.MODULE_INFO_FILE }))
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
for (module in chunk) {
|
||||
for (classpathRoot in module.getClasspathRoots()) {
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.jetbrains.kotlin.cli.jvm.compiler
|
||||
|
||||
import com.intellij.codeInsight.ExternalAnnotationsManager
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.psi.*
|
||||
|
||||
class MockExternalAnnotationsManager : ExternalAnnotationsManager() {
|
||||
@@ -41,8 +40,4 @@ class MockExternalAnnotationsManager : ExternalAnnotationsManager() {
|
||||
override fun editExternalAnnotation(listOwner: PsiModifierListOwner, annotationFQN: String, value: Array<out PsiNameValuePair>?): Boolean {
|
||||
throw UnsupportedOperationException("not implemented")
|
||||
}
|
||||
|
||||
override fun hasAnnotationRootsForFile(file: VirtualFile): Boolean {
|
||||
throw UnsupportedOperationException("not implemented")
|
||||
}
|
||||
}
|
||||
@@ -17,10 +17,8 @@
|
||||
package org.jetbrains.kotlin.cli.jvm.modules
|
||||
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.psi.PsiJavaModule
|
||||
import org.jetbrains.kotlin.resolve.jvm.modules.JavaModule
|
||||
import org.jetbrains.kotlin.resolve.jvm.modules.JavaModuleFinder
|
||||
import org.jetbrains.kotlin.resolve.jvm.modules.JavaModuleInfo
|
||||
|
||||
class CliJavaModuleFinder(jrtFileSystemRoot: VirtualFile?) : JavaModuleFinder {
|
||||
private val modulesRoot = jrtFileSystemRoot?.findChild("modules")
|
||||
@@ -40,8 +38,11 @@ class CliJavaModuleFinder(jrtFileSystemRoot: VirtualFile?) : JavaModuleFinder {
|
||||
modulesRoot?.findChild(name)?.let(this::findSystemModule) ?: userModules[name]
|
||||
|
||||
private fun findSystemModule(moduleRoot: VirtualFile): JavaModule.Explicit? {
|
||||
/*
|
||||
val file = moduleRoot.findChild(PsiJavaModule.MODULE_INFO_CLS_FILE) ?: return null
|
||||
val moduleInfo = JavaModuleInfo.read(file) ?: return null
|
||||
return JavaModule.Explicit(moduleInfo, listOf(JavaModule.Root(moduleRoot, isBinary = true)), file)
|
||||
*/
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +50,6 @@ messages/**)
|
||||
-dontwarn net.jpountz.lz4.LZ4Factory
|
||||
-dontwarn org.jetbrains.annotations.ReadOnly
|
||||
-dontwarn org.jetbrains.annotations.Mutable
|
||||
-dontwarn com.intellij.util.io.TarUtil
|
||||
|
||||
#-libraryjars '<rtjar>'
|
||||
#-libraryjars '<jssejar>'
|
||||
|
||||
@@ -28,8 +28,8 @@ enum class JvmTarget(override val description: String) : TargetPlatformVersion {
|
||||
JVM_1_6 -> Opcodes.V1_6
|
||||
JVM_1_8 ->
|
||||
when {
|
||||
java.lang.Boolean.valueOf(System.getProperty("kotlin.test.substitute.bytecode.1.8.to.10")) -> Opcodes.V9 + 1
|
||||
java.lang.Boolean.valueOf(System.getProperty("kotlin.test.substitute.bytecode.1.8.to.1.9")) -> Opcodes.V9
|
||||
java.lang.Boolean.valueOf(System.getProperty("kotlin.test.substitute.bytecode.1.8.to.10")) -> Opcodes.V1_9 + 1
|
||||
java.lang.Boolean.valueOf(System.getProperty("kotlin.test.substitute.bytecode.1.8.to.1.9")) -> Opcodes.V1_9
|
||||
else -> Opcodes.V1_8
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ import org.jetbrains.kotlin.load.java.structure.*
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.KtPsiUtil
|
||||
import org.jetbrains.kotlin.psi.psiUtil.contains
|
||||
|
||||
class JavaClassImpl(psiClass: PsiClass) : JavaClassifierImpl<PsiClass>(psiClass), VirtualFileBoundJavaClass, JavaAnnotationOwnerImpl, JavaModifierListOwnerImpl {
|
||||
init {
|
||||
@@ -114,7 +115,7 @@ class JavaClassImpl(psiClass: PsiClass) : JavaClassifierImpl<PsiClass>(psiClass)
|
||||
override val virtualFile: VirtualFile?
|
||||
get() = psi.containingFile?.virtualFile
|
||||
|
||||
override fun isFromSourceCodeInScope(scope: SearchScope): Boolean = psi.containingFile.virtualFile in scope
|
||||
override fun isFromSourceCodeInScope(scope: SearchScope): Boolean = psi.containingFile in scope
|
||||
|
||||
override fun getAnnotationOwnerPsi() = psi.modifierList
|
||||
|
||||
|
||||
@@ -22,7 +22,6 @@ import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.components.ServiceManager
|
||||
import com.intellij.openapi.util.Computable
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.psi.PsiJavaModule
|
||||
|
||||
class KotlinBinaryClassCache : Disposable {
|
||||
private class RequestCache {
|
||||
@@ -56,8 +55,6 @@ class KotlinBinaryClassCache : Disposable {
|
||||
fun getKotlinBinaryClass(file: VirtualFile, fileContent: ByteArray? = null): KotlinJvmBinaryClass? {
|
||||
if (file.fileType !== JavaClassFileType.INSTANCE) return null
|
||||
|
||||
if (file.name == PsiJavaModule.MODULE_INFO_CLS_FILE) return null
|
||||
|
||||
val service = ServiceManager.getService(KotlinBinaryClassCache::class.java)
|
||||
val requestCache = service.cache.get()
|
||||
|
||||
|
||||
@@ -17,15 +17,15 @@
|
||||
package org.jetbrains.kotlin.resolve.jvm.modules
|
||||
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.psi.PsiJavaModule
|
||||
//import com.intellij.psi.PsiJavaModule
|
||||
import com.intellij.psi.PsiModifier
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.utils.compact
|
||||
import org.jetbrains.org.objectweb.asm.ClassReader
|
||||
import org.jetbrains.org.objectweb.asm.ClassVisitor
|
||||
import org.jetbrains.org.objectweb.asm.ModuleVisitor
|
||||
//import org.jetbrains.org.objectweb.asm.ModuleVisitor
|
||||
import org.jetbrains.org.objectweb.asm.Opcodes
|
||||
import org.jetbrains.org.objectweb.asm.Opcodes.ACC_TRANSITIVE
|
||||
//import org.jetbrains.org.objectweb.asm.Opcodes.ACC_TRANSITIVE
|
||||
import java.io.IOException
|
||||
|
||||
class JavaModuleInfo(
|
||||
@@ -41,7 +41,7 @@ class JavaModuleInfo(
|
||||
"Module $moduleName (${requires.size} requires, ${exports.size} exports)"
|
||||
|
||||
companion object {
|
||||
fun create(psiJavaModule: PsiJavaModule): JavaModuleInfo {
|
||||
/*fun create(psiJavaModule: PsiJavaModule): JavaModuleInfo {
|
||||
return JavaModuleInfo(
|
||||
psiJavaModule.name,
|
||||
psiJavaModule.requires.mapNotNull { statement ->
|
||||
@@ -55,9 +55,9 @@ class JavaModuleInfo(
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}*/
|
||||
|
||||
fun read(file: VirtualFile): JavaModuleInfo? {
|
||||
/*fun read(file: VirtualFile): JavaModuleInfo? {
|
||||
val contents = try { file.contentsToByteArray() } catch (e: IOException) { return null }
|
||||
|
||||
var moduleName: String? = null
|
||||
@@ -84,6 +84,6 @@ class JavaModuleInfo(
|
||||
return if (moduleName != null)
|
||||
JavaModuleInfo(moduleName!!, requires.compact(), exports.compact())
|
||||
else null
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.constants.ConstantValue
|
||||
import org.jetbrains.kotlin.resolve.constants.ErrorValue
|
||||
|
||||
val JVM_STATIC_ANNOTATION_FQ_NAME = FqName("kotlin.jvm.JvmStatic")
|
||||
private val JVM_STATIC_ANNOTATION_FQ_NAME = FqName("kotlin.jvm.JvmStatic")
|
||||
|
||||
val JVM_FIELD_ANNOTATION_FQ_NAME = FqName("kotlin.jvm.JvmField")
|
||||
|
||||
|
||||
@@ -55,12 +55,6 @@ abstract class KtLightAbstractAnnotation(parent: PsiElement, computeDelegate: ()
|
||||
|
||||
override fun getParameterList() = clsDelegate.parameterList
|
||||
|
||||
override fun canNavigate(): Boolean = super<KtLightElementBase>.canNavigate()
|
||||
|
||||
override fun canNavigateToSource(): Boolean = super<KtLightElementBase>.canNavigateToSource()
|
||||
|
||||
override fun navigate(requestFocus: Boolean) = super<KtLightElementBase>.navigate(requestFocus)
|
||||
|
||||
open fun fqNameMatches(fqName: String): Boolean = qualifiedName == fqName
|
||||
}
|
||||
|
||||
@@ -273,7 +267,7 @@ class KtLightAnnotationForSourceEntry(
|
||||
PsiNameValuePair {
|
||||
override fun setValue(newValue: PsiAnnotationMemberValue): PsiAnnotationMemberValue = psiNameValuePair.setValue(newValue)
|
||||
override fun getNameIdentifier(): PsiIdentifier? = psiNameValuePair.nameIdentifier
|
||||
override fun getLiteralValue(): String? = (value as? PsiLiteralValue)?.value?.toString()
|
||||
override fun getLiteralValue(): String? = (value as? PsiLiteral)?.value?.toString()
|
||||
override val kotlinOrigin: KtElement? = null
|
||||
|
||||
override fun getValue(): PsiAnnotationMemberValue? = psiNameValuePair.value?.let { wrapAnnotationValue(it) }
|
||||
@@ -319,12 +313,6 @@ class KtLightNonExistentAnnotation(parent: KtLightElement<*, *>) : KtLightElemen
|
||||
override fun findDeclaredAttributeValue(attributeName: String?) = null
|
||||
override fun getMetaData() = null
|
||||
override fun getParameterList() = KtLightEmptyAnnotationParameterList(this)
|
||||
|
||||
override fun canNavigate(): Boolean = super<KtLightElementBase>.canNavigate()
|
||||
|
||||
override fun canNavigateToSource(): Boolean = super<KtLightElementBase>.canNavigateToSource()
|
||||
|
||||
override fun navigate(requestFocus: Boolean) = super<KtLightElementBase>.navigate(requestFocus)
|
||||
}
|
||||
|
||||
class KtLightEmptyAnnotationParameterList(parent: PsiElement) : KtLightElementBase(parent), PsiAnnotationParameterList {
|
||||
|
||||
@@ -325,8 +325,6 @@ class KtPsiFactory @JvmOverloads constructor(private val project: Project, val m
|
||||
return createProperty(text + " val x").modifierList!!
|
||||
}
|
||||
|
||||
fun createEmptyModifierList() = createModifierList(KtTokens.PRIVATE_KEYWORD).apply { firstChild.delete() }
|
||||
|
||||
fun createModifier(modifier: KtModifierKeywordToken): PsiElement {
|
||||
return createModifierList(modifier.value).getModifier(modifier)!!
|
||||
}
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
// FILE: a/a.java
|
||||
package a;
|
||||
|
||||
public class a {}
|
||||
|
||||
// FILE: a/b.java
|
||||
package a;
|
||||
|
||||
public class b {
|
||||
public void a_b() {}
|
||||
}
|
||||
|
||||
// FILE: test/a.java
|
||||
package test;
|
||||
|
||||
public class a {}
|
||||
|
||||
// FILE: test/d.java
|
||||
package test;
|
||||
|
||||
public class d {
|
||||
public a.b getB() { return null; }
|
||||
}
|
||||
|
||||
// FILE: b.kt
|
||||
package test
|
||||
|
||||
val x = d().getB()
|
||||
|
||||
// FILE: test/c.java
|
||||
package test;
|
||||
|
||||
import a.a;
|
||||
|
||||
public class c {
|
||||
public static a getA() { return null; }
|
||||
}
|
||||
|
||||
// FILE: c.kt
|
||||
package test
|
||||
|
||||
fun foo() {
|
||||
val a = c.getA()
|
||||
a.<!UNRESOLVED_REFERENCE!>a<!>
|
||||
a.<!UNRESOLVED_REFERENCE!>a<!>()
|
||||
}
|
||||
@@ -139,8 +139,18 @@ abstract class AbstractDiagnosticsTest : BaseDiagnosticsTest() {
|
||||
}
|
||||
|
||||
var exceptionFromDescriptorValidation: Throwable? = null
|
||||
val originalTestFile = testDataFile.readText()
|
||||
try {
|
||||
val expectedFile = getExpectedDescriptorFile(testDataFile, files)
|
||||
val postfix = when {
|
||||
InTextDirectivesUtils.isDirectiveDefined(originalTestFile, "// JAVAC_EXPECTED_FILE") &&
|
||||
environment.configuration.getBoolean(JVMConfigurationKeys.USE_JAVAC) -> ".javac.txt"
|
||||
|
||||
InTextDirectivesUtils.isDirectiveDefined(originalTestFile, "// NI_EXPECTED_FILE") &&
|
||||
files.any { it.newInferenceEnabled } && !USE_OLD_INFERENCE_DIAGNOSTICS_FOR_NI -> ".ni.txt"
|
||||
|
||||
else -> ".txt"
|
||||
}
|
||||
val expectedFile = File(FileUtil.getNameWithoutExtension(testDataFile.absolutePath) + postfix)
|
||||
validateAndCompareDescriptorWithFile(expectedFile, files, modules)
|
||||
} catch (e: Throwable) {
|
||||
exceptionFromDescriptorValidation = e
|
||||
@@ -175,7 +185,7 @@ abstract class AbstractDiagnosticsTest : BaseDiagnosticsTest() {
|
||||
exceptionFromDynamicCallDescriptorsValidation = e
|
||||
}
|
||||
|
||||
KotlinTestUtils.assertEqualsToFile(getExpectedDiagnosticsFile(testDataFile), actualText.toString())
|
||||
KotlinTestUtils.assertEqualsToFile(testDataFile, actualText.toString())
|
||||
|
||||
assertTrue("Diagnostics mismatch. See the output above", ok)
|
||||
|
||||
@@ -187,26 +197,6 @@ abstract class AbstractDiagnosticsTest : BaseDiagnosticsTest() {
|
||||
performAdditionalChecksAfterDiagnostics(testDataFile, files, groupedByModule, modules, moduleBindings)
|
||||
}
|
||||
|
||||
protected open fun getExpectedDiagnosticsFile(testDataFile: File): File {
|
||||
return testDataFile
|
||||
}
|
||||
|
||||
protected open fun getExpectedDescriptorFile(testDataFile: File, files: List<TestFile>): File {
|
||||
val originalTestFileText = testDataFile.readText()
|
||||
|
||||
val postfix = when {
|
||||
InTextDirectivesUtils.isDirectiveDefined(originalTestFileText, "// JAVAC_EXPECTED_FILE") &&
|
||||
environment.configuration.getBoolean(JVMConfigurationKeys.USE_JAVAC) -> ".javac.txt"
|
||||
|
||||
InTextDirectivesUtils.isDirectiveDefined(originalTestFileText, "// NI_EXPECTED_FILE") &&
|
||||
files.any { it.newInferenceEnabled } && !USE_OLD_INFERENCE_DIAGNOSTICS_FOR_NI -> ".ni.txt"
|
||||
|
||||
else -> ".txt"
|
||||
}
|
||||
|
||||
return File(FileUtil.getNameWithoutExtension(testDataFile.absolutePath) + postfix)
|
||||
}
|
||||
|
||||
protected open fun performAdditionalChecksAfterDiagnostics(
|
||||
testDataFile: File,
|
||||
testFiles: List<TestFile>,
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.jetbrains.kotlin.checkers.javac
|
||||
|
||||
import org.jetbrains.kotlin.checkers.AbstractDiagnosticsTest
|
||||
import org.jetbrains.kotlin.config.JVMConfigurationKeys
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import java.io.File
|
||||
|
||||
abstract class AbstractJavacDiagnosticsTest : AbstractDiagnosticsTest() {
|
||||
@@ -40,19 +39,5 @@ abstract class AbstractJavacDiagnosticsTest : AbstractDiagnosticsTest() {
|
||||
super.doTest(path)
|
||||
}
|
||||
|
||||
override fun getExpectedDiagnosticsFile(testDataFile: File): File {
|
||||
val suffix = if (useJavac) ".WithJavac.txt" else ".WithoutJavac.txt"
|
||||
val specialFile = File(testDataFile.parent, testDataFile.name + suffix)
|
||||
return specialFile.takeIf { it.exists() } ?: super.getExpectedDiagnosticsFile(testDataFile)
|
||||
}
|
||||
|
||||
override fun createTestFiles(file: File, expectedText: String, modules: MutableMap<String, ModuleAndDependencies>?): List<TestFile> {
|
||||
val specialFile = getExpectedDiagnosticsFile(file)
|
||||
if (file.path == specialFile.path) {
|
||||
return super.createTestFiles(file, expectedText, modules)
|
||||
}
|
||||
|
||||
return super.createTestFiles(specialFile, KotlinTestUtils.doLoadFile(specialFile), modules)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,6 @@ import com.intellij.psi.impl.PsiFileFactoryImpl;
|
||||
import com.intellij.rt.execution.junit.FileComparisonFailure;
|
||||
import com.intellij.testFramework.LightVirtualFile;
|
||||
import com.intellij.testFramework.TestDataFile;
|
||||
import com.intellij.util.PathUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import junit.framework.TestCase;
|
||||
import kotlin.collections.CollectionsKt;
|
||||
@@ -74,6 +73,7 @@ import org.jetbrains.kotlin.util.slicedMap.ReadOnlySlice;
|
||||
import org.jetbrains.kotlin.util.slicedMap.SlicedMap;
|
||||
import org.jetbrains.kotlin.util.slicedMap.WritableSlice;
|
||||
import org.jetbrains.kotlin.utils.ExceptionUtilsKt;
|
||||
import org.jetbrains.kotlin.utils.PathUtil;
|
||||
import org.junit.Assert;
|
||||
|
||||
import javax.tools.*;
|
||||
@@ -384,7 +384,7 @@ public class KotlinTestUtils {
|
||||
}
|
||||
|
||||
public static String getAndroidSdkSystemIndependentPath() {
|
||||
return PathUtil.toSystemIndependentName(findAndroidSdk().getAbsolutePath());
|
||||
return com.intellij.util.PathUtil.toSystemIndependentName(findAndroidSdk().getAbsolutePath());
|
||||
}
|
||||
|
||||
public static File getAnnotationsJar() {
|
||||
@@ -565,8 +565,8 @@ public class KotlinTestUtils {
|
||||
configuration.put(JVMConfigurationKeys.JDK_HOME, home);
|
||||
}
|
||||
}
|
||||
else if (SystemInfo.IS_AT_LEAST_JAVA9) {
|
||||
configuration.put(JVMConfigurationKeys.JDK_HOME, new File(System.getProperty("java.home")));
|
||||
else {
|
||||
JvmContentRootsKt.addJvmClasspathRoots(configuration, PathUtil.getJdkClassesRootsFromCurrentJre());
|
||||
}
|
||||
|
||||
if (configurationKind.getWithRuntime()) {
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.test.testFramework
|
||||
|
||||
import com.intellij.mock.MockApplication
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import org.jetbrains.annotations.TestOnly
|
||||
import java.lang.reflect.InvocationTargetException
|
||||
import javax.swing.SwingUtilities
|
||||
@@ -41,12 +39,7 @@ fun runInEdtAndWait(runnable: () -> Unit) {
|
||||
}
|
||||
else {
|
||||
try {
|
||||
val application = ApplicationManager.getApplication()
|
||||
.takeIf { it !is MockApplication } // because MockApplication do nothing instead of `invokeAndWait`
|
||||
if (application != null)
|
||||
application.invokeAndWait(runnable)
|
||||
else
|
||||
SwingUtilities.invokeAndWait(runnable)
|
||||
SwingUtilities.invokeAndWait(runnable)
|
||||
}
|
||||
catch (e: InvocationTargetException) {
|
||||
throw e.cause ?: e
|
||||
|
||||
@@ -52,7 +52,6 @@ import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
@SuppressWarnings("UseOfSystemOutOrSystemErr")
|
||||
public abstract class KtUsefulTestCase extends TestCase {
|
||||
@@ -218,11 +217,9 @@ public abstract class KtUsefulTestCase extends TestCase {
|
||||
protected void runTest() throws Throwable {
|
||||
Throwable[] throwables = new Throwable[1];
|
||||
|
||||
AtomicBoolean completed = new AtomicBoolean(false);
|
||||
Runnable runnable = () -> {
|
||||
try {
|
||||
super.runTest();
|
||||
completed.set(true);
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
e.fillInStackTrace();
|
||||
@@ -242,9 +239,6 @@ public abstract class KtUsefulTestCase extends TestCase {
|
||||
if (throwables[0] != null) {
|
||||
throw throwables[0];
|
||||
}
|
||||
if (!completed.get()) {
|
||||
throw new IllegalStateException("test didn't start");
|
||||
}
|
||||
}
|
||||
|
||||
private static void invokeTestRunnable(@NotNull Runnable runnable) throws Exception {
|
||||
|
||||
@@ -19,7 +19,6 @@ import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.EditorFactory;
|
||||
import com.intellij.openapi.editor.EditorKind;
|
||||
import com.intellij.openapi.editor.event.EditorEventMulticaster;
|
||||
import com.intellij.openapi.editor.event.EditorFactoryListener;
|
||||
import com.intellij.openapi.editor.impl.DocumentImpl;
|
||||
@@ -28,7 +27,6 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.text.CharArrayCharSequence;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class MockEditorFactory extends EditorFactory {
|
||||
@Override
|
||||
@@ -61,27 +59,6 @@ public class MockEditorFactory extends EditorFactory {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Editor createEditor(
|
||||
@NotNull Document document, @Nullable Project project, @NotNull EditorKind kind
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Editor createEditor(
|
||||
@NotNull Document document, Project project, @NotNull VirtualFile file, boolean isViewer, @NotNull EditorKind kind
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Editor createViewer(
|
||||
@NotNull Document document, @Nullable Project project, @NotNull EditorKind kind
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void releaseEditor(@NotNull Editor editor) {
|
||||
}
|
||||
|
||||
@@ -30,15 +30,14 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
public class MockFileManager implements FileManager {
|
||||
private final PsiManagerEx myManager;
|
||||
// in mock tests it's LightVirtualFile, they're only alive when they're referenced,
|
||||
// and there can not be several instances representing the same file
|
||||
private final ConcurrentMap<VirtualFile, FileViewProvider> myViewProviders = new ConcurrentWeakFactoryMap<VirtualFile, FileViewProvider>() {
|
||||
private final FactoryMap<VirtualFile, FileViewProvider> myViewProviders = new ConcurrentWeakFactoryMap<VirtualFile, FileViewProvider>() {
|
||||
@Override
|
||||
protected ConcurrentMap<VirtualFile, FileViewProvider> createMap() {
|
||||
protected Map<VirtualFile, FileViewProvider> createMap() {
|
||||
return ContainerUtil.createConcurrentWeakKeyWeakValueMap();
|
||||
}
|
||||
|
||||
|
||||
@@ -190,8 +190,4 @@ public class MockPsiManager extends PsiManagerEx {
|
||||
@Override
|
||||
public void beforeChildAddition(@NotNull PsiTreeChangeEventImpl event) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dropPsiCaches() {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ import org.jetbrains.kotlin.android.configure.AbstractConfigureProjectTest
|
||||
import org.jetbrains.kotlin.android.folding.AbstractAndroidResourceFoldingTest
|
||||
import org.jetbrains.kotlin.android.intention.AbstractAndroidIntentionTest
|
||||
import org.jetbrains.kotlin.android.intention.AbstractAndroidResourceIntentionTest
|
||||
import org.jetbrains.kotlin.android.lint.AbstractKotlinLintTest
|
||||
import org.jetbrains.kotlin.android.parcel.AbstractParcelBytecodeListingTest
|
||||
import org.jetbrains.kotlin.android.quickfix.AbstractAndroidLintQuickfixTest
|
||||
import org.jetbrains.kotlin.android.quickfix.AbstractAndroidQuickFixMultiFileTest
|
||||
@@ -108,8 +107,6 @@ import org.jetbrains.kotlin.idea.intentions.declarations.AbstractJoinLinesTest
|
||||
import org.jetbrains.kotlin.idea.internal.AbstractBytecodeToolWindowTest
|
||||
import org.jetbrains.kotlin.idea.kdoc.AbstractKDocHighlightingTest
|
||||
import org.jetbrains.kotlin.idea.kdoc.AbstractKDocTypingTest
|
||||
import org.jetbrains.kotlin.idea.maven.AbstractKotlinMavenInspectionTest
|
||||
import org.jetbrains.kotlin.idea.maven.configuration.AbstractMavenConfigureProjectByChangingFileTest
|
||||
import org.jetbrains.kotlin.idea.navigation.*
|
||||
import org.jetbrains.kotlin.idea.parameterInfo.AbstractParameterInfoTest
|
||||
import org.jetbrains.kotlin.idea.quickfix.AbstractQuickFixMultiFileTest
|
||||
@@ -133,9 +130,7 @@ import org.jetbrains.kotlin.idea.scratch.AbstractScratchRunActionTest
|
||||
import org.jetbrains.kotlin.idea.script.AbstractScriptConfigurationCompletionTest
|
||||
import org.jetbrains.kotlin.idea.script.AbstractScriptConfigurationHighlightingTest
|
||||
import org.jetbrains.kotlin.idea.script.AbstractScriptConfigurationNavigationTest
|
||||
import org.jetbrains.kotlin.idea.slicer.AbstractSlicerLeafGroupingTest
|
||||
import org.jetbrains.kotlin.idea.slicer.AbstractSlicerNullnessGroupingTest
|
||||
import org.jetbrains.kotlin.idea.slicer.AbstractSlicerTreeTest
|
||||
import org.jetbrains.kotlin.idea.slicer.AbstractSlicerTest
|
||||
import org.jetbrains.kotlin.idea.structureView.AbstractKotlinFileStructureTest
|
||||
import org.jetbrains.kotlin.idea.stubs.AbstractMultiFileHighlightingTest
|
||||
import org.jetbrains.kotlin.idea.stubs.AbstractResolveByStubTest
|
||||
@@ -144,10 +139,10 @@ import org.jetbrains.kotlin.incremental.*
|
||||
import org.jetbrains.kotlin.j2k.AbstractJavaToKotlinConverterForWebDemoTest
|
||||
import org.jetbrains.kotlin.j2k.AbstractJavaToKotlinConverterMultiFileTest
|
||||
import org.jetbrains.kotlin.j2k.AbstractJavaToKotlinConverterSingleFileTest
|
||||
import org.jetbrains.kotlin.jps.build.*
|
||||
import org.jetbrains.kotlin.jps.build.android.AbstractAndroidJpsTestCase
|
||||
import org.jetbrains.kotlin.jps.incremental.AbstractJsProtoComparisonTest
|
||||
import org.jetbrains.kotlin.jps.incremental.AbstractJvmProtoComparisonTest
|
||||
//import org.jetbrains.kotlin.jps.build.*
|
||||
//import org.jetbrains.kotlin.jps.build.android.AbstractAndroidJpsTestCase
|
||||
//import org.jetbrains.kotlin.jps.incremental.AbstractJsProtoComparisonTest
|
||||
//import org.jetbrains.kotlin.jps.incremental.AbstractJvmProtoComparisonTest
|
||||
import org.jetbrains.kotlin.kapt3.test.AbstractClassFileToSourceStubConverterTest
|
||||
import org.jetbrains.kotlin.kapt3.test.AbstractKotlinKaptContextTest
|
||||
import org.jetbrains.kotlin.noarg.AbstractBlackBoxCodegenTestForNoArg
|
||||
@@ -727,18 +722,10 @@ fun main(args: Array<String>) {
|
||||
model("refactoring/nameSuggestionProvider")
|
||||
}
|
||||
|
||||
testClass<AbstractSlicerTreeTest> {
|
||||
testClass<AbstractSlicerTest> {
|
||||
model("slicer", singleClass = true)
|
||||
}
|
||||
|
||||
testClass<AbstractSlicerLeafGroupingTest> {
|
||||
model("slicer/inflow", singleClass = true)
|
||||
}
|
||||
|
||||
testClass<AbstractSlicerNullnessGroupingTest> {
|
||||
model("slicer/inflow", singleClass = true)
|
||||
}
|
||||
|
||||
testClass<AbstractScratchRunActionTest> {
|
||||
model("scratch", extension = "kts", testMethod = "doCompilingTest", testClassName = "Compiling", recursive = false)
|
||||
model("scratch", extension = "kts", testMethod = "doReplTest", testClassName = "Repl", recursive = false)
|
||||
@@ -746,24 +733,27 @@ fun main(args: Array<String>) {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
// Maven and Gradle are not relevant for AS branch
|
||||
|
||||
testGroup("idea/idea-maven/test", "idea/idea-maven/testData") {
|
||||
testClass<AbstractMavenConfigureProjectByChangingFileTest> {
|
||||
model("configurator/jvm", extension = null, recursive = false, testMethod = "doTestWithMaven")
|
||||
model("configurator/js", extension = null, recursive = false, testMethod = "doTestWithJSMaven")
|
||||
}
|
||||
|
||||
testClass<AbstractKotlinMavenInspectionTest> {
|
||||
model("maven-inspections", pattern = "^([\\w\\-]+).xml$", singleClass = true)
|
||||
}
|
||||
}
|
||||
|
||||
testGroup("idea/idea-gradle/tests", "idea/testData") {
|
||||
testClass<AbstractGradleConfigureProjectByChangingFileTest> {
|
||||
model("configuration/gradle", extension = null, recursive = false, testMethod = "doTestGradle")
|
||||
model("configuration/gsk", extension = null, recursive = false, testMethod = "doTestGradle")
|
||||
model("configuration/gradle", pattern = """(\w+)_before\.gradle$""", testMethod = "doTestGradle")
|
||||
model("configuration/gsk", pattern = """(\w+)_before\.gradle.kts$""", testMethod = "doTestGradle")
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
testGroup("idea/tests", "compiler/testData") {
|
||||
testClass<AbstractResolveByStubTest> {
|
||||
model("loadJava/compiledKotlin")
|
||||
@@ -889,6 +879,8 @@ fun main(args: Array<String>) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
testGroup("jps-plugin/jps-tests/test", "jps-plugin/testData") {
|
||||
testClass<AbstractIncrementalJpsTest> {
|
||||
model("incremental/multiModule", extension = null, excludeParentDirs = true)
|
||||
@@ -965,6 +957,8 @@ fun main(args: Array<String>) {
|
||||
model("incremental/multiplatform", extension = null, excludeParentDirs = true)
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
testGroup("plugins/android-extensions/android-extensions-compiler/test", "plugins/android-extensions/android-extensions-compiler/testData") {
|
||||
testClass<AbstractAndroidSyntheticPropertyDescriptorTest> {
|
||||
@@ -1082,10 +1076,6 @@ fun main(args: Array<String>) {
|
||||
model("android/quickfix", pattern = """^(\w+)\.((before\.Main\.\w+)|(test))$""", testMethod = "doTestWithExtraFile")
|
||||
}
|
||||
|
||||
testClass<AbstractKotlinLintTest> {
|
||||
model("android/lint", excludeParentDirs = true)
|
||||
}
|
||||
|
||||
testClass<AbstractAndroidLintQuickfixTest> {
|
||||
model("android/lintQuickfix", pattern = "^([\\w\\-_]+)\\.kt$")
|
||||
}
|
||||
@@ -1099,9 +1089,16 @@ fun main(args: Array<String>) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
|
||||
|
||||
testGroup("plugins/android-extensions/android-extensions-jps/test", "plugins/android-extensions/android-extensions-jps/testData") {
|
||||
testClass<AbstractAndroidJpsTestCase> {
|
||||
model("android", recursive = false, extension = null)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
*/
|
||||
}
|
||||
|
||||
@@ -9,3 +9,5 @@ kotlin.compiler.newInferenceEnabled=true
|
||||
#bootstrap.kotlin.repo=https://dl.bintray.com/kotlin/kotlin-dev
|
||||
#bootstrap.kotlin.version=1.1.50-dev-1451
|
||||
#signingRequired=true
|
||||
|
||||
intellijUltimateEnabled=false
|
||||
|
||||
@@ -11,7 +11,7 @@ dependencies {
|
||||
compileOnly(project(":idea:idea-jvm"))
|
||||
|
||||
compile(intellijDep())
|
||||
|
||||
|
||||
runtimeOnly(files(toolsJar()))
|
||||
}
|
||||
|
||||
|
||||
@@ -91,14 +91,15 @@ dependencies {
|
||||
testCompileOnly(commonDep("com.google.code.findbugs", "jsr305"))
|
||||
testCompileOnly(intellijPluginDep("gradle")) { includeJars("gradle-base-services", "gradle-tooling-extension-impl", "gradle-wrapper", rootProject = rootProject) }
|
||||
testCompileOnly(intellijPluginDep("Groovy")) { includeJars("Groovy") }
|
||||
testCompileOnly(intellijPluginDep("maven")) { includeJars("maven", "maven-server-api") }
|
||||
//testCompileOnly(intellijPluginDep("maven")) { includeJars("maven", "maven-server-api") }
|
||||
|
||||
testRuntime(intellijPluginDep("junit"))
|
||||
testRuntime(intellijPluginDep("gradle"))
|
||||
testRuntime(intellijPluginDep("Groovy"))
|
||||
testRuntime(intellijPluginDep("coverage"))
|
||||
testRuntime(intellijPluginDep("maven"))
|
||||
//testRuntime(intellijPluginDep("maven"))
|
||||
testRuntime(intellijPluginDep("android"))
|
||||
testRuntime(intellijPluginDep("smali"))
|
||||
testRuntime(intellijPluginDep("testng"))
|
||||
}
|
||||
|
||||
|
||||
@@ -85,13 +85,12 @@ public class KotlinCommonCodeStyleSettings extends CommonCodeStyleSettings {
|
||||
private void writeExternalBase(Element element, CommonCodeStyleSettings defaultSettings) throws WriteExternalException {
|
||||
Set<String> supportedFields = getSupportedFields();
|
||||
if (supportedFields != null) {
|
||||
supportedFields.add("PARENT_SETTINGS_INSTALLED");
|
||||
supportedFields.add("FORCE_REARRANGE_MODE");
|
||||
supportedFields.add("CODE_STYLE_DEFAULTS");
|
||||
}
|
||||
//noinspection deprecation
|
||||
DefaultJDOMExternalizer.writeExternal(this, element, new SupportedFieldsDiffFilter(this, supportedFields, defaultSettings));
|
||||
List<Integer> softMargins = getSoftMargins();
|
||||
serializeInto(softMargins, element);
|
||||
|
||||
IndentOptions myIndentOptions = getIndentOptions();
|
||||
if (myIndentOptions != null) {
|
||||
@@ -140,21 +139,6 @@ public class KotlinCommonCodeStyleSettings extends CommonCodeStyleSettings {
|
||||
commonSettings.setArrangementSettings(arrangementSettings.clone());
|
||||
}
|
||||
|
||||
try {
|
||||
Method setRootSettingsMethod = ArraysKt.singleOrNull(
|
||||
CommonCodeStyleSettings.class.getDeclaredMethods(),
|
||||
method -> "setSoftMargins".equals(method.getName()));
|
||||
|
||||
if (setRootSettingsMethod != null) {
|
||||
// Method was introduced in 173
|
||||
setRootSettingsMethod.setAccessible(true);
|
||||
setRootSettingsMethod.invoke(commonSettings, getSoftMargins());
|
||||
}
|
||||
}
|
||||
catch (IllegalAccessException | InvocationTargetException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
|
||||
return commonSettings;
|
||||
}
|
||||
|
||||
@@ -169,9 +153,6 @@ public class KotlinCommonCodeStyleSettings extends CommonCodeStyleSettings {
|
||||
}
|
||||
|
||||
CommonCodeStyleSettings other = (CommonCodeStyleSettings) obj;
|
||||
if (!getSoftMargins().equals(other.getSoftMargins())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
IndentOptions options = getIndentOptions();
|
||||
if ((options == null && other.getIndentOptions() != null) ||
|
||||
@@ -179,14 +160,7 @@ public class KotlinCommonCodeStyleSettings extends CommonCodeStyleSettings {
|
||||
return false;
|
||||
}
|
||||
|
||||
return arrangementSettingsEqual(other);
|
||||
}
|
||||
|
||||
// SoftMargins.serializeInfo
|
||||
private void serializeInto(@NotNull List<Integer> softMargins, @NotNull Element element) {
|
||||
if (softMargins.size() > 0) {
|
||||
XmlSerializer.serializeInto(this, element);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
//</editor-fold>
|
||||
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="module" module-name="backend" />
|
||||
<orderEntry type="module" module-name="frontend" />
|
||||
<orderEntry type="module" module-name="frontend.java" />
|
||||
<orderEntry type="module" module-name="light-classes" />
|
||||
<orderEntry type="module" module-name="eval4j" />
|
||||
<orderEntry type="module-library">
|
||||
<library>
|
||||
<CLASSES>
|
||||
<root url="jar://$MODULE_DIR$/../../ideaSDK/core/annotations.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</orderEntry>
|
||||
<orderEntry type="library" name="guava" level="project" />
|
||||
<orderEntry type="module" module-name="js.frontend" />
|
||||
<orderEntry type="module" module-name="js.serializer" />
|
||||
<orderEntry type="library" name="trove4j" level="project" />
|
||||
<orderEntry type="module" module-name="ide-common" exported="" />
|
||||
<orderEntry type="module" module-name="util" />
|
||||
<orderEntry type="module" module-name="idea-core" />
|
||||
<orderEntry type="module" module-name="idea-jps-common" />
|
||||
<orderEntry type="module" module-name="cli-common" />
|
||||
<orderEntry type="module" module-name="descriptors" />
|
||||
<orderEntry type="library" exported="" name="idea-full" level="project" />
|
||||
<orderEntry type="library" name="uast-java" level="project" />
|
||||
<orderEntry type="module" module-name="frontend.script" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -11,7 +11,6 @@ import com.intellij.openapi.components.ServiceManager
|
||||
import com.intellij.openapi.fileTypes.FileTypeRegistry
|
||||
import com.intellij.openapi.module.Module
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.project.rootManager
|
||||
import com.intellij.openapi.roots.ModuleRootEvent
|
||||
import com.intellij.openapi.roots.ModuleRootListener
|
||||
import com.intellij.openapi.util.Disposer
|
||||
@@ -33,6 +32,7 @@ import org.jetbrains.kotlin.idea.caches.project.getNullableModuleInfo
|
||||
import org.jetbrains.kotlin.idea.stubindex.PackageIndexUtil
|
||||
import org.jetbrains.kotlin.idea.util.getSourceRoot
|
||||
import org.jetbrains.kotlin.idea.util.sourceRoot
|
||||
import org.jetbrains.kotlin.idea.util.rootManager
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.psi.KtPackageDirective
|
||||
@@ -60,7 +60,7 @@ class KotlinPackageContentModificationListener(private val project: Project) {
|
||||
events
|
||||
.asSequence()
|
||||
.filter { it.file != null }
|
||||
.filter(::isRelevant)
|
||||
.filter(this::isRelevant)
|
||||
.filter {
|
||||
val vFile = it.file!!
|
||||
vFile.isDirectory || FileTypeRegistry.getInstance().getFileTypeByFileName(vFile.name) == KotlinFileType.INSTANCE
|
||||
|
||||
@@ -33,7 +33,7 @@ class KtLightClassForDecompiledDeclaration(
|
||||
override val kotlinOrigin: KtClassOrObject?,
|
||||
private val file: KtClsFile
|
||||
) : KtLightClassBase(clsDelegate.manager) {
|
||||
val fqName = kotlinOrigin?.fqName ?: FqName(clsDelegate.qualifiedName.orEmpty())
|
||||
val fqName = kotlinOrigin?.fqName ?: FqName(clsDelegate.qualifiedName)
|
||||
|
||||
override fun copy() = this
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ dependencies {
|
||||
compileOnly(project(":kotlin-android-extensions-runtime"))
|
||||
compileOnly(intellijDep()) { includeJars("openapi", "idea", "extensions", "util", "guava", "android-base-common", rootProject = rootProject) }
|
||||
compileOnly(intellijPluginDep("android")) {
|
||||
includeJars("android", "android-common", "sdk-common", "sdklib", "sdk-tools", "layoutlib-api")
|
||||
includeJars("android", "android-common", "common", "sdk-common", "sdklib", "sdk-tools", "layoutlib-api", rootProject = rootProject)
|
||||
}
|
||||
|
||||
testCompile(projectDist(":kotlin-test:kotlin-test-jvm"))
|
||||
@@ -37,10 +37,10 @@ dependencies {
|
||||
testCompile(projectTests(":idea:idea-gradle"))
|
||||
testCompile(commonDep("junit:junit"))
|
||||
|
||||
testCompile(intellijDep()) { includeJars("gson", rootProject = rootProject) }
|
||||
testCompile(intellijDep()) { includeJars("android-base-common", "gson", rootProject = rootProject) }
|
||||
testCompile(intellijPluginDep("properties"))
|
||||
testCompileOnly(intellijPluginDep("android")) {
|
||||
includeJars("android", "android-common", "sdk-common", "sdklib", "sdk-tools", "layoutlib-api")
|
||||
includeJars("android", "android-common", "build-common", "common", "sdk-common", "sdklib", "sdk-tools", "layoutlib-api", rootProject = rootProject)
|
||||
}
|
||||
|
||||
testRuntime(projectDist(":kotlin-reflect"))
|
||||
@@ -51,6 +51,7 @@ dependencies {
|
||||
testRuntime(project(":allopen-ide-plugin"))
|
||||
|
||||
testRuntime(intellijPluginDep("android"))
|
||||
testRuntime(intellijPluginDep("smali"))
|
||||
testRuntime(intellijPluginDep("copyright"))
|
||||
testRuntime(intellijPluginDep("coverage"))
|
||||
testRuntime(intellijPluginDep("gradle"))
|
||||
@@ -59,7 +60,7 @@ dependencies {
|
||||
testRuntime(intellijPluginDep("java-decompiler"))
|
||||
testRuntime(intellijPluginDep("java-i18n"))
|
||||
testRuntime(intellijPluginDep("junit"))
|
||||
testRuntime(intellijPluginDep("maven"))
|
||||
//testRuntime(intellijPluginDep("maven"))
|
||||
testRuntime(intellijPluginDep("testng"))
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ dependencies {
|
||||
compileOnly(intellijCoreDep()) { includeJars("intellij-core") }
|
||||
compileOnly(intellijDep()) { includeJars("guava", "android-base-common", rootProject = rootProject) }
|
||||
compileOnly(intellijPluginDep("gradle")) { includeJars("gradle-tooling-api", rootProject = rootProject) }
|
||||
compileOnly(intellijPluginDep("android")) { includeJars("android", "android-common", "sdk-common") }
|
||||
compileOnly(intellijPluginDep("android")) { includeJars("android", "android-common", "common", "sdk-common", rootProject = rootProject) }
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2010-2017 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.kotlin.android
|
||||
|
||||
import com.android.tools.idea.npw.template.ConvertJavaToKotlinProvider
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.psi.PsiFile
|
||||
import com.intellij.psi.PsiJavaFile
|
||||
import org.jetbrains.kotlin.android.configure.KotlinAndroidGradleModuleConfigurator
|
||||
import org.jetbrains.kotlin.idea.actions.JavaToKotlinAction
|
||||
import org.jetbrains.kotlin.idea.configuration.KotlinProjectConfigurator
|
||||
import org.jetbrains.kotlin.idea.configuration.getCanBeConfiguredModules
|
||||
import org.jetbrains.kotlin.idea.versions.bundledRuntimeVersion
|
||||
|
||||
class ConvertJavaToKotlinProviderImpl : ConvertJavaToKotlinProvider {
|
||||
override fun configureKotlin(project: Project) {
|
||||
val configurator = KotlinProjectConfigurator.EP_NAME.findExtension(KotlinAndroidGradleModuleConfigurator::class.java)
|
||||
val nonConfiguredModules = getCanBeConfiguredModules(project, configurator)
|
||||
configurator.configureSilently(project, nonConfiguredModules, bundledRuntimeVersion())
|
||||
}
|
||||
|
||||
override fun getKotlinVersion(): String {
|
||||
return bundledRuntimeVersion()
|
||||
}
|
||||
|
||||
override fun convertToKotlin(project: Project, files: List<PsiJavaFile>): List<PsiFile> {
|
||||
return JavaToKotlinAction.convertFiles(files, project, askExternalCodeProcessing = false)
|
||||
}
|
||||
}
|
||||
@@ -34,6 +34,7 @@ import com.intellij.ui.awt.RelativePoint
|
||||
import com.intellij.util.Function
|
||||
import org.jetbrains.android.dom.manifest.Manifest
|
||||
import org.jetbrains.android.facet.AndroidFacet
|
||||
import org.jetbrains.android.resourceManagers.ModuleResourceManagers
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.unsafeResolveToDescriptor
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
@@ -95,7 +96,8 @@ class KotlinAndroidLineMarkerProvider : LineMarkerProvider {
|
||||
return
|
||||
}
|
||||
|
||||
val files = androidFacet
|
||||
val files = ModuleResourceManagers
|
||||
.getInstance(androidFacet)
|
||||
.localResourceManager
|
||||
.findResourcesByFieldName(resClassName, info.fieldName)
|
||||
.filterIsInstance<PsiFile>()
|
||||
|
||||
@@ -23,8 +23,8 @@ import com.android.ide.common.resources.ResourceRepository;
|
||||
import com.android.ide.common.resources.ResourceResolver;
|
||||
import com.android.resources.ResourceType;
|
||||
import com.android.tools.idea.configurations.Configuration;
|
||||
import com.android.tools.idea.configurations.ConfigurationManager;
|
||||
import com.android.tools.idea.res.AppResourceRepository;
|
||||
import com.android.tools.idea.res.LocalResourceRepository;
|
||||
import com.android.tools.idea.res.ResourceHelper;
|
||||
import com.android.tools.idea.ui.resourcechooser.ColorPicker;
|
||||
import com.android.utils.XmlUtils;
|
||||
@@ -61,15 +61,13 @@ import java.awt.*;
|
||||
import java.io.File;
|
||||
|
||||
import static com.android.SdkConstants.*;
|
||||
import static com.android.SdkConstants.ANDROID_URI;
|
||||
import static com.android.SdkConstants.ATTR_DRAWABLE;
|
||||
import static com.android.tools.idea.uibuilder.property.renderer.NlDefaultRenderer.ICON_SIZE;
|
||||
import static org.jetbrains.android.AndroidColorAnnotator.pickLayoutFile;
|
||||
|
||||
/**
|
||||
* Contains copied privates from AndroidColorAnnotator, so we could use them for Kotlin AndroidResourceReferenceAnnotator
|
||||
*/
|
||||
public class ResourceReferenceAnnotatorUtil {
|
||||
public static final int ICON_SIZE = 14;
|
||||
|
||||
@Nullable
|
||||
public static File pickBitmapFromXml(@NotNull File file, @NotNull ResourceResolver resourceResolver, @NotNull Project project) {
|
||||
try {
|
||||
@@ -146,7 +144,7 @@ public class ResourceReferenceAnnotatorUtil {
|
||||
ResourceItem item = frameworkResources.getResourceItem(type, name);
|
||||
return item.getResourceValue(type, configuration.getFullConfig(), false);
|
||||
} else {
|
||||
LocalResourceRepository appResources = AppResourceRepository.getAppResources(module, true);
|
||||
AppResourceRepository appResources = AppResourceRepository.getOrCreateInstance(module);
|
||||
if (appResources == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -161,26 +159,27 @@ public class ResourceReferenceAnnotatorUtil {
|
||||
@Nullable
|
||||
public static Configuration pickConfiguration(AndroidFacet facet, Module module, PsiFile file) {
|
||||
VirtualFile virtualFile = file.getVirtualFile();
|
||||
if (virtualFile == null) {
|
||||
if(virtualFile == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
VirtualFile parent = virtualFile.getParent();
|
||||
if (parent == null) {
|
||||
return null;
|
||||
}
|
||||
VirtualFile layout;
|
||||
String parentName = parent.getName();
|
||||
if (!parentName.startsWith(FD_RES_LAYOUT)) {
|
||||
layout = pickLayoutFile(module, facet);
|
||||
if (layout == null) {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
layout = virtualFile;
|
||||
}
|
||||
VirtualFile parent = virtualFile.getParent();
|
||||
if(parent == null) {
|
||||
return null;
|
||||
} else {
|
||||
String parentName = parent.getName();
|
||||
VirtualFile layout;
|
||||
if(!parentName.startsWith("layout")) {
|
||||
layout = ResourceHelper.pickAnyLayoutFile(module, facet);
|
||||
if(layout == null) {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
layout = virtualFile;
|
||||
}
|
||||
|
||||
return facet.getConfigurationManager().getConfiguration(layout);
|
||||
return ConfigurationManager.getOrCreateInstance(module).getConfiguration(layout);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class ColorRenderer extends GutterIconRenderer {
|
||||
|
||||
@@ -60,10 +60,12 @@ class AndroidGradleModelFacade : KotlinGradleModelFacade {
|
||||
|
||||
override fun getDependencyModules(ideModule: DataNode<ModuleData>, gradleIdeaProject: IdeaProject): Collection<DataNode<ModuleData>> {
|
||||
val ideProject = ideModule.parent as DataNode<ProjectData>
|
||||
ExternalSystemApiUtil.find(ideModule, AndroidProjectKeys.JAVA_MODULE_MODEL)?.let { javaModuleModel ->
|
||||
/*
|
||||
ExternalSystemApiUtil.find(ideModule, AndroidProjectKeys.JAVA_PROJECT)?.let { javaModuleModel ->
|
||||
val moduleNames = javaModuleModel.data.javaModuleDependencies.map { it.moduleName }.toHashSet()
|
||||
return findModulesByNames(moduleNames, gradleIdeaProject, ideProject)
|
||||
}
|
||||
*/
|
||||
ExternalSystemApiUtil.find(ideModule, AndroidProjectKeys.ANDROID_MODEL)?.let { androidModel ->
|
||||
val libraries = androidModel.data.mainArtifact.dependencies.javaLibraries
|
||||
val projects = androidModel.data.mainArtifact.dependencies.projects
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2010-2017 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.kotlin.android.configure
|
||||
|
||||
import com.android.tools.idea.gradle.project.model.AndroidModuleModel
|
||||
import com.android.tools.idea.gradle.project.sync.setup.post.ModuleSetupStep
|
||||
import com.intellij.openapi.module.Module
|
||||
import com.intellij.openapi.progress.ProgressIndicator
|
||||
import org.jetbrains.android.facet.AndroidFacet
|
||||
import org.jetbrains.kotlin.idea.configuration.compilerArgumentsBySourceSet
|
||||
import org.jetbrains.kotlin.idea.configuration.configureFacetByCompilerArguments
|
||||
import org.jetbrains.kotlin.idea.configuration.sourceSetName
|
||||
import org.jetbrains.kotlin.idea.facet.KotlinFacet
|
||||
|
||||
class KotlinAndroidModuleSetupStep : ModuleSetupStep() {
|
||||
override fun setUpModule(module: Module, progressIndicator: ProgressIndicator?) {
|
||||
val facet = AndroidFacet.getInstance(module) ?: return
|
||||
val androidModel = AndroidModuleModel.get(facet) ?: return
|
||||
val sourceSetName = androidModel.selectedVariant.name
|
||||
if (module.sourceSetName == sourceSetName) return
|
||||
val argsInfo = module.compilerArgumentsBySourceSet?.get(sourceSetName) ?: return
|
||||
val kotlinFacet = KotlinFacet.get(module) ?: return
|
||||
module.sourceSetName = sourceSetName
|
||||
configureFacetByCompilerArguments(kotlinFacet, argsInfo, null)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright 2010-2017 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.kotlin.android.configure
|
||||
|
||||
import com.android.tools.idea.gradle.project.model.AndroidModuleModel
|
||||
import com.intellij.openapi.externalSystem.model.DataNode
|
||||
import com.intellij.openapi.externalSystem.model.Key
|
||||
import com.intellij.openapi.externalSystem.model.ProjectKeys
|
||||
import com.intellij.openapi.externalSystem.model.project.ProjectData
|
||||
import com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider
|
||||
import com.intellij.openapi.externalSystem.service.project.manage.AbstractProjectDataService
|
||||
import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil
|
||||
import com.intellij.openapi.project.Project
|
||||
import org.jetbrains.kotlin.idea.configuration.GradleProjectImportHandler
|
||||
import org.jetbrains.kotlin.idea.configuration.configureFacetByGradleModule
|
||||
|
||||
class KotlinGradleAndroidModuleModelProjectDataService : AbstractProjectDataService<AndroidModuleModel, Void>() {
|
||||
companion object {
|
||||
val KEY = Key<AndroidModuleModel>(AndroidModuleModel::class.qualifiedName!!, 0)
|
||||
}
|
||||
|
||||
override fun getTargetDataKey() = KEY
|
||||
|
||||
override fun postProcess(
|
||||
toImport: MutableCollection<DataNode<AndroidModuleModel>>,
|
||||
projectData: ProjectData?,
|
||||
project: Project,
|
||||
modelsProvider: IdeModifiableModelsProvider
|
||||
) {
|
||||
super.postProcess(toImport, projectData, project, modelsProvider)
|
||||
for (moduleModelNode in toImport) {
|
||||
val moduleNode = ExternalSystemApiUtil.findParent(moduleModelNode, ProjectKeys.MODULE) ?: continue
|
||||
val moduleData = moduleNode.data
|
||||
val ideModule = modelsProvider.findIdeModule(moduleData) ?: continue
|
||||
val sourceSetName = moduleModelNode.data.selectedVariant.name
|
||||
val kotlinFacet = configureFacetByGradleModule(moduleNode, sourceSetName, ideModule, modelsProvider) ?: continue
|
||||
GradleProjectImportHandler.getInstances(project).forEach { it.importByModule(kotlinFacet, moduleNode) }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,7 @@ import com.intellij.openapi.roots.ProjectRootModificationTracker
|
||||
import com.intellij.psi.util.CachedValueProvider
|
||||
import com.intellij.psi.util.CachedValuesManager
|
||||
import org.jetbrains.android.facet.AndroidFacet
|
||||
import org.jetbrains.android.sdk.AndroidSdkData
|
||||
import org.jetbrains.kotlin.idea.debugger.evaluate.classLoading.AndroidDexer
|
||||
import org.jetbrains.kotlin.idea.debugger.evaluate.classLoading.ClassToLoad
|
||||
import java.io.File
|
||||
@@ -56,7 +57,7 @@ class AndroidDexerImpl(val project: Project) : AndroidDexer {
|
||||
private fun doGetAndroidDexFile(): File? {
|
||||
for (module in ModuleManager.getInstance(project).modules) {
|
||||
val androidFacet = AndroidFacet.getInstance(module) ?: continue
|
||||
val sdkData = androidFacet.sdkData ?: continue
|
||||
val sdkData = AndroidSdkData.getSdkData(androidFacet) ?: continue
|
||||
val latestBuildTool = sdkData.getLatestBuildTool(/* allowPreview = */ false)
|
||||
?: sdkData.getLatestBuildTool(/* allowPreview = */ true)
|
||||
?: continue
|
||||
|
||||
@@ -47,7 +47,6 @@ class ResourceFoldingBuilder : FoldingBuilderEx() {
|
||||
// See lint's StringFormatDetector
|
||||
private val FORMAT = Pattern.compile("%(\\d+\\$)?([-+#, 0(<]*)?(\\d+)?(\\.\\d+)?([tT])?([a-zA-Z%])")
|
||||
private val FOLD_MAX_LENGTH = 60
|
||||
private val FORCE_PROJECT_RESOURCE_LOADING = true
|
||||
private val UNIT_TEST_MODE: Boolean = ApplicationManager.getApplication().isUnitTestMode
|
||||
private val RESOURCE_TYPES = listOf(ResourceType.STRING,
|
||||
ResourceType.DIMEN,
|
||||
@@ -254,6 +253,6 @@ class ResourceFoldingBuilder : FoldingBuilderEx() {
|
||||
}
|
||||
|
||||
private fun getAppResources(element: PsiElement): LocalResourceRepository? = ModuleUtilCore.findModuleForPsiElement(element)?.let {
|
||||
AppResourceRepository.getAppResources(it, FORCE_PROJECT_RESOURCE_LOADING)
|
||||
AppResourceRepository.findExistingInstance(it)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.android.inspection
|
||||
|
||||
import com.android.tools.idea.model.AndroidModuleInfo
|
||||
import com.intellij.codeInspection.*
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.psi.PsiElementVisitor
|
||||
@@ -28,7 +29,11 @@ import org.jetbrains.kotlin.psi.psiUtil.addTypeArgument
|
||||
|
||||
class TypeParameterFindViewByIdInspection : AbstractKotlinInspection(), CleanupLocalInspectionTool {
|
||||
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean, session: LocalInspectionToolSession): PsiElementVisitor {
|
||||
val compileSdk = AndroidFacet.getInstance(session.file)?.androidModuleInfo?.buildSdkVersion?.apiLevel
|
||||
val compileSdk = AndroidFacet.getInstance(session.file)
|
||||
?.let { facet -> AndroidModuleInfo.getInstance(facet) }
|
||||
?.buildSdkVersion
|
||||
?.apiLevel
|
||||
|
||||
if (compileSdk == null || compileSdk < 26) {
|
||||
return KtVisitorVoid()
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.jetbrains.android.dom.resources.Attr;
|
||||
import org.jetbrains.android.dom.resources.DeclareStyleable;
|
||||
import org.jetbrains.android.facet.AndroidFacet;
|
||||
import org.jetbrains.android.resourceManagers.LocalResourceManager;
|
||||
import org.jetbrains.android.resourceManagers.ModuleResourceManagers;
|
||||
import org.jetbrains.android.resourceManagers.ResourceManager;
|
||||
import org.jetbrains.android.util.AndroidResourceUtil;
|
||||
import org.jetbrains.android.util.AndroidUtils;
|
||||
@@ -68,9 +69,10 @@ public class KotlinAndroidGotoDeclarationHandler implements GotoDeclarationHandl
|
||||
collectManifestElements(nestedClassName, fieldName, facet, resourceList);
|
||||
}
|
||||
else {
|
||||
ModuleResourceManagers managers = ModuleResourceManagers.getInstance(facet);
|
||||
ResourceManager manager = info.isSystem()
|
||||
? facet.getSystemResourceManager(false)
|
||||
: facet.getLocalResourceManager();
|
||||
? managers.getSystemResourceManager(false)
|
||||
: managers.getLocalResourceManager();
|
||||
if (manager == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@ import com.intellij.psi.util.PsiTreeUtil
|
||||
import com.intellij.psi.PsiClass
|
||||
import org.jetbrains.android.util.AndroidUtils
|
||||
import com.android.SdkConstants
|
||||
import com.intellij.openapi.module.ModuleUtil
|
||||
import org.jetbrains.android.augment.AndroidPsiElementFinder
|
||||
import org.jetbrains.kotlin.idea.references.mainReference
|
||||
import org.jetbrains.kotlin.psi.KtDotQualifiedExpression
|
||||
@@ -68,7 +67,6 @@ private fun getReferredInfo(
|
||||
val firstPart = getReceiverAsSimpleNameExpression(middlePart) ?: return null
|
||||
|
||||
val resolvedClass = firstPart.mainReference.resolve() as? PsiClass ?: return null
|
||||
val resolvedModule = ModuleUtil.findModuleForPsiElement(resolvedClass)
|
||||
|
||||
//the following code is copied from
|
||||
// org.jetbrains.android.util.AndroidResourceUtil.getReferredResourceOrManifestField
|
||||
@@ -83,7 +81,7 @@ private fun getReferredInfo(
|
||||
val qName = resolvedClass.qualifiedName
|
||||
|
||||
if (SdkConstants.CLASS_R == qName || AndroidPsiElementFinder.INTERNAL_R_CLASS_QNAME == qName) {
|
||||
return AndroidResourceUtil.MyReferredResourceFieldInfo(resClassName, resFieldName, resolvedModule, true, false)
|
||||
return AndroidResourceUtil.MyReferredResourceFieldInfo(resClassName, resFieldName, facet.module, true, false)
|
||||
}
|
||||
val containingFile = resolvedClass.containingFile ?: return null
|
||||
|
||||
@@ -95,7 +93,7 @@ private fun getReferredInfo(
|
||||
return null
|
||||
}
|
||||
|
||||
return AndroidResourceUtil.MyReferredResourceFieldInfo(resClassName, resFieldName, resolvedModule, false, fromManifest)
|
||||
return AndroidResourceUtil.MyReferredResourceFieldInfo(resClassName, resFieldName, facet.module, false, fromManifest)
|
||||
}
|
||||
|
||||
private fun getReceiverAsSimpleNameExpression(exp: KtSimpleNameExpression): KtSimpleNameExpression? {
|
||||
|
||||
@@ -14,13 +14,15 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.android.inspections.klint
|
||||
package org.jetbrains.kotlin.android.quickfix
|
||||
|
||||
import com.android.SdkConstants
|
||||
import com.android.tools.klint.checks.ApiDetector.REQUIRES_API_ANNOTATION
|
||||
import com.android.tools.lint.checks.ApiDetector.REQUIRES_API_ANNOTATION
|
||||
import com.intellij.codeInsight.FileModificationService
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import org.jetbrains.android.inspections.lint.AndroidLintQuickFix
|
||||
import org.jetbrains.android.inspections.lint.AndroidQuickfixContexts
|
||||
import org.jetbrains.android.util.AndroidBundle
|
||||
import org.jetbrains.kotlin.android.hasBackingField
|
||||
import org.jetbrains.kotlin.idea.util.addAnnotation
|
||||
@@ -14,12 +14,14 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.android.inspections.klint
|
||||
package org.jetbrains.kotlin.android.quickfix
|
||||
|
||||
import com.intellij.codeInsight.FileModificationService
|
||||
import com.intellij.psi.PsiDocumentManager
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import org.jetbrains.android.inspections.lint.AndroidLintQuickFix
|
||||
import org.jetbrains.android.inspections.lint.AndroidQuickfixContexts
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||
import org.jetbrains.kotlin.idea.codeInsight.surroundWith.statement.KotlinIfSurrounder
|
||||
import org.jetbrains.kotlin.idea.core.ShortenReferences
|
||||
@@ -14,11 +14,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.android.inspections.klint
|
||||
package org.jetbrains.kotlin.android.quickfix
|
||||
|
||||
import com.android.sdklib.SdkVersionInfo
|
||||
import com.android.sdklib.SdkVersionInfo.*
|
||||
|
||||
|
||||
fun getVersionField(api: Int, fullyQualified: Boolean): String = SdkVersionInfo.getBuildCode(api)?.let {
|
||||
fun getVersionField(api: Int, fullyQualified: Boolean): String = getBuildCode(api)?.let {
|
||||
if (fullyQualified) "android.os.Build.VERSION_CODES.$it" else it
|
||||
} ?: api.toString()
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright 2010-2017 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.kotlin.android.quickfix
|
||||
|
||||
import com.android.SdkConstants.SUPPORT_ANNOTATIONS_PREFIX
|
||||
import com.android.tools.lint.checks.ApiDetector
|
||||
import com.android.tools.lint.checks.CommentDetector
|
||||
import com.android.tools.lint.checks.ParcelDetector
|
||||
import com.android.tools.lint.detector.api.Issue
|
||||
import com.intellij.psi.JavaPsiFacade
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.search.GlobalSearchScope
|
||||
import org.jetbrains.android.inspections.lint.AndroidLintQuickFix
|
||||
import org.jetbrains.android.inspections.lint.AndroidLintQuickFixProvider
|
||||
import java.util.regex.Pattern
|
||||
|
||||
|
||||
class KotlinAndroidQuickFixProvider : AndroidLintQuickFixProvider {
|
||||
override fun getQuickFixes(
|
||||
issue: Issue,
|
||||
startElement: PsiElement,
|
||||
endElement: PsiElement,
|
||||
message: String,
|
||||
data: Any?
|
||||
): Array<AndroidLintQuickFix> {
|
||||
val fixes: Array<AndroidLintQuickFix> = when (issue) {
|
||||
ApiDetector.UNSUPPORTED, ApiDetector.INLINED -> getApiQuickFixes(issue, startElement, message)
|
||||
ParcelDetector.ISSUE -> arrayOf(ParcelableQuickFix())
|
||||
else -> emptyArray()
|
||||
}
|
||||
|
||||
if (issue != CommentDetector.STOP_SHIP) {
|
||||
return fixes + SuppressLintQuickFix(issue.id)
|
||||
}
|
||||
|
||||
return fixes
|
||||
}
|
||||
|
||||
fun getApiQuickFixes(issue: Issue, element: PsiElement, message: String): Array<AndroidLintQuickFix> {
|
||||
val api = getRequiredVersion(message)
|
||||
if (api == -1) {
|
||||
return AndroidLintQuickFix.EMPTY_ARRAY
|
||||
}
|
||||
|
||||
val project = element.project
|
||||
if (JavaPsiFacade.getInstance(project).findClass(REQUIRES_API_ANNOTATION, GlobalSearchScope.allScope(project)) != null) {
|
||||
return arrayOf(AddTargetApiQuickFix(api, true), AddTargetApiQuickFix(api, false), AddTargetVersionCheckQuickFix(api))
|
||||
}
|
||||
|
||||
return arrayOf(AddTargetApiQuickFix(api, false), AddTargetVersionCheckQuickFix(api))
|
||||
}
|
||||
|
||||
private fun getRequiredVersion(errorMessage: String): Int {
|
||||
val pattern = Pattern.compile("\\s(\\d+)\\s")
|
||||
val matcher = pattern.matcher(errorMessage)
|
||||
if (matcher.find()) {
|
||||
return Integer.parseInt(matcher.group(1))
|
||||
}
|
||||
|
||||
return -1
|
||||
}
|
||||
|
||||
companion object {
|
||||
val REQUIRES_API_ANNOTATION = SUPPORT_ANNOTATIONS_PREFIX + "RequiresApi"
|
||||
}
|
||||
}
|
||||
@@ -14,10 +14,12 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.android.inspections.klint
|
||||
package org.jetbrains.kotlin.android.quickfix
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import org.jetbrains.android.inspections.lint.AndroidLintQuickFix
|
||||
import org.jetbrains.android.inspections.lint.AndroidQuickfixContexts
|
||||
import org.jetbrains.android.util.AndroidBundle
|
||||
import org.jetbrains.kotlin.android.canAddParcelable
|
||||
import org.jetbrains.kotlin.android.implementParcelable
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
* Copyright 2010-2017 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.
|
||||
@@ -14,52 +14,26 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.android.inspections.klint
|
||||
package org.jetbrains.kotlin.android.quickfix
|
||||
|
||||
import com.android.SdkConstants.FQCN_SUPPRESS_LINT
|
||||
import com.android.SdkConstants
|
||||
import com.intellij.codeInsight.FileModificationService
|
||||
import com.intellij.codeInsight.intention.IntentionAction
|
||||
import com.intellij.icons.AllIcons
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.util.Iconable
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiFile
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import org.jetbrains.android.inspections.lint.AndroidLintQuickFix
|
||||
import org.jetbrains.android.inspections.lint.AndroidQuickfixContexts
|
||||
import org.jetbrains.android.util.AndroidBundle
|
||||
import org.jetbrains.kotlin.android.hasBackingField
|
||||
import org.jetbrains.kotlin.idea.util.addAnnotation
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import javax.swing.Icon
|
||||
|
||||
|
||||
class SuppressLintIntentionAction(val id: String, val element: PsiElement) : IntentionAction, Iconable {
|
||||
|
||||
private companion object {
|
||||
val INTENTION_NAME_PREFIX = "AndroidKLint"
|
||||
val SUPPRESS_LINT_MESSAGE = "android.lint.fix.suppress.lint.api.annotation"
|
||||
val FQNAME_SUPPRESS_LINT = FqName(FQCN_SUPPRESS_LINT)
|
||||
}
|
||||
|
||||
class SuppressLintQuickFix(id: String) : AndroidLintQuickFix {
|
||||
private val lintId = getLintId(id)
|
||||
|
||||
override fun isAvailable(project: Project, editor: Editor?, file: PsiFile?) = true
|
||||
|
||||
override fun getText(): String = AndroidBundle.message(SUPPRESS_LINT_MESSAGE, lintId)
|
||||
|
||||
override fun getFamilyName() = text
|
||||
|
||||
override fun getIcon(flags: Int): Icon? = AllIcons.Actions.Cancel
|
||||
|
||||
override fun startInWriteAction() = true
|
||||
|
||||
override fun invoke(project: Project, editor: Editor?, file: PsiFile?) {
|
||||
if (file !is KtFile) {
|
||||
return
|
||||
}
|
||||
|
||||
val annotationContainer = PsiTreeUtil.findFirstParent(element, true) { it.isSuppressLintTarget() } ?: return
|
||||
override fun apply(startElement: PsiElement, endElement: PsiElement, context: AndroidQuickfixContexts.Context) {
|
||||
val annotationContainer = PsiTreeUtil.findFirstParent(startElement, true) { it.isSuppressLintTarget() } ?: return
|
||||
if (!FileModificationService.getInstance().preparePsiElementForWrite(annotationContainer)) {
|
||||
return
|
||||
}
|
||||
@@ -67,14 +41,24 @@ class SuppressLintIntentionAction(val id: String, val element: PsiElement) : Int
|
||||
val argument = "\"$lintId\""
|
||||
|
||||
when (annotationContainer) {
|
||||
is KtModifierListOwner -> annotationContainer.addAnnotation(
|
||||
FQNAME_SUPPRESS_LINT,
|
||||
argument,
|
||||
whiteSpaceText = if (annotationContainer.isNewLineNeededForAnnotation()) "\n" else " ",
|
||||
addToExistingAnnotation = { entry -> addArgumentToAnnotation(entry, argument) })
|
||||
is KtModifierListOwner -> {
|
||||
annotationContainer.addAnnotation(
|
||||
FQNAME_SUPPRESS_LINT,
|
||||
argument,
|
||||
whiteSpaceText = if (annotationContainer.isNewLineNeededForAnnotation()) "\n" else " ",
|
||||
addToExistingAnnotation = { entry -> addArgumentToAnnotation(entry, argument) })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun getName(): String = AndroidBundle.message(SUPPRESS_LINT_MESSAGE, lintId)
|
||||
|
||||
override fun isApplicable(
|
||||
startElement: PsiElement,
|
||||
endElement: PsiElement,
|
||||
contextType: AndroidQuickfixContexts.ContextType
|
||||
): Boolean = true
|
||||
|
||||
private fun addArgumentToAnnotation(entry: KtAnnotationEntry, argument: String): Boolean {
|
||||
// add new arguments to an existing entry
|
||||
val args = entry.valueArgumentList
|
||||
@@ -107,4 +91,9 @@ class SuppressLintIntentionAction(val id: String, val element: PsiElement) : Int
|
||||
this !is KtFunctionLiteral &&
|
||||
this !is KtDestructuringDeclaration
|
||||
}
|
||||
private companion object {
|
||||
val INTENTION_NAME_PREFIX = "AndroidLint"
|
||||
val SUPPRESS_LINT_MESSAGE = "android.lint.fix.suppress.lint.api.annotation"
|
||||
val FQNAME_SUPPRESS_LINT = FqName(SdkConstants.FQCN_SUPPRESS_LINT)
|
||||
}
|
||||
}
|
||||
@@ -1,84 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2016 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.kotlin.android.lint
|
||||
|
||||
import com.intellij.codeInspection.InspectionProfileEntry
|
||||
import com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl
|
||||
import com.intellij.util.PathUtil
|
||||
import org.jetbrains.android.inspections.klint.AndroidLintInspectionBase
|
||||
import org.jetbrains.kotlin.android.KotlinAndroidTestCase
|
||||
import org.jetbrains.kotlin.idea.test.ConfigLibraryUtil
|
||||
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
||||
import org.jetbrains.kotlin.test.InTextDirectivesUtils.findStringWithPrefixes
|
||||
import java.io.File
|
||||
|
||||
abstract class AbstractKotlinLintTest : KotlinAndroidTestCase() {
|
||||
|
||||
override fun setUp() {
|
||||
super.setUp()
|
||||
AndroidLintInspectionBase.invalidateInspectionShortName2IssueMap()
|
||||
(myFixture as CodeInsightTestFixtureImpl).setVirtualFileFilter { false } // Allow access to tree elements.
|
||||
ConfigLibraryUtil.configureKotlinRuntime(myModule)
|
||||
ConfigLibraryUtil.addLibrary(myModule, "androidExtensionsRuntime", "dist/kotlinc/lib", arrayOf("android-extensions-runtime.jar"))
|
||||
}
|
||||
|
||||
override fun tearDown() {
|
||||
ConfigLibraryUtil.unConfigureKotlinRuntime(myModule)
|
||||
ConfigLibraryUtil.removeLibrary(myModule, "androidExtensionsRuntime")
|
||||
super.tearDown()
|
||||
}
|
||||
|
||||
fun doTest(path: String) {
|
||||
val ktFile = File(path)
|
||||
val fileText = ktFile.readText()
|
||||
val mainInspectionClassName = findStringWithPrefixes(fileText, "// INSPECTION_CLASS: ") ?: error("Empty class name")
|
||||
val dependencies = InTextDirectivesUtils.findLinesWithPrefixesRemoved(fileText, "// DEPENDENCY: ")
|
||||
|
||||
val inspectionClassNames = mutableListOf(mainInspectionClassName)
|
||||
for (i in 2..100) {
|
||||
val className = findStringWithPrefixes(ktFile.readText(), "// INSPECTION_CLASS$i: ") ?: break
|
||||
inspectionClassNames += className
|
||||
}
|
||||
|
||||
myFixture.enableInspections(*inspectionClassNames.map { className ->
|
||||
val inspectionClass = Class.forName(className)
|
||||
inspectionClass.newInstance() as InspectionProfileEntry
|
||||
}.toTypedArray())
|
||||
|
||||
val additionalResourcesDir = File(ktFile.parentFile, getTestName(true))
|
||||
if (additionalResourcesDir.exists()) {
|
||||
for (file in additionalResourcesDir.listFiles()) {
|
||||
if (file.isFile) {
|
||||
myFixture.copyFileToProject(file.absolutePath, file.name)
|
||||
}
|
||||
else if (file.isDirectory) {
|
||||
myFixture.copyDirectoryToProject(file.absolutePath, file.name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val virtualFile = myFixture.copyFileToProject(ktFile.absolutePath, "src/${PathUtil.getFileName(path)}")
|
||||
myFixture.configureFromExistingVirtualFile(virtualFile)
|
||||
|
||||
dependencies.forEach { dependency ->
|
||||
val (dependencyFile, dependencyTargetPath) = dependency.split(" -> ").map(String::trim)
|
||||
myFixture.copyFileToProject("${PathUtil.getParentPath(path)}/$dependencyFile", "src/$dependencyTargetPath")
|
||||
}
|
||||
|
||||
myFixture.checkHighlighting(true, false, true)
|
||||
}
|
||||
}
|
||||
@@ -1,195 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.android.lint;
|
||||
|
||||
import com.intellij.testFramework.TestDataPath;
|
||||
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils;
|
||||
import org.jetbrains.kotlin.test.TargetBackend;
|
||||
import org.jetbrains.kotlin.test.TestMetadata;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
|
||||
@SuppressWarnings("all")
|
||||
@TestMetadata("idea/testData/android/lint")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public class KotlinLintTestGenerated extends AbstractKotlinLintTest {
|
||||
@TestMetadata("alarm.kt")
|
||||
public void testAlarm() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/android/lint/alarm.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInLint() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/android/lint"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
|
||||
}
|
||||
|
||||
@TestMetadata("apiCheck.kt")
|
||||
public void testApiCheck() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/android/lint/apiCheck.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("callSuper.kt")
|
||||
public void testCallSuper() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/android/lint/callSuper.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("closeCursor.kt")
|
||||
public void testCloseCursor() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/android/lint/closeCursor.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("commitFragment.kt")
|
||||
public void testCommitFragment() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/android/lint/commitFragment.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("findViewById.kt")
|
||||
public void testFindViewById() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/android/lint/findViewById.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("javaPerformance.kt")
|
||||
public void testJavaPerformance() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/android/lint/javaPerformance.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("javaScriptInterface.kt")
|
||||
public void testJavaScriptInterface() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/android/lint/javaScriptInterface.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("layoutInflation.kt")
|
||||
public void testLayoutInflation() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/android/lint/layoutInflation.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("log.kt")
|
||||
public void testLog() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/android/lint/log.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("noInternationalSms.kt")
|
||||
public void testNoInternationalSms() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/android/lint/noInternationalSms.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("overrideConcrete.kt")
|
||||
public void testOverrideConcrete() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/android/lint/overrideConcrete.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("parcel.kt")
|
||||
public void testParcel() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/android/lint/parcel.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("sdCardTest.kt")
|
||||
public void testSdCardTest() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/android/lint/sdCardTest.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("setJavaScriptEnabled.kt")
|
||||
public void testSetJavaScriptEnabled() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/android/lint/setJavaScriptEnabled.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("sharedPrefs.kt")
|
||||
public void testSharedPrefs() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/android/lint/sharedPrefs.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("showDiagnosticsWhenFileIsRed.kt")
|
||||
public void testShowDiagnosticsWhenFileIsRed() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/android/lint/showDiagnosticsWhenFileIsRed.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("sqlite.kt")
|
||||
public void testSqlite() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/android/lint/sqlite.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("supportAnnotation.kt")
|
||||
public void testSupportAnnotation() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/android/lint/supportAnnotation.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("systemServices.kt")
|
||||
public void testSystemServices() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/android/lint/systemServices.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("toast.kt")
|
||||
public void testToast() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/android/lint/toast.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("valueOf.kt")
|
||||
public void testValueOf() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/android/lint/valueOf.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("velocityTrackerRecycle.kt")
|
||||
public void testVelocityTrackerRecycle() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/android/lint/velocityTrackerRecycle.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("viewConstructor.kt")
|
||||
public void testViewConstructor() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/android/lint/viewConstructor.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("viewHolder.kt")
|
||||
public void testViewHolder() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/android/lint/viewHolder.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("wrongAnnotation.kt")
|
||||
public void testWrongAnnotation() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/android/lint/wrongAnnotation.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("wrongImport.kt")
|
||||
public void testWrongImport() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/android/lint/wrongImport.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("wrongViewCall.kt")
|
||||
public void testWrongViewCall() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/android/lint/wrongViewCall.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,7 @@ package org.jetbrains.kotlin.android.quickfix
|
||||
import com.intellij.codeInspection.InspectionProfileEntry
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import com.intellij.util.PathUtil
|
||||
import org.jetbrains.android.inspections.klint.AndroidLintInspectionBase
|
||||
import org.jetbrains.android.inspections.lint.AndroidLintInspectionBase
|
||||
import org.jetbrains.kotlin.android.KotlinAndroidTestCase
|
||||
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
||||
import java.io.File
|
||||
|
||||
@@ -70,6 +70,7 @@ import org.jetbrains.kotlin.util.kind
|
||||
import org.jetbrains.kotlin.util.supertypesWithAny
|
||||
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
|
||||
import java.util.*
|
||||
|
||||
class BasicCompletionSession(
|
||||
configuration: CompletionSessionConfiguration,
|
||||
@@ -223,13 +224,6 @@ class BasicCompletionSession(
|
||||
}
|
||||
}
|
||||
|
||||
withCollectRequiredContextVariableTypes { lookupFactory ->
|
||||
DslMembersCompletion(
|
||||
prefixMatcher, lookupFactory, receiverTypes,
|
||||
collector, indicesHelper(true), callTypeAndReceiver
|
||||
).completeDslFunctions()
|
||||
}
|
||||
|
||||
val contextVariableTypesForSmartCompletion = withCollectRequiredContextVariableTypes(::completeWithSmartCompletion)
|
||||
|
||||
val contextVariableTypesForReferenceVariants = withCollectRequiredContextVariableTypes { lookupElementFactory ->
|
||||
@@ -464,14 +458,8 @@ class BasicCompletionSession(
|
||||
.filterNot { it.original in foundDescriptors }
|
||||
.onEach { foundDescriptors += it.original }
|
||||
|
||||
collector.addDescriptorElements(
|
||||
unique.toList(), factory,
|
||||
prohibitDuplicates = true
|
||||
)
|
||||
collector.addDescriptorElements(
|
||||
uniqueNotImportedExtensions.toList(), factory,
|
||||
notImported = true, prohibitDuplicates = true
|
||||
)
|
||||
collector.addDescriptorElements(unique.toList(), factory)
|
||||
collector.addDescriptorElements(uniqueNotImportedExtensions.toList(), factory, notImported = true)
|
||||
|
||||
flushToResultSet()
|
||||
}
|
||||
@@ -792,14 +780,8 @@ class BasicCompletionSession(
|
||||
|
||||
private fun addReferenceVariantElements(lookupElementFactory: LookupElementFactory, descriptorKindFilter: DescriptorKindFilter) {
|
||||
fun addReferenceVariants(referenceVariants: ReferenceVariants) {
|
||||
collector.addDescriptorElements(
|
||||
referenceVariantsHelper.excludeNonInitializedVariable(referenceVariants.imported, position),
|
||||
lookupElementFactory, prohibitDuplicates = true
|
||||
)
|
||||
collector.addDescriptorElements(
|
||||
referenceVariants.notImportedExtensions, lookupElementFactory,
|
||||
notImported = true, prohibitDuplicates = true
|
||||
)
|
||||
collector.addDescriptorElements(referenceVariantsHelper.excludeNonInitializedVariable(referenceVariants.imported, position), lookupElementFactory)
|
||||
collector.addDescriptorElements(referenceVariants.notImportedExtensions, lookupElementFactory, notImported = true)
|
||||
}
|
||||
|
||||
val referenceVariantsCollector = referenceVariantsCollector!!
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.jetbrains.kotlin.idea.completion
|
||||
|
||||
import com.intellij.codeInsight.lookup.*
|
||||
import com.intellij.openapi.editor.colors.EditorColorsManager
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.psi.PsiClass
|
||||
import com.intellij.psi.PsiElement
|
||||
@@ -30,7 +29,6 @@ import org.jetbrains.kotlin.idea.completion.handlers.KotlinClassifierInsertHandl
|
||||
import org.jetbrains.kotlin.idea.completion.handlers.KotlinFunctionInsertHandler
|
||||
import org.jetbrains.kotlin.idea.core.completion.DeclarationLookupObject
|
||||
import org.jetbrains.kotlin.idea.core.completion.PackageLookupObject
|
||||
import org.jetbrains.kotlin.idea.highlighter.dsl.DslHighlighterExtension
|
||||
import org.jetbrains.kotlin.load.java.JvmAbi
|
||||
import org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
@@ -39,10 +37,11 @@ import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
||||
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.isExtension
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.module
|
||||
import org.jetbrains.kotlin.synthetic.SamAdapterExtensionFunctionDescriptor
|
||||
import org.jetbrains.kotlin.synthetic.SyntheticJavaPropertyDescriptor
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.firstNotNullResult
|
||||
import java.awt.Font
|
||||
import javax.swing.Icon
|
||||
|
||||
class BasicLookupElementFactory(
|
||||
private val project: Project,
|
||||
@@ -234,14 +233,6 @@ class BasicLookupElementFactory(
|
||||
|
||||
if (descriptor is CallableDescriptor) {
|
||||
appendContainerAndReceiverInformation(descriptor) { element = element.appendTailText(it, true) }
|
||||
|
||||
val dslTextAttributes = DslHighlighterExtension.dslCustomTextStyle(descriptor)?.let {
|
||||
EditorColorsManager.getInstance().globalScheme.getAttributes(it)
|
||||
}
|
||||
if (dslTextAttributes != null) {
|
||||
element = element.withBoldness(dslTextAttributes.fontType == Font.BOLD)
|
||||
dslTextAttributes.foregroundColor?.let { element = element.withItemTextForeground(it) }
|
||||
}
|
||||
}
|
||||
|
||||
if (descriptor is PropertyDescriptor) {
|
||||
|
||||
@@ -41,6 +41,7 @@ import org.jetbrains.kotlin.idea.project.TargetPlatformDetector
|
||||
import org.jetbrains.kotlin.idea.project.languageVersionSettings
|
||||
import org.jetbrains.kotlin.idea.references.mainReference
|
||||
import org.jetbrains.kotlin.idea.util.*
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.module
|
||||
@@ -49,9 +50,9 @@ import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
||||
import org.jetbrains.kotlin.types.typeUtil.isUnit
|
||||
import org.jetbrains.kotlin.types.typeUtil.makeNotNullable
|
||||
import java.util.*
|
||||
import kotlin.collections.LinkedHashMap
|
||||
|
||||
class CompletionSessionConfiguration(
|
||||
val useBetterPrefixMatcherForNonImportedClasses: Boolean,
|
||||
@@ -271,12 +272,6 @@ abstract class CompletionSession(
|
||||
|
||||
sorter = sorter.weighAfter("kotlin.proximity", ByNameAlphabeticalWeigher, PreferLessParametersWeigher)
|
||||
|
||||
if (expectedInfos.all { it.fuzzyType?.type?.isUnit() == true }) {
|
||||
sorter = sorter.weighBefore("prefix", PreferDslMembers)
|
||||
} else {
|
||||
sorter = sorter.weighAfter("kotlin.preferContextElements", PreferDslMembers)
|
||||
}
|
||||
|
||||
return sorter
|
||||
}
|
||||
|
||||
|
||||
@@ -79,7 +79,6 @@ enum class ItemPriority {
|
||||
}
|
||||
|
||||
val ITEM_PRIORITY_KEY = Key<ItemPriority>("ITEM_PRIORITY_KEY")
|
||||
var LookupElement.isDslMember: Boolean? by UserDataProperty(Key.create("DSL_LOOKUP_ITEM"))
|
||||
|
||||
fun LookupElement.assignPriority(priority: ItemPriority): LookupElement {
|
||||
putUserData(ITEM_PRIORITY_KEY, priority)
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.completion
|
||||
|
||||
import com.intellij.codeInsight.completion.PrefixMatcher
|
||||
import com.intellij.codeInsight.lookup.LookupElement
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.idea.core.KotlinIndicesHelper
|
||||
import org.jetbrains.kotlin.idea.util.CallTypeAndReceiver
|
||||
import org.jetbrains.kotlin.idea.util.ReceiverType
|
||||
import org.jetbrains.kotlin.psi.KtModifierListOwner
|
||||
import org.jetbrains.kotlin.psi.psiUtil.collectAnnotationEntriesFromStubOrPsi
|
||||
import org.jetbrains.kotlin.resolve.calls.DslMarkerUtils
|
||||
|
||||
class DslMembersCompletion(
|
||||
private val prefixMatcher: PrefixMatcher,
|
||||
private val elementFactory: LookupElementFactory,
|
||||
receiverTypes: Collection<ReceiverType>?,
|
||||
private val collector: LookupElementsCollector,
|
||||
private val indicesHelper: KotlinIndicesHelper,
|
||||
private val callTypeAndReceiver: CallTypeAndReceiver<*, *>
|
||||
) {
|
||||
private val nearestReceiver = receiverTypes?.firstOrNull()
|
||||
private val nearestReceiverMarkers = nearestReceiver?.takeIf { it.implicit }
|
||||
?.let { DslMarkerUtils.extractDslMarkerFqNames(it.type) }.orEmpty()
|
||||
|
||||
private val factory = object : AbstractLookupElementFactory {
|
||||
override fun createLookupElement(
|
||||
descriptor: DeclarationDescriptor,
|
||||
useReceiverTypes: Boolean,
|
||||
qualifyNestedClasses: Boolean,
|
||||
includeClassTypeArguments: Boolean,
|
||||
parametersAndTypeGrayed: Boolean
|
||||
): LookupElement? {
|
||||
error("Should not be called")
|
||||
}
|
||||
|
||||
override fun createStandardLookupElementsForDescriptor(
|
||||
descriptor: DeclarationDescriptor,
|
||||
useReceiverTypes: Boolean
|
||||
): Collection<LookupElement> {
|
||||
return elementFactory.createStandardLookupElementsForDescriptor(descriptor, useReceiverTypes).also {
|
||||
it.forEach { element ->
|
||||
element.isDslMember = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun completeDslFunctions() {
|
||||
if (nearestReceiver == null || nearestReceiverMarkers.isEmpty()) return
|
||||
|
||||
val receiverMarkersShortNames = nearestReceiverMarkers.map { it.shortName() }.distinct()
|
||||
val extensionDescriptors = indicesHelper.getCallableTopLevelExtensions(
|
||||
nameFilter = { prefixMatcher.prefixMatches(it) },
|
||||
declarationFilter = {
|
||||
(it as KtModifierListOwner).modifierList?.collectAnnotationEntriesFromStubOrPsi()?.any { it.shortName in receiverMarkersShortNames }
|
||||
?: false
|
||||
},
|
||||
callTypeAndReceiver = callTypeAndReceiver,
|
||||
receiverTypes = listOf(nearestReceiver.type)
|
||||
)
|
||||
extensionDescriptors.forEach {
|
||||
collector.addDescriptorElements(it, factory, notImported = true, withReceiverCast = false, prohibitDuplicates = true)
|
||||
}
|
||||
|
||||
collector.flushToResultSet()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -22,7 +22,6 @@ import com.intellij.codeInsight.lookup.LookupElement
|
||||
import com.intellij.codeInsight.lookup.LookupElementDecorator
|
||||
import com.intellij.openapi.util.TextRange
|
||||
import com.intellij.patterns.ElementPattern
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.idea.completion.handlers.WithExpressionPrefixInsertHandler
|
||||
import org.jetbrains.kotlin.idea.completion.handlers.WithTailInsertHandler
|
||||
@@ -48,7 +47,6 @@ class LookupElementsCollector(
|
||||
.withRelevanceSorter(sorter)
|
||||
|
||||
private val postProcessors = ArrayList<(LookupElement) -> LookupElement>()
|
||||
private val processedCallables = mutableSetOf<CallableDescriptor>()
|
||||
|
||||
var isResultEmpty: Boolean = true
|
||||
private set
|
||||
@@ -68,27 +66,22 @@ class LookupElementsCollector(
|
||||
postProcessors.add(processor)
|
||||
}
|
||||
|
||||
fun addDescriptorElements(
|
||||
descriptors: Iterable<DeclarationDescriptor>,
|
||||
lookupElementFactory: AbstractLookupElementFactory,
|
||||
notImported: Boolean = false,
|
||||
withReceiverCast: Boolean = false,
|
||||
prohibitDuplicates: Boolean = false
|
||||
fun addDescriptorElements(descriptors: Iterable<DeclarationDescriptor>,
|
||||
lookupElementFactory: LookupElementFactory,
|
||||
notImported: Boolean = false,
|
||||
withReceiverCast: Boolean = false
|
||||
) {
|
||||
for (descriptor in descriptors) {
|
||||
addDescriptorElements(descriptor, lookupElementFactory, notImported, withReceiverCast, prohibitDuplicates)
|
||||
addDescriptorElements(descriptor, lookupElementFactory, notImported, withReceiverCast)
|
||||
}
|
||||
}
|
||||
|
||||
fun addDescriptorElements(
|
||||
descriptor: DeclarationDescriptor,
|
||||
lookupElementFactory: AbstractLookupElementFactory,
|
||||
notImported: Boolean = false,
|
||||
withReceiverCast: Boolean = false,
|
||||
prohibitDuplicates: Boolean = false
|
||||
descriptor: DeclarationDescriptor,
|
||||
lookupElementFactory: LookupElementFactory,
|
||||
notImported: Boolean = false,
|
||||
withReceiverCast: Boolean = false
|
||||
) {
|
||||
if (prohibitDuplicates && descriptor is CallableDescriptor && descriptor in processedCallables) return
|
||||
|
||||
var lookupElements = lookupElementFactory.createStandardLookupElementsForDescriptor(descriptor, useReceiverTypes = true)
|
||||
|
||||
if (withReceiverCast) {
|
||||
@@ -96,8 +89,6 @@ class LookupElementsCollector(
|
||||
}
|
||||
|
||||
addElements(lookupElements, notImported)
|
||||
|
||||
if (prohibitDuplicates && descriptor is CallableDescriptor) processedCallables.add(descriptor)
|
||||
}
|
||||
|
||||
fun addElement(element: LookupElement, notImported: Boolean = false) {
|
||||
|
||||
@@ -43,13 +43,6 @@ object PriorityWeigher : LookupElementWeigher("kotlin.priority") {
|
||||
= element.getUserData(ITEM_PRIORITY_KEY) ?: ItemPriority.DEFAULT
|
||||
}
|
||||
|
||||
object PreferDslMembers : LookupElementWeigher("kotlin.preferDsl") {
|
||||
override fun weigh(element: LookupElement, context: WeighingContext): Boolean {
|
||||
if (element.isDslMember == true) return false // high priority
|
||||
return true // lower priority
|
||||
}
|
||||
}
|
||||
|
||||
class NotImportedWeigher(private val classifier: ImportableFqNameClassifier) : LookupElementWeigher("kotlin.notImported") {
|
||||
private enum class Weight {
|
||||
default,
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
// RUNTIME
|
||||
package test
|
||||
|
||||
import bar.r
|
||||
import bar.foo3
|
||||
|
||||
fun main() {
|
||||
val foo5 = 3
|
||||
r {
|
||||
val j: String = foo<caret>
|
||||
}
|
||||
}
|
||||
|
||||
@DslMarker
|
||||
annotation class Dsl
|
||||
|
||||
|
||||
@Dsl
|
||||
class R
|
||||
|
||||
fun r(body: R.() -> Unit) {
|
||||
|
||||
}
|
||||
|
||||
fun foo1(i: Int): String ""
|
||||
|
||||
fun foo3() {
|
||||
|
||||
}
|
||||
|
||||
@Dsl
|
||||
fun R.foobar2(): String = ""
|
||||
|
||||
@Dsl
|
||||
fun R.foobar4() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ORDER: foobar2
|
||||
// ORDER: foo1
|
||||
// ORDER: foo5
|
||||
// ORDER: foobar4
|
||||
// ORDER: foo3
|
||||
@@ -1,42 +0,0 @@
|
||||
package bar
|
||||
|
||||
@DslMarker
|
||||
annotation class Dsl
|
||||
|
||||
|
||||
@Dsl
|
||||
class R
|
||||
|
||||
fun r(body: R.() -> Unit) {
|
||||
|
||||
}
|
||||
|
||||
fun foo1(i: Int) {
|
||||
|
||||
}
|
||||
|
||||
fun foo3() {
|
||||
|
||||
}
|
||||
|
||||
@Dsl
|
||||
fun R.foo2() {}
|
||||
|
||||
@Dsl
|
||||
fun R.foo4() {
|
||||
|
||||
}
|
||||
|
||||
@Dsl
|
||||
fun R.fooloooooong() {
|
||||
|
||||
}
|
||||
|
||||
val R.fooval
|
||||
get() = Unit
|
||||
|
||||
@Dsl
|
||||
fun R.SomethingSomethingFooSomething() {
|
||||
|
||||
}
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
// RUNTIME
|
||||
package test
|
||||
|
||||
import bar.r
|
||||
import bar.foo3
|
||||
|
||||
fun main() {
|
||||
val foo5 = 3
|
||||
r {
|
||||
foo<caret>
|
||||
}
|
||||
}
|
||||
|
||||
// ORDER: foo2
|
||||
// ORDER: foo4
|
||||
// ORDER: fooloooooong
|
||||
// ORDER: foo3
|
||||
// ORDER: foo5
|
||||
// ORDER: fooval
|
||||
// ORDER: foo1
|
||||
@@ -1,8 +0,0 @@
|
||||
package dsl
|
||||
|
||||
import test.Dsl
|
||||
import test.R
|
||||
|
||||
@Dsl
|
||||
fun R.foo2() {}
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
// RUNTIME
|
||||
package test
|
||||
|
||||
class HasFoo {
|
||||
fun foo10() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
fun main() {
|
||||
val foo5 = 3
|
||||
with(0) {
|
||||
with("") {
|
||||
with(HasFoo()) {
|
||||
r {
|
||||
foo<caret>
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@DslMarker
|
||||
annotation class Dsl
|
||||
|
||||
|
||||
@Dsl
|
||||
class R
|
||||
|
||||
fun r(body: R.() -> Unit) {
|
||||
|
||||
}
|
||||
|
||||
fun foo1(i: Int) {
|
||||
|
||||
}
|
||||
|
||||
// ORDER: foo2
|
||||
// ORDER: foo10
|
||||
// ORDER: foo1
|
||||
// ORDER: foo5
|
||||
@@ -41,7 +41,7 @@ abstract class AbstractCompletionHandlerTest(private val defaultCompletionType:
|
||||
|
||||
val settingManager = CodeStyleSettingsManager.getInstance()
|
||||
val tempSettings = settingManager.currentSettings.clone()
|
||||
settingManager.setTemporarySettings(tempSettings)
|
||||
settingManager.temporarySettings = tempSettings
|
||||
try {
|
||||
val fileText = FileUtil.loadFile(File(testPath))
|
||||
assertTrue("\"<caret>\" is missing in file \"$testPath\"", fileText.contains("<caret>"));
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.intellij.codeInsight.completion.CompletionType
|
||||
import org.jetbrains.kotlin.idea.completion.test.RELATIVE_COMPLETION_TEST_DATA_BASE_PATH
|
||||
import org.jetbrains.kotlin.idea.completion.test.configureWithExtraFile
|
||||
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
|
||||
import org.jetbrains.kotlin.idea.test.KotlinLightProjectDescriptor
|
||||
import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor
|
||||
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
||||
import org.junit.Assert
|
||||
@@ -43,6 +44,7 @@ abstract class AbstractCompletionWeigherTest(val completionType: CompletionType,
|
||||
}
|
||||
|
||||
abstract class AbstractBasicCompletionWeigherTest() : AbstractCompletionWeigherTest(CompletionType.BASIC, "weighers/basic") {
|
||||
override fun getProjectDescriptor() = KotlinLightProjectDescriptor.INSTANCE
|
||||
}
|
||||
|
||||
abstract class AbstractSmartCompletionWeigherTest() : AbstractCompletionWeigherTest(CompletionType.SMART, "weighers/smart") {
|
||||
|
||||
@@ -61,24 +61,6 @@ public class BasicCompletionWeigherTestGenerated extends AbstractBasicCompletion
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("DslCallWithExpectedType.kt")
|
||||
public void testDslCallWithExpectedType() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/weighers/basic/DslCallWithExpectedType.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("DslCalls.kt")
|
||||
public void testDslCalls() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/weighers/basic/DslCalls.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("DslCallsWithMultipleReceivers.kt")
|
||||
public void testDslCallsWithMultipleReceivers() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/weighers/basic/DslCallsWithMultipleReceivers.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("ExactMatchForKeyword.kt")
|
||||
public void testExactMatchForKeyword() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/weighers/basic/ExactMatchForKeyword.kt");
|
||||
|
||||
@@ -20,6 +20,8 @@ dependencies {
|
||||
compile(project(":plugins:android-extensions-compiler"))
|
||||
compile(commonDep("org.jetbrains.kotlinx", "kotlinx-coroutines-core")) { isTransitive = false }
|
||||
compile(commonDep("org.jetbrains.kotlinx", "kotlinx-coroutines-jdk8")) { isTransitive = false }
|
||||
// compile(commonDep("org.jetbrains.uast", "uast-common")) { isTransitive = false }
|
||||
// compile(commonDep("org.jetbrains.uast", "uast-java")) { isTransitive = false }
|
||||
compileOnly(intellijCoreDep()) { includeJars("intellij-core") }
|
||||
compileOnly(intellijDep()) { includeJars("util", "openapi", "idea", "asm-all", "jdom", "annotations", "trove4j", "guava", rootProject = rootProject) }
|
||||
compileOnly(intellijPluginDep("gradle")) { includeJars("gradle-tooling-api", "gradle", rootProject = rootProject) }
|
||||
|
||||
@@ -145,8 +145,7 @@ class KotlinIndicesHelper(
|
||||
fun getCallableTopLevelExtensions(
|
||||
callTypeAndReceiver: CallTypeAndReceiver<*, *>,
|
||||
receiverTypes: Collection<KotlinType>,
|
||||
nameFilter: (String) -> Boolean,
|
||||
declarationFilter: (KtDeclaration) -> Boolean = { true }
|
||||
nameFilter: (String) -> Boolean
|
||||
): Collection<CallableDescriptor> {
|
||||
if (receiverTypes.isEmpty()) return emptyList()
|
||||
|
||||
@@ -162,7 +161,7 @@ class KotlinIndicesHelper(
|
||||
KotlinTopLevelExtensionsByReceiverTypeIndex.receiverTypeNameFromKey(it) in receiverTypeNames
|
||||
&& nameFilter(KotlinTopLevelExtensionsByReceiverTypeIndex.callableNameFromKey(it))
|
||||
}
|
||||
.flatMap { index.get(it, project, scope).asSequence() }.filter(declarationFilter)
|
||||
.flatMap { index.get(it, project, scope).asSequence() }
|
||||
|
||||
val suitableExtensions = findSuitableExtensions(declarations, receiverTypes, callTypeAndReceiver.callType)
|
||||
|
||||
|
||||
@@ -32,7 +32,6 @@ import org.jetbrains.kotlin.lexer.KtModifierKeywordToken
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.addRemoveModifier.MODIFIERS_ORDER
|
||||
import org.jetbrains.kotlin.psi.psiUtil.*
|
||||
import org.jetbrains.kotlin.psi.typeRefHelpers.setReceiverTypeReference
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
@@ -44,7 +43,6 @@ import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.isError
|
||||
import org.jetbrains.kotlin.utils.KotlinExceptionWithAttachments
|
||||
import org.jetbrains.kotlin.utils.SmartList
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
inline fun <reified T : PsiElement> PsiElement.replaced(newElement: T): T {
|
||||
@@ -449,30 +447,6 @@ fun KtParameter.setDefaultValue(newDefaultValue: KtExpression): PsiElement? {
|
||||
return addAfter(newDefaultValue, eq) as KtExpression
|
||||
}
|
||||
|
||||
fun KtModifierList.appendModifier(modifier: KtModifierKeywordToken) {
|
||||
add(KtPsiFactory(this).createModifier(modifier))
|
||||
}
|
||||
|
||||
fun KtModifierList.normalize(): KtModifierList {
|
||||
val psiFactory = KtPsiFactory(this)
|
||||
return psiFactory.createEmptyModifierList().also { newList ->
|
||||
val modifiers = SmartList<PsiElement>()
|
||||
allChildren.forEach {
|
||||
val elementType = it.node.elementType
|
||||
when {
|
||||
it is KtAnnotation || it is KtAnnotationEntry -> newList.add(it)
|
||||
elementType is KtModifierKeywordToken -> {
|
||||
if (elementType == KtTokens.DEFAULT_VISIBILITY_KEYWORD) return@forEach
|
||||
if (elementType == KtTokens.FINALLY_KEYWORD && !hasModifier(KtTokens.OVERRIDE_KEYWORD)) return@forEach
|
||||
modifiers.add(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
modifiers.sortBy { MODIFIERS_ORDER.indexOf(it.node.elementType) }
|
||||
modifiers.forEach { newList.add(it) }
|
||||
}
|
||||
}
|
||||
|
||||
fun KtBlockStringTemplateEntry.canDropBraces() =
|
||||
expression is KtNameReferenceExpression && canPlaceAfterSimpleNameEntry(nextSibling)
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ import com.intellij.openapi.components.ServiceManager
|
||||
import com.intellij.openapi.progress.ProgressIndicator
|
||||
import com.intellij.openapi.progress.Task
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.project.isProjectOrWorkspaceFile
|
||||
import com.intellij.openapi.project.ProjectUtil
|
||||
import com.intellij.openapi.roots.ProjectRootManager
|
||||
import com.intellij.openapi.roots.ex.ProjectRootManagerEx
|
||||
import com.intellij.openapi.util.EmptyRunnable
|
||||
@@ -267,7 +267,7 @@ class ScriptDependenciesUpdater(
|
||||
// the isUnitTestMode check fixes ScriptConfigurationHighlighting & Navigation tests, since they are not trigger proper update mechanims
|
||||
// TODO: find out the reason, then consider to fix tests and remove this check
|
||||
(application.isUnitTestMode ||
|
||||
scriptDefinitionProvider.isScript(it.name) && projectFileIndex.isInContent(it)) && !isProjectOrWorkspaceFile(it)
|
||||
scriptDefinitionProvider.isScript(it.name) && projectFileIndex.isInContent(it)) && !ProjectUtil.isProjectOrWorkspaceFile(it)
|
||||
}
|
||||
}
|
||||
requestUpdate(modifiedScripts)
|
||||
|
||||
@@ -60,8 +60,9 @@ dependencies {
|
||||
testRuntime(intellijPluginDep("gradle"))
|
||||
testRuntime(intellijPluginDep("Groovy"))
|
||||
testRuntime(intellijPluginDep("coverage")) { includeJars("jacocoant") }
|
||||
testRuntime(intellijPluginDep("maven"))
|
||||
//testRuntime(intellijPluginDep("maven"))
|
||||
testRuntime(intellijPluginDep("android"))
|
||||
testRuntime(intellijPluginDep("smali"))
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
|
||||
@@ -14,12 +14,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.jps.build
|
||||
@file:JvmName("GradleKotlinDSLConstants")
|
||||
|
||||
import org.jetbrains.jps.ModuleChunk
|
||||
import org.jetbrains.jps.incremental.CompileContext
|
||||
package org.jetbrains.kotlin.gradle.kdsl
|
||||
|
||||
fun ModuleChunk.isDummy(context: CompileContext): Boolean {
|
||||
val targetIndex = context.projectDescriptor.buildTargetIndex
|
||||
return targets.all { targetIndex.isDummy(it) }
|
||||
}
|
||||
const val DEFAULT_SCRIPT_NAME = "build.gradle.kts"
|
||||
@@ -0,0 +1,55 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.jetbrains.kotlin.gradle.kdsl.GradleFrameworksWizardStep">
|
||||
<grid id="27dc6" binding="myPanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="500" height="400"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="22e59" layout-manager="BorderLayout" hgap="0" vgap="0">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="ad16" binding="myOptionsPanel" layout-manager="CardLayout" hgap="0" vgap="0">
|
||||
<constraints border-constraint="Center"/>
|
||||
<properties/>
|
||||
<clientProperties>
|
||||
<BorderFactoryClass class="java.lang.String" value="com.intellij.ui.IdeBorderFactory$PlainSmallWithoutIndent"/>
|
||||
</clientProperties>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="27a92" layout-manager="BorderLayout" hgap="0" vgap="0">
|
||||
<constraints>
|
||||
<card name="templates card"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<grid id="b50ee" binding="myFrameworksPanelPlaceholder" layout-manager="BorderLayout" hgap="0" vgap="0">
|
||||
<constraints>
|
||||
<card name="frameworks card"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="916d9" class="com.intellij.ui.components.JBLabel" binding="myFrameworksLabel">
|
||||
<constraints border-constraint="North"/>
|
||||
<properties>
|
||||
<text value="Additional Libraries and &Frameworks:"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* Copyright 2010-2017 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.kotlin.gradle.kdsl;
|
||||
|
||||
import com.intellij.framework.addSupport.FrameworkSupportInModuleProvider;
|
||||
import com.intellij.ide.util.newProjectWizard.AddSupportForFrameworksPanel;
|
||||
import com.intellij.ide.util.newProjectWizard.impl.FrameworkSupportModelBase;
|
||||
import com.intellij.ide.util.projectWizard.ModuleBuilder;
|
||||
import com.intellij.ide.util.projectWizard.ModuleWizardStep;
|
||||
import com.intellij.ide.util.projectWizard.WizardContext;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.ModifiableRootModel;
|
||||
import com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContainer;
|
||||
import com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContainerFactory;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.ui.components.JBLabel;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.gradle.kdsl.frameworkSupport.GradleFrameworkSupportProvider;
|
||||
import org.jetbrains.kotlin.gradle.kdsl.frameworkSupport.GradleJavaFrameworkSupportProvider;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class GradleFrameworksWizardStep extends ModuleWizardStep implements Disposable {
|
||||
|
||||
private JPanel myPanel;
|
||||
private final AddSupportForFrameworksPanel myFrameworksPanel;
|
||||
private JPanel myFrameworksPanelPlaceholder;
|
||||
private JPanel myOptionsPanel;
|
||||
@SuppressWarnings("unused") private JBLabel myFrameworksLabel;
|
||||
|
||||
public GradleFrameworksWizardStep(WizardContext context, final ModuleBuilder builder) {
|
||||
|
||||
Project project = context.getProject();
|
||||
final LibrariesContainer container = LibrariesContainerFactory.createContainer(context.getProject());
|
||||
FrameworkSupportModelBase model = new FrameworkSupportModelBase(project, null, container) {
|
||||
@NotNull
|
||||
@Override
|
||||
public String getBaseDirectoryForLibrariesPath() {
|
||||
return StringUtil.notNullize(builder.getContentEntryPath());
|
||||
}
|
||||
};
|
||||
|
||||
myFrameworksPanel =
|
||||
new AddSupportForFrameworksPanel(Collections.emptyList(), model, true, null);
|
||||
|
||||
List<FrameworkSupportInModuleProvider> providers = ContainerUtil.newArrayList();
|
||||
Collections.addAll(providers, GradleFrameworkSupportProvider.EP_NAME.getExtensions());
|
||||
|
||||
myFrameworksPanel.setProviders(providers, Collections.emptySet(), Collections.singleton(GradleJavaFrameworkSupportProvider.ID));
|
||||
Disposer.register(this, myFrameworksPanel);
|
||||
myFrameworksPanelPlaceholder.add(myFrameworksPanel.getMainPanel());
|
||||
|
||||
ModuleBuilder.ModuleConfigurationUpdater configurationUpdater = new ModuleBuilder.ModuleConfigurationUpdater() {
|
||||
@Override
|
||||
public void update(@NotNull Module module, @NotNull ModifiableRootModel rootModel) {
|
||||
myFrameworksPanel.addSupport(module, rootModel);
|
||||
}
|
||||
};
|
||||
builder.addModuleConfigurationUpdater(configurationUpdater);
|
||||
|
||||
((CardLayout)myOptionsPanel.getLayout()).show(myOptionsPanel, "frameworks card");
|
||||
}
|
||||
|
||||
@Override
|
||||
public JComponent getComponent() {
|
||||
return myPanel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDataModel() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disposeUIResources() {
|
||||
Disposer.dispose(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,474 @@
|
||||
/*
|
||||
* Copyright 2010-2017 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.kotlin.gradle.kdsl;
|
||||
|
||||
import com.intellij.ide.fileTemplates.FileTemplate;
|
||||
import com.intellij.ide.fileTemplates.FileTemplateManager;
|
||||
import com.intellij.ide.highlighter.ModuleFileType;
|
||||
import com.intellij.ide.projectWizard.ProjectSettingsStep;
|
||||
import com.intellij.ide.util.EditorHelper;
|
||||
import com.intellij.ide.util.projectWizard.JavaModuleBuilder;
|
||||
import com.intellij.ide.util.projectWizard.ModuleWizardStep;
|
||||
import com.intellij.ide.util.projectWizard.SettingsStep;
|
||||
import com.intellij.ide.util.projectWizard.WizardContext;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.application.ModalityState;
|
||||
import com.intellij.openapi.components.StorageScheme;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.externalSystem.model.ExternalSystemDataKeys;
|
||||
import com.intellij.openapi.externalSystem.model.project.ProjectData;
|
||||
import com.intellij.openapi.externalSystem.model.project.ProjectId;
|
||||
import com.intellij.openapi.externalSystem.service.execution.ProgressExecutionMode;
|
||||
import com.intellij.openapi.externalSystem.service.project.wizard.AbstractExternalModuleBuilder;
|
||||
import com.intellij.openapi.externalSystem.service.project.wizard.ExternalModuleSettingsStep;
|
||||
import com.intellij.openapi.externalSystem.settings.AbstractExternalSystemSettings;
|
||||
import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil;
|
||||
import com.intellij.openapi.externalSystem.util.ExternalSystemUtil;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.fileEditor.impl.LoadTextUtil;
|
||||
import com.intellij.openapi.module.*;
|
||||
import com.intellij.openapi.options.ConfigurationException;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.project.ex.ProjectManagerEx;
|
||||
import com.intellij.openapi.projectRoots.JavaSdkType;
|
||||
import com.intellij.openapi.projectRoots.SdkTypeId;
|
||||
import com.intellij.openapi.roots.ModifiableRootModel;
|
||||
import com.intellij.openapi.roots.ui.configuration.ModulesProvider;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.util.InvalidDataException;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.io.FileUtilRt;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VfsUtil;
|
||||
import com.intellij.openapi.vfs.VfsUtilCore;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiManager;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.gradle.util.GradleVersion;
|
||||
import org.jdom.JDOMException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.gradle.kdsl.frameworkSupport.BuildScriptDataBuilder;
|
||||
import org.jetbrains.kotlin.gradle.kdsl.frameworkSupport.KotlinBuildScriptDataBuilder;
|
||||
import org.jetbrains.plugins.gradle.service.settings.GradleProjectSettingsControl;
|
||||
import org.jetbrains.plugins.gradle.settings.DistributionType;
|
||||
import org.jetbrains.plugins.gradle.settings.GradleProjectSettings;
|
||||
import org.jetbrains.plugins.gradle.util.GradleConstants;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.jetbrains.kotlin.gradle.kdsl.GradleKotlinDSLConstants.DEFAULT_SCRIPT_NAME;
|
||||
|
||||
public class GradleModuleBuilder extends AbstractExternalModuleBuilder<GradleProjectSettings> {
|
||||
|
||||
private static final Logger LOG = Logger.getInstance(GradleModuleBuilder.class);
|
||||
|
||||
private static final String TEMPLATE_GRADLE_SETTINGS = "Gradle Kotlin DSL Settings.gradle";
|
||||
private static final String TEMPLATE_GRADLE_SETTINGS_MERGE = "Gradle Settings merge.gradle";
|
||||
private static final String TEMPLATE_GRADLE_BUILD_WITH_WRAPPER = "Gradle Build Script with wrapper.gradle";
|
||||
private static final String DEFAULT_TEMPLATE_GRADLE_BUILD = "Gradle Kotlin DSL Build Script.gradle";
|
||||
|
||||
private static final String TEMPLATE_ATTRIBUTE_PROJECT_NAME = "PROJECT_NAME";
|
||||
private static final String TEMPLATE_ATTRIBUTE_MODULE_PATH = "MODULE_PATH";
|
||||
private static final String TEMPLATE_ATTRIBUTE_MODULE_FLAT_DIR = "MODULE_FLAT_DIR";
|
||||
private static final String TEMPLATE_ATTRIBUTE_MODULE_NAME = "MODULE_NAME";
|
||||
private static final String TEMPLATE_ATTRIBUTE_MODULE_GROUP = "MODULE_GROUP";
|
||||
private static final String TEMPLATE_ATTRIBUTE_MODULE_VERSION = "MODULE_VERSION";
|
||||
private static final String TEMPLATE_ATTRIBUTE_GRADLE_VERSION = "GRADLE_VERSION";
|
||||
private static final String TEMPLATE_ATTRIBUTE_BUILD_FILE_NAME = "BUILD_FILE_NAME";
|
||||
private static final Key<KotlinBuildScriptDataBuilder> BUILD_SCRIPT_DATA =
|
||||
Key.create("gradle.module.kotlinBuildScriptData");
|
||||
|
||||
private WizardContext myWizardContext;
|
||||
|
||||
@Nullable
|
||||
private ProjectData myParentProject;
|
||||
private boolean myInheritGroupId;
|
||||
private boolean myInheritVersion;
|
||||
private ProjectId myProjectId;
|
||||
private String rootProjectPath;
|
||||
|
||||
public GradleModuleBuilder() {
|
||||
super(GradleConstants.SYSTEM_ID, new GradleProjectSettings());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPresentableName() {
|
||||
return "Gradle (Kotlin DSL)";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Module createModule(@NotNull ModifiableModuleModel moduleModel)
|
||||
throws InvalidDataException, IOException, ModuleWithNameAlreadyExists, JDOMException, ConfigurationException {
|
||||
LOG.assertTrue(getName() != null);
|
||||
final String originModuleFilePath = getModuleFilePath();
|
||||
LOG.assertTrue(originModuleFilePath != null);
|
||||
|
||||
String moduleName;
|
||||
if (myProjectId == null) {
|
||||
moduleName = getName();
|
||||
}
|
||||
else {
|
||||
moduleName = ModuleGrouperKt.isQualifiedModuleNamesEnabled() && StringUtil.isNotEmpty(myProjectId.getGroupId())
|
||||
? (myProjectId.getGroupId() + '.' + myProjectId.getArtifactId())
|
||||
: myProjectId.getArtifactId();
|
||||
}
|
||||
Project contextProject = myWizardContext.getProject();
|
||||
String projectFileDirectory = null;
|
||||
if (myWizardContext.isCreatingNewProject() || contextProject == null || contextProject.getBasePath() == null) {
|
||||
projectFileDirectory = myWizardContext.getProjectFileDirectory();
|
||||
}
|
||||
else if (myWizardContext.getProjectStorageFormat() == StorageScheme.DEFAULT) {
|
||||
String moduleFileDirectory = getModuleFileDirectory();
|
||||
if (moduleFileDirectory != null) {
|
||||
projectFileDirectory = moduleFileDirectory;
|
||||
}
|
||||
}
|
||||
if (projectFileDirectory == null) {
|
||||
projectFileDirectory = contextProject.getBasePath();
|
||||
}
|
||||
if (myWizardContext.getProjectStorageFormat() == StorageScheme.DIRECTORY_BASED) {
|
||||
projectFileDirectory += "/.idea/modules";
|
||||
}
|
||||
String moduleFilePath = projectFileDirectory + "/" + moduleName + ModuleFileType.DOT_DEFAULT_EXTENSION;
|
||||
deleteModuleFile(moduleFilePath);
|
||||
final ModuleType moduleType = getModuleType();
|
||||
final Module module = moduleModel.newModule(moduleFilePath, moduleType.getId());
|
||||
setupModule(module);
|
||||
return module;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setupRootModel(final ModifiableRootModel modifiableRootModel) throws ConfigurationException {
|
||||
String contentEntryPath = getContentEntryPath();
|
||||
if (StringUtil.isEmpty(contentEntryPath)) {
|
||||
return;
|
||||
}
|
||||
File contentRootDir = new File(contentEntryPath);
|
||||
FileUtilRt.createDirectory(contentRootDir);
|
||||
LocalFileSystem fileSystem = LocalFileSystem.getInstance();
|
||||
VirtualFile modelContentRootDir = fileSystem.refreshAndFindFileByIoFile(contentRootDir);
|
||||
if (modelContentRootDir == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
modifiableRootModel.addContentEntry(modelContentRootDir);
|
||||
// todo this should be moved to generic ModuleBuilder
|
||||
if (myJdk != null) {
|
||||
modifiableRootModel.setSdk(myJdk);
|
||||
}
|
||||
else {
|
||||
modifiableRootModel.inheritSdk();
|
||||
}
|
||||
|
||||
final Project project = modifiableRootModel.getProject();
|
||||
if (myParentProject != null) {
|
||||
rootProjectPath = myParentProject.getLinkedExternalProjectPath();
|
||||
}
|
||||
else {
|
||||
rootProjectPath =
|
||||
FileUtil.toCanonicalPath(myWizardContext.isCreatingNewProject() ? project.getBasePath() : modelContentRootDir.getPath());
|
||||
}
|
||||
assert rootProjectPath != null;
|
||||
|
||||
final VirtualFile gradleBuildFile = setupGradleBuildFile(modelContentRootDir);
|
||||
setupGradleSettingsFile(
|
||||
rootProjectPath, modelContentRootDir, modifiableRootModel.getProject().getName(),
|
||||
myProjectId == null ? modifiableRootModel.getModule().getName() : myProjectId.getArtifactId(),
|
||||
myWizardContext.isCreatingNewProject() || myParentProject == null
|
||||
);
|
||||
|
||||
if (gradleBuildFile != null) {
|
||||
modifiableRootModel.getModule().putUserData(
|
||||
BUILD_SCRIPT_DATA, new KotlinBuildScriptDataBuilder(gradleBuildFile));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setupModule(Module module) throws ConfigurationException {
|
||||
super.setupModule(module);
|
||||
assert rootProjectPath != null;
|
||||
|
||||
VirtualFile buildScriptFile = null;
|
||||
final BuildScriptDataBuilder buildScriptDataBuilder = getBuildScriptData(module);
|
||||
try {
|
||||
if (buildScriptDataBuilder != null) {
|
||||
buildScriptFile = buildScriptDataBuilder.getBuildScriptFile();
|
||||
String lineSeparator = lineSeparator(buildScriptFile);
|
||||
String configurationPart = StringUtil.convertLineSeparators(buildScriptDataBuilder.buildConfigurationPart(), lineSeparator);
|
||||
String existingText = StringUtil.trimTrailing(VfsUtilCore.loadText(buildScriptFile));
|
||||
String content = (!configurationPart.isEmpty() ? configurationPart + lineSeparator : "") +
|
||||
(!existingText.isEmpty() ? existingText + lineSeparator : "") +
|
||||
lineSeparator +
|
||||
StringUtil.convertLineSeparators(buildScriptDataBuilder.buildMainPart(), lineSeparator);
|
||||
VfsUtil.saveText(buildScriptFile, content);
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
LOG.warn("Unexpected exception on applying frameworks templates", e);
|
||||
}
|
||||
|
||||
final Project project = module.getProject();
|
||||
if (myWizardContext.isCreatingNewProject()) {
|
||||
getExternalProjectSettings().setExternalProjectPath(rootProjectPath);
|
||||
AbstractExternalSystemSettings settings = ExternalSystemApiUtil.getSettings(project, GradleConstants.SYSTEM_ID);
|
||||
project.putUserData(ExternalSystemDataKeys.NEWLY_CREATED_PROJECT, Boolean.TRUE);
|
||||
//noinspection unchecked
|
||||
settings.linkProject(getExternalProjectSettings());
|
||||
}
|
||||
else {
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
final GradleProjectSettings gradleProjectSettings = getExternalProjectSettings();
|
||||
final VirtualFile finalBuildScriptFile = buildScriptFile;
|
||||
Runnable runnable = () -> {
|
||||
if (myParentProject == null) {
|
||||
gradleProjectSettings.setExternalProjectPath(rootProjectPath);
|
||||
AbstractExternalSystemSettings settings = ExternalSystemApiUtil.getSettings(project, GradleConstants.SYSTEM_ID);
|
||||
//noinspection unchecked
|
||||
settings.linkProject(gradleProjectSettings);
|
||||
}
|
||||
|
||||
ExternalSystemUtil.refreshProject(
|
||||
project, GradleConstants.SYSTEM_ID, rootProjectPath, false,
|
||||
ProgressExecutionMode.IN_BACKGROUND_ASYNC);
|
||||
|
||||
final PsiFile psiFile;
|
||||
if (finalBuildScriptFile != null) {
|
||||
psiFile = PsiManager.getInstance(project).findFile(finalBuildScriptFile);
|
||||
if (psiFile != null) {
|
||||
EditorHelper.openInEditor(psiFile);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// execute when current dialog is closed
|
||||
ExternalSystemUtil.invokeLater(project, ModalityState.NON_MODAL, runnable);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModuleWizardStep[] createWizardSteps(@NotNull WizardContext wizardContext, @NotNull ModulesProvider modulesProvider) {
|
||||
myWizardContext = wizardContext;
|
||||
return new ModuleWizardStep[]{
|
||||
new GradleModuleWizardStep(this, wizardContext),
|
||||
new ExternalModuleSettingsStep<>(
|
||||
wizardContext, this, new GradleProjectSettingsControl(getExternalProjectSettings()))
|
||||
};
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ModuleWizardStep getCustomOptionsStep(WizardContext context, Disposable parentDisposable) {
|
||||
final GradleFrameworksWizardStep step = new GradleFrameworksWizardStep(context, this);
|
||||
Disposer.register(parentDisposable, step);
|
||||
return step;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSuitableSdkType(SdkTypeId sdk) {
|
||||
return sdk instanceof JavaSdkType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getParentGroup() {
|
||||
return JavaModuleType.BUILD_TOOLS_GROUP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWeight() {
|
||||
return JavaModuleBuilder.BUILD_SYSTEM_WEIGHT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModuleType getModuleType() {
|
||||
return StdModuleTypes.JAVA;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private VirtualFile setupGradleBuildFile(@NotNull VirtualFile modelContentRootDir)
|
||||
throws ConfigurationException {
|
||||
final VirtualFile file = getOrCreateExternalProjectConfigFile(modelContentRootDir.getPath(), GradleKotlinDSLConstants.DEFAULT_SCRIPT_NAME);
|
||||
|
||||
if (file != null) {
|
||||
final String templateName = getExternalProjectSettings().getDistributionType() == DistributionType.WRAPPED
|
||||
? TEMPLATE_GRADLE_BUILD_WITH_WRAPPER
|
||||
: DEFAULT_TEMPLATE_GRADLE_BUILD;
|
||||
Map<String, String> attributes = ContainerUtil.newHashMap();
|
||||
if (myProjectId != null) {
|
||||
attributes.put(TEMPLATE_ATTRIBUTE_MODULE_VERSION, myProjectId.getVersion());
|
||||
attributes.put(TEMPLATE_ATTRIBUTE_MODULE_GROUP, myProjectId.getGroupId());
|
||||
attributes.put(TEMPLATE_ATTRIBUTE_GRADLE_VERSION, GradleVersion.current().getVersion());
|
||||
}
|
||||
saveFile(file, templateName, attributes);
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static VirtualFile setupGradleSettingsFile(@NotNull String rootProjectPath,
|
||||
@NotNull VirtualFile modelContentRootDir,
|
||||
String projectName,
|
||||
String moduleName,
|
||||
boolean renderNewFile)
|
||||
throws ConfigurationException {
|
||||
final VirtualFile file = getOrCreateExternalProjectConfigFile(rootProjectPath, GradleConstants.SETTINGS_FILE_NAME);
|
||||
if (file == null) return null;
|
||||
|
||||
if (renderNewFile) {
|
||||
final String moduleDirName = VfsUtilCore.getRelativePath(modelContentRootDir, file.getParent(), '/');
|
||||
|
||||
Map<String, String> attributes = ContainerUtil.newHashMap();
|
||||
attributes.put(TEMPLATE_ATTRIBUTE_PROJECT_NAME, projectName);
|
||||
attributes.put(TEMPLATE_ATTRIBUTE_MODULE_PATH, moduleDirName);
|
||||
attributes.put(TEMPLATE_ATTRIBUTE_MODULE_NAME, moduleName);
|
||||
attributes.put(TEMPLATE_ATTRIBUTE_BUILD_FILE_NAME, DEFAULT_SCRIPT_NAME); // TODO: gradle > 4.0 doesn't need this
|
||||
saveFile(file, TEMPLATE_GRADLE_SETTINGS, attributes);
|
||||
}
|
||||
else {
|
||||
char separatorChar = file.getParent() == null || !VfsUtilCore.isAncestor(file.getParent(), modelContentRootDir, true) ? '/' : ':';
|
||||
String modulePath = VfsUtil.getPath(file, modelContentRootDir, separatorChar);
|
||||
|
||||
Map<String, String> attributes = ContainerUtil.newHashMap();
|
||||
attributes.put(TEMPLATE_ATTRIBUTE_MODULE_NAME, moduleName);
|
||||
// check for flat structure
|
||||
final String flatStructureModulePath =
|
||||
modulePath != null && StringUtil.startsWith(modulePath, "../") ? StringUtil.trimStart(modulePath, "../") : null;
|
||||
if (StringUtil.equals(flatStructureModulePath, modelContentRootDir.getName())) {
|
||||
attributes.put(TEMPLATE_ATTRIBUTE_MODULE_FLAT_DIR, "true");
|
||||
attributes.put(TEMPLATE_ATTRIBUTE_MODULE_PATH, flatStructureModulePath);
|
||||
}
|
||||
else {
|
||||
attributes.put(TEMPLATE_ATTRIBUTE_MODULE_PATH, modulePath);
|
||||
}
|
||||
|
||||
appendToFile(file, TEMPLATE_GRADLE_SETTINGS_MERGE, attributes);
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
private static void saveFile(@NotNull VirtualFile file, @NotNull String templateName, @Nullable Map templateAttributes)
|
||||
throws ConfigurationException {
|
||||
FileTemplateManager manager = FileTemplateManager.getDefaultInstance();
|
||||
FileTemplate template = manager.getInternalTemplate(templateName);
|
||||
try {
|
||||
appendToFile(file, templateAttributes != null ? template.getText(templateAttributes) : template.getText());
|
||||
}
|
||||
catch (IOException e) {
|
||||
LOG.warn(String.format("Unexpected exception on applying template %s config", GradleConstants.SYSTEM_ID.getReadableName()), e);
|
||||
throw new ConfigurationException(
|
||||
e.getMessage(), String.format("Can't apply %s template config text", GradleConstants.SYSTEM_ID.getReadableName())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private static void appendToFile(@NotNull VirtualFile file, @NotNull String templateName, @Nullable Map templateAttributes)
|
||||
throws ConfigurationException {
|
||||
FileTemplateManager manager = FileTemplateManager.getDefaultInstance();
|
||||
FileTemplate template = manager.getInternalTemplate(templateName);
|
||||
try {
|
||||
appendToFile(file, templateAttributes != null ? template.getText(templateAttributes) : template.getText());
|
||||
}
|
||||
catch (IOException e) {
|
||||
LOG.warn(String.format("Unexpected exception on appending template %s config", GradleConstants.SYSTEM_ID.getReadableName()), e);
|
||||
throw new ConfigurationException(
|
||||
e.getMessage(), String.format("Can't append %s template config text", GradleConstants.SYSTEM_ID.getReadableName())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
private static VirtualFile getOrCreateExternalProjectConfigFile(@NotNull String parent, @NotNull String fileName) {
|
||||
File file = new File(parent, fileName);
|
||||
FileUtilRt.createIfNotExists(file);
|
||||
return LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file);
|
||||
}
|
||||
|
||||
public void setParentProject(@Nullable ProjectData parentProject) {
|
||||
myParentProject = parentProject;
|
||||
}
|
||||
|
||||
public boolean isInheritGroupId() {
|
||||
return myInheritGroupId;
|
||||
}
|
||||
|
||||
public void setInheritGroupId(boolean inheritGroupId) {
|
||||
myInheritGroupId = inheritGroupId;
|
||||
}
|
||||
|
||||
public boolean isInheritVersion() {
|
||||
return myInheritVersion;
|
||||
}
|
||||
|
||||
public void setInheritVersion(boolean inheritVersion) {
|
||||
myInheritVersion = inheritVersion;
|
||||
}
|
||||
|
||||
public ProjectId getProjectId() {
|
||||
return myProjectId;
|
||||
}
|
||||
|
||||
public void setProjectId(@NotNull ProjectId projectId) {
|
||||
myProjectId = projectId;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ModuleWizardStep modifySettingsStep(@NotNull SettingsStep settingsStep) {
|
||||
if (settingsStep instanceof ProjectSettingsStep) {
|
||||
final ProjectSettingsStep projectSettingsStep = (ProjectSettingsStep)settingsStep;
|
||||
if (myProjectId != null) {
|
||||
final JTextField moduleNameField = settingsStep.getModuleNameField();
|
||||
if (moduleNameField != null) {
|
||||
moduleNameField.setText(myProjectId.getArtifactId());
|
||||
}
|
||||
projectSettingsStep.setModuleName(myProjectId.getArtifactId());
|
||||
}
|
||||
projectSettingsStep.bindModuleSettings();
|
||||
}
|
||||
return super.modifySettingsStep(settingsStep);
|
||||
}
|
||||
|
||||
public static void appendToFile(@NotNull VirtualFile file, @NotNull String text) throws IOException {
|
||||
String lineSeparator = lineSeparator(file);
|
||||
final String existingText = StringUtil.trimTrailing(VfsUtilCore.loadText(file));
|
||||
String content = (StringUtil.isNotEmpty(existingText) ? existingText + lineSeparator : "") +
|
||||
StringUtil.convertLineSeparators(text, lineSeparator);
|
||||
VfsUtil.saveText(file, content);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String lineSeparator(@NotNull VirtualFile file) {
|
||||
String lineSeparator = LoadTextUtil.detectLineSeparator(file, true);
|
||||
if (lineSeparator == null) {
|
||||
lineSeparator = CodeStyleSettingsManager.getSettings(ProjectManagerEx.getInstanceEx().getDefaultProject()).getLineSeparator();
|
||||
}
|
||||
return lineSeparator;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static BuildScriptDataBuilder getBuildScriptData(@Nullable Module module) {
|
||||
return module == null ? null : module.getUserData(BUILD_SCRIPT_DATA);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.jetbrains.kotlin.gradle.kdsl.GradleModuleWizardStep">
|
||||
<grid id="27dc6" binding="myMainPanel" layout-manager="GridLayoutManager" row-count="5" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="529" height="386"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="ddae6" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<labelFor value="d7d25"/>
|
||||
<text value="GroupId"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="bbb74" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<labelFor value="efb5e"/>
|
||||
<text value="ArtifactId"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="4eb56" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<labelFor value="b1344"/>
|
||||
<text value="Version"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="d7d25" class="javax.swing.JTextField" binding="myGroupIdField">
|
||||
<constraints>
|
||||
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="150" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="efb5e" class="javax.swing.JTextField" binding="myArtifactIdField">
|
||||
<constraints>
|
||||
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="150" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="b1344" class="javax.swing.JTextField" binding="myVersionField">
|
||||
<constraints>
|
||||
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="150" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="d0095" class="javax.swing.JCheckBox" binding="myInheritGroupIdCheckBox">
|
||||
<constraints>
|
||||
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Inherit"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="897ff" class="javax.swing.JCheckBox" binding="myInheritVersionCheckBox">
|
||||
<constraints>
|
||||
<grid row="3" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Inherit"/>
|
||||
</properties>
|
||||
</component>
|
||||
<grid id="102d8" binding="myAddToPanel" layout-manager="BorderLayout" hgap="0" vgap="0">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="3" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="true"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<grid id="90185" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="4" column="0" row-span="1" col-span="3" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<enabled value="true"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<vspacer id="f04b8">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
@@ -0,0 +1,257 @@
|
||||
/*
|
||||
* Copyright 2010-2017 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.kotlin.gradle.kdsl;
|
||||
|
||||
import com.intellij.ide.util.PropertiesComponent;
|
||||
import com.intellij.ide.util.projectWizard.ModuleWizardStep;
|
||||
import com.intellij.ide.util.projectWizard.WizardContext;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.externalSystem.model.project.ProjectData;
|
||||
import com.intellij.openapi.externalSystem.model.project.ProjectId;
|
||||
import com.intellij.openapi.externalSystem.service.project.wizard.ExternalModuleSettingsStep;
|
||||
import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.options.ConfigurationException;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.wm.IdeFocusManager;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.gradle.service.project.wizard.GradleParentProjectForm;
|
||||
import org.jetbrains.plugins.gradle.util.GradleConstants;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
public class GradleModuleWizardStep extends ModuleWizardStep {
|
||||
private static final Icon WIZARD_ICON = null;
|
||||
|
||||
private static final String INHERIT_GROUP_ID_KEY = "GradleModuleWizard.inheritGroupId";
|
||||
private static final String INHERIT_VERSION_KEY = "GradleModuleWizard.inheritVersion";
|
||||
private static final String DEFAULT_VERSION = "1.0-SNAPSHOT";
|
||||
|
||||
@Nullable
|
||||
private final Project myProjectOrNull;
|
||||
@NotNull
|
||||
private final GradleModuleBuilder myBuilder;
|
||||
@NotNull
|
||||
private final WizardContext myContext;
|
||||
@NotNull
|
||||
private final GradleParentProjectForm myParentProjectForm;
|
||||
|
||||
private String myInheritedGroupId;
|
||||
private String myInheritedVersion;
|
||||
|
||||
private JPanel myMainPanel;
|
||||
|
||||
private JTextField myGroupIdField;
|
||||
private JCheckBox myInheritGroupIdCheckBox;
|
||||
private JTextField myArtifactIdField;
|
||||
private JTextField myVersionField;
|
||||
private JCheckBox myInheritVersionCheckBox;
|
||||
private JPanel myAddToPanel;
|
||||
|
||||
public GradleModuleWizardStep(@NotNull GradleModuleBuilder builder, @NotNull WizardContext context) {
|
||||
myProjectOrNull = context.getProject();
|
||||
myBuilder = builder;
|
||||
myContext = context;
|
||||
myParentProjectForm = new GradleParentProjectForm(context, parentProject -> updateComponents());
|
||||
initComponents();
|
||||
loadSettings();
|
||||
}
|
||||
|
||||
private void initComponents() {
|
||||
myAddToPanel.add(myParentProjectForm.getComponent());
|
||||
ActionListener updatingListener = new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
updateComponents();
|
||||
}
|
||||
};
|
||||
myInheritGroupIdCheckBox.addActionListener(updatingListener);
|
||||
myInheritVersionCheckBox.addActionListener(updatingListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JComponent getPreferredFocusedComponent() {
|
||||
return myGroupIdField;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStepLeaving() {
|
||||
saveSettings();
|
||||
}
|
||||
|
||||
private void loadSettings() {
|
||||
myBuilder.setInheritGroupId(getSavedValue(INHERIT_GROUP_ID_KEY, true));
|
||||
myBuilder.setInheritVersion(getSavedValue(INHERIT_VERSION_KEY, true));
|
||||
}
|
||||
|
||||
private void saveSettings() {
|
||||
saveValue(INHERIT_GROUP_ID_KEY, myInheritGroupIdCheckBox.isSelected());
|
||||
saveValue(INHERIT_VERSION_KEY, myInheritVersionCheckBox.isSelected());
|
||||
}
|
||||
|
||||
private static boolean getSavedValue(String key, boolean defaultValue) {
|
||||
return getSavedValue(key, String.valueOf(defaultValue)).equals(String.valueOf(true));
|
||||
}
|
||||
|
||||
private static String getSavedValue(String key, String defaultValue) {
|
||||
String value = PropertiesComponent.getInstance().getValue(key);
|
||||
return value == null ? defaultValue : value;
|
||||
}
|
||||
|
||||
private static void saveValue(String key, boolean value) {
|
||||
saveValue(key, String.valueOf(value));
|
||||
}
|
||||
|
||||
private static void saveValue(String key, String value) {
|
||||
PropertiesComponent.getInstance().setValue(key, value);
|
||||
}
|
||||
|
||||
public JComponent getComponent() {
|
||||
return myMainPanel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validate() throws ConfigurationException {
|
||||
if (StringUtil.isEmptyOrSpaces(myArtifactIdField.getText())) {
|
||||
ApplicationManager.getApplication().invokeLater(
|
||||
() -> IdeFocusManager.getInstance(myProjectOrNull).requestFocus(myArtifactIdField, true));
|
||||
throw new ConfigurationException("Please, specify artifactId");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateStep() {
|
||||
ProjectData parentProject = myParentProjectForm.getParentProject();
|
||||
ProjectId projectId = myBuilder.getProjectId();
|
||||
|
||||
if (projectId == null) {
|
||||
setTestIfEmpty(myArtifactIdField, myBuilder.getName());
|
||||
setTestIfEmpty(myGroupIdField, parentProject == null ? myBuilder.getName() : parentProject.getGroup());
|
||||
setTestIfEmpty(myVersionField, parentProject == null ? DEFAULT_VERSION : parentProject.getVersion());
|
||||
}
|
||||
else {
|
||||
setTestIfEmpty(myArtifactIdField, projectId.getArtifactId());
|
||||
setTestIfEmpty(myGroupIdField, projectId.getGroupId());
|
||||
setTestIfEmpty(myVersionField, projectId.getVersion());
|
||||
}
|
||||
|
||||
myInheritGroupIdCheckBox.setSelected(myBuilder.isInheritGroupId());
|
||||
myInheritVersionCheckBox.setSelected(myBuilder.isInheritVersion());
|
||||
|
||||
updateComponents();
|
||||
}
|
||||
|
||||
|
||||
private void updateComponents() {
|
||||
final boolean isAddToVisible = myParentProjectForm.isVisible();
|
||||
|
||||
myInheritGroupIdCheckBox.setVisible(isAddToVisible);
|
||||
myInheritVersionCheckBox.setVisible(isAddToVisible);
|
||||
|
||||
myParentProjectForm.updateComponents();
|
||||
ProjectData parentProject = myParentProjectForm.getParentProject();
|
||||
if (parentProject == null) {
|
||||
myContext.putUserData(ExternalModuleSettingsStep.SKIP_STEP_KEY, Boolean.FALSE);
|
||||
myGroupIdField.setEnabled(true);
|
||||
myVersionField.setEnabled(true);
|
||||
myInheritGroupIdCheckBox.setEnabled(false);
|
||||
myInheritVersionCheckBox.setEnabled(false);
|
||||
|
||||
setTestIfEmpty(myArtifactIdField, myBuilder.getName());
|
||||
setTestIfEmpty(myGroupIdField, "");
|
||||
setTestIfEmpty(myVersionField, DEFAULT_VERSION);
|
||||
}
|
||||
else {
|
||||
myContext.putUserData(ExternalModuleSettingsStep.SKIP_STEP_KEY, Boolean.TRUE);
|
||||
myGroupIdField.setEnabled(!myInheritGroupIdCheckBox.isSelected());
|
||||
myVersionField.setEnabled(!myInheritVersionCheckBox.isSelected());
|
||||
|
||||
if (myInheritGroupIdCheckBox.isSelected()
|
||||
|| myGroupIdField.getText().equals(myInheritedGroupId)) {
|
||||
myGroupIdField.setText(parentProject.getGroup());
|
||||
}
|
||||
if (myInheritVersionCheckBox.isSelected()
|
||||
|| myVersionField.getText().equals(myInheritedVersion)) {
|
||||
myVersionField.setText(parentProject.getVersion());
|
||||
}
|
||||
myInheritedGroupId = myGroupIdField.getText();
|
||||
myInheritedVersion = myVersionField.getText();
|
||||
|
||||
myInheritGroupIdCheckBox.setEnabled(true);
|
||||
myInheritVersionCheckBox.setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isGradleModuleExist(WizardContext myContext) {
|
||||
for (Module module : myContext.getModulesProvider().getModules()) {
|
||||
if (ExternalSystemApiUtil.isExternalSystemAwareModule(GradleConstants.SYSTEM_ID, module)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDataModel() {
|
||||
myContext.setProjectBuilder(myBuilder);
|
||||
ProjectData parentProject = myParentProjectForm.getParentProject();
|
||||
myBuilder.setParentProject(parentProject);
|
||||
|
||||
myBuilder.setProjectId(new ProjectId(myGroupIdField.getText(),
|
||||
myArtifactIdField.getText(),
|
||||
myVersionField.getText()));
|
||||
myBuilder.setInheritGroupId(myInheritGroupIdCheckBox.isSelected());
|
||||
myBuilder.setInheritVersion(myInheritVersionCheckBox.isSelected());
|
||||
|
||||
if (StringUtil.isNotEmpty(myBuilder.getProjectId().getArtifactId())) {
|
||||
myContext.setProjectName(myBuilder.getProjectId().getArtifactId());
|
||||
}
|
||||
if (parentProject != null) {
|
||||
myContext.setProjectFileDirectory(parentProject.getLinkedExternalProjectPath() + '/' + myContext.getProjectName());
|
||||
}
|
||||
else {
|
||||
if (myProjectOrNull != null) {
|
||||
myContext.setProjectFileDirectory(myProjectOrNull.getBaseDir().getPath() + '/' + myContext.getProjectName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Icon getIcon() {
|
||||
return WIZARD_ICON;
|
||||
}
|
||||
|
||||
private static void setTestIfEmpty(@NotNull JTextField field, @Nullable String text) {
|
||||
if (StringUtil.isEmpty(field.getText())) {
|
||||
field.setText(StringUtil.notNullize(text));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelpId() {
|
||||
return "Gradle_Archetype_Dialog";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disposeUIResources() {
|
||||
Disposer.dispose(myParentProjectForm);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,158 @@
|
||||
/*
|
||||
* Copyright 2000-2017 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.kotlin.gradle.kdsl.frameworkSupport;
|
||||
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class BuildScriptDataBuilder {
|
||||
@NotNull private final VirtualFile myBuildScriptFile;
|
||||
private final Set<String> plugins = ContainerUtil.newTreeSet();
|
||||
private final Set<String> pluginsInGroup = ContainerUtil.newTreeSet();
|
||||
private final Set<String> repositories = ContainerUtil.newTreeSet();
|
||||
private final Set<String> dependencies = ContainerUtil.newTreeSet();
|
||||
private final Set<String> properties = ContainerUtil.newTreeSet();
|
||||
private final Set<String> buildScriptProperties = ContainerUtil.newTreeSet();
|
||||
private final Set<String> buildScriptRepositories = ContainerUtil.newTreeSet();
|
||||
private final Set<String> buildScriptDependencies = ContainerUtil.newTreeSet();
|
||||
private final Set<String> other = ContainerUtil.newTreeSet();
|
||||
|
||||
public BuildScriptDataBuilder(@NotNull VirtualFile buildScriptFile) {
|
||||
myBuildScriptFile = buildScriptFile;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public VirtualFile getBuildScriptFile() {
|
||||
return myBuildScriptFile;
|
||||
}
|
||||
|
||||
public String buildConfigurationPart() {
|
||||
List<String> lines = ContainerUtil.newArrayList();
|
||||
addBuildscriptLines(lines, BuildScriptDataBuilder::padding);
|
||||
if (!pluginsInGroup.isEmpty()) {
|
||||
lines.add("plugins {");
|
||||
lines.addAll(ContainerUtil.map(pluginsInGroup, BuildScriptDataBuilder::padding));
|
||||
lines.add("}");
|
||||
lines.add("");
|
||||
}
|
||||
return StringUtil.join(lines, "\n");
|
||||
}
|
||||
|
||||
public String buildMainPart() {
|
||||
List<String> lines = ContainerUtil.newArrayList();
|
||||
if (!plugins.isEmpty()) {
|
||||
lines.addAll(plugins);
|
||||
lines.add("");
|
||||
}
|
||||
if (!properties.isEmpty()) {
|
||||
lines.addAll(properties);
|
||||
lines.add("");
|
||||
}
|
||||
if (!repositories.isEmpty()) {
|
||||
lines.add("repositories {");
|
||||
lines.addAll(ContainerUtil.map(repositories, BuildScriptDataBuilder::padding));
|
||||
lines.add("}");
|
||||
lines.add("");
|
||||
}
|
||||
if (!dependencies.isEmpty()) {
|
||||
lines.add("dependencies {");
|
||||
lines.addAll(ContainerUtil.map(dependencies, BuildScriptDataBuilder::padding));
|
||||
lines.add("}");
|
||||
lines.add("");
|
||||
}
|
||||
if (!other.isEmpty()) {
|
||||
lines.addAll(other);
|
||||
}
|
||||
return StringUtil.join(lines, "\n");
|
||||
}
|
||||
|
||||
private void addBuildscriptLines(@NotNull List<String> lines, @NotNull Function<String, String> padding) {
|
||||
if (!buildScriptRepositories.isEmpty() || !buildScriptDependencies.isEmpty() || !buildScriptProperties.isEmpty()) {
|
||||
lines.add("buildscript {");
|
||||
final List<String> buildScriptLines = ContainerUtil.newSmartList();
|
||||
if (!buildScriptProperties.isEmpty()) {
|
||||
buildScriptLines.addAll(buildScriptProperties);
|
||||
buildScriptLines.add("");
|
||||
}
|
||||
if (!buildScriptRepositories.isEmpty()) {
|
||||
buildScriptLines.add("repositories {");
|
||||
buildScriptLines.addAll(ContainerUtil.map(buildScriptRepositories, padding));
|
||||
buildScriptLines.add("}");
|
||||
}
|
||||
if (!buildScriptDependencies.isEmpty()) {
|
||||
buildScriptLines.add("dependencies {");
|
||||
buildScriptLines.addAll(ContainerUtil.map(buildScriptDependencies, padding));
|
||||
buildScriptLines.add("}");
|
||||
}
|
||||
lines.addAll(ContainerUtil.map(buildScriptLines, padding));
|
||||
lines.add("}");
|
||||
lines.add("");
|
||||
}
|
||||
}
|
||||
|
||||
public BuildScriptDataBuilder addBuildscriptPropertyDefinition(@NotNull String definition) {
|
||||
buildScriptProperties.add(definition.trim());
|
||||
return this;
|
||||
}
|
||||
|
||||
public BuildScriptDataBuilder addBuildscriptRepositoriesDefinition(@NotNull String definition) {
|
||||
buildScriptRepositories.add(definition.trim());
|
||||
return this;
|
||||
}
|
||||
|
||||
public BuildScriptDataBuilder addBuildscriptDependencyNotation(@NotNull String notation) {
|
||||
buildScriptDependencies.add(notation.trim());
|
||||
return this;
|
||||
}
|
||||
|
||||
public BuildScriptDataBuilder addPluginDefinitionInPluginsGroup(@NotNull String definition) {
|
||||
pluginsInGroup.add(definition.trim());
|
||||
return this;
|
||||
}
|
||||
|
||||
public BuildScriptDataBuilder addPluginDefinition(@NotNull String definition) {
|
||||
plugins.add(definition.trim());
|
||||
return this;
|
||||
}
|
||||
|
||||
public BuildScriptDataBuilder addRepositoriesDefinition(@NotNull String definition) {
|
||||
repositories.add(definition.trim());
|
||||
return this;
|
||||
}
|
||||
|
||||
public BuildScriptDataBuilder addDependencyNotation(@NotNull String notation) {
|
||||
dependencies.add(notation.trim());
|
||||
return this;
|
||||
}
|
||||
|
||||
public BuildScriptDataBuilder addPropertyDefinition(@NotNull String definition) {
|
||||
properties.add(definition.trim());
|
||||
return this;
|
||||
}
|
||||
|
||||
public BuildScriptDataBuilder addOther(@NotNull String definition) {
|
||||
other.add(definition.trim());
|
||||
return this;
|
||||
}
|
||||
|
||||
private static String padding(String s) {return StringUtil.isNotEmpty(s) ? " " + s : "";}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright 2010-2017 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.kotlin.gradle.kdsl.frameworkSupport;
|
||||
|
||||
import com.intellij.framework.addSupport.FrameworkSupportInModuleConfigurable;
|
||||
import com.intellij.framework.addSupport.FrameworkSupportInModuleProvider;
|
||||
import com.intellij.ide.util.frameworkSupport.FrameworkSupportModel;
|
||||
import com.intellij.openapi.extensions.ExtensionPointName;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleType;
|
||||
import com.intellij.openapi.roots.ModifiableModelsProvider;
|
||||
import com.intellij.openapi.roots.ModifiableRootModel;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
import static org.jetbrains.kotlin.gradle.kdsl.GradleModuleBuilder.getBuildScriptData;
|
||||
|
||||
public abstract class GradleFrameworkSupportProvider extends FrameworkSupportInModuleProvider {
|
||||
|
||||
public static final ExtensionPointName<GradleFrameworkSupportProvider> EP_NAME =
|
||||
ExtensionPointName.create("org.jetbrains.kotlin.gradleFrameworkSupport");
|
||||
|
||||
public abstract void addSupport(@NotNull Module module, @NotNull ModifiableRootModel rootModel,
|
||||
@NotNull ModifiableModelsProvider modifiableModelsProvider,
|
||||
@NotNull BuildScriptDataBuilder buildScriptData);
|
||||
|
||||
public JComponent createComponent() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public FrameworkSupportInModuleConfigurable createConfigurable(@NotNull FrameworkSupportModel model) {
|
||||
return new FrameworkSupportInModuleConfigurable() {
|
||||
@Nullable
|
||||
@Override
|
||||
public JComponent createComponent() {
|
||||
return GradleFrameworkSupportProvider.this.createComponent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addSupport(@NotNull Module module,
|
||||
@NotNull ModifiableRootModel rootModel,
|
||||
@NotNull ModifiableModelsProvider modifiableModelsProvider) {
|
||||
final BuildScriptDataBuilder buildScriptData = getBuildScriptData(module);
|
||||
if (buildScriptData != null) {
|
||||
GradleFrameworkSupportProvider.this.addSupport(module, rootModel, modifiableModelsProvider, buildScriptData);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabledForModuleType(@NotNull ModuleType moduleType) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright 2010-2017 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.kotlin.gradle.kdsl.frameworkSupport;
|
||||
|
||||
import com.intellij.framework.FrameworkTypeEx;
|
||||
import com.intellij.framework.addSupport.FrameworkSupportInModuleProvider;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.roots.ModifiableModelsProvider;
|
||||
import com.intellij.openapi.roots.ModifiableRootModel;
|
||||
import icons.JetgroovyIcons;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class GradleGroovyFrameworkSupportProvider extends GradleFrameworkSupportProvider {
|
||||
|
||||
public static final String ID = "groovy";
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public FrameworkTypeEx getFrameworkType() {
|
||||
return new FrameworkTypeEx(ID) {
|
||||
@NotNull
|
||||
@Override
|
||||
public FrameworkSupportInModuleProvider createProvider() {
|
||||
return GradleGroovyFrameworkSupportProvider.this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getPresentableName() {
|
||||
return "Groovy";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Icon getIcon() {
|
||||
return JetgroovyIcons.Groovy.Groovy_16x16;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addSupport(@NotNull Module module,
|
||||
@NotNull ModifiableRootModel rootModel,
|
||||
@NotNull ModifiableModelsProvider modifiableModelsProvider,
|
||||
@NotNull BuildScriptDataBuilder buildScriptData) {
|
||||
buildScriptData
|
||||
.addPluginDefinition("plugin(\"groovy\")")
|
||||
.addRepositoriesDefinition("mavenCentral()")
|
||||
.addDependencyNotation("compile(\"org.codehaus.groovy:groovy-all:2.3.11\")")
|
||||
.addDependencyNotation("testCompile(\"junit\", \"junit\", \"4.12\")");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright 2000-2015 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.kotlin.gradle.kdsl.frameworkSupport;
|
||||
|
||||
import com.intellij.framework.FrameworkTypeEx;
|
||||
import com.intellij.framework.addSupport.FrameworkSupportInModuleProvider;
|
||||
import com.intellij.icons.AllIcons;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.roots.ModifiableModelsProvider;
|
||||
import com.intellij.openapi.roots.ModifiableRootModel;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class GradleJavaFrameworkSupportProvider extends GradleFrameworkSupportProvider {
|
||||
|
||||
public static final String ID = "java";
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public FrameworkTypeEx getFrameworkType() {
|
||||
return new FrameworkTypeEx(ID) {
|
||||
@NotNull
|
||||
@Override
|
||||
public FrameworkSupportInModuleProvider createProvider() {
|
||||
return GradleJavaFrameworkSupportProvider.this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getPresentableName() {
|
||||
return "Java";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Icon getIcon() {
|
||||
return AllIcons.Nodes.Module;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addSupport(@NotNull Module module,
|
||||
@NotNull ModifiableRootModel rootModel,
|
||||
@NotNull ModifiableModelsProvider modifiableModelsProvider,
|
||||
@NotNull BuildScriptDataBuilder buildScriptData) {
|
||||
buildScriptData
|
||||
.addPluginDefinition("plugin(\"java\")")
|
||||
// TODO: in gradle > 4.0 it is just 'java { ... }'
|
||||
.addOther("configure<JavaPluginConvention> {\n sourceCompatibility = JavaVersion.VERSION_1_8\n}")
|
||||
.addRepositoriesDefinition("mavenCentral()")
|
||||
.addDependencyNotation("testCompile(\"junit\", \"junit\", \"4.12\")");
|
||||
}
|
||||
}
|
||||
@@ -14,36 +14,34 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.configuration
|
||||
package org.jetbrains.kotlin.gradle.kdsl.frameworkSupport
|
||||
|
||||
import com.intellij.framework.FrameworkTypeEx
|
||||
import com.intellij.framework.addSupport.FrameworkSupportInModuleProvider
|
||||
import com.intellij.openapi.externalSystem.model.project.ProjectId
|
||||
import com.intellij.openapi.module.Module
|
||||
import com.intellij.openapi.roots.ModifiableModelsProvider
|
||||
import com.intellij.openapi.roots.ModifiableRootModel
|
||||
import com.intellij.openapi.vfs.VfsUtil
|
||||
import org.jetbrains.kotlin.idea.KotlinIcons
|
||||
import org.jetbrains.kotlin.idea.configuration.*
|
||||
import org.jetbrains.kotlin.idea.configuration.KotlinBuildScriptManipulator.Companion.GSK_KOTLIN_VERSION_PROPERTY_NAME
|
||||
import org.jetbrains.kotlin.idea.configuration.KotlinBuildScriptManipulator.Companion.getCompileDependencySnippet
|
||||
import org.jetbrains.kotlin.idea.configuration.KotlinBuildScriptManipulator.Companion.getKotlinGradlePluginClassPathSnippet
|
||||
import org.jetbrains.kotlin.idea.versions.*
|
||||
import org.jetbrains.plugins.gradle.frameworkSupport.BuildScriptDataBuilder
|
||||
import org.jetbrains.plugins.gradle.frameworkSupport.KotlinDslGradleFrameworkSupportProvider
|
||||
import javax.swing.Icon
|
||||
|
||||
abstract class KotlinDslGradleKotlinFrameworkSupportProvider(
|
||||
abstract class GradleKotlinDSLKotlinFrameworkSupportProvider(
|
||||
val frameworkTypeId: String,
|
||||
val displayName: String,
|
||||
val frameworkIcon: Icon
|
||||
) : KotlinDslGradleFrameworkSupportProvider() {
|
||||
) : GradleFrameworkSupportProvider() {
|
||||
override fun getFrameworkType(): FrameworkTypeEx = object : FrameworkTypeEx(frameworkTypeId) {
|
||||
override fun getIcon(): Icon = frameworkIcon
|
||||
override fun getPresentableName(): String = displayName
|
||||
override fun createProvider(): FrameworkSupportInModuleProvider = this@KotlinDslGradleKotlinFrameworkSupportProvider
|
||||
override fun createProvider(): FrameworkSupportInModuleProvider = this@GradleKotlinDSLKotlinFrameworkSupportProvider
|
||||
}
|
||||
|
||||
override fun addSupport(
|
||||
projectId: ProjectId,
|
||||
module: Module,
|
||||
rootModel: ModifiableRootModel,
|
||||
modifiableModelsProvider: ModifiableModelsProvider,
|
||||
@@ -68,20 +66,18 @@ abstract class KotlinDslGradleKotlinFrameworkSupportProvider(
|
||||
.addBuildscriptRepositoriesDefinition("mavenCentral()")
|
||||
.addRepositoriesDefinition("mavenCentral()")
|
||||
// TODO: in gradle > 4.1 this could be single declaration e.g. 'val kotlin_version: String by extra { "1.1.11" }'
|
||||
.addBuildscriptPropertyDefinition("var $GSK_KOTLIN_VERSION_PROPERTY_NAME: String by extra\n $GSK_KOTLIN_VERSION_PROPERTY_NAME = \"$kotlinVersion\"")
|
||||
.addBuildscriptPropertyDefinition("var $GSK_KOTLIN_VERSION_PROPERTY_NAME: String by extra\n$GSK_KOTLIN_VERSION_PROPERTY_NAME = \"$kotlinVersion\"")
|
||||
.addDependencyNotation(getRuntimeLibrary(rootModel))
|
||||
.addBuildscriptDependencyNotation(getKotlinGradlePluginClassPathSnippet())
|
||||
}
|
||||
|
||||
private fun RepositoryDescription.toKotlinRepositorySnippet() = "maven { setUrl(\"$url\") }"
|
||||
|
||||
protected abstract fun getRuntimeLibrary(rootModel: ModifiableRootModel): String
|
||||
|
||||
protected abstract fun getPluginDefinition(): String
|
||||
}
|
||||
|
||||
class KotlinDslGradleKotlinJavaFrameworkSupportProvider :
|
||||
KotlinDslGradleKotlinFrameworkSupportProvider("KOTLIN", "Kotlin (Java)", KotlinIcons.SMALL_LOGO) {
|
||||
class GradleKotlinDSLKotlinJavaFrameworkSupportProvider :
|
||||
GradleKotlinDSLKotlinFrameworkSupportProvider("KOTLIN", "Kotlin (Java)", KotlinIcons.SMALL_LOGO) {
|
||||
|
||||
override fun getPluginDefinition() = "plugin(\"${KotlinGradleModuleConfigurator.KOTLIN}\")"
|
||||
|
||||
@@ -89,24 +85,28 @@ class KotlinDslGradleKotlinJavaFrameworkSupportProvider :
|
||||
getCompileDependencySnippet(KOTLIN_GROUP_ID, getStdlibArtifactId(rootModel.sdk, bundledRuntimeVersion()))
|
||||
|
||||
override fun addSupport(
|
||||
projectId: ProjectId,
|
||||
module: Module,
|
||||
rootModel: ModifiableRootModel,
|
||||
modifiableModelsProvider: ModifiableModelsProvider,
|
||||
buildScriptData: BuildScriptDataBuilder
|
||||
) {
|
||||
super.addSupport(projectId, module, rootModel, modifiableModelsProvider, buildScriptData)
|
||||
super.addSupport(module, rootModel, modifiableModelsProvider, buildScriptData)
|
||||
val jvmTarget = getDefaultJvmTarget(rootModel.sdk, bundledRuntimeVersion())
|
||||
if (jvmTarget != null) {
|
||||
buildScriptData
|
||||
.addImport("import org.jetbrains.kotlin.gradle.tasks.KotlinCompile")
|
||||
.addImports("import org.jetbrains.kotlin.gradle.tasks.KotlinCompile")
|
||||
.addOther("tasks.withType<KotlinCompile> {\n kotlinOptions.jvmTarget = \"1.8\"\n}\n")
|
||||
}
|
||||
}
|
||||
|
||||
private fun BuildScriptDataBuilder.addImports(vararg import: String): BuildScriptDataBuilder = apply {
|
||||
val text = VfsUtil.loadText(buildScriptFile)
|
||||
VfsUtil.saveText(buildScriptFile, import.joinToString(separator = "\n") + "\n\n" + text)
|
||||
}
|
||||
}
|
||||
|
||||
class KotlinDslGradleKotlinJSFrameworkSupportProvider :
|
||||
KotlinDslGradleKotlinFrameworkSupportProvider("KOTLIN_JS", "Kotlin (JavaScript)", KotlinIcons.JS) {
|
||||
class GradleKotlinDSLKotlinJSFrameworkSupportProvider :
|
||||
GradleKotlinDSLKotlinFrameworkSupportProvider("KOTLIN_JS", "Kotlin (JavaScript)", KotlinIcons.JS) {
|
||||
|
||||
override fun getPluginDefinition(): String = "plugin(\"${KotlinJsGradleModuleConfigurator.KOTLIN_JS}\")"
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright 2010-2017 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.kotlin.gradle.kdsl.frameworkSupport
|
||||
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.util.containers.ContainerUtil
|
||||
|
||||
class KotlinBuildScriptDataBuilder(buildScriptFile: VirtualFile) : BuildScriptDataBuilder(buildScriptFile) {
|
||||
private val plugins: MutableSet<String> = ContainerUtil.newTreeSet<String>()
|
||||
private val properties: MutableSet<String> = ContainerUtil.newTreeSet<String>()
|
||||
private val repositories: MutableSet<String> = ContainerUtil.newTreeSet<String>()
|
||||
private val dependencies: MutableSet<String> = ContainerUtil.newTreeSet<String>()
|
||||
|
||||
private val buildScriptProperties: MutableSet<String> = ContainerUtil.newTreeSet<String>()
|
||||
private val buildScriptRepositories: MutableSet<String> = ContainerUtil.newTreeSet<String>()
|
||||
private val buildScriptDependencies: MutableSet<String> = ContainerUtil.newTreeSet<String>()
|
||||
private val other: MutableSet<String> = ContainerUtil.newTreeSet<String>()
|
||||
|
||||
override fun addPluginDefinition(definition: String): BuildScriptDataBuilder = apply { plugins.add(definition) }
|
||||
|
||||
override fun addRepositoriesDefinition(definition: String): BuildScriptDataBuilder = apply { repositories.add(definition) }
|
||||
|
||||
override fun addPropertyDefinition(definition: String): BuildScriptDataBuilder = apply { properties.add(definition) }
|
||||
|
||||
override fun addDependencyNotation(notation: String): BuildScriptDataBuilder = apply { dependencies.add(notation) }
|
||||
|
||||
override fun addBuildscriptPropertyDefinition(definition: String): BuildScriptDataBuilder = apply { buildScriptProperties.add(definition) }
|
||||
|
||||
override fun addBuildscriptRepositoriesDefinition(definition: String): BuildScriptDataBuilder = apply { buildScriptRepositories.add(definition) }
|
||||
|
||||
override fun addBuildscriptDependencyNotation(notation: String): BuildScriptDataBuilder = apply { buildScriptDependencies.add(notation) }
|
||||
|
||||
override fun addOther(definition: String): BuildScriptDataBuilder = apply { other.add(definition) }
|
||||
|
||||
override fun buildMainPart(): String = buildString {
|
||||
|
||||
appendlnIfNotNull(buildBuildScriptBlock())
|
||||
|
||||
appendlnIfNotNull(buildBlock("apply", plugins))
|
||||
|
||||
if (properties.isNotEmpty()) {
|
||||
properties.forEach { appendln(it) }
|
||||
appendln()
|
||||
}
|
||||
|
||||
appendlnIfNotNull(buildBlock("repositories", repositories))
|
||||
|
||||
appendlnIfNotNull(buildBlock("dependencies", dependencies))
|
||||
|
||||
other.forEach { appendln(it) }
|
||||
}
|
||||
|
||||
private fun buildBuildScriptBlock(): String? = buildString {
|
||||
if (buildScriptProperties.isEmpty() || buildScriptRepositories.isEmpty() || buildScriptDependencies.isEmpty()) {
|
||||
return null
|
||||
}
|
||||
|
||||
appendln("buildscript {")
|
||||
buildScriptProperties.forEach { appendln(it.withMargin) }
|
||||
appendln()
|
||||
appendlnIfNotNull(buildBlock("repositories", buildScriptRepositories)?.withMargin)
|
||||
appendlnIfNotNull(buildBlock("dependencies", buildScriptDependencies)?.withMargin)
|
||||
appendln("}")
|
||||
}
|
||||
|
||||
private fun buildBlock(name: String, lines: Set<String>): String? = buildString {
|
||||
if (lines.isEmpty()) {
|
||||
return null
|
||||
}
|
||||
|
||||
appendln("$name {")
|
||||
lines.forEach { appendln(it.withMargin) }
|
||||
appendln("}")
|
||||
}
|
||||
|
||||
private val String.withMargin: String
|
||||
get() = lines().joinToString(separator = "\n") { " " + it }
|
||||
|
||||
private fun StringBuilder.appendlnIfNotNull(text: String?) = text?.let { appendln(it) }
|
||||
}
|
||||
@@ -103,7 +103,7 @@ class KotlinGradleMultiplatformModuleBuilder : GradleModuleBuilder() {
|
||||
val buildGradle = moduleDir.createChildData(null, "build.gradle")
|
||||
val buildScriptData = BuildScriptDataBuilder(buildGradle)
|
||||
extendScript(buildScriptData, sdk ?: rootModule.rootManager.sdk)
|
||||
VfsUtil.saveText(buildGradle, buildScriptData.buildConfigurationPart() + buildScriptData.buildMainPart())
|
||||
VfsUtil.saveText(buildGradle, buildScriptData.build())
|
||||
}
|
||||
|
||||
private fun setupCommonModule(
|
||||
|
||||
@@ -31,6 +31,7 @@ import com.intellij.openapi.roots.OrderRootType
|
||||
import com.intellij.openapi.roots.impl.libraries.LibraryEx
|
||||
import com.intellij.openapi.roots.impl.libraries.LibraryImpl
|
||||
import com.intellij.openapi.roots.libraries.PersistentLibraryKind
|
||||
import com.intellij.openapi.util.Key
|
||||
import com.intellij.util.PathUtil
|
||||
import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments
|
||||
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
|
||||
@@ -40,6 +41,8 @@ import org.jetbrains.kotlin.config.JvmTarget
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.config.TargetPlatformKind
|
||||
import org.jetbrains.kotlin.extensions.ProjectExtensionDescriptor
|
||||
import org.jetbrains.kotlin.gradle.ArgsInfo
|
||||
import org.jetbrains.kotlin.gradle.CompilerArgumentsBySourceSet
|
||||
import org.jetbrains.kotlin.idea.facet.*
|
||||
import org.jetbrains.kotlin.idea.framework.CommonLibraryKind
|
||||
import org.jetbrains.kotlin.idea.framework.JSLibraryKind
|
||||
@@ -47,11 +50,18 @@ import org.jetbrains.kotlin.idea.framework.detectLibraryKind
|
||||
import org.jetbrains.kotlin.idea.inspections.gradle.findAll
|
||||
import org.jetbrains.kotlin.idea.inspections.gradle.findKotlinPluginVersion
|
||||
import org.jetbrains.kotlin.idea.inspections.gradle.getResolvedKotlinStdlibVersionByModuleData
|
||||
import org.jetbrains.kotlin.psi.UserDataProperty
|
||||
import org.jetbrains.plugins.gradle.model.data.BuildScriptClasspathData
|
||||
import org.jetbrains.plugins.gradle.model.data.GradleSourceSetData
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
|
||||
var Module.compilerArgumentsBySourceSet
|
||||
by UserDataProperty(Key.create<CompilerArgumentsBySourceSet>("CURRENT_COMPILER_ARGUMENTS"))
|
||||
|
||||
var Module.sourceSetName
|
||||
by UserDataProperty(Key.create<String>("SOURCE_SET_NAME"))
|
||||
|
||||
interface GradleProjectImportHandler {
|
||||
companion object : ProjectExtensionDescriptor<GradleProjectImportHandler>(
|
||||
"org.jetbrains.kotlin.gradleProjectImportHandler",
|
||||
@@ -76,7 +86,8 @@ class KotlinGradleSourceSetDataService : AbstractProjectDataService<GradleSource
|
||||
val ideModule = modelsProvider.findIdeModule(sourceSetData) ?: continue
|
||||
|
||||
val moduleNode = ExternalSystemApiUtil.findParent(sourceSetNode, ProjectKeys.MODULE) ?: continue
|
||||
val kotlinFacet = configureFacetByGradleModule(moduleNode, sourceSetNode, ideModule, modelsProvider) ?: continue
|
||||
val sourceSetName = sourceSetNode.data.id.let { it.substring(it.lastIndexOf(':') + 1) }
|
||||
val kotlinFacet = configureFacetByGradleModule(moduleNode, sourceSetName, ideModule, modelsProvider) ?: continue
|
||||
GradleProjectImportHandler.getInstances(project).forEach { it.importBySourceSet(kotlinFacet, sourceSetNode) }
|
||||
}
|
||||
}
|
||||
@@ -172,11 +183,11 @@ private fun detectPlatformByLibrary(moduleNode: DataNode<ModuleData>): TargetPla
|
||||
return detectedPlatforms.singleOrNull() ?: detectedPlatforms.firstOrNull { it != TargetPlatformKind.Common }
|
||||
}
|
||||
|
||||
private fun configureFacetByGradleModule(
|
||||
moduleNode: DataNode<ModuleData>,
|
||||
sourceSetNode: DataNode<GradleSourceSetData>?,
|
||||
ideModule: Module,
|
||||
modelsProvider: IdeModifiableModelsProvider
|
||||
fun configureFacetByGradleModule(
|
||||
moduleNode: DataNode<ModuleData>,
|
||||
sourceSetName: String?,
|
||||
ideModule: Module,
|
||||
modelsProvider: IdeModifiableModelsProvider
|
||||
): KotlinFacet? {
|
||||
if (!moduleNode.isResolved) return null
|
||||
|
||||
@@ -200,21 +211,16 @@ private fun configureFacetByGradleModule(
|
||||
val kotlinFacet = ideModule.getOrCreateFacet(modelsProvider, false)
|
||||
kotlinFacet.configureFacet(compilerVersion, coroutinesProperty, platformKind, modelsProvider)
|
||||
|
||||
val sourceSetName = sourceSetNode?.data?.id?.let { it.substring(it.lastIndexOf(':') + 1) }
|
||||
ideModule.compilerArgumentsBySourceSet = moduleNode.compilerArgumentsBySourceSet
|
||||
ideModule.sourceSetName = sourceSetName
|
||||
|
||||
val argsInfo = moduleNode.compilerArgumentsBySourceSet?.get(sourceSetName ?: "main")
|
||||
if (argsInfo != null) {
|
||||
val currentCompilerArguments = argsInfo.currentArguments
|
||||
val defaultCompilerArguments = argsInfo.defaultArguments
|
||||
val dependencyClasspath = argsInfo.dependencyClasspath.map { PathUtil.toSystemIndependentName(it) }
|
||||
if (currentCompilerArguments.isNotEmpty()) {
|
||||
parseCompilerArgumentsToFacet(currentCompilerArguments, defaultCompilerArguments, kotlinFacet, modelsProvider)
|
||||
}
|
||||
adjustClasspath(kotlinFacet, dependencyClasspath)
|
||||
configureFacetByCompilerArguments(kotlinFacet, argsInfo, modelsProvider)
|
||||
}
|
||||
|
||||
with(kotlinFacet.configuration.settings) {
|
||||
implementedModuleNames = (sourceSetNode ?: moduleNode).implementedModuleNames
|
||||
implementedModuleNames = sourceSetName?.let { listOf(it) } ?: moduleNode.implementedModuleNames
|
||||
productionOutputPath = getExplicitOutputPath(moduleNode, platformKind, "main")
|
||||
testOutputPath = getExplicitOutputPath(moduleNode, platformKind, "test")
|
||||
}
|
||||
@@ -224,6 +230,16 @@ private fun configureFacetByGradleModule(
|
||||
return kotlinFacet
|
||||
}
|
||||
|
||||
fun configureFacetByCompilerArguments(kotlinFacet: KotlinFacet, argsInfo: ArgsInfo, modelsProvider: IdeModifiableModelsProvider?) {
|
||||
val currentCompilerArguments = argsInfo.currentArguments
|
||||
val defaultCompilerArguments = argsInfo.defaultArguments
|
||||
val dependencyClasspath = argsInfo.dependencyClasspath.map { PathUtil.toSystemIndependentName(it) }
|
||||
if (currentCompilerArguments.isNotEmpty()) {
|
||||
parseCompilerArgumentsToFacet(currentCompilerArguments, defaultCompilerArguments, kotlinFacet, modelsProvider)
|
||||
}
|
||||
adjustClasspath(kotlinFacet, dependencyClasspath)
|
||||
}
|
||||
|
||||
private fun getExplicitOutputPath(moduleNode: DataNode<ModuleData>, platformKind: TargetPlatformKind<*>?, sourceSet: String): String? {
|
||||
if (platformKind !== TargetPlatformKind.JavaScript) return null
|
||||
val k2jsArgumentList = moduleNode.compilerArgumentsBySourceSet?.get(sourceSet)?.currentArguments ?: return null
|
||||
|
||||
@@ -91,14 +91,19 @@ abstract class KotlinWithGradleConfigurator : KotlinProjectConfigurator {
|
||||
dialog.show()
|
||||
if (!dialog.isOK) return
|
||||
|
||||
project.executeCommand("Configure Kotlin") {
|
||||
val collector = configureSilently(project, dialog.modulesToConfigure, dialog.kotlinVersion)
|
||||
collector.showNotification()
|
||||
}
|
||||
|
||||
fun configureSilently(project: Project, modules: List<Module>, version: String): NotificationMessageCollector {
|
||||
return project.executeCommand("Configure Kotlin") {
|
||||
val collector = createConfigureKotlinNotificationCollector(project)
|
||||
val changedFiles = configureWithVersion(project, dialog.modulesToConfigure, dialog.kotlinVersion, collector)
|
||||
val changedFiles = configureWithVersion(project, modules, version, collector)
|
||||
|
||||
for (file in changedFiles) {
|
||||
OpenFileAction.openFile(file.virtualFile, project)
|
||||
}
|
||||
collector.showNotification()
|
||||
collector
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -233,10 +233,10 @@ class GradleScriptDefinitionsContributor(private val project: Project) : ScriptD
|
||||
override val dependencyResolver: DependenciesResolver = ErrorScriptDependenciesResolver(message)
|
||||
|
||||
override fun getScriptName(script: KtScript) =
|
||||
Name.identifier(script.containingKtFile.name.removeSuffix(GradleConstants.KOTLIN_DSL_SCRIPT_EXTENSION))
|
||||
Name.identifier(script.containingKtFile.name.removeSuffix(".gradle.kts"))
|
||||
|
||||
override fun isScript(fileName: String): Boolean =
|
||||
fileName.endsWith(GradleConstants.KOTLIN_DSL_SCRIPT_EXTENSION)
|
||||
fileName.endsWith(".gradle.kts")
|
||||
}
|
||||
|
||||
private class ErrorScriptDependenciesResolver(private val message: String? = null) : DependenciesResolver {
|
||||
@@ -267,7 +267,7 @@ class ReloadGradleTemplatesOnSync : ExternalSystemTaskNotificationListenerAdapte
|
||||
internal val gradleState = GradleSyncState()
|
||||
}
|
||||
|
||||
override fun onStart(id: ExternalSystemTaskId, workingDir: String?) {
|
||||
override fun onStart(id: ExternalSystemTaskId) {
|
||||
if (id.type == ExternalSystemTaskType.RESOLVE_PROJECT && id.projectSystemId == GRADLE_SYSTEM_ID) {
|
||||
gradleState.isSyncInProgress = true
|
||||
}
|
||||
|
||||
@@ -54,7 +54,8 @@ class ScriptModificationListener(private val project: Project) {
|
||||
}) {
|
||||
return
|
||||
}
|
||||
ExternalProjectsManager.getInstance(project).externalProjectsWatcher.markDirty(project.basePath)
|
||||
// externalProjectsWatcher is not avaliable in 171
|
||||
//ExternalProjectsManager.getInstance(project).externalProjectsWatcher.markDirty(project.basePath)
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -67,6 +68,8 @@ class ScriptModificationListener(private val project: Project) {
|
||||
changedDocumentsQueue.activate()
|
||||
|
||||
EditorFactory.getInstance().eventMulticaster.addDocumentListener(object : DocumentListener {
|
||||
override fun beforeDocumentChange(event: DocumentEvent?) {}
|
||||
|
||||
override fun documentChanged(event: DocumentEvent) {
|
||||
if (project.isDisposed) return
|
||||
|
||||
|
||||
@@ -18,9 +18,10 @@ package org.jetbrains.kotlin.idea.run
|
||||
|
||||
import com.intellij.execution.configurations.JavaRunConfigurationModule
|
||||
import com.intellij.execution.configurations.ModuleBasedConfiguration
|
||||
import com.intellij.openapi.externalSystem.ExternalSystemModulePropertyManager
|
||||
import com.intellij.openapi.diagnostic.Logger
|
||||
import com.intellij.openapi.externalSystem.model.project.ExternalSystemSourceType
|
||||
import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil
|
||||
import com.intellij.openapi.externalSystem.util.ExternalSystemConstants
|
||||
import com.intellij.openapi.module.Module
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.roots.ModuleOrderEntry
|
||||
@@ -120,8 +121,7 @@ class MultiplatformGradleOrderEnumeratorHandler(val factory: MultiplatformGradle
|
||||
if (!ExternalSystemApiUtil.isExternalSystemAwareModule(GradleConstants.SYSTEM_ID, rootModel.module)) return false
|
||||
|
||||
if (!GradleSystemRunningSettings.getInstance().isUseGradleAwareMake) {
|
||||
val gradleProjectPath =
|
||||
ExternalSystemModulePropertyManager.getInstance(rootModel.module).getRootProjectPath() ?: return false
|
||||
val gradleProjectPath = rootModel.module.getOptionValue(ExternalSystemConstants.ROOT_PROJECT_PATH_KEY);
|
||||
val externalProjectDataCache = ExternalProjectDataCache.getInstance(rootModel.module.project)!!
|
||||
val externalRootProject = externalProjectDataCache.getRootExternalProject(
|
||||
GradleConstants.SYSTEM_ID,
|
||||
@@ -156,7 +156,11 @@ class MultiplatformGradleOrderEnumeratorHandler(val factory: MultiplatformGradle
|
||||
}
|
||||
|
||||
private fun addOutputModuleRoots(directorySet: ExternalSourceDirectorySet?, result: MutableCollection<String>) {
|
||||
directorySet?.gradleOutputDirs?.mapTo(result) { VfsUtilCore.pathToUrl(it.absolutePath) }
|
||||
if (directorySet == null) return;
|
||||
|
||||
if (directorySet.isCompilerOutputPathInherited) return
|
||||
val path = directorySet.outputDir.absolutePath
|
||||
result.add(VfsUtilCore.pathToUrl(path))
|
||||
}
|
||||
|
||||
class FactoryImpl : Factory() {
|
||||
|
||||
@@ -24,7 +24,7 @@ import com.intellij.openapi.externalSystem.model.ProjectSystemId;
|
||||
import com.intellij.openapi.externalSystem.model.project.ProjectData;
|
||||
import com.intellij.openapi.externalSystem.service.execution.ProgressExecutionMode;
|
||||
import com.intellij.openapi.externalSystem.service.project.ExternalProjectRefreshCallback;
|
||||
import com.intellij.openapi.externalSystem.service.project.ProjectDataManager;
|
||||
import com.intellij.openapi.externalSystem.service.project.manage.ProjectDataManager;
|
||||
import com.intellij.openapi.externalSystem.settings.AbstractExternalSystemSettings;
|
||||
import com.intellij.openapi.externalSystem.settings.ExternalProjectSettings;
|
||||
import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil;
|
||||
|
||||
@@ -45,7 +45,7 @@ import org.junit.Test
|
||||
internal fun GradleImportingTestCase.facetSettings(moduleName: String) = KotlinFacet.get(getModule(moduleName))!!.configuration.settings
|
||||
|
||||
internal val GradleImportingTestCase.facetSettings: KotlinFacetSettings
|
||||
get() = facetSettings("project_main")
|
||||
get() = facetSettings("project")
|
||||
|
||||
internal val GradleImportingTestCase.testFacetSettings: KotlinFacetSettings
|
||||
get() = facetSettings("project_test")
|
||||
@@ -100,7 +100,8 @@ class GradleFacetImportTest : GradleImportingTestCase() {
|
||||
compilerSettings!!.additionalArguments
|
||||
)
|
||||
}
|
||||
with(testFacetSettings) {
|
||||
/*
|
||||
with (testFacetSettings) {
|
||||
Assert.assertEquals("1.1", languageLevel!!.versionString)
|
||||
Assert.assertEquals("1.0", apiLevel!!.versionString)
|
||||
Assert.assertFalse(compilerArguments!!.autoAdvanceLanguageVersion)
|
||||
@@ -112,7 +113,7 @@ class GradleFacetImportTest : GradleImportingTestCase() {
|
||||
compilerSettings!!.additionalArguments
|
||||
)
|
||||
}
|
||||
|
||||
*/
|
||||
assertAllModulesConfigured()
|
||||
}
|
||||
|
||||
@@ -213,7 +214,8 @@ compileTestKotlin {
|
||||
compilerSettings!!.additionalArguments
|
||||
)
|
||||
}
|
||||
with(testFacetSettings) {
|
||||
/*
|
||||
with (testFacetSettings) {
|
||||
Assert.assertEquals("1.1", languageLevel!!.versionString)
|
||||
Assert.assertEquals("1.0", apiLevel!!.versionString)
|
||||
Assert.assertEquals(TargetPlatformKind.Jvm[JvmTarget.JVM_1_6], targetPlatformKind)
|
||||
@@ -223,6 +225,7 @@ compileTestKotlin {
|
||||
compilerSettings!!.additionalArguments
|
||||
)
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -278,7 +281,8 @@ compileTestKotlin {
|
||||
)
|
||||
importProject()
|
||||
|
||||
with(facetSettings("project_myMain")) {
|
||||
/*
|
||||
with (facetSettings("project_myMain")) {
|
||||
Assert.assertEquals("1.1", languageLevel!!.versionString)
|
||||
Assert.assertEquals("1.1", apiLevel!!.versionString)
|
||||
Assert.assertEquals(TargetPlatformKind.Jvm[JvmTarget.JVM_1_8], targetPlatformKind)
|
||||
@@ -298,7 +302,7 @@ compileTestKotlin {
|
||||
compilerSettings!!.additionalArguments
|
||||
)
|
||||
}
|
||||
|
||||
*/
|
||||
assertAllModulesConfigured()
|
||||
}
|
||||
|
||||
@@ -357,8 +361,8 @@ compileTestKotlin {
|
||||
"""
|
||||
)
|
||||
importProject()
|
||||
|
||||
with(facetSettings("project_myMain")) {
|
||||
/*
|
||||
with (facetSettings("project_myMain")) {
|
||||
Assert.assertEquals("1.1", languageLevel!!.versionString)
|
||||
Assert.assertEquals("1.1", apiLevel!!.versionString)
|
||||
Assert.assertEquals(TargetPlatformKind.Jvm[JvmTarget.JVM_1_8], targetPlatformKind)
|
||||
@@ -378,6 +382,7 @@ compileTestKotlin {
|
||||
compilerSettings!!.additionalArguments
|
||||
)
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -513,8 +518,8 @@ compileTestKotlin {
|
||||
compilerSettings!!.additionalArguments
|
||||
)
|
||||
}
|
||||
|
||||
with(testFacetSettings) {
|
||||
/*
|
||||
with (testFacetSettings) {
|
||||
Assert.assertEquals("1.1", languageLevel!!.versionString)
|
||||
Assert.assertEquals("1.0", apiLevel!!.versionString)
|
||||
Assert.assertFalse(compilerArguments!!.autoAdvanceLanguageVersion)
|
||||
@@ -529,9 +534,9 @@ compileTestKotlin {
|
||||
compilerSettings!!.additionalArguments
|
||||
)
|
||||
}
|
||||
|
||||
val rootManager = ModuleRootManager.getInstance(getModule("project_main"))
|
||||
val stdlib = rootManager.orderEntries.filterIsInstance<LibraryOrderEntry>().single().library
|
||||
*/
|
||||
val rootManager = ModuleRootManager.getInstance(getModule("project"))
|
||||
val stdlib = rootManager.orderEntries.filterIsInstance<LibraryOrderEntry>().first().library
|
||||
assertEquals(JSLibraryKind, (stdlib as LibraryEx).kind)
|
||||
assertTrue(stdlib.getFiles(OrderRootType.CLASSES).isNotEmpty())
|
||||
|
||||
@@ -580,7 +585,7 @@ compileTestKotlin {
|
||||
Assert.assertEquals(TargetPlatformKind.JavaScript, targetPlatformKind)
|
||||
}
|
||||
|
||||
val rootManager = ModuleRootManager.getInstance(getModule("project_main"))
|
||||
val rootManager = ModuleRootManager.getInstance(getModule("project"))
|
||||
val stdlib = rootManager.orderEntries
|
||||
.filterIsInstance<LibraryOrderEntry>()
|
||||
.map { it.library as LibraryEx }
|
||||
@@ -641,8 +646,8 @@ compileTestKotlin {
|
||||
"""
|
||||
)
|
||||
importProject()
|
||||
|
||||
with(facetSettings("project_myMain")) {
|
||||
/*
|
||||
with (facetSettings("project_myMain")) {
|
||||
Assert.assertEquals("1.1", languageLevel!!.versionString)
|
||||
Assert.assertEquals("1.1", apiLevel!!.versionString)
|
||||
Assert.assertEquals(TargetPlatformKind.JavaScript, targetPlatformKind)
|
||||
@@ -669,7 +674,7 @@ compileTestKotlin {
|
||||
compilerSettings!!.additionalArguments
|
||||
)
|
||||
}
|
||||
|
||||
*/
|
||||
assertAllModulesConfigured()
|
||||
}
|
||||
|
||||
@@ -776,10 +781,10 @@ compileTestKotlin {
|
||||
Assert.assertEquals(TargetPlatformKind.JavaScript, targetPlatformKind)
|
||||
}
|
||||
|
||||
val rootManager = ModuleRootManager.getInstance(getModule("project_main"))
|
||||
val rootManager = ModuleRootManager.getInstance(getModule("project"))
|
||||
val libraries = rootManager.orderEntries.filterIsInstance<LibraryOrderEntry>().mapNotNull { it.library as LibraryEx }
|
||||
assertEquals(JSLibraryKind, libraries.single { it.name?.contains("kotlin-stdlib-js") == true }.kind)
|
||||
assertEquals(CommonLibraryKind, libraries.single { it.name?.contains("kotlin-stdlib-common") == true }.kind)
|
||||
assertEquals(JSLibraryKind, libraries.first { it.name?.contains("kotlin-stdlib-js") == true }.kind)
|
||||
assertEquals(CommonLibraryKind, libraries.first { it.name?.contains("kotlin-stdlib-common") == true }.kind)
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -822,8 +827,8 @@ compileTestKotlin {
|
||||
Assert.assertEquals(TargetPlatformKind.Common, targetPlatformKind)
|
||||
}
|
||||
|
||||
val rootManager = ModuleRootManager.getInstance(getModule("project_main"))
|
||||
val stdlib = rootManager.orderEntries.filterIsInstance<LibraryOrderEntry>().single().library
|
||||
val rootManager = ModuleRootManager.getInstance(getModule("project"))
|
||||
val stdlib = rootManager.orderEntries.filterIsInstance<LibraryOrderEntry>().first().library
|
||||
assertEquals(CommonLibraryKind, (stdlib as LibraryEx).kind)
|
||||
}
|
||||
|
||||
@@ -867,8 +872,9 @@ compileTestKotlin {
|
||||
}
|
||||
|
||||
val rootManager = ModuleRootManager.getInstance(getModule("project"))
|
||||
val stdlib = rootManager.orderEntries.filterIsInstance<LibraryOrderEntry>().mapTo(HashSet()) { it.library }.single()
|
||||
assertEquals(CommonLibraryKind, (stdlib as LibraryEx).kind)
|
||||
rootManager.orderEntries.filterIsInstance<LibraryOrderEntry>().mapTo(HashSet()) { it.library }.first {
|
||||
(it as LibraryEx).kind == CommonLibraryKind
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1335,10 +1341,10 @@ compileTestKotlin {
|
||||
)
|
||||
importProject()
|
||||
|
||||
Assert.assertNotNull(KotlinFacet.get(getModule("gr01_main")))
|
||||
Assert.assertNotNull(KotlinFacet.get(getModule("gr01_test")))
|
||||
Assert.assertNull(KotlinFacet.get(getModule("m1_main")))
|
||||
Assert.assertNull(KotlinFacet.get(getModule("m1_test")))
|
||||
Assert.assertNotNull(KotlinFacet.get(getModule("gr01")))
|
||||
// Assert.assertNotNull(KotlinFacet.get(getModule("gr01_test")))
|
||||
Assert.assertNull(KotlinFacet.get(getModule("m1")))
|
||||
// Assert.assertNull(KotlinFacet.get(getModule("m1_test")))
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1457,7 +1463,7 @@ compileTestKotlin {
|
||||
)
|
||||
importProject()
|
||||
|
||||
val moduleSDK = ModuleRootManager.getInstance(getModule("project_main")).sdk!!
|
||||
val moduleSDK = ModuleRootManager.getInstance(getModule("project")).sdk!!
|
||||
Assert.assertTrue(moduleSDK.sdkType is JavaSdk)
|
||||
Assert.assertEquals("myJDK", moduleSDK.name)
|
||||
Assert.assertEquals("my/path/to/jdk", moduleSDK.homePath)
|
||||
@@ -1574,11 +1580,12 @@ compileTestKotlin {
|
||||
)
|
||||
|
||||
importProject()
|
||||
|
||||
/*
|
||||
Assert.assertEquals(listOf("MultiTest_main"), facetSettings("MultiTest-jvm_main").implementedModuleNames)
|
||||
Assert.assertEquals(listOf("MultiTest_test"), facetSettings("MultiTest-jvm_test").implementedModuleNames)
|
||||
Assert.assertEquals(listOf("MultiTest_main"), facetSettings("MultiTest-js_main").implementedModuleNames)
|
||||
Assert.assertEquals(listOf("MultiTest_test"), facetSettings("MultiTest-js_test").implementedModuleNames)
|
||||
*/
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1723,11 +1730,12 @@ compileTestKotlin {
|
||||
)
|
||||
|
||||
importProject()
|
||||
|
||||
/*
|
||||
Assert.assertEquals(listOf("MultiTest_myMain"), facetSettings("MultiTest-jvm_myMain").implementedModuleNames)
|
||||
Assert.assertEquals(listOf("MultiTest_myTest"), facetSettings("MultiTest-jvm_myTest").implementedModuleNames)
|
||||
Assert.assertEquals(listOf("MultiTest_myMain"), facetSettings("MultiTest-js_myMain").implementedModuleNames)
|
||||
Assert.assertEquals(listOf("MultiTest_myTest"), facetSettings("MultiTest-js_myTest").implementedModuleNames)
|
||||
*/
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -120,7 +120,7 @@ public abstract class GradleImportingTestCase extends ExternalSystemImportingTes
|
||||
}
|
||||
}.execute();
|
||||
Messages.setTestDialog(TestDialog.DEFAULT);
|
||||
FileUtil.delete(BuildManager.getInstance().getBuildSystemDirectory().toFile());
|
||||
FileUtil.delete(BuildManager.getInstance().getBuildSystemDirectory());
|
||||
}
|
||||
finally {
|
||||
super.tearDown();
|
||||
|
||||
@@ -350,6 +350,7 @@ class GradleInspectionTest : GradleImportingTestCase() {
|
||||
|
||||
val foundProblems = presentation.problemElements
|
||||
.values
|
||||
.flatMap { it.toList() }
|
||||
.mapNotNull { it as? ProblemDescriptorBase }
|
||||
.map { it.descriptionTemplate }
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user