Skip to content

Commit

Permalink
[v0.2.2] Real supported for Kotlin/Native in CLion and AppCode!
Browse files Browse the repository at this point in the history
  • Loading branch information
zxj5470 committed Apr 11, 2018
1 parent bb497b0 commit 80fc23f
Show file tree
Hide file tree
Showing 12 changed files with 119 additions and 53 deletions.
24 changes: 17 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,32 @@ plugins {
id "org.jetbrains.intellij" version '0.3.1'
}

def useCLion = true
//def useCLion = false
def bugKtDoc = []

allprojects {
apply plugin: 'java'
apply plugin: 'kotlin'
apply plugin: 'org.jetbrains.intellij'
intellij {
version '2017.3'
type idea_type
updateSinceUntilBuild false
instrumentCode true
plugins 'kotlin'
if (useCLion) {
localPath local_path
bugKtDoc += 'org.intellij.plugins.markdown:181.2668'
bugKtDoc += 'org.jetbrains.kotlin.native.clion:181.4445.17'
} else {
version idea_version
bugKtDoc += 'kotlin'
}
plugins bugKtDoc.toArray()
}
}

patchPluginXml {
pluginDescription(file("src/main/resources/META-INF/description.html").text)
pluginDescription(file("description.html").text)
changeNotes(file("changeNotes.html").text)
}

group 'com.github.zxj5470'
Expand All @@ -37,14 +48,13 @@ repositories {
}

dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
compileOnly "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
testCompile group: 'junit', name: 'junit', version: '4.12'
}
sourceSets {
main.java {
srcDirs += ['src/main/java','src/main/kotlin']
srcDirs += ['src/main/java', 'src/main/kotlin']
}

}

compileKotlin {
Expand Down
17 changes: 17 additions & 0 deletions changeNotes.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
v0.2.2<br/>
<ul>
<li>Big News: Add supports to CLion and AppCode!</li>
<li>Add more options</li>
</ul>

v0.2.1<br/>
<ul>
<li>Add setting options</li>
</ul>

v0.2.0<br/>
<ul>
<li>Only need to press <kbd>Enter</kbd> Key after /** just like in Java !
Disable it on editor | BugKotlinDocument.
</li>
</ul>
File renamed without changes.
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ plugin_name=BugKotlinDocument
idea_version=2017.3
idea_type=IC
systemProp.file.encoding=UTF-8
plugin_version=0.2.2
plugin_version=0.2.2
local_path=/Users/paul/Library/Application Support/JetBrains/Toolbox/apps/CLion/ch-1/181.4445.17/CLion.app/Contents/
Binary file added images/pic04.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# BugKotlinDocument
Plugin for IntelliJ IDEA / Android Studio / CLion.
Plugin for **IntelliJ IDEA** / **Android Studio** / **CLion**.
And now **AppCode** is available!

- Generate document comments for Kotlin file.
- Just generate it as Java do.
Expand All @@ -16,6 +17,9 @@ Plugin for IntelliJ IDEA / Android Studio / CLion.
# Screenshots
![png](images/pic02.png)

## AppCode and CLion support!
![png](images/pic04.png)

## Settings

**Settings/Preferences** | **Editor** | **BugKotlinDocument**
Expand Down
6 changes: 5 additions & 1 deletion src/main/kotlin/com/github/zxj5470/bugktdoc/BugKtDocTools.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.github.zxj5470.bugktdoc
import com.github.zxj5470.bugktdoc.options.BugKtDocGlobalSettings
import com.intellij.CommonBundle
import com.intellij.openapi.components.ServiceManager
import com.intellij.util.PlatformUtils
import org.jetbrains.annotations.NonNls
import org.jetbrains.annotations.PropertyKey
import org.jetbrains.kotlin.idea.intentions.SpecifyTypeExplicitlyIntention
Expand Down Expand Up @@ -41,4 +42,7 @@ object BugKtDocBundle {
}

inline val KtCallableDeclaration.itsType
get() = SpecifyTypeExplicitlyIntention.getTypeForDeclaration(this).unwrap().toString()
get() = SpecifyTypeExplicitlyIntention.getTypeForDeclaration(this).unwrap().toString()

val isKotlinNative
get() = PlatformUtils.isAppCode() || PlatformUtils.isCLion()
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,8 @@ class BugKtDocumentationProvider : DocumentationProviderEx(), CodeDocumentationP
override fun parseContext(startPoint: PsiElement): Pair<PsiElement, PsiComment>? {
var current = startPoint
while (true) {
if (PlatformUtils.isCLion()) {
if (current is KDocImpl) {
return Pair.create(if (current is PsiField) current.modifierList else current, current)
} else if (PackageUtil.isPackageInfoFile(current)) {
return Pair.create(current, getPackageInfoComment(current))
}
if (current is KDocImpl) {
return Pair.create(if (current is PsiField) current.modifierList else current, current)
} else if (PackageUtil.isPackageInfoFile(current)) {
return Pair.create(current, getPackageInfoComment(current))
}
Expand Down Expand Up @@ -168,5 +164,5 @@ class BugKtDocumentationProvider : DocumentationProviderEx(), CodeDocumentationP
}

override fun findExistingDocComment(contextElement: PsiComment?): PsiComment? =
if (!PlatformUtils.isCLion()) (contextElement as? KDocImpl)?.getOwner()?.docComment else contextElement
if (!isKotlinNative) (contextElement as? KDocImpl)?.getOwner()?.docComment else contextElement
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,9 @@
import javax.swing.*;

public abstract class BugKtDocConfigureForm implements Configurable {
protected @NotNull
JPanel mainPanel;
protected @NotNull
JCheckBox useBugKtDoc;
protected @NotNull
JCheckBox showUnitTypeDefault;
protected @NotNull
JCheckBox showClassFieldProperty;
protected @NotNull
JCheckBox showConstructor;
protected JPanel mainPanel;
protected JCheckBox useBugKtDoc;
protected JCheckBox showUnitTypeDefault;
protected JCheckBox showClassFieldProperty;
protected JCheckBox showConstructor;
}
Original file line number Diff line number Diff line change
@@ -1,44 +1,73 @@
@file:Suppress("SENSELESS_COMPARISON")

package com.github.zxj5470.bugktdoc.options

import com.github.zxj5470.bugktdoc.BugKtDocBundle
import com.github.zxj5470.bugktdoc.globalSettings
import com.github.zxj5470.bugktdoc.isKotlinNative
import com.github.zxj5470.bugktdoc.util.*
import com.intellij.ui.layout.verticalPanel
import com.intellij.util.PlatformUtils
import javax.swing.JCheckBox
import javax.swing.JPanel

/**
* @author zxj5470
* @date 2018/4/2
*/
class BugKtDocConfigureFormImpl : BugKtDocConfigureForm() {
private val thisPanel: JPanel
get() {
// what the hell it is in CLion?
// mainPanel is null in CLion.
if (mainPanel == null) {
mainPanel = verticalPanel { }
useBugKtDoc = JCheckBox(BugKtDocBundle.message("bugktdoc.options.use"))
.apply { mainPanel.add(this) }
showUnitTypeDefault = JCheckBox(BugKtDocBundle.message("bugktdoc.options.default.unit"))
.apply { mainPanel.add(this) }
showClassFieldProperty = JCheckBox(BugKtDocBundle.message("bugktdoc.options.default.property"))
.apply { mainPanel.add(this) }
showConstructor = JCheckBox(BugKtDocBundle.message("bugktdoc.options.default.constructor"))
.apply { mainPanel.add(this) }
}
useBugKtDoc.isSelected = globalSettings.useBugKtDoc
showUnitTypeDefault.isSelected = globalSettings.alwaysShowUnitReturnType
showClassFieldProperty.isSelected = globalSettings.alwaysShowClassFieldProperty
showConstructor.isSelected = globalSettings.alwaysShowConstructor
return mainPanel
}

init {
// what the hell it is in CLion?
// mainPanel is null in CLion.
if (mainPanel == null) {
mainPanel = verticalPanel { }
useBugKtDoc = JCheckBox(BugKtDocBundle.message("bugktdoc.options.use"))
.apply { mainPanel.add(this) }
showUnitTypeDefault = JCheckBox(BugKtDocBundle.message("bugktdoc.options.default.unit"))
.apply { mainPanel.add(this) }
showClassFieldProperty = JCheckBox(BugKtDocBundle.message("bugktdoc.options.default.property"))
.apply { mainPanel.add(this) }
showConstructor = JCheckBox(BugKtDocBundle.message("bugktdoc.options.default.constructor"))
.apply { mainPanel.add(this) }
if (isKotlinNative) {
thisPanel
}
addSwitchListener()
initListener()
}

private fun addSwitchListener() {
useBugKtDoc.addActionListener {
showUnitTypeDefault.isEnabled = !showUnitTypeDefault.isEnabled
showClassFieldProperty.isEnabled = !showClassFieldProperty.isEnabled
showConstructor.isEnabled = !showConstructor.isEnabled
useBugKtDoc.isSelected {
showUnitTypeDefault.isEnabled = true
showClassFieldProperty.isEnabled = true
showConstructor.isEnabled = true
}.orElse {
showUnitTypeDefault.isEnabled = false
showClassFieldProperty.isEnabled = false
showConstructor.isEnabled = false
}
}
loadSettings()
}

private fun loadSettings() {
useBugKtDoc.isSelected = globalSettings.useBugKtDoc
showUnitTypeDefault.isSelected = globalSettings.alwaysShowUnitReturnType
showClassFieldProperty.isSelected = globalSettings.alwaysShowClassFieldProperty
showConstructor.isSelected = globalSettings.alwaysShowConstructor
private fun initListener() {
useBugKtDoc.isSelected {
showUnitTypeDefault.isEnabled = true
showClassFieldProperty.isEnabled = true
showConstructor.isEnabled = true
}.orElse {
showUnitTypeDefault.isEnabled = false
showClassFieldProperty.isEnabled = false
showConstructor.isEnabled = false
}
}

override fun isModified(): Boolean {
Expand All @@ -50,7 +79,7 @@ class BugKtDocConfigureFormImpl : BugKtDocConfigureForm() {
globalSettings.alwaysShowUnitReturnType = false
globalSettings.alwaysShowClassFieldProperty = true
globalSettings.alwaysShowConstructor = true
loadSettings()
initListener()
}

override fun getDisplayName() = BugKtDocBundle.message("bugktdoc.settings.title")
Expand All @@ -62,6 +91,5 @@ class BugKtDocConfigureFormImpl : BugKtDocConfigureForm() {
globalSettings.alwaysShowConstructor = showConstructor.isSelected
}

override fun createComponent() = mainPanel

override fun createComponent() = thisPanel
}
10 changes: 10 additions & 0 deletions src/main/kotlin/com/github/zxj5470/bugktdoc/util/dsl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,14 @@ fun String.log(tag: String = "") {
println("------$tag--------")
println(this)
println("--------------")
}

operator fun Boolean.invoke(block: () -> Unit): Boolean {
if (this) block()
return this
}

fun Boolean.orElse(block: () -> Unit): Boolean {
if (!this) block()
return this
}
1 change: 1 addition & 0 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<vendor email="[email protected]" url="https://github.com/zxj5470/BugKotlinDocument">zxj5470</vendor>
<depends optional="true">org.jetbrains.kotlin</depends>
<depends optional="true">org.jetbrains.kotlin.native.clion</depends>
<depends optional="true">org.jetbrains.kotlin.native.appcode</depends>
<depends>com.intellij.modules.lang</depends>

<description>To generate Kotlin document comment in Kotlin File</description>
Expand Down

0 comments on commit 80fc23f

Please sign in to comment.