improved quoting for identifier added

This commit is contained in:
Sergey Ignatov
2011-11-08 15:19:57 +04:00
parent 846ac36fab
commit 54265da366
9 changed files with 75 additions and 5 deletions
@@ -7,6 +7,7 @@ import org.jetbrains.annotations.NotNull;
*/
public class IdentifierImpl extends Expression implements Identifier {
private final String myName;
private boolean myHasDollar;
private boolean myNullable = true;
public IdentifierImpl(String name) {
@@ -18,6 +19,12 @@ public class IdentifierImpl extends Expression implements Identifier {
myNullable = nullable;
}
public IdentifierImpl(String name, boolean hasDollar, boolean nullable) {
myName = name;
myHasDollar = hasDollar;
myNullable = nullable;
}
@Override
public String getName() {
return myName;
@@ -37,11 +44,17 @@ public class IdentifierImpl extends Expression implements Identifier {
return myNullable;
}
private String ifNeedQuote(String name) {
if (ONLY_KOTLIN_KEYWORDS.contains(name) || name.contains("$"))
return quote(name);
return name;
}
@NotNull
@Override
public String toKotlin() {
if (ONLY_KOTLIN_KEYWORDS.contains(myName))
return quote(myName);
return myName;
if (myHasDollar)
return DOLLAR + ifNeedQuote(myName);
return ifNeedQuote(myName);
}
}
+2 -1
View File
@@ -37,8 +37,9 @@ public abstract class Node implements INode {
static final String COLON = ":";
static final String IN = "in";
static final String AT = "@";
static final String DOLLAR = "$";
static final String BACKTICK = "`";
static final String QUEST = "?";
static final String COMMA_WITH_SPACE = "," + SPACE;
static final String STAR = "*";
}
}
@@ -234,7 +234,7 @@ public class ExpressionVisitor extends StatementVisitor implements Visitor {
boolean isNullable = typeToType(expression.getType()).isNullable();
final IdentifierImpl identifier = hasDollar ?
new IdentifierImpl("$" + expression.getReferenceName(), isNullable) :
new IdentifierImpl(expression.getReferenceName(), hasDollar, isNullable) :
new IdentifierImpl(expression.getReferenceName(), isNullable);
myResult = new CallChainExpression(
expressionToExpression(expression.getQualifierExpression()),
@@ -0,0 +1 @@
$$$$$
@@ -0,0 +1 @@
`$$$$$`
@@ -0,0 +1,13 @@
class $$$$$ {}
class $ {}
class $$ extends $ {
final $$$$$ $$$;
public $$($$$$$ $$$$) {
$$$ = $$$$;
}
public $$$$$ $$$$$$() {return $$$;}
}
@@ -0,0 +1,13 @@
open class `$$$$$`() {
}
open class `$`() {
}
open class `$$`(`$$$$` : `$$$$$`?) : `$` {
val `$$$` : `$$$$$`?
{
$`$$$` = `$$$$`
}
open public fun `$$$$$$`() : `$$$$$`? {
return `$$$`
}
}
@@ -0,0 +1,5 @@
int
namespace, in, val, var, when, object,
out, in, is, as, ref, override,
open, attribute, lazy, set, get,
fun, where, by, trait, type, This;
@@ -0,0 +1,23 @@
var `namespace` : Int
var `in` : Int
var `val` : Int
var `var` : Int
var `when` : Int
var `object` : Int
var `out` : Int
var `in` : Int
var `is` : Int
var `as` : Int
var `ref` : Int
var `override` : Int
var `open` : Int
var `attribute` : Int
var `lazy` : Int
var `set` : Int
var `get` : Int
var `fun` : Int
var `where` : Int
var `by` : Int
var `trait` : Int
var `type` : Int
var `This` : Int