KT-652 Convert correctly statements with prohibited qualifiers inside
This commit is contained in:
@@ -9,6 +9,7 @@ public class IdentifierImpl extends Expression implements Identifier {
|
||||
private final String myName;
|
||||
private boolean myHasDollar = false;
|
||||
private boolean myIsNullable = true;
|
||||
private boolean myQuotingNeeded = true;
|
||||
|
||||
public IdentifierImpl(String name) {
|
||||
myName = name;
|
||||
@@ -25,6 +26,11 @@ public class IdentifierImpl extends Expression implements Identifier {
|
||||
myIsNullable = isNullable;
|
||||
}
|
||||
|
||||
public IdentifierImpl(String name, boolean hasDollar, boolean isNullable, boolean quotingNeeded) {
|
||||
this(name, hasDollar, isNullable);
|
||||
myQuotingNeeded = quotingNeeded;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return myName.length() == 0;
|
||||
@@ -39,17 +45,17 @@ public class IdentifierImpl extends Expression implements Identifier {
|
||||
return myIsNullable;
|
||||
}
|
||||
|
||||
private static String ifNeedQuote(String name) {
|
||||
if (ONLY_KOTLIN_KEYWORDS.contains(name) || name.contains("$"))
|
||||
return quote(name);
|
||||
return name;
|
||||
private String ifNeedQuote() {
|
||||
if (myQuotingNeeded && (ONLY_KOTLIN_KEYWORDS.contains(myName) || myName.contains("$")))
|
||||
return quote(myName);
|
||||
return myName;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
if (myHasDollar)
|
||||
return DOLLAR + ifNeedQuote(myName);
|
||||
return ifNeedQuote(myName);
|
||||
return DOLLAR + ifNeedQuote();
|
||||
return ifNeedQuote();
|
||||
}
|
||||
}
|
||||
@@ -160,6 +160,7 @@ public class ExpressionVisitor extends StatementVisitor {
|
||||
|
||||
final Object value = expression.getValue();
|
||||
String text = expression.getText();
|
||||
boolean isQuotingNeeded = true;
|
||||
|
||||
final PsiType type = expression.getType();
|
||||
if (type != null) {
|
||||
@@ -172,8 +173,13 @@ public class ExpressionVisitor extends StatementVisitor {
|
||||
text = text.replace("L", "").replace("l", "");
|
||||
if (canonicalTypeStr.equals("int") || canonicalTypeStr.equals("java.lang.Integer")) // need for hex support
|
||||
text = value != null ? value.toString() : text;
|
||||
|
||||
if (canonicalTypeStr.equals("java.lang.String"))
|
||||
isQuotingNeeded = false;
|
||||
if (canonicalTypeStr.equals("char") || canonicalTypeStr.equals("java.lang.Character"))
|
||||
isQuotingNeeded = false;
|
||||
}
|
||||
myResult = new LiteralExpression(new IdentifierImpl(text));
|
||||
myResult = new LiteralExpression(new IdentifierImpl(text, false, false, isQuotingNeeded));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package demo;
|
||||
|
||||
class Test {
|
||||
void test() {
|
||||
String name = "$$$$";
|
||||
name = name.replaceAll("\\$[0-9]+", "\\$")
|
||||
|
||||
char c = '$';
|
||||
System.out.println(c);
|
||||
|
||||
Character C = '$';
|
||||
System.out.println(C);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace demo
|
||||
open class Test() {
|
||||
open fun test() : Unit {
|
||||
var name : String? = "$$$$"
|
||||
name = name?.replaceAll("\\$[0-9]+", "\\$")
|
||||
var c : Char = '$'
|
||||
System.out?.println(c)
|
||||
var C : Char? = '$'
|
||||
System.out?.println(C)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user