mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-122732 Javadoc invalid html closing tags
This commit is contained in:
@@ -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; <code>null</code> otherwise
|
||||
*/
|
||||
@Nullable
|
||||
static CharSequence getTagName(@NotNull CharSequence text, int afterTagOffset) {
|
||||
static String getTagName(@NotNull CharSequence text, int afterTagOffset) {
|
||||
if (afterTagOffset > text.length()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
/** <!--comment--<caret> */
|
||||
public class A {}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
/** <!--comment--><caret> */
|
||||
public class A {}
|
||||
@@ -0,0 +1,2 @@
|
||||
/** <br<caret> */
|
||||
public class A {}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
/** <br><caret> */
|
||||
public class A {}
|
||||
+38
@@ -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");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user