IDEA-117389 Groovy: Introduce refactorings from dollar-slashy strings/regexs

This commit is contained in:
Max Medvedev
2014-01-31 16:38:54 +04:00
parent 5331b63e58
commit 41a6fe5a51
3 changed files with 40 additions and 14 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 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.
@@ -602,12 +602,12 @@ public class GrStringUtil {
}
public static String getEndQuote(String text) {
if (text.startsWith(TRIPLE_QUOTES)) return TRIPLE_QUOTES;
if (text.startsWith(QUOTE)) return QUOTE;
if (text.startsWith(TRIPLE_DOUBLE_QUOTES)) return TRIPLE_DOUBLE_QUOTES;
if (text.startsWith(DOUBLE_QUOTES)) return DOUBLE_QUOTES;
if (text.startsWith(SLASH)) return SLASH;
if (text.startsWith(SLASH_DOLLAR)) return SLASH_DOLLAR;
if (text.endsWith(TRIPLE_QUOTES)) return TRIPLE_QUOTES;
if (text.endsWith(QUOTE)) return QUOTE;
if (text.endsWith(TRIPLE_DOUBLE_QUOTES)) return TRIPLE_DOUBLE_QUOTES;
if (text.endsWith(DOUBLE_QUOTES)) return DOUBLE_QUOTES;
if (text.endsWith(SLASH)) return SLASH;
if (text.endsWith(SLASH_DOLLAR)) return SLASH_DOLLAR;
return "";
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 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.
@@ -46,14 +46,31 @@ public class StringPartInfo {
final PsiElement fin = file.findElementAt(endOffset - 1);
if (start == null || fin == null) return null;
final PsiElement parent = PsiTreeUtil.findCommonParent(start, fin);
final PsiElement psi = PsiTreeUtil.findCommonParent(start, fin);
if (psi == null) return null;
if (parent != null && isStringLiteral(parent.getParent()) && !parent.getParent().getTextRange().equalsToRange(startOffset, endOffset)) {
return new StringPartInfo((GrLiteral)parent.getParent(), new TextRange(startOffset, endOffset));
GrLiteral literal = findLiteral(psi);
if (literal != null && !literal.getTextRange().equalsToRange(startOffset, endOffset)) {
return new StringPartInfo(literal, new TextRange(startOffset, endOffset));
}
if (parent instanceof GrString && !parent.getTextRange().equalsToRange(startOffset, endOffset)) {
return new StringPartInfo((GrLiteral)parent, new TextRange(startOffset, endOffset));
return null;
}
@Nullable
private static GrLiteral findLiteral(@NotNull PsiElement psi) {
if (isStringLiteral(psi.getParent())) {
return (GrLiteral)psi.getParent();
}
if (isStringLiteral(psi.getParent().getParent())) {
return (GrLiteral)psi.getParent().getParent();
}
if (psi instanceof GrString) {
return (GrLiteral)psi;
}
return null;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 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.
@@ -119,6 +119,15 @@ def foo() {
''')
}
void testDollarSlashyString() {
doTest('''\
print($/a<begin>b<end>c/$)
''', '''\
def preved = $/b/$
print($/a/$ + preved + $/c/$)
''')
}
protected static final String ALL_MARKER = "<all>"
private void processFile(String fileText, boolean explicitType) {