diff --git a/java/java-impl/src/com/intellij/codeInsight/editorActions/JavadocTypedHandler.java b/java/java-impl/src/com/intellij/codeInsight/editorActions/JavadocTypedHandler.java index f957efb1ecf4..27c391730833 100644 --- a/java/java-impl/src/com/intellij/codeInsight/editorActions/JavadocTypedHandler.java +++ b/java/java-impl/src/com/intellij/codeInsight/editorActions/JavadocTypedHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. + * Copyright 2000-2014 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. @@ -25,6 +25,7 @@ import com.intellij.psi.impl.source.javadoc.PsiDocParamRef; import com.intellij.psi.impl.source.tree.JavaDocElementType; import com.intellij.psi.javadoc.PsiDocTag; import com.intellij.psi.javadoc.PsiDocTagValue; +import com.intellij.xml.util.HtmlUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -39,6 +40,7 @@ public class JavadocTypedHandler extends TypedHandlerDelegate { private static final char START_TAG_SYMBOL = '<'; private static final char CLOSE_TAG_SYMBOL = '>'; private static final char SLASH = '/'; + private static final String COMMENT_PREFIX = "!--"; @Override public Result charTyped(char c, Project project, @NotNull Editor editor, @NotNull PsiFile file) { @@ -73,8 +75,8 @@ public class JavadocTypedHandler extends TypedHandlerDelegate { // (e.g. don't insert anything on single '>' symbol typing). int offset = editor.getCaretModel().getOffset(); Document document = editor.getDocument(); - CharSequence tagName = getTagName(document.getText(), offset); - if (tagName == null) { + String tagName = getTagName(document.getText(), offset); + if (tagName == null || HtmlUtil.isSingleHtmlTag(tagName) || tagName.startsWith(COMMENT_PREFIX)) { return false; } @@ -99,7 +101,7 @@ public class JavadocTypedHandler extends TypedHandlerDelegate { * @return tag name if the one is parsed; null otherwise */ @Nullable - static CharSequence getTagName(@NotNull CharSequence text, int afterTagOffset) { + static String getTagName(@NotNull CharSequence text, int afterTagOffset) { if (afterTagOffset > text.length()) { return null; } diff --git a/java/java-tests/testData/codeInsight/editorActions/javadocTypedHandler/comment.java b/java/java-tests/testData/codeInsight/editorActions/javadocTypedHandler/comment.java new file mode 100644 index 000000000000..3513c5b9ae0b --- /dev/null +++ b/java/java-tests/testData/codeInsight/editorActions/javadocTypedHandler/comment.java @@ -0,0 +1,2 @@ +/** */ +public class A {} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/editorActions/javadocTypedHandler/emptyTag.java b/java/java-tests/testData/codeInsight/editorActions/javadocTypedHandler/emptyTag.java new file mode 100644 index 000000000000..c1ba70ac7a4c --- /dev/null +++ b/java/java-tests/testData/codeInsight/editorActions/javadocTypedHandler/emptyTag.java @@ -0,0 +1,2 @@ +/** */ +public class A {} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/editorActions/javadocTypedHandler/emptyTag_after.java b/java/java-tests/testData/codeInsight/editorActions/javadocTypedHandler/emptyTag_after.java new file mode 100644 index 000000000000..b78fe118b169 --- /dev/null +++ b/java/java-tests/testData/codeInsight/editorActions/javadocTypedHandler/emptyTag_after.java @@ -0,0 +1,2 @@ +/**
*/ +public class A {} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/editorActions/JavadocTypedHandlerFunctionalTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/editorActions/JavadocTypedHandlerFunctionalTest.java new file mode 100644 index 000000000000..561c16b3cc18 --- /dev/null +++ b/java/java-tests/testSrc/com/intellij/codeInsight/editorActions/JavadocTypedHandlerFunctionalTest.java @@ -0,0 +1,38 @@ +/* + * Copyright 2000-2014 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 com.intellij.codeInsight.editorActions; + +import com.intellij.testFramework.LightPlatformCodeInsightTestCase; + +public class JavadocTypedHandlerFunctionalTest extends LightPlatformCodeInsightTestCase { + private static final String BASE_PATH = "/codeInsight/editorActions/javadocTypedHandler/"; + + public void testEmptyTag() { + doTest(); + } + + public void testComment() { + doTest(); + } + + private void doTest() { + String testName = getTestName(true); + configureByFile(BASE_PATH + testName + ".java"); + type('>'); + checkResultByFile(BASE_PATH + testName + "_after.java"); + } + +}