diff --git a/compiler/util/src/org/jetbrains/kotlin/utils/KotlinPaths.java b/compiler/util/src/org/jetbrains/kotlin/utils/KotlinPaths.java
index 796cb1ecc51..e3a5611ba2f 100644
--- a/compiler/util/src/org/jetbrains/kotlin/utils/KotlinPaths.java
+++ b/compiler/util/src/org/jetbrains/kotlin/utils/KotlinPaths.java
@@ -63,6 +63,9 @@ public interface KotlinPaths {
@NotNull
File getNoArgPluginJarPath();
+ @NotNull
+ File getSamWithReceiverJarPath();
+
@NotNull
File getCompilerPath();
diff --git a/compiler/util/src/org/jetbrains/kotlin/utils/KotlinPathsFromHomeDir.java b/compiler/util/src/org/jetbrains/kotlin/utils/KotlinPathsFromHomeDir.java
index 4265a5d3c5f..debdded57da 100644
--- a/compiler/util/src/org/jetbrains/kotlin/utils/KotlinPathsFromHomeDir.java
+++ b/compiler/util/src/org/jetbrains/kotlin/utils/KotlinPathsFromHomeDir.java
@@ -106,6 +106,12 @@ public class KotlinPathsFromHomeDir implements KotlinPaths {
return getLibraryFile(PathUtil.NOARG_PLUGIN_JAR_NAME);
}
+ @NotNull
+ @Override
+ public File getSamWithReceiverJarPath() {
+ return getLibraryFile(PathUtil.SAM_WITH_RECEIVER_PLUGIN_JAR_NAME);
+ }
+
@NotNull
@Override
public File getCompilerPath() {
diff --git a/compiler/util/src/org/jetbrains/kotlin/utils/PathUtil.java b/compiler/util/src/org/jetbrains/kotlin/utils/PathUtil.java
index 330960bdc2e..2d9b0c60780 100644
--- a/compiler/util/src/org/jetbrains/kotlin/utils/PathUtil.java
+++ b/compiler/util/src/org/jetbrains/kotlin/utils/PathUtil.java
@@ -33,6 +33,7 @@ public class PathUtil {
public static final String JS_LIB_10_JAR_NAME = "kotlin-jslib.jar";
public static final String ALLOPEN_PLUGIN_JAR_NAME = "allopen-compiler-plugin.jar";
public static final String NOARG_PLUGIN_JAR_NAME = "noarg-compiler-plugin.jar";
+ public static final String SAM_WITH_RECEIVER_PLUGIN_JAR_NAME = "sam-with-receiver-compiler-plugin.jar";
public static final String JS_LIB_SRC_JAR_NAME = "kotlin-stdlib-js-sources.jar";
public static final String KOTLIN_JAVA_RUNTIME_JAR = "kotlin-runtime.jar";
public static final String KOTLIN_JAVA_RUNTIME_JRE7_JAR = "kotlin-stdlib-jre7.jar";
diff --git a/idea/src/META-INF/gradle.xml b/idea/src/META-INF/gradle.xml
index 4cc518500a4..ac0280c269d 100644
--- a/idea/src/META-INF/gradle.xml
+++ b/idea/src/META-INF/gradle.xml
@@ -40,6 +40,7 @@
+
diff --git a/idea/src/META-INF/maven.xml b/idea/src/META-INF/maven.xml
index dea8c99a851..b89ce698b44 100644
--- a/idea/src/META-INF/maven.xml
+++ b/idea/src/META-INF/maven.xml
@@ -4,6 +4,7 @@
+
diff --git a/libraries/pom.xml b/libraries/pom.xml
index 0fb67e6feda..22e9b9ed440 100644
--- a/libraries/pom.xml
+++ b/libraries/pom.xml
@@ -93,11 +93,13 @@
tools/kotlin-annotation-processing-maven
tools/kotlin-maven-allopen
tools/kotlin-maven-noarg
+ tools/kotlin-maven-sam-with-receiver
tools/kotlin-sam-with-receiver-compiler-plugin
tools/kotlin-source-sections-compiler-plugin
tools/kotlin-script-util
tools/kotlin-android-extensions
+ tools/kotlin-android-extensions-runtime
tools/kotlin-maven-plugin-test
examples/annotation-processor-example
diff --git a/libraries/tools/gradle-tools/settings.gradle b/libraries/tools/gradle-tools/settings.gradle
index 293ec66918b..80fd68d4cda 100644
--- a/libraries/tools/gradle-tools/settings.gradle
+++ b/libraries/tools/gradle-tools/settings.gradle
@@ -3,6 +3,7 @@ include ':kotlin-gradle-plugin-api',
':kotlin-gradle-plugin-integration-tests',
':kotlin-allopen',
':kotlin-noarg',
+ ':kotlin-sam-with-receiver',
':kotlin-gradle-subplugin-example'
project(':kotlin-gradle-plugin-api').projectDir = file("../kotlin-gradle-plugin-api")
@@ -10,4 +11,5 @@ project(':kotlin-gradle-plugin').projectDir = file("../kotlin-gradle-plugin")
project(':kotlin-gradle-plugin-integration-tests').projectDir = file("../kotlin-gradle-plugin-integration-tests")
project(':kotlin-allopen').projectDir = file("../kotlin-allopen")
project(':kotlin-noarg').projectDir = file("../kotlin-noarg")
+project(':kotlin-sam-with-receiver').projectDir = file("../kotlin-sam-with-receiver")
project(':kotlin-gradle-subplugin-example').projectDir = file("../../examples/kotlin-gradle-subplugin-example")
\ No newline at end of file
diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/SimpleKotlinGradleIT.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/SimpleKotlinGradleIT.kt
index 9f448abea6a..ed056b0dfc4 100644
--- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/SimpleKotlinGradleIT.kt
+++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/SimpleKotlinGradleIT.kt
@@ -163,4 +163,11 @@ class SimpleKotlinGradleIT : BaseGradleIT() {
checkClass("Test2")
}
}
+
+ @Test
+ fun testSamWithReceiverSimple() {
+ Project("samWithReceiverSimple", GRADLE_VERSION).build("build") {
+ assertSuccessful()
+ }
+ }
}
\ No newline at end of file
diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/samWithReceiverSimple/build.gradle b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/samWithReceiverSimple/build.gradle
new file mode 100644
index 00000000000..df553f76754
--- /dev/null
+++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/samWithReceiverSimple/build.gradle
@@ -0,0 +1,28 @@
+buildscript {
+ repositories {
+ mavenLocal()
+ }
+ dependencies {
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
+ classpath "org.jetbrains.kotlin:kotlin-sam-with-receiver:$kotlin_version"
+ }
+}
+
+apply plugin: "kotlin"
+apply plugin: "kotlin-sam-with-receiver"
+
+repositories {
+ mavenLocal()
+}
+
+sourceSets {
+ main.kotlin.srcDir 'src'
+}
+
+samWithReceiver {
+ annotation("lib.SamWithReceiver")
+}
+
+dependencies {
+ compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
+}
\ No newline at end of file
diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/samWithReceiverSimple/src/lib/Job.java b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/samWithReceiverSimple/src/lib/Job.java
new file mode 100644
index 00000000000..737ce40e0bd
--- /dev/null
+++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/samWithReceiverSimple/src/lib/Job.java
@@ -0,0 +1,6 @@
+package lib;
+
+@SamWithReceiver
+public interface Job {
+ public void execute(String context, int other);
+}
\ No newline at end of file
diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/samWithReceiverSimple/src/lib/JobWithoutReceiver.java b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/samWithReceiverSimple/src/lib/JobWithoutReceiver.java
new file mode 100644
index 00000000000..bcee0b331fb
--- /dev/null
+++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/samWithReceiverSimple/src/lib/JobWithoutReceiver.java
@@ -0,0 +1,5 @@
+package lib;
+
+public interface JobWithoutReceiver {
+ public void execute(String context, int other);
+}
\ No newline at end of file
diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/samWithReceiverSimple/src/lib/Manager.java b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/samWithReceiverSimple/src/lib/Manager.java
new file mode 100644
index 00000000000..3bb0d5cfd9e
--- /dev/null
+++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/samWithReceiverSimple/src/lib/Manager.java
@@ -0,0 +1,6 @@
+package lib;
+
+public class Manager {
+ public void doJob(Job job) {}
+ public void doJobWithoutReceiver(JobWithoutReceiver job) {}
+}
\ No newline at end of file
diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/samWithReceiverSimple/src/lib/SamWithReceiver.java b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/samWithReceiverSimple/src/lib/SamWithReceiver.java
new file mode 100644
index 00000000000..a58f20d6e6f
--- /dev/null
+++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/samWithReceiverSimple/src/lib/SamWithReceiver.java
@@ -0,0 +1,3 @@
+package lib;
+
+public @interface SamWithReceiver {}
\ No newline at end of file
diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/samWithReceiverSimple/src/test.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/samWithReceiverSimple/src/test.kt
new file mode 100644
index 00000000000..52070610951
--- /dev/null
+++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/samWithReceiverSimple/src/test.kt
@@ -0,0 +1,25 @@
+/*
+ * 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 test
+
+import lib.*
+
+fun test() {
+ val manager = Manager()
+ manager.doJob { other -> println(this) }
+ manager.doJobWithoutReceiver { context, other -> println(context) }
+}
\ No newline at end of file
diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-sam-with-receiver-simple/pom.xml b/libraries/tools/kotlin-maven-plugin-test/src/it/test-sam-with-receiver-simple/pom.xml
new file mode 100644
index 00000000000..c3d0f88ffc1
--- /dev/null
+++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-sam-with-receiver-simple/pom.xml
@@ -0,0 +1,101 @@
+
+
+ 4.0.0
+
+ org.jetbrains.kotlin
+ test-sam-with-receiver-simple
+ 1.0-SNAPSHOT
+
+
+
+ junit
+ junit
+ 4.9
+
+
+ org.jetbrains.kotlin
+ kotlin-stdlib
+ ${kotlin.version}
+
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 2.3.2
+
+ 1.6
+ 1.6
+
+
+
+ org.apache.maven.plugins
+ maven-source-plugin
+ 2.1.2
+
+
+
+
+ ${project.basedir}/src/main/kotlin
+
+
+ kotlin-maven-plugin
+ org.jetbrains.kotlin
+ ${kotlin.version}
+
+
+ compile
+ compile
+
+
+ ${project.basedir}/src/main/kotlin
+ ${project.basedir}/src/main/java
+
+
+
+
+
+
+
+ sam-with-receiver
+
+
+
+
+
+
+
+
+
+ org.jetbrains.kotlin
+ kotlin-maven-sam-with-receiver
+ ${kotlin.version}
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.5.1
+
+
+
+ default-compile
+ none
+
+
+ java-compile
+ compile
+ compile
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-sam-with-receiver-simple/src/main/java/lib/Job.java b/libraries/tools/kotlin-maven-plugin-test/src/it/test-sam-with-receiver-simple/src/main/java/lib/Job.java
new file mode 100644
index 00000000000..737ce40e0bd
--- /dev/null
+++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-sam-with-receiver-simple/src/main/java/lib/Job.java
@@ -0,0 +1,6 @@
+package lib;
+
+@SamWithReceiver
+public interface Job {
+ public void execute(String context, int other);
+}
\ No newline at end of file
diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-sam-with-receiver-simple/src/main/java/lib/JobWithoutReceiver.java b/libraries/tools/kotlin-maven-plugin-test/src/it/test-sam-with-receiver-simple/src/main/java/lib/JobWithoutReceiver.java
new file mode 100644
index 00000000000..bcee0b331fb
--- /dev/null
+++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-sam-with-receiver-simple/src/main/java/lib/JobWithoutReceiver.java
@@ -0,0 +1,5 @@
+package lib;
+
+public interface JobWithoutReceiver {
+ public void execute(String context, int other);
+}
\ No newline at end of file
diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-sam-with-receiver-simple/src/main/java/lib/Manager.java b/libraries/tools/kotlin-maven-plugin-test/src/it/test-sam-with-receiver-simple/src/main/java/lib/Manager.java
new file mode 100644
index 00000000000..3bb0d5cfd9e
--- /dev/null
+++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-sam-with-receiver-simple/src/main/java/lib/Manager.java
@@ -0,0 +1,6 @@
+package lib;
+
+public class Manager {
+ public void doJob(Job job) {}
+ public void doJobWithoutReceiver(JobWithoutReceiver job) {}
+}
\ No newline at end of file
diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-sam-with-receiver-simple/src/main/java/lib/SamWithReceiver.java b/libraries/tools/kotlin-maven-plugin-test/src/it/test-sam-with-receiver-simple/src/main/java/lib/SamWithReceiver.java
new file mode 100644
index 00000000000..a58f20d6e6f
--- /dev/null
+++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-sam-with-receiver-simple/src/main/java/lib/SamWithReceiver.java
@@ -0,0 +1,3 @@
+package lib;
+
+public @interface SamWithReceiver {}
\ No newline at end of file
diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-sam-with-receiver-simple/src/main/kotlin/test.kt b/libraries/tools/kotlin-maven-plugin-test/src/it/test-sam-with-receiver-simple/src/main/kotlin/test.kt
new file mode 100644
index 00000000000..abb913e8d2f
--- /dev/null
+++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-sam-with-receiver-simple/src/main/kotlin/test.kt
@@ -0,0 +1,9 @@
+package test
+
+import lib.*
+
+fun test() {
+ val manager = Manager()
+ manager.doJob { other -> println(this) }
+ manager.doJobWithoutReceiver { context, other -> println(context) }
+}
\ No newline at end of file
diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-sam-with-receiver-simple/verify.bsh b/libraries/tools/kotlin-maven-plugin-test/src/it/test-sam-with-receiver-simple/verify.bsh
new file mode 100644
index 00000000000..86ac27a1cd3
--- /dev/null
+++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-sam-with-receiver-simple/verify.bsh
@@ -0,0 +1,6 @@
+import java.io.*;
+
+File file = new File(basedir, "target/test-sam-with-receiver-simple-1.0-SNAPSHOT.jar");
+if (!file.exists() || !file.isFile()) {
+ throw new FileNotFoundException("Could not find generated JAR: " + file);
+}
diff --git a/libraries/tools/kotlin-maven-sam-with-receiver/pom.xml b/libraries/tools/kotlin-maven-sam-with-receiver/pom.xml
new file mode 100755
index 00000000000..fdcfb015907
--- /dev/null
+++ b/libraries/tools/kotlin-maven-sam-with-receiver/pom.xml
@@ -0,0 +1,131 @@
+
+
+
+ 4.0.0
+
+ 3.0.5
+ ${basedir}/../../../plugins/sam-with-receiver/sam-with-receiver-cli/src
+ ${basedir}/src/main/kotlin
+ ${basedir}/src/main/resources
+ ${basedir}/target/src/main/kotlin
+ ${basedir}/target/resource
+
+
+
+ org.jetbrains.kotlin
+ kotlin-project
+ 1.1-SNAPSHOT
+ ../../pom.xml
+
+
+ kotlin-maven-sam-with-receiver
+ jar
+
+ "SAM with Receiver" plugin for Maven
+
+
+
+ jetbrains-utils
+ http://repository.jetbrains.com/utils
+
+
+
+
+
+ org.jetbrains.kotlin
+ kotlin-stdlib
+ ${project.version}
+
+
+ org.jetbrains.kotlin
+ kotlin-maven-plugin
+ ${project.version}
+ provided
+
+
+
+
+ ${sam.target-src}
+
+
+ ${sam.target-resources}
+
+
+
+
+
+ maven-resources-plugin
+ 3.0.0
+
+
+ copy-sources
+ validate
+
+ copy-resources
+
+
+ ${sam.target-src}
+
+ ${sam.src}
+ ${sam.maven.plugin.src}
+
+
+
+
+ copy-resources
+ validate
+
+ copy-resources
+
+
+ ${sam.target-resources}/META-INF
+
+ ${sam.src}/META-INF
+ ${sam.maven.plugin.resources}/META-INF
+
+
+
+
+
+
+ kotlin-maven-plugin
+ org.jetbrains.kotlin
+ ${project.version}
+
+
+
+ compile
+ compile
+ compile
+
+
+ ${sam.target-src}
+
+
+
+
+
+
+ org.codehaus.plexus
+ plexus-component-metadata
+ 1.7.1
+
+
+ process-classes
+
+ generate-metadata
+
+
+
+ process-test-classes
+
+ generate-test-metadata
+
+
+
+
+
+
+
diff --git a/libraries/tools/kotlin-maven-sam-with-receiver/src/main/kotlin/SamWithReceiverMavenPluginExtensions.kt b/libraries/tools/kotlin-maven-sam-with-receiver/src/main/kotlin/SamWithReceiverMavenPluginExtensions.kt
new file mode 100644
index 00000000000..c3024bec276
--- /dev/null
+++ b/libraries/tools/kotlin-maven-sam-with-receiver/src/main/kotlin/SamWithReceiverMavenPluginExtensions.kt
@@ -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.test
+
+import org.apache.maven.plugin.*
+import org.apache.maven.project.*
+import org.codehaus.plexus.component.annotations.*
+import org.codehaus.plexus.logging.*
+import org.jetbrains.kotlin.maven.*
+
+val SAM_WITH_RECEIVER_COMPILER_PLUGIN_ID = "org.jetbrains.kotlin.samWithReceiver"
+
+@Component(role = KotlinMavenPluginExtension::class, hint = "sam-with-receiver")
+class KotlinSamWithReceiverMavenPluginExtension : KotlinMavenPluginExtension {
+ @Requirement
+ lateinit var logger: Logger
+
+ override fun getCompilerPluginId() = SAM_WITH_RECEIVER_COMPILER_PLUGIN_ID
+
+ override fun isApplicable(project: MavenProject, execution: MojoExecution) = true
+
+ override fun getPluginOptions(project: MavenProject, execution: MojoExecution): List {
+ logger.debug("Loaded Maven plugin " + javaClass.name)
+ return emptyList()
+ }
+}
\ No newline at end of file
diff --git a/libraries/tools/kotlin-sam-with-receiver/build.gradle b/libraries/tools/kotlin-sam-with-receiver/build.gradle
new file mode 100644
index 00000000000..3a104b19f08
--- /dev/null
+++ b/libraries/tools/kotlin-sam-with-receiver/build.gradle
@@ -0,0 +1,42 @@
+apply plugin: 'kotlin'
+
+configureJvmProject(project)
+configurePublishing(project)
+
+compileJava {
+ sourceCompatibility = 1.8
+ targetCompatibility = 1.8
+ options.fork = false
+}
+
+repositories {
+ mavenLocal()
+ jcenter()
+ maven { url 'http://repository.jetbrains.com/utils' }
+}
+
+dependencies {
+ compile project(':kotlin-gradle-plugin-api')
+
+ compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
+ compileOnly "org.jetbrains.kotlin:kotlin-compiler-embeddable:$kotlin_version"
+
+ compileOnly 'org.jetbrains.kotlin:gradle-api:1.6'
+}
+
+def originalSrc = "$kotlin_root/plugins/sam-with-receiver/sam-with-receiver-cli/src"
+def targetSrc = file("$buildDir/sam-with-receiver-target-src")
+
+task preprocessSources(type: Copy) {
+ from originalSrc
+ into targetSrc
+ filter { it.replaceAll('(?
+
+
+ 4.0.0
+
+ 3.0.4
+ ${basedir}/../../../plugins/sam-with-receiver/sam-with-receiver-cli/src
+ ${basedir}/src/main/kotlin
+ ${basedir}/src/main/resources
+ ${basedir}/target/src/main/kotlin
+ ${basedir}/target/resource
+
+
+
+ org.jetbrains.kotlin
+ kotlin-project
+ 1.1-SNAPSHOT
+ ../../pom.xml
+
+
+ kotlin-sam-with-receiver
+ jar
+
+ All-open plugin for Gradle
+
+
+
+ jetbrains-utils
+ http://repository.jetbrains.com/utils
+
+
+
+
+
+ org.jetbrains.kotlin
+ kotlin-stdlib
+ ${project.version}
+
+
+ org.jetbrains.kotlin
+ kotlin-compiler-embeddable
+ ${project.version}
+ provided
+
+
+ org.jetbrains.kotlin
+ kotlin-gradle-plugin-api
+ ${project.version}
+ provided
+
+
+ org.jetbrains.kotlin
+ gradle-api
+ 1.6
+ provided
+
+
+
+
+ ${sam.target-src}
+
+
+ ${sam.target-resources}
+
+
+
+
+
+ maven-resources-plugin
+ 3.0.0
+
+
+ copy-sources
+ validate
+
+ copy-resources
+
+
+ ${sam.target-src}
+
+ ${sam.src}
+ ${sam.gradle.plugin.src}
+
+
+
+
+ copy-resources
+ validate
+
+ copy-resources
+
+
+ ${sam.target-resources}/META-INF
+
+ ${sam.src}/META-INF
+ ${sam.gradle.plugin.resources}/META-INF
+
+
+
+
+
+
+ com.google.code.maven-replacer-plugin
+ replacer
+ 1.5.3
+
+
+ generate-sources
+
+ replace
+
+
+
+
+
+ ${sam.target-src}/**
+
+
+
+ (?<!\.)com\.intellij
+ org.jetbrains.kotlin.com.intellij
+
+
+
+
+
+ kotlin-maven-plugin
+ org.jetbrains.kotlin
+ ${project.version}
+
+
+
+ compile
+ compile
+ compile
+
+
+ ${sam.target-src}
+
+
+
+
+
+
+
+
diff --git a/libraries/tools/kotlin-sam-with-receiver/src/main/kotlin/org/jetbrains/kotlin/noarg/gradle/SamWithReceiverExtension.kt b/libraries/tools/kotlin-sam-with-receiver/src/main/kotlin/org/jetbrains/kotlin/noarg/gradle/SamWithReceiverExtension.kt
new file mode 100644
index 00000000000..4fb4c03e873
--- /dev/null
+++ b/libraries/tools/kotlin-sam-with-receiver/src/main/kotlin/org/jetbrains/kotlin/noarg/gradle/SamWithReceiverExtension.kt
@@ -0,0 +1,34 @@
+/*
+ * 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.samWithReceiver.gradle
+
+open class SamWithReceiverExtension {
+ internal val myAnnotations = mutableListOf()
+ internal val myPresets = mutableListOf()
+
+ open fun annotation(fqName: String) {
+ myAnnotations.add(fqName)
+ }
+
+ open fun annotations(fqNames: List) {
+ myAnnotations.addAll(fqNames)
+ }
+
+ open fun annotations(vararg fqNames: String) {
+ myAnnotations.addAll(fqNames)
+ }
+}
\ No newline at end of file
diff --git a/libraries/tools/kotlin-sam-with-receiver/src/main/kotlin/org/jetbrains/kotlin/noarg/gradle/SamWithReceiverSubplugin.kt b/libraries/tools/kotlin-sam-with-receiver/src/main/kotlin/org/jetbrains/kotlin/noarg/gradle/SamWithReceiverSubplugin.kt
new file mode 100644
index 00000000000..901e35b4eb8
--- /dev/null
+++ b/libraries/tools/kotlin-sam-with-receiver/src/main/kotlin/org/jetbrains/kotlin/noarg/gradle/SamWithReceiverSubplugin.kt
@@ -0,0 +1,105 @@
+/*
+ * 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.samWithReceiver.gradle
+
+import org.gradle.api.Plugin
+import org.gradle.api.Project
+import org.gradle.api.internal.AbstractTask
+import org.gradle.api.artifacts.ResolvedArtifact
+import org.gradle.api.internal.ConventionTask
+import org.gradle.api.tasks.SourceSet
+import org.gradle.api.tasks.compile.AbstractCompile
+import org.jetbrains.kotlin.gradle.plugin.KotlinGradleSubplugin
+import org.jetbrains.kotlin.gradle.plugin.SubpluginOption
+
+class SamWithReceiverGradleSubplugin : Plugin {
+ companion object {
+ fun isEnabled(project: Project) = project.plugins.findPlugin(SamWithReceiverGradleSubplugin::class.java) != null
+
+ fun getSamWithReceiverExtension(project: Project): SamWithReceiverExtension {
+ return project.extensions.getByType(SamWithReceiverExtension::class.java)
+ }
+ }
+
+ fun Project.getBuildscriptArtifacts(): Set =
+ buildscript.configurations.findByName("classpath")?.resolvedConfiguration?.resolvedArtifacts ?: emptySet()
+
+ override fun apply(project: Project) {
+ val samWithReceiverExtension = project.extensions.create("samWithReceiver", SamWithReceiverExtension::class.java)
+
+ project.afterEvaluate {
+ val fqNamesAsString = samWithReceiverExtension.myAnnotations.joinToString(",")
+ val presetsAsString = samWithReceiverExtension.myPresets.joinToString(",")
+ project.extensions.extraProperties.set("kotlinSamWithReceiverAnnotations", fqNamesAsString)
+
+ val allBuildscriptArtifacts = project.getBuildscriptArtifacts() + project.rootProject.getBuildscriptArtifacts()
+ val samWithReceiverCompilerPluginFile = allBuildscriptArtifacts.filter {
+ val id = it.moduleVersion.id
+ id.group == SamWithReceiverKotlinGradleSubplugin.SAM_WITH_RECEIVER_GROUP_NAME
+ && id.name == SamWithReceiverKotlinGradleSubplugin.SAM_WITH_RECEIVER_ARTIFACT_NAME
+ }.firstOrNull()?.file?.absolutePath ?: ""
+
+ open class TaskForSamWithReceiver : AbstractTask()
+ project.tasks.add(project.tasks.create("samWithReceiverDataStorageTask", TaskForSamWithReceiver::class.java).apply {
+ isEnabled = false
+ description = "Supported annotations: " + fqNamesAsString +
+ "; Presets: $presetsAsString" +
+ "; Compiler plugin classpath: $samWithReceiverCompilerPluginFile"
+ })
+ }
+ }
+}
+
+class SamWithReceiverKotlinGradleSubplugin : KotlinGradleSubplugin {
+ companion object {
+ val SAM_WITH_RECEIVER_GROUP_NAME = "org.jetbrains.kotlin"
+ val SAM_WITH_RECEIVER_ARTIFACT_NAME = "kotlin-sam-with-receiver"
+
+ private val ANNOTATION_ARG_NAME = "annotation"
+ private val PRESET_ARG_NAME = "preset"
+ }
+
+ override fun isApplicable(project: Project, task: AbstractCompile) = SamWithReceiverGradleSubplugin.isEnabled(project)
+
+ override fun apply(
+ project: Project,
+ kotlinCompile: AbstractCompile,
+ javaCompile: AbstractCompile,
+ variantData: Any?,
+ javaSourceSet: SourceSet?
+ ): List {
+ if (!SamWithReceiverGradleSubplugin.isEnabled(project)) return emptyList()
+
+ val samWithReceiverExtension = project.extensions.findByType(SamWithReceiverExtension::class.java) ?: return emptyList()
+
+ val options = mutableListOf()
+
+ for (anno in samWithReceiverExtension.myAnnotations) {
+ options += SubpluginOption(ANNOTATION_ARG_NAME, anno)
+ }
+
+ for (preset in samWithReceiverExtension.myPresets) {
+ options += SubpluginOption(PRESET_ARG_NAME, preset)
+ }
+
+ return options
+ }
+
+ override fun getArtifactName() = "kotlin-sam-with-receiver"
+ override fun getGroupName() = "org.jetbrains.kotlin"
+ override fun getCompilerPluginId() = "org.jetbrains.kotlin.samWithReceiver"
+}
\ No newline at end of file
diff --git a/libraries/tools/kotlin-sam-with-receiver/src/main/resources/META-INF/gradle-plugins/kotlin-sam-with-receiver.properties b/libraries/tools/kotlin-sam-with-receiver/src/main/resources/META-INF/gradle-plugins/kotlin-sam-with-receiver.properties
new file mode 100644
index 00000000000..0f416ab25a0
--- /dev/null
+++ b/libraries/tools/kotlin-sam-with-receiver/src/main/resources/META-INF/gradle-plugins/kotlin-sam-with-receiver.properties
@@ -0,0 +1 @@
+implementation-class=org.jetbrains.kotlin.samWithReceiver.gradle.SamWithReceiverGradleSubplugin
\ No newline at end of file
diff --git a/libraries/tools/kotlin-sam-with-receiver/src/main/resources/META-INF/gradle-plugins/org.jetbrains.kotlin.plugin.sam.with.receiver.properties b/libraries/tools/kotlin-sam-with-receiver/src/main/resources/META-INF/gradle-plugins/org.jetbrains.kotlin.plugin.sam.with.receiver.properties
new file mode 100644
index 00000000000..0f416ab25a0
--- /dev/null
+++ b/libraries/tools/kotlin-sam-with-receiver/src/main/resources/META-INF/gradle-plugins/org.jetbrains.kotlin.plugin.sam.with.receiver.properties
@@ -0,0 +1 @@
+implementation-class=org.jetbrains.kotlin.samWithReceiver.gradle.SamWithReceiverGradleSubplugin
\ No newline at end of file
diff --git a/libraries/tools/kotlin-sam-with-receiver/src/main/resources/META-INF/services/org.jetbrains.kotlin.gradle.plugin.KotlinGradleSubplugin b/libraries/tools/kotlin-sam-with-receiver/src/main/resources/META-INF/services/org.jetbrains.kotlin.gradle.plugin.KotlinGradleSubplugin
new file mode 100644
index 00000000000..fb0c7a152d3
--- /dev/null
+++ b/libraries/tools/kotlin-sam-with-receiver/src/main/resources/META-INF/services/org.jetbrains.kotlin.gradle.plugin.KotlinGradleSubplugin
@@ -0,0 +1 @@
+org.jetbrains.kotlin.samWithReceiver.gradle.SamWithReceiverKotlinGradleSubplugin
\ No newline at end of file
diff --git a/plugins/allopen/allopen-ide/src/IdeAllOpenDeclarationAttributeAltererExtension.kt b/plugins/allopen/allopen-ide/src/IdeAllOpenDeclarationAttributeAltererExtension.kt
index 0bb57cc587c..26f6751f462 100644
--- a/plugins/allopen/allopen-ide/src/IdeAllOpenDeclarationAttributeAltererExtension.kt
+++ b/plugins/allopen/allopen-ide/src/IdeAllOpenDeclarationAttributeAltererExtension.kt
@@ -25,10 +25,10 @@ import com.intellij.psi.util.CachedValue
import com.intellij.psi.util.CachedValueProvider
import com.intellij.psi.util.CachedValuesManager
import org.jetbrains.kotlin.allopen.AbstractAllOpenDeclarationAttributeAltererExtension
-import org.jetbrains.kotlin.idea.facet.KotlinFacet
import org.jetbrains.kotlin.psi.KtModifierListOwner
import org.jetbrains.kotlin.allopen.AllOpenCommandLineProcessor.Companion.PLUGIN_ID
import org.jetbrains.kotlin.allopen.AllOpenCommandLineProcessor.Companion.ANNOTATION_OPTION
+import org.jetbrains.kotlin.annotation.plugin.ide.getSpecialAnnotations
import java.util.*
class IdeAllOpenDeclarationAttributeAltererExtension(val project: Project) : AbstractAllOpenDeclarationAttributeAltererExtension() {
@@ -48,14 +48,7 @@ class IdeAllOpenDeclarationAttributeAltererExtension(val project: Project) : Abs
if (modifierListOwner == null) return emptyList()
val module = ModuleUtilCore.findModuleForPsiElement(modifierListOwner) ?: return emptyList()
- return cache.value.getOrPut(module) {
- val kotlinFacet = KotlinFacet.get(module) ?: return@getOrPut emptyList()
- val commonArgs = kotlinFacet.configuration.settings.compilerArguments ?: return@getOrPut emptyList()
-
- commonArgs.pluginOptions?.filter { it.startsWith(ANNOTATION_OPTION_PREFIX) }
- ?.map { it.substring(ANNOTATION_OPTION_PREFIX.length) }
- ?: emptyList()
- }
+ return cache.value.getOrPut(module) { module.getSpecialAnnotations(ANNOTATION_OPTION_PREFIX) }
}
private fun cachedValue(project: Project, result: () -> CachedValueProvider.Result): CachedValue {
diff --git a/plugins/annotation-based-compiler-plugins-ide-support/src/idePluginUtils.kt b/plugins/annotation-based-compiler-plugins-ide-support/src/idePluginUtils.kt
index 8540a85760c..13a53e593ef 100644
--- a/plugins/annotation-based-compiler-plugins-ide-support/src/idePluginUtils.kt
+++ b/plugins/annotation-based-compiler-plugins-ide-support/src/idePluginUtils.kt
@@ -16,10 +16,21 @@
package org.jetbrains.kotlin.annotation.plugin.ide
+import com.intellij.openapi.module.Module
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
import org.jetbrains.kotlin.idea.facet.KotlinFacet
import java.io.File
+fun Module.getSpecialAnnotations(prefix: String): List {
+ val kotlinFacet = org.jetbrains.kotlin.idea.facet.KotlinFacet.get(this) ?: return emptyList()
+ val commonArgs = kotlinFacet.configuration.settings.compilerArguments ?: return emptyList()
+
+ return commonArgs.pluginOptions
+ ?.filter { it.startsWith(prefix) }
+ ?.map { it.substring(prefix.length) }
+ ?: emptyList()
+}
+
internal class AnnotationBasedCompilerPluginSetup(val annotationFqNames: List, val classpath: List)
internal fun modifyCompilerArgumentsForPlugin(
diff --git a/plugins/noarg/noarg-ide/src/IdeNoArgDeclarationChecker.kt b/plugins/noarg/noarg-ide/src/IdeNoArgDeclarationChecker.kt
index d9d47699c0a..f39aa122fd1 100644
--- a/plugins/noarg/noarg-ide/src/IdeNoArgDeclarationChecker.kt
+++ b/plugins/noarg/noarg-ide/src/IdeNoArgDeclarationChecker.kt
@@ -23,7 +23,7 @@ import com.intellij.openapi.roots.ProjectRootModificationTracker
import com.intellij.psi.util.CachedValue
import com.intellij.psi.util.CachedValueProvider
import com.intellij.psi.util.CachedValuesManager
-import org.jetbrains.kotlin.idea.facet.KotlinFacet
+import org.jetbrains.kotlin.annotation.plugin.ide.getSpecialAnnotations
import org.jetbrains.kotlin.noarg.NoArgCommandLineProcessor.Companion.ANNOTATION_OPTION
import org.jetbrains.kotlin.noarg.NoArgCommandLineProcessor.Companion.PLUGIN_ID
import org.jetbrains.kotlin.noarg.diagnostic.AbstractNoArgDeclarationChecker
@@ -43,15 +43,7 @@ class IdeNoArgDeclarationChecker(val project: Project) : AbstractNoArgDeclaratio
if (modifierListOwner == null) return emptyList()
val module = ModuleUtilCore.findModuleForPsiElement(modifierListOwner) ?: return emptyList()
- return cache.value.getOrPut(module) {
- val kotlinFacet = KotlinFacet.get(module) ?: return@getOrPut emptyList()
- val commonArgs = kotlinFacet.configuration.settings.compilerArguments ?: return@getOrPut emptyList()
-
- commonArgs.pluginOptions
- ?.filter { it.startsWith(ANNOTATION_OPTION_PREFIX) }
- ?.map { it.substring(ANNOTATION_OPTION_PREFIX.length) }
- ?: emptyList()
- }
+ return cache.value.getOrPut(module) { module.getSpecialAnnotations(ANNOTATION_OPTION_PREFIX) }
}
private fun cachedValue(project: Project, result: () -> CachedValueProvider.Result): CachedValue {
diff --git a/plugins/sam-with-receiver/sam-with-receiver-cli/src/SamWithReceiverPlugin.kt b/plugins/sam-with-receiver/sam-with-receiver-cli/src/SamWithReceiverPlugin.kt
index f262b25f0d6..ae50ca78724 100644
--- a/plugins/sam-with-receiver/sam-with-receiver-cli/src/SamWithReceiverPlugin.kt
+++ b/plugins/sam-with-receiver/sam-with-receiver-cli/src/SamWithReceiverPlugin.kt
@@ -29,17 +29,26 @@ import org.jetbrains.kotlin.container.get
import org.jetbrains.kotlin.extensions.StorageComponentContainerContributor
import org.jetbrains.kotlin.load.java.sam.SamWithReceiverResolver
import org.jetbrains.kotlin.samWithReceiver.SamWithReceiverConfigurationKeys.ANNOTATION
+import org.jetbrains.kotlin.samWithReceiver.SamWithReceiverConfigurationKeys.PRESET
+import org.jetbrains.kotlin.samWithReceiver.SamWithReceiverCommandLineProcessor.Companion.SUPPORTED_PRESETS
object SamWithReceiverConfigurationKeys {
val ANNOTATION: CompilerConfigurationKey> =
CompilerConfigurationKey.create("annotation qualified name")
+
+ val PRESET: CompilerConfigurationKey> = CompilerConfigurationKey.create("annotation preset")
}
class SamWithReceiverCommandLineProcessor : CommandLineProcessor {
companion object {
+ val SUPPORTED_PRESETS = emptyMap>()
+
val ANNOTATION_OPTION = CliOption("annotation", "", "Annotation qualified names",
required = false, allowMultipleOccurrences = true)
+ val PRESET_OPTION = CliOption("preset", "", "Preset name (${SUPPORTED_PRESETS.keys.joinToString()})",
+ required = false, allowMultipleOccurrences = true)
+
val PLUGIN_ID = "org.jetbrains.kotlin.samWithReceiver"
}
@@ -48,13 +57,17 @@ class SamWithReceiverCommandLineProcessor : CommandLineProcessor {
override fun processOption(option: CliOption, value: String, configuration: CompilerConfiguration) = when (option) {
ANNOTATION_OPTION -> configuration.appendList(ANNOTATION, value)
+ PRESET_OPTION -> configuration.appendList(PRESET, value)
else -> throw CliOptionProcessingException("Unknown option: ${option.name}")
}
}
class SamWithReceiverComponentRegistrar : ComponentRegistrar {
override fun registerProjectComponents(project: MockProject, configuration: CompilerConfiguration) {
- val annotations = configuration.get(SamWithReceiverConfigurationKeys.ANNOTATION) ?: return
+ val annotations = configuration.get(ANNOTATION)?.toMutableList() ?: mutableListOf()
+ configuration.get(PRESET)?.forEach { preset ->
+ SUPPORTED_PRESETS[preset]?.let { annotations += it }
+ }
if (annotations.isEmpty()) return
StorageComponentContainerContributor.registerExtension(project, CliSamWithReceiverComponentContributor(annotations))
diff --git a/plugins/sam-with-receiver/sam-with-receiver-ide/sam-with-receiver-ide.iml b/plugins/sam-with-receiver/sam-with-receiver-ide/sam-with-receiver-ide.iml
index 3d267117702..cfea7744ab2 100644
--- a/plugins/sam-with-receiver/sam-with-receiver-ide/sam-with-receiver-ide.iml
+++ b/plugins/sam-with-receiver/sam-with-receiver-ide/sam-with-receiver-ide.iml
@@ -8,9 +8,14 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/plugins/sam-with-receiver/sam-with-receiver-ide/src/IdeSamWithReceiverComponentContributor.kt b/plugins/sam-with-receiver/sam-with-receiver-ide/src/IdeSamWithReceiverComponentContributor.kt
index cf5e05d62bd..1995be33637 100644
--- a/plugins/sam-with-receiver/sam-with-receiver-ide/src/IdeSamWithReceiverComponentContributor.kt
+++ b/plugins/sam-with-receiver/sam-with-receiver-ide/src/IdeSamWithReceiverComponentContributor.kt
@@ -16,20 +16,43 @@
package org.jetbrains.kotlin.samWithReceiver.ide
+import com.intellij.openapi.module.Module
+import com.intellij.openapi.project.Project
+import com.intellij.openapi.roots.ProjectRootModificationTracker
+import com.intellij.psi.util.CachedValueProvider.*
+import com.intellij.psi.util.CachedValuesManager
import org.jetbrains.kotlin.analyzer.ModuleInfo
+import org.jetbrains.kotlin.annotation.plugin.ide.getSpecialAnnotations
import org.jetbrains.kotlin.container.ComponentProvider
import org.jetbrains.kotlin.container.get
import org.jetbrains.kotlin.extensions.StorageComponentContainerContributor
+import org.jetbrains.kotlin.idea.caches.resolve.ModuleProductionSourceInfo
import org.jetbrains.kotlin.idea.caches.resolve.ScriptDependenciesModuleInfo
import org.jetbrains.kotlin.idea.caches.resolve.ScriptModuleInfo
import org.jetbrains.kotlin.load.java.sam.SamWithReceiverResolver
import org.jetbrains.kotlin.samWithReceiver.SamWithReceiverResolverExtension
+import org.jetbrains.kotlin.samWithReceiver.SamWithReceiverCommandLineProcessor.Companion.PLUGIN_ID
+import org.jetbrains.kotlin.samWithReceiver.SamWithReceiverCommandLineProcessor.Companion.ANNOTATION_OPTION
+import java.util.*
+
+class IdeSamWithReceiverComponentContributor(val project: Project) : StorageComponentContainerContributor {
+ private companion object {
+ val ANNOTATION_OPTION_PREFIX = "plugin:$PLUGIN_ID:${ANNOTATION_OPTION.name}="
+ }
+
+ private val cache = CachedValuesManager.getManager(project).createCachedValue({
+ Result.create(WeakHashMap>(), ProjectRootModificationTracker.getInstance(project))
+ }, /* trackValue = */ false)
+
+ private fun getAnnotationsForModule(module: Module): List {
+ return cache.value.getOrPut(module) { module.getSpecialAnnotations(ANNOTATION_OPTION_PREFIX) }
+ }
-class IdeSamWithReceiverComponentContributor : StorageComponentContainerContributor {
override fun onContainerComposed(container: ComponentProvider, moduleInfo: ModuleInfo?) {
val annotations = when (moduleInfo) {
is ScriptModuleInfo -> moduleInfo.scriptDefinition.annotationsForSamWithReceivers
is ScriptDependenciesModuleInfo -> moduleInfo.scriptModuleInfo?.scriptDefinition?.annotationsForSamWithReceivers
+ is ModuleProductionSourceInfo -> getAnnotationsForModule(moduleInfo.module)
else -> null
} ?: return
diff --git a/plugins/sam-with-receiver/sam-with-receiver-ide/src/SamWithReceiverGradleProjectImportHandler.kt b/plugins/sam-with-receiver/sam-with-receiver-ide/src/SamWithReceiverGradleProjectImportHandler.kt
new file mode 100644
index 00000000000..6d2014f60ba
--- /dev/null
+++ b/plugins/sam-with-receiver/sam-with-receiver-ide/src/SamWithReceiverGradleProjectImportHandler.kt
@@ -0,0 +1,39 @@
+/*
+ * 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.samWithReceiver.ide
+
+import org.jetbrains.kotlin.annotation.plugin.ide.AbstractGradleImportHandler
+import org.jetbrains.kotlin.samWithReceiver.SamWithReceiverCommandLineProcessor
+import org.jetbrains.kotlin.utils.PathUtil
+
+class SamWithReceiverGradleProjectImportHandler : AbstractGradleImportHandler() {
+ override val compilerPluginId = SamWithReceiverCommandLineProcessor.PLUGIN_ID
+ override val pluginName = "sam-with-receiver"
+ override val annotationOptionName = SamWithReceiverCommandLineProcessor.ANNOTATION_OPTION.name
+ override val dataStorageTaskName = "samWithReceiverDataStorageTask"
+ override val pluginJarFileFromIdea = PathUtil.getKotlinPathsForIdeaPlugin().allOpenPluginJarPath
+
+ override fun getAnnotationsForPreset(presetName: String): List {
+ for ((name, annotations) in SamWithReceiverCommandLineProcessor.SUPPORTED_PRESETS.entries) {
+ if (presetName == name) {
+ return annotations
+ }
+ }
+
+ return super.getAnnotationsForPreset(presetName)
+ }
+}
\ No newline at end of file
diff --git a/plugins/sam-with-receiver/sam-with-receiver-ide/src/SamWithReceiverMavenProjectImportHandler.kt b/plugins/sam-with-receiver/sam-with-receiver-ide/src/SamWithReceiverMavenProjectImportHandler.kt
new file mode 100644
index 00000000000..67f45c8ed6c
--- /dev/null
+++ b/plugins/sam-with-receiver/sam-with-receiver-ide/src/SamWithReceiverMavenProjectImportHandler.kt
@@ -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.samWithReceiver.ide
+
+import org.jetbrains.kotlin.annotation.plugin.ide.AbstractMavenImportHandler
+import org.jetbrains.kotlin.samWithReceiver.SamWithReceiverCommandLineProcessor
+import org.jetbrains.kotlin.utils.PathUtil
+
+class SamWithReceiverMavenProjectImportHandler : AbstractMavenImportHandler() {
+ private companion object {
+ val ANNOTATION_PARAMETER_PREFIX = "sam-with-receiver:${SamWithReceiverCommandLineProcessor.ANNOTATION_OPTION.name}="
+ }
+
+ override val compilerPluginId = SamWithReceiverCommandLineProcessor.PLUGIN_ID
+ override val pluginName = "samWithReceiver"
+ override val annotationOptionName = SamWithReceiverCommandLineProcessor.ANNOTATION_OPTION.name
+ override val mavenPluginArtifactName = "kotlin-maven-sam-with-receiver"
+ override val pluginJarFileFromIdea = PathUtil.getKotlinPathsForIdeaPlugin().allOpenPluginJarPath
+
+ override fun getAnnotations(enabledCompilerPlugins: List, compilerPluginOptions: List): List? {
+ if ("sam-with-receiver" !in enabledCompilerPlugins) {
+ return null
+ }
+
+ val annotations = mutableListOf()
+
+ for ((presetName, presetAnnotations) in SamWithReceiverCommandLineProcessor.SUPPORTED_PRESETS) {
+ if (presetName in enabledCompilerPlugins) {
+ annotations.addAll(presetAnnotations)
+ }
+ }
+
+ annotations.addAll(compilerPluginOptions.mapNotNull { text ->
+ if (!text.startsWith(ANNOTATION_PARAMETER_PREFIX)) return@mapNotNull null
+ text.substring(ANNOTATION_PARAMETER_PREFIX.length)
+ })
+
+ return annotations
+ }
+}
\ No newline at end of file