Maven: review

This commit is contained in:
Sergey Mashkov
2016-04-07 14:34:22 +03:00
parent 072ec26452
commit d9dabeed76
22 changed files with 268 additions and 165 deletions
@@ -0,0 +1,6 @@
<html>
<body>
If you have kotlin-test and junit dependency
then most likely you better to include kotlin-test-junit instead of just kotlin-test
</body>
</html>
@@ -0,0 +1,5 @@
<html>
<body>
Reports different kotlin stdlib and compiler versions that could lead to unpredictable issues
</body>
</html>
@@ -0,0 +1,6 @@
<html>
<body>
Reports different IDE and Maven plugin versions that can lead do different
behaviour of your code
</body>
</html>
@@ -1,5 +1,5 @@
<html>
<body>
This intention moves source directory from execution's configuration to build the corresponding source directory tag
Move source directory from execution's configuration to build the corresponding source directory tag
</body>
</html>
@@ -1,6 +1,6 @@
<html>
<body>
This intention moves source directory from build source directory tag
Move source directory from build source directory tag
to the corresponding kotlin-maven-plugin execution's configuration
</body>
</html>
@@ -33,8 +33,8 @@ import org.jetbrains.kotlin.idea.maven.configuration.KotlinJavaMavenConfigurator
import org.jetbrains.kotlin.idea.maven.configuration.KotlinMavenConfigurator
import org.jetbrains.kotlin.psi.psiUtil.endOffset
class GenerateMavenCompileExecutionAction : PomFileActionBase(KotlinMavenExecutionProvider("compile", PomFile.DefaultPhases.Compile))
class GenerateMavenTestCompileExecutionAction : PomFileActionBase(KotlinMavenExecutionProvider("test-compile", PomFile.DefaultPhases.TestCompile))
class GenerateMavenCompileExecutionAction : PomFileActionBase(KotlinMavenExecutionProvider(PomFile.KotlinGoals.Compile, PomFile.DefaultPhases.Compile))
class GenerateMavenTestCompileExecutionAction : PomFileActionBase(KotlinMavenExecutionProvider(PomFile.KotlinGoals.TestCompile, PomFile.DefaultPhases.TestCompile))
class GenerateMavenPluginAction : PomFileActionBase(KotlinMavenPluginProvider())
private val DefaultKotlinVersion = "\${kotlin.version}"
@@ -62,18 +62,10 @@ private class KotlinMavenPluginProvider : AbstractDomGenerateProvider<MavenDomPl
}
val pom = PomFile(DomUtil.getFile(parent))
val plugin = pom.addPlugin(MavenId(KotlinMavenConfigurator.GROUP_ID, KotlinMavenConfigurator.MAVEN_PLUGIN_ID, version))
val range = plugin.version.ensureTagExists().value.textRange
if (editor != null) {
editor.caretModel.moveToOffset(range.endOffset)
editor.selectionModel.setSelection(range.startOffset, range.endOffset)
}
return plugin
return pom.addPlugin(MavenId(KotlinMavenConfigurator.GROUP_ID, KotlinMavenConfigurator.MAVEN_PLUGIN_ID, version))
}
override fun getElementToNavigate(t: MavenDomPlugin?) = null
override fun getElementToNavigate(t: MavenDomPlugin?) = t?.version
override fun getParentDomElement(project: Project?, editor: Editor?, file: PsiFile?): DomElement? {
if (project == null || editor == null || file == null) {
@@ -121,7 +113,7 @@ private class KotlinMavenExecutionProvider(val goal: String, val phase: String)
val plugin = contextElement.findPlugin()
return plugin != null
&& plugin.isKotlinMavenPlugin()
&& plugin.executions.executions.none { it.goals.goals.any { it.rawText == goal } }
&& plugin.executions.executions.none { it.goals.goals.any { it.value == goal } }
}
}
@@ -34,12 +34,8 @@ class KotlinJavaMavenConfigurator : KotlinMavenConfigurator(KotlinJavaMavenConfi
}
override fun createExecutions(pomFile: PomFile, kotlinPlugin: MavenDomPlugin, module: Module) {
createExecution(pomFile, kotlinPlugin, module, false)
createExecution(pomFile, kotlinPlugin, module, true)
}
override fun getGoal(isTest: Boolean): String {
return if (isTest) PomFile.KotlinGoals.TestCompile else PomFile.KotlinGoals.Compile
createExecution(pomFile, kotlinPlugin, PomFile.DefaultPhases.Compile, PomFile.KotlinGoals.Compile, module, false)
createExecution(pomFile, kotlinPlugin, PomFile.DefaultPhases.TestCompile, PomFile.KotlinGoals.TestCompile, module, true)
}
override fun getTargetPlatform(): TargetPlatform {
@@ -34,16 +34,8 @@ class KotlinJavascriptMavenConfigurator : KotlinMavenConfigurator(KotlinJavascri
}
override fun createExecutions(pomFile: PomFile, kotlinPlugin: MavenDomPlugin, module: Module) {
createExecution(pomFile, kotlinPlugin, module, false)
createExecution(pomFile, kotlinPlugin, module, true)
}
override fun getExecutionId(isTest: Boolean): String {
return JS_EXECUTION_ID + if (isTest) "-test" else ""
}
override fun getGoal(isTest: Boolean): String {
return if (isTest) JS_TEST_GOAL else JS_GOAL
createExecution(pomFile, kotlinPlugin, PomFile.DefaultPhases.Compile, PomFile.KotlinGoals.Js, module, false)
createExecution(pomFile, kotlinPlugin, PomFile.DefaultPhases.Compile, PomFile.KotlinGoals.TestJs, module, true)
}
override fun getTargetPlatform(): TargetPlatform {
@@ -53,9 +45,6 @@ class KotlinJavascriptMavenConfigurator : KotlinMavenConfigurator(KotlinJavascri
companion object {
private val NAME = "js maven"
val STD_LIB_ID = "kotlin-js-library"
private val JS_GOAL = "js"
private val JS_TEST_GOAL = "test-js"
private val JS_EXECUTION_ID = "js"
private val PRESENTABLE_TEXT = "JavaScript Maven - experimental"
}
}
@@ -49,9 +49,7 @@ abstract class KotlinMavenConfigurator protected constructor(private val stdlibA
return KotlinPluginUtil.isMavenModule(module)
}
override fun getPresentableText(): String {
return presentableText
}
override fun getPresentableText() = presentableText
override fun getName(): String {
return name
@@ -75,19 +73,7 @@ abstract class KotlinMavenConfigurator protected constructor(private val stdlibA
val plugin = mavenProject.findPlugin(GROUP_ID, MAVEN_PLUGIN_ID) ?: return false
if (plugin.executions != null) {
for (execution in plugin.executions) {
if (execution.goals != null) {
for (goal in execution.goals) {
if (goal != null && isRelevantGoal(goal)) {
return true
}
}
}
}
}
return false
return plugin.executions?.any { it.goals?.any { it != null && isRelevantGoal(it) } ?: false } ?: false
}
override fun configure(project: Project, excludeModules: Collection<Module>) {
@@ -115,12 +101,6 @@ abstract class KotlinMavenConfigurator protected constructor(private val stdlibA
protected abstract fun createExecutions(pomFile: PomFile, kotlinPlugin: MavenDomPlugin, module: Module)
protected abstract fun getGoal(isTest: Boolean): String
protected open fun getExecutionId(isTest: Boolean): String {
return if (isTest) TEST_COMPILE_EXECUTION_ID else COMPILE_EXECUTION_ID
}
fun changePomFile(
module: Module,
file: PsiFile,
@@ -163,10 +143,11 @@ abstract class KotlinMavenConfigurator protected constructor(private val stdlibA
protected fun createExecution(
pomFile: PomFile,
kotlinPlugin: MavenDomPlugin,
executionId: String,
goalName: String,
module: Module,
isTest: Boolean) {
pomFile.addKotlinExecution(module, kotlinPlugin, getExecutionId(isTest), PomFile.getPhase(hasJavaFiles(module), isTest), isTest,
listOf(getGoal(isTest)))
pomFile.addKotlinExecution(module, kotlinPlugin, executionId, PomFile.getPhase(hasJavaFiles(module), isTest), isTest, listOf(goalName))
}
companion object {
@@ -179,9 +160,6 @@ abstract class KotlinMavenConfigurator protected constructor(private val stdlibA
private val SONATYPE_OSS_REPOSITORY_NAME = "Sonatype OSS Snapshot Repository"
private val SONATYPE_OSS_REPOSITORY_URL = "http://oss.sonatype.org/content/repositories/snapshots"
private val TEST_COMPILE_EXECUTION_ID = "test-compile"
private val COMPILE_EXECUTION_ID = "compile"
private fun hasJavaFiles(module: Module): Boolean {
return !FileTypeIndex.getFiles(JavaFileType.INSTANCE, GlobalSearchScope.moduleScope(module)).isEmpty()
}
@@ -43,7 +43,7 @@ import org.jetbrains.kotlin.idea.maven.configuration.KotlinMavenConfigurator
import java.util.*
class KotlinMavenPluginPhaseInspection : DomElementsInspection<MavenDomProjectModel>(MavenDomProjectModel::class.java) {
override fun getStaticDescription() = "The inspecition's purpose is to check Maven pom and kotlin maven plugin configuration"
override fun getStaticDescription() = "Reports kotlin-maven-plugin configuration issues"
override fun checkFileElement(domFileElement: DomFileElement<MavenDomProjectModel>?, holder: DomElementAnnotationHolder?) {
if (domFileElement == null || holder == null) {
@@ -149,7 +149,7 @@ class KotlinMavenPluginPhaseInspection : DomElementsInspection<MavenDomProjectMo
private class AddExecutionLocalFix(val file: XmlFile, val module: Module, val kotlinPlugin: MavenDomPlugin, val goal: String) : LocalQuickFix {
override fun getName() = "Create $goal execution"
override fun getFamilyName() = "Kotlin"
override fun getFamilyName() = "Create kotlin execution"
override fun applyFix(project: Project, descriptor: ProblemDescriptor) {
val pom = PomFile(file)
@@ -161,7 +161,7 @@ class KotlinMavenPluginPhaseInspection : DomElementsInspection<MavenDomProjectMo
private class FixExecutionPhaseLocalFix(val execution: MavenDomPluginExecution, val newPhase: String) : LocalQuickFix {
override fun getName() = "Change phase to $newPhase"
override fun getFamilyName() = "Kotlin"
override fun getFamilyName() = "Change phase"
override fun applyFix(project: Project, descriptor: ProblemDescriptor) {
execution.phase.value = newPhase
@@ -170,7 +170,7 @@ class KotlinMavenPluginPhaseInspection : DomElementsInspection<MavenDomProjectMo
private class FixAddStdlibLocalFix(val pomFile: XmlFile, val id: String, val version: String?) : LocalQuickFix {
override fun getName() = "Add $id dependency"
override fun getFamilyName() = "Kotlin"
override fun getFamilyName() = "Add dependency"
override fun applyFix(project: Project, descriptor: ProblemDescriptor) {
val file = PomFile(pomFile)
@@ -180,7 +180,7 @@ class KotlinMavenPluginPhaseInspection : DomElementsInspection<MavenDomProjectMo
private class ConfigurePluginExecutionLocalFix(val module: Module, val xmlFile: XmlFile, val goal: String, val version: String?) : LocalQuickFix {
override fun getName() = "Create $goal execution of kotlin-maven-compiler"
override fun getFamilyName() = "Kotlin"
override fun getFamilyName() = "Create kotlin execution"
override fun applyFix(project: Project, descriptor: ProblemDescriptor) {
val pom = PomFile(xmlFile)
@@ -88,8 +88,8 @@ class KotlinMavenUnresolvedReferenceQuickFixProvider : UnresolvedReferenceQuickF
}
class AddMavenDependencyQuickFix(val className: String, val smartPsiElementPointer: SmartPsiElementPointer<KtSimpleNameExpression>) : IntentionAction, LowPriorityAction {
override fun getText() = "Add dependency..."
override fun getFamilyName() = "Kotlin"
override fun getText() = "Add Maven dependency..."
override fun getFamilyName() = text
override fun startInWriteAction() = false
override fun isAvailable(project: Project, editor: Editor?, file: PsiFile?) =
smartPsiElementPointer.element.let { it != null && it.isValid } && file != null && MavenDomUtil.findContainingProject(file) != null
@@ -119,29 +119,3 @@ class AddMavenDependencyQuickFix(val className: String, val smartPsiElementPoint
}
}
object PlatformUnresolvedProvider : KotlinIntentionActionFactoryWithDelegate<KtNameReferenceExpression, String>() {
override fun getElementOfInterest(diagnostic: Diagnostic) = QuickFixUtil.getParentElementOfType(diagnostic, KtNameReferenceExpression::class.java)
override fun extractFixData(element: KtNameReferenceExpression, diagnostic: Diagnostic) = element.getReferencedName()
override fun createFixes(originalElementPointer: SmartPsiElementPointer<KtNameReferenceExpression>, diagnostic: Diagnostic, quickFixDataFactory: () -> String?): List<QuickFixWithDelegateFactory> {
val result = ArrayList<QuickFixWithDelegateFactory>()
originalElementPointer.element?.references?.filterIsInstance<KtSimpleNameReference>()?.firstOrNull()?.let { reference ->
UnresolvedReferenceQuickFixProvider.registerReferenceFixes(reference, object: QuickFixActionRegistrar {
override fun register(action: IntentionAction) {
result.add(QuickFixWithDelegateFactory(IntentionActionPriority.LOW) { action })
}
override fun register(fixRange: TextRange, action: IntentionAction, key: HighlightDisplayKey?) {
register(action)
}
override fun unregister(condition: Condition<IntentionAction>) {
}
})
}
return result
}
}
@@ -58,7 +58,7 @@ class KotlinTestJUnitInspection : DomElementsInspection<MavenDomProjectModel>(Ma
private class ReplaceToKotlinTest(val dependency: MavenDomDependency) : LocalQuickFix {
override fun getName() = "Replace with kotlin-test-junit"
override fun getFamilyName() = "Kotlin"
override fun getFamilyName() = name
override fun applyFix(project: Project, descriptor: ProblemDescriptor) {
if (dependency.isValid) {
@@ -22,22 +22,19 @@ import com.intellij.util.xml.highlighting.DomElementAnnotationHolder
import com.intellij.util.xml.highlighting.DomElementsInspection
import org.jetbrains.idea.maven.dom.model.MavenDomPlugin
import org.jetbrains.idea.maven.dom.model.MavenDomProjectModel
import org.jetbrains.kotlin.idea.maven.PomFile
import org.jetbrains.kotlin.idea.versions.bundledRuntimeVersion
class SameVersionIDEPluginInspection : DomElementsInspection<MavenDomProjectModel>(MavenDomProjectModel::class.java) {
private val idePluginVersion by lazy {
SameVersionIDEPluginInspection::class.java.classLoader?.getResourceAsStream("META-INF/build.txt")?.bufferedReader()?.use { it.readText() }
}
private val idePluginVersion by lazy { bundledRuntimeVersion() }
override fun checkFileElement(domFileElement: DomFileElement<MavenDomProjectModel>?, holder: DomElementAnnotationHolder?) {
if (domFileElement == null || holder == null) {
return
}
domFileElement.rootElement.build.plugins.plugins.filter { it.version.exists() && it.version.stringValue != idePluginVersion }.forEach { plugin ->
createProblem(holder, plugin)
}
domFileElement.rootElement.build.pluginManagement.plugins.plugins.filter { it.version.exists() && it.version.stringValue != idePluginVersion }.forEach { plugin ->
val pomFile = PomFile(domFileElement.file)
pomFile.findKotlinPlugins().filter { it.version.exists() && it.version.stringValue != idePluginVersion }.forEach { plugin ->
createProblem(holder, plugin)
}
}
@@ -16,12 +16,18 @@
package org.jetbrains.kotlin.idea.maven.inspections
import com.intellij.codeInspection.LocalQuickFix
import com.intellij.codeInspection.ProblemDescriptor
import com.intellij.lang.annotation.HighlightSeverity
import com.intellij.openapi.project.Project
import com.intellij.util.xml.DomFileElement
import com.intellij.util.xml.GenericDomValue
import com.intellij.util.xml.highlighting.DomElementAnnotationHolder
import com.intellij.util.xml.highlighting.DomElementsInspection
import org.jetbrains.idea.maven.dom.MavenVersionComparable
import org.jetbrains.idea.maven.dom.model.MavenDomProjectModel
import org.jetbrains.idea.maven.model.MavenId
import org.jetbrains.idea.maven.project.MavenProject
import org.jetbrains.idea.maven.project.MavenProjectsManager
import org.jetbrains.kotlin.idea.maven.PomFile
import org.jetbrains.kotlin.idea.maven.configuration.KotlinJavaMavenConfigurator
@@ -47,14 +53,49 @@ class SameVersionInspection : DomElementsInspection<MavenDomProjectModel>(MavenD
val pomFile = PomFile(file)
pomFile.findKotlinPlugins().filter { it.version.stringValue != stdlibVersion.singleOrNull() }.forEach { plugin ->
holder.createProblem(plugin.version, HighlightSeverity.WARNING,
"Plugin version (${plugin.version}) is not the same as library version (${stdlibVersion.joinToString(",", "", "")})")
val fixes = plugin.version.stringValue?.let { version ->
createFixes(project, plugin.version, stdlibVersion + version)
} ?: emptyList()
holder.createProblem(plugin.version,
HighlightSeverity.WARNING,
"Plugin version (${plugin.version}) is not the same as library version (${stdlibVersion.joinToString(",", "", "")})",
*fixes.toTypedArray()
)
}
pomFile.findDependencies(MavenId(KotlinMavenConfigurator.GROUP_ID, KotlinJavaMavenConfigurator.STD_LIB_ID, null))
.filter { it.version.stringValue != pluginVersion }
.forEach { dependency ->
holder.createProblem(dependency.version, HighlightSeverity.WARNING, "Plugin version ($pluginVersion) is not the same as library version (${dependency.version})")
val fixes = dependency.version.stringValue?.let { version ->
createFixes(project, dependency.version, listOf(version, pluginVersion))
} ?: emptyList()
holder.createProblem(dependency.version,
HighlightSeverity.WARNING,
"Plugin version ($pluginVersion) is not the same as library version (${dependency.version})",
*fixes.toTypedArray())
}
}
private fun createFixes(project: MavenProject, versionElement: GenericDomValue<*>, versions: List<String>): List<SetVersionQuickFix> {
val bestVersion = versions.maxBy { MavenVersionComparable(it) }!!
if (bestVersion == versionElement.stringValue) {
return emptyList()
}
val properties = project.properties.entries.filter { it.value == bestVersion }.map { "\${${it.key}}" }
return properties.map { SetVersionQuickFix(versionElement, it, bestVersion) } +
SetVersionQuickFix(versionElement, bestVersion, null)
}
private class SetVersionQuickFix(val versionElement: GenericDomValue<*>, val newVersion: String, val versionResolved: String?) : LocalQuickFix {
override fun getName() = if (versionResolved == null) "Change version to $newVersion" else "Change version to $newVersion ($versionResolved)"
override fun getFamilyName() = "Change version"
override fun applyFix(project: Project, descriptor: ProblemDescriptor) {
versionElement.value = newVersion
}
}
}
@@ -54,7 +54,7 @@ import java.util.List;
import java.util.concurrent.TimeUnit;
public abstract class MavenTestCase extends UsefulTestCase {
protected static final MavenConsole NULL_MAVEN_CONSOLE = new NullMavenConsole();
protected static final MavenConsole NULL_MAVEN_CONSOLE = NullMavenConsole.INSTANCE;
// should not be static
protected static MavenProgressIndicator EMPTY_MAVEN_PROCESS = new MavenProgressIndicator(new EmptyProgressIndicator());
@@ -1,49 +0,0 @@
/*
* Copyright 2010-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.idea.maven;
import com.intellij.execution.process.ProcessHandler;
import org.jetbrains.idea.maven.execution.MavenExecutionOptions;
import org.jetbrains.idea.maven.project.MavenConsole;
public class NullMavenConsole extends MavenConsole {
public NullMavenConsole() {
super(MavenExecutionOptions.LoggingLevel.DISABLED, false);
}
@Override
public boolean canPause() {
return false;
}
@Override
public boolean isOutputPaused() {
return false;
}
@Override
public void setOutputPaused(boolean outputPaused) {
}
@Override
public void attachToProcess(ProcessHandler processHandler) {
}
@Override
protected void doPrint(String text, MavenConsole.OutputType type) {
}
}
@@ -0,0 +1,34 @@
/*
* Copyright 2010-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.idea.maven
import com.intellij.execution.process.ProcessHandler
import org.jetbrains.idea.maven.execution.MavenExecutionOptions
import org.jetbrains.idea.maven.project.MavenConsole
object NullMavenConsole : MavenConsole(MavenExecutionOptions.LoggingLevel.DISABLED, false) {
override fun canPause() = false
override fun isOutputPaused() = false
override fun setOutputPaused(outputPaused: Boolean) {
}
override fun attachToProcess(processHandler: ProcessHandler) {
}
override fun doPrint(text: String, type: MavenConsole.OutputType) {
}
}
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.jetbrains.kotlin.test</groupId>
<artifactId>configure-maven-test</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<kotlin.version.1>1.0.1</kotlin.version.1>
<kotlin.version.2>1.0.1-2</kotlin.version.2>
</properties>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>${kotlin.version.2}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version.2}</version>
</plugin>
</plugins>
</build>
</project>
<!-- inspection: org.jetbrains.kotlin.idea.maven.inspections.SameVersionInspection -->
<!-- problem: on ${kotlin.version.1}, title Plugin version (1.0.1) is not the same as library version (1.0.1-2) -->
<!-- problem: on ${kotlin.version.2}, title Plugin version (1.0.1) is not the same as library version (1.0.1-2) -->
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.jetbrains.kotlin.test</groupId>
<artifactId>configure-maven-test</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<kotlin.version.1>1.0.1</kotlin.version.1>
<kotlin.version.2>1.0.1-2</kotlin.version.2>
</properties>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>${kotlin.version.2}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>1.0.1-2</version>
</plugin>
</plugins>
</build>
</project>
<!-- inspection: org.jetbrains.kotlin.idea.maven.inspections.SameVersionInspection -->
<!-- problem: on ${kotlin.version.1}, title Plugin version (1.0.1) is not the same as library version (1.0.1-2) -->
<!-- problem: on ${kotlin.version.2}, title Plugin version (1.0.1) is not the same as library version (1.0.1-2) -->
+8 -8
View File
@@ -5,7 +5,7 @@
</extensions>
<extensions defaultExtensionNs="org.jetbrains.idea.maven">
<importer implementation="org.jetbrains.kotlin.idea.maven.KotlinMavenImporter" />
<archetypesProvider implementation="org.jetbrains.kotlin.idea.configuration.KotlinMavenArchetypesProvider" />
<archetypesProvider implementation="org.jetbrains.kotlin.idea.maven.KotlinMavenArchetypesProvider" />
<pluginDescriptor mavenId="org.jetbrains.kotlin:kotlin-maven-plugin">
<param name="sourceDirs/dir" refProvider="org.jetbrains.idea.maven.plugins.api.common.MavenCommonParamReferenceProviders$DirPath"/>
@@ -17,16 +17,16 @@
</pluginDescriptor>
</extensions>
<extensions defaultExtensionNs="com.intellij">
<localInspection implementationClass="org.jetbrains.kotlin.idea.configuration.KotlinMavenPluginPhaseInspection"
displayName="Kotlin Maven Plugin inspection"
<localInspection implementationClass="org.jetbrains.kotlin.idea.maven.inspections.KotlinMavenPluginPhaseInspection"
displayName="Kotlin Maven Plugin misconfigured"
groupName="Kotlin"
enabledByDefault="true"
language="XML"
hasStaticDescription="true"
level="WARNING" />
<localInspection implementationClass="org.jetbrains.kotlin.idea.configuration.KotlinTestJUnitInspection"
displayName="Kotlin Maven: kotlin-test-junit inspection"
<localInspection implementationClass="org.jetbrains.kotlin.idea.maven.inspections.KotlinTestJUnitInspection"
displayName="kotlin-test-junit could be used"
groupName="Kotlin"
enabledByDefault="true"
language="XML"
@@ -34,15 +34,15 @@
level="WARNING" />
<localInspection implementationClass="org.jetbrains.kotlin.idea.maven.inspections.SameVersionInspection"
displayName="Kotlin Maven: library and plugin inspection"
displayName="Library and maven plugin versions are different"
groupName="Kotlin"
enabledByDefault="true"
language="XML"
hasStaticDescription="true"
level="WARNING" />
<localInspection implementationClass="org.jetbrains.kotlin.idea.configuration.SameVersionIDEPluginInspection"
displayName="Kotlin Maven: Maven and IDE plugins versions inspection"
<localInspection implementationClass="org.jetbrains.kotlin.idea.maven.inspections.SameVersionIDEPluginInspection"
displayName="Maven and IDE plugins versions are different"
groupName="Kotlin"
enabledByDefault="true"
language="XML"
@@ -0,0 +1,60 @@
/*
* 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.idea.inspections
import com.intellij.codeInsight.daemon.HighlightDisplayKey
import com.intellij.codeInsight.daemon.QuickFixActionRegistrar
import com.intellij.codeInsight.intention.IntentionAction
import com.intellij.codeInsight.quickfix.UnresolvedReferenceQuickFixProvider
import com.intellij.openapi.util.Condition
import com.intellij.openapi.util.TextRange
import com.intellij.psi.SmartPsiElementPointer
import org.jetbrains.kotlin.diagnostics.Diagnostic
import org.jetbrains.kotlin.idea.core.quickfix.QuickFixUtil
import org.jetbrains.kotlin.idea.quickfix.IntentionActionPriority
import org.jetbrains.kotlin.idea.quickfix.KotlinIntentionActionFactoryWithDelegate
import org.jetbrains.kotlin.idea.quickfix.QuickFixWithDelegateFactory
import org.jetbrains.kotlin.idea.references.KtSimpleNameReference
import org.jetbrains.kotlin.psi.KtNameReferenceExpression
import java.util.*
object PlatformUnresolvedProvider : KotlinIntentionActionFactoryWithDelegate<KtNameReferenceExpression, String>() {
override fun getElementOfInterest(diagnostic: Diagnostic) = QuickFixUtil.getParentElementOfType(diagnostic, KtNameReferenceExpression::class.java)
override fun extractFixData(element: KtNameReferenceExpression, diagnostic: Diagnostic) = element.getReferencedName()
override fun createFixes(originalElementPointer: SmartPsiElementPointer<KtNameReferenceExpression>, diagnostic: Diagnostic, quickFixDataFactory: () -> String?): List<QuickFixWithDelegateFactory> {
val result = ArrayList<QuickFixWithDelegateFactory>()
originalElementPointer.element?.references?.filterIsInstance<KtSimpleNameReference>()?.firstOrNull()?.let { reference ->
UnresolvedReferenceQuickFixProvider.registerReferenceFixes(reference, object: QuickFixActionRegistrar {
override fun register(action: IntentionAction) {
result.add(QuickFixWithDelegateFactory(IntentionActionPriority.LOW) { action })
}
override fun register(fixRange: TextRange, action: IntentionAction, key: HighlightDisplayKey?) {
register(action)
}
override fun unregister(condition: Condition<IntentionAction>) {
}
})
}
return result
}
}
@@ -19,7 +19,7 @@ package org.jetbrains.kotlin.idea.quickfix
import com.intellij.codeInsight.intention.IntentionAction
import org.jetbrains.kotlin.diagnostics.DiagnosticFactory
import org.jetbrains.kotlin.diagnostics.Errors.*
import org.jetbrains.kotlin.idea.maven.inspections.PlatformUnresolvedProvider
import org.jetbrains.kotlin.idea.inspections.PlatformUnresolvedProvider
import org.jetbrains.kotlin.idea.core.overrideImplement.ImplementAsConstructorParameter
import org.jetbrains.kotlin.idea.core.overrideImplement.ImplementMembersHandler
import org.jetbrains.kotlin.idea.inspections.AddModifierFixFactory