From 2ad1bfa7438ef9c81e3d80192928459bcc3cc984 Mon Sep 17 00:00:00 2001 From: Sergey Rostov Date: Wed, 22 May 2013 19:23:59 +0400 Subject: [PATCH] KT-3161 JetCommenter implementation stub --- .../jetbrains/jet/plugin/JetCommenter.java | 42 +++++++++++++- .../editor/commenter/generateDocComment.kt | 2 + .../commenter/generateDocComment_after.kt | 4 ++ .../editor/commenter/newLineInComment.kt | 4 ++ .../commenter/newLineInComment_after.kt | 5 ++ .../jet/editor/JetCommenterTest.java | 58 +++++++++++++++++++ 6 files changed, 113 insertions(+), 2 deletions(-) create mode 100644 idea/testData/editor/commenter/generateDocComment.kt create mode 100644 idea/testData/editor/commenter/generateDocComment_after.kt create mode 100644 idea/testData/editor/commenter/newLineInComment.kt create mode 100644 idea/testData/editor/commenter/newLineInComment_after.kt create mode 100644 idea/tests/org/jetbrains/jet/editor/JetCommenterTest.java diff --git a/idea/src/org/jetbrains/jet/plugin/JetCommenter.java b/idea/src/org/jetbrains/jet/plugin/JetCommenter.java index b7c260dfa93..2e3d3ba5e1f 100644 --- a/idea/src/org/jetbrains/jet/plugin/JetCommenter.java +++ b/idea/src/org/jetbrains/jet/plugin/JetCommenter.java @@ -16,9 +16,12 @@ package org.jetbrains.jet.plugin; -import com.intellij.lang.Commenter; +import com.intellij.lang.CodeDocumentationAwareCommenter; +import com.intellij.psi.PsiComment; +import com.intellij.psi.tree.IElementType; +import org.jetbrains.jet.lexer.JetTokens; -public class JetCommenter implements Commenter { +public class JetCommenter implements CodeDocumentationAwareCommenter { @Override public String getLineCommentPrefix() { return "//"; @@ -43,4 +46,39 @@ public class JetCommenter implements Commenter { public String getCommentedBlockCommentSuffix() { return null; } + + @Override + public IElementType getLineCommentTokenType() { + return JetTokens.EOL_COMMENT; + } + + @Override + public IElementType getBlockCommentTokenType() { + return JetTokens.BLOCK_COMMENT; + } + + @Override + public IElementType getDocumentationCommentTokenType() { + return JetTokens.DOC_COMMENT; + } + + @Override + public String getDocumentationCommentPrefix() { + return "/**"; + } + + @Override + public String getDocumentationCommentLinePrefix() { + return "*"; + } + + @Override + public String getDocumentationCommentSuffix() { + return "*/"; + } + + @Override + public boolean isDocumentationComment(PsiComment element) { + return element.getTokenType().equals(JetTokens.DOC_COMMENT); + } } diff --git a/idea/testData/editor/commenter/generateDocComment.kt b/idea/testData/editor/commenter/generateDocComment.kt new file mode 100644 index 00000000000..7e76a37c71b --- /dev/null +++ b/idea/testData/editor/commenter/generateDocComment.kt @@ -0,0 +1,2 @@ +/** +fun test() = 0 \ No newline at end of file diff --git a/idea/testData/editor/commenter/generateDocComment_after.kt b/idea/testData/editor/commenter/generateDocComment_after.kt new file mode 100644 index 00000000000..f60322d8e68 --- /dev/null +++ b/idea/testData/editor/commenter/generateDocComment_after.kt @@ -0,0 +1,4 @@ +/** + * + */ +fun test() = 0 \ No newline at end of file diff --git a/idea/testData/editor/commenter/newLineInComment.kt b/idea/testData/editor/commenter/newLineInComment.kt new file mode 100644 index 00000000000..5f9507de398 --- /dev/null +++ b/idea/testData/editor/commenter/newLineInComment.kt @@ -0,0 +1,4 @@ +/** + * x + */ +fun test() = 0 \ No newline at end of file diff --git a/idea/testData/editor/commenter/newLineInComment_after.kt b/idea/testData/editor/commenter/newLineInComment_after.kt new file mode 100644 index 00000000000..130bcc93cb1 --- /dev/null +++ b/idea/testData/editor/commenter/newLineInComment_after.kt @@ -0,0 +1,5 @@ +/** + * x + * + */ +fun test() = 0 \ No newline at end of file diff --git a/idea/tests/org/jetbrains/jet/editor/JetCommenterTest.java b/idea/tests/org/jetbrains/jet/editor/JetCommenterTest.java new file mode 100644 index 00000000000..967ef967b7d --- /dev/null +++ b/idea/tests/org/jetbrains/jet/editor/JetCommenterTest.java @@ -0,0 +1,58 @@ +/* + * Copyright 2010-2013 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.jet.editor; + +import com.intellij.openapi.util.io.FileUtil; +import com.intellij.openapi.util.text.StringUtil; +import com.intellij.testFramework.EditorTestUtil; +import com.intellij.testFramework.LightCodeInsightTestCase; +import org.jetbrains.jet.plugin.PluginTestCaseBase; + +import java.io.File; + +public class JetCommenterTest extends LightCodeInsightTestCase { + private static final String BASE_PATH = + new File(PluginTestCaseBase.getTestDataPathBase(), "/editor/commenter/").getAbsolutePath(); + + public void testGenerateDocComment() throws Exception { + doNewLineTypingTest(); + } + + public void testNewLineInComment() throws Exception { + doNewLineTypingTest(); + } + + private void doNewLineTypingTest() throws Exception { + configure(); + EditorTestUtil.performTypingAction(getEditor(), '\n'); + check(); + } + + private void configure() throws Exception { + configureFromFileText("a.kt", loadFile(getTestName(false) + ".kt")); + } + + private void check() throws Exception { + checkResultByText(loadFile(getTestName(false) + "_after.kt")); + } + + protected static String loadFile(String name) throws Exception { + String text = FileUtil.loadFile(new File(BASE_PATH, name)); + text = StringUtil.convertLineSeparators(text); + return text; + } +}