This repository has been archived by the owner on Nov 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 39
/
literals.dart
88 lines (78 loc) · 2.42 KB
/
literals.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import 'package:analyzer/dart/ast/ast.dart';
import 'implementation.dart';
class Literals {
static String processNullLiteral(NullLiteral literal) {
var csharp = "";
for (var entity in literal.childEntities) {
csharp += Implementation.processEntity(entity);
}
return csharp;
}
static String processDoubleLiteral(DoubleLiteral literal) {
var csharp = "";
for (var entity in literal.childEntities) {
csharp += Implementation.processEntity(entity);
}
return csharp;
}
static String processBooleanLiteral(BooleanLiteral literal) {
var csharp = "";
for (var entity in literal.childEntities) {
csharp += Implementation.processEntity(entity);
}
return csharp;
}
static String processIntegerLiteral(IntegerLiteral literal) {
var csharp = "";
for (var entity in literal.childEntities) {
csharp += Implementation.processEntity(entity);
}
return csharp;
}
static String processMapLiteral(MapLiteral literal) {
var csharp = "new Dictionary";
for (var entity in literal.childEntities) {
csharp += Implementation.processEntity(entity);
}
return csharp;
}
static String processMapLiteralEntry(MapLiteralEntry entry) {
var csharp = "";
for (var entity in entry.childEntities) {
if (entity.toString() == ':')
csharp += ', ';
else
csharp += Implementation.processEntity(entity);
}
return '{' + csharp + '}';
}
static String processSimpleStringLiteral(SimpleStringLiteral literal) {
var stringValue = literal.toString();
stringValue = stringValue.substring(1, stringValue.length - 1);
if (stringValue.length == 1 ||
(stringValue.startsWith('\\') && stringValue.length == 2))
return "'$stringValue'";
else
return '"$stringValue"';
}
static String processListLiteral(ListLiteral literal) {
var csharp = 'new List';
var args = false;
for (var entity in literal.childEntities) {
if (entity.toString() == '[')
csharp += '{';
else if (entity.toString() == ']') {
var length = args == true ? 2 : 0;
csharp = csharp.substring(0, csharp.length - length) + '}';
}
else if (entity is TypeArgumentList)
{
csharp += Implementation.processEntity(entity) + '()';
} else {
csharp += Implementation.processEntity(entity) + ', ';
args = true;
}
}
return csharp;
}
}