-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
119 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.github.zxj5470.bugktdoc | ||
|
||
import cn.wjdghd.* | ||
import com.intellij.codeInsight.editorActions.enter.EnterHandlerDelegate | ||
import com.intellij.openapi.actionSystem.DataContext | ||
import com.intellij.openapi.application.ApplicationManager | ||
import com.intellij.openapi.command.CommandProcessor | ||
import com.intellij.openapi.editor.Editor | ||
import com.intellij.openapi.editor.actionSystem.EditorActionHandler | ||
import com.intellij.openapi.util.Ref | ||
import com.intellij.psi.PsiFile | ||
|
||
class BugKotlinEnterHandlerDelegate : EnterHandlerDelegate { | ||
var ok = false | ||
|
||
override fun postProcessEnter(psiFile: PsiFile, editor: Editor, context: DataContext): EnterHandlerDelegate.Result { | ||
if (ok) { | ||
val document = editor.document | ||
val offset = editor.caretModel.currentCaret.offset | ||
val stringFac = genDocString(getFunctionNextLine(editor)) | ||
ApplicationManager.getApplication().runWriteAction { | ||
CommandProcessor.getInstance().runUndoTransparentAction { | ||
document.insertString(offset, stringFac) | ||
} | ||
} | ||
} | ||
return EnterHandlerDelegate.Result.Continue | ||
} | ||
|
||
|
||
override fun preprocessEnter(p0: PsiFile, editor: Editor, p2: Ref<Int>, p3: Ref<Int>, p4: DataContext, p5: EditorActionHandler?): EnterHandlerDelegate.Result { | ||
ok = getCurrentLine(editor).endsWith("/**") && !editorNextLine(editor).trim().startsWith("*") | ||
return EnterHandlerDelegate.Result.Continue | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/kotlin/com/github/zxj5470/bugktdoc/constants/constant.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.github.zxj5470.bugktdoc.constants | ||
|
||
/** | ||
* @author: zxj5470 | ||
* @date: 2018/4/1 | ||
*/ | ||
object DocControl { | ||
val END = " */" | ||
val INNER = " * " | ||
val LF = "\n" | ||
val SPACE = " " | ||
val TYPE_SPLIT_COLON = " : " | ||
} | ||
|
||
object DocDecoration { | ||
val AUTHOR = "@author" | ||
val PARAM = "@param" | ||
val RETURN = "@return" | ||
val THROWS = "@throws" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.github.zxj5470.bugktdoc | ||
|
||
import cn.wjdghd.entity.splitWithParams | ||
import cn.wjdghd.getFunctionDeclarationLine | ||
import com.github.zxj5470.bugktdoc.constants.* | ||
import com.intellij.openapi.editor.Editor | ||
import com.intellij.openapi.util.TextRange | ||
|
||
/** | ||
* @author: zxj5470 | ||
* @date: 2018/4/1 | ||
*/ | ||
|
||
fun editorNextLine(editor: Editor): String { | ||
val document = editor.document | ||
val caretModel = editor.caretModel | ||
val caretOffset = caretModel.offset | ||
val lineNum = document.getLineNumber(caretOffset) + 1 | ||
val lineStartOffset = document.getLineStartOffset(lineNum) | ||
val lineEndOffset = document.getLineEndOffset(lineNum) | ||
return document.getText(TextRange(lineStartOffset, lineEndOffset)) | ||
} | ||
|
||
fun getCurrentLine(editor: Editor): String { | ||
val document = editor.document | ||
val caretModel = editor.caretModel | ||
val caretOffset = caretModel.offset | ||
val lineNum = document.getLineNumber(caretOffset) | ||
val lineStartOffset = document.getLineStartOffset(lineNum) | ||
val lineEndOffset = document.getLineEndOffset(lineNum) | ||
return document.getText(TextRange(lineStartOffset, lineEndOffset)) | ||
} | ||
|
||
fun genDocString(realNextLine: String): String = buildString { | ||
append(DocControl.LF) | ||
getFunctionDeclarationLine(realNextLine) | ||
.splitWithParams() | ||
.filter { it.isNotEmpty() } | ||
.forEachIndexed { index, it -> | ||
if (index >= 1) { | ||
append(DocControl.LF) | ||
} | ||
append(DocControl.INNER) | ||
append(DocDecoration.PARAM) | ||
append(DocControl.SPACE) | ||
append(it) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<idea-plugin> | ||
<id>cn.wjdghd.plugin.id</id> | ||
<id>com.github.zxj5470.bugktdoc</id> | ||
<name>BugKotlinDocument</name> | ||
<version>0.2.0</version> | ||
<vendor email="[email protected]" url="https://github.com/zxj5470/BugKotlinDocument/issues">zxj5470</vendor> | ||
|
@@ -14,7 +14,7 @@ | |
<idea-version since-build="139"/> | ||
|
||
<extensions defaultExtensionNs="com.intellij"> | ||
<enterHandlerDelegate implementation="com.github.zxj5470.BKDTypedHandler"/> | ||
<enterHandlerDelegate implementation="com.github.zxj5470.bugktdoc.BugKotlinEnterHandlerDelegate"/> | ||
</extensions> | ||
|
||
<actions> | ||
|