mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[groovy] fix string content range computing (IDEA-187605)
This commit is contained in:
+15
-16
@@ -1,18 +1,4 @@
|
||||
/*
|
||||
* Copyright 2000-2017 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.
|
||||
*/
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package org.jetbrains.plugins.groovy.editor;
|
||||
|
||||
import com.intellij.codeInsight.editorActions.StringLiteralCopyPasteProcessor;
|
||||
@@ -36,6 +22,7 @@ import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes;
|
||||
import org.jetbrains.plugins.groovy.lang.lexer.TokenSets;
|
||||
import org.jetbrains.plugins.groovy.lang.parser.GroovyElementTypes;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.util.GrStringUtil;
|
||||
import org.jetbrains.plugins.groovy.lang.resolve.GroovyStringLiteralManipulator;
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
@@ -61,7 +48,19 @@ public class GroovyLiteralCopyPasteProcessor extends StringLiteralCopyPasteProce
|
||||
@Nullable
|
||||
@Override
|
||||
protected TextRange getEscapedRange(@NotNull PsiElement token) {
|
||||
return isStringLiteral(token) ? token.getTextRange() : null; // TODO: calculate correct ranges for different types of literals
|
||||
final ASTNode node = token.getNode();
|
||||
if (node == null) return null;
|
||||
|
||||
final IElementType tokenType = node.getElementType();
|
||||
if (tokenType == GroovyTokenTypes.mSTRING_LITERAL || tokenType == GroovyTokenTypes.mGSTRING_LITERAL) {
|
||||
final String text = token.getText();
|
||||
if (text == null) return null;
|
||||
return GroovyStringLiteralManipulator.getLiteralRange(text);
|
||||
}
|
||||
if (tokenType == GroovyTokenTypes.mREGEX_CONTENT) {
|
||||
return token.getTextRange();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package org.jetbrains.plugins.groovy
|
||||
|
||||
import com.intellij.codeInsight.CodeInsightSettings
|
||||
@@ -165,4 +165,109 @@ print CONST<caret>
|
||||
" //text<caret>\n" +
|
||||
"}")
|
||||
}
|
||||
|
||||
|
||||
void 'test single-quoted string'() {
|
||||
doTest($/<selection>'\\'</selection>/$, '', $/'\\'/$)
|
||||
}
|
||||
|
||||
void 'test single-quoted string partial'() {
|
||||
doTest($/<selection>'\\</selection>'/$, '', $/'\\/$)
|
||||
}
|
||||
|
||||
void 'test single-quoted string content'() {
|
||||
doTest($/'<selection>\\</selection>'/$, '', $/\/$)
|
||||
}
|
||||
|
||||
|
||||
void 'test double-quoted string'() {
|
||||
doTest($/<selection>"\\"</selection>/$, '', $/"\\"/$)
|
||||
}
|
||||
|
||||
void 'test double-quoted string partial'() {
|
||||
doTest($/<selection>"\\</selection>"/$, '', $/"\\/$)
|
||||
}
|
||||
|
||||
void 'test double-quoted string content'() {
|
||||
doTest($/"<selection>\\</selection>"/$, '', $/\/$)
|
||||
}
|
||||
|
||||
|
||||
void 'test triple-single-quoted string'() {
|
||||
doTest($/<selection>'''\\'''</selection>/$, '', $/'''\\'''/$)
|
||||
}
|
||||
|
||||
void 'test triple-single-quoted string partial start quote 1'() {
|
||||
doTest($/'<selection>''\\'''</selection>/$, '', $/''\\'''/$)
|
||||
}
|
||||
|
||||
void 'test triple-single-quoted string partial start quote 2'() {
|
||||
doTest($/''<selection>'\\'''</selection>/$, '', $/'\\'''/$)
|
||||
}
|
||||
|
||||
void 'test triple-single-quoted string partial start quote 3'() {
|
||||
doTest($/'''<selection>\\'''</selection>/$, '', $/\\'''/$)
|
||||
}
|
||||
|
||||
void 'test triple-single-quoted string partial end quote 1'() {
|
||||
doTest($/<selection>'''\\</selection>'''/$, '', $/'''\\/$)
|
||||
}
|
||||
|
||||
void 'test triple-single-quoted string partial end quote 2'() {
|
||||
doTest($/<selection>'''\\'</selection>''/$, '', $/'''\\'/$)
|
||||
}
|
||||
|
||||
void 'test triple-single-quoted string partial end quote 3'() {
|
||||
doTest($/<selection>'''\\''</selection>'/$, '', $/'''\\''/$)
|
||||
}
|
||||
|
||||
void 'test triple-single-quoted string content'() {
|
||||
doTest($/'''<selection>\\</selection>'''/$, '', $/\/$)
|
||||
}
|
||||
|
||||
|
||||
void 'test triple-double-quoted string'() {
|
||||
doTest($/<selection>"""\\"""</selection>/$, '', $/"""\\"""/$)
|
||||
}
|
||||
|
||||
void 'test triple-double-quoted string partial start quote 1'() {
|
||||
doTest($/"<selection>""\\"""</selection>/$, '', $/""\\"""/$)
|
||||
}
|
||||
|
||||
void 'test triple-double-quoted string partial start quote 2'() {
|
||||
doTest($/""<selection>"\\"""</selection>/$, '', $/"\\"""/$)
|
||||
}
|
||||
|
||||
void 'test triple-double-quoted string partial start quote 3'() {
|
||||
doTest($/"""<selection>\\"""</selection>/$, '', $/\\"""/$)
|
||||
}
|
||||
|
||||
void 'test triple-double-quoted string partial end quote 1'() {
|
||||
doTest($/<selection>"""\\</selection>"""/$, '', $/"""\\/$)
|
||||
}
|
||||
|
||||
void 'test triple-double-quoted string partial end quote 2'() {
|
||||
doTest($/<selection>"""\\"</selection>""/$, '', $/"""\\"/$)
|
||||
}
|
||||
|
||||
void 'test triple-double-quoted string partial end quote 3'() {
|
||||
doTest($/<selection>"""\\""</selection>"/$, '', $/"""\\""/$)
|
||||
}
|
||||
|
||||
void 'test triple-double-quoted string content'() {
|
||||
doTest($/"""<selection>\\</selection>"""/$, '', $/\/$)
|
||||
}
|
||||
|
||||
|
||||
void 'test slashy string'() {
|
||||
doTest($/<selection>/\//</selection>/$, '', $//\///$)
|
||||
}
|
||||
|
||||
void 'test slashy string partial'() {
|
||||
doTest($/<selection>/\/</selection>//$, '', $//\//$)
|
||||
}
|
||||
|
||||
void 'test slashy string content'() {
|
||||
doTest($//<selection>\/</selection>//$, '', $///$)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user