1
|
|
|
/* |
2
|
|
|
* This file is part of ArakneLangLoader. |
3
|
|
|
* |
4
|
|
|
* ArakneLangLoader is free software: you can redistribute it and/or modify |
5
|
|
|
* it under the terms of the GNU Lesser General Public License as published by |
6
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
7
|
|
|
* (at your option) any later version. |
8
|
|
|
* |
9
|
|
|
* ArakneLangLoader is distributed in the hope that it will be useful, |
10
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
11
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12
|
|
|
* GNU Lesser General Public License for more details. |
13
|
|
|
* |
14
|
|
|
* You should have received a copy of the GNU Lesser General Public License |
15
|
|
|
* along with ArakneLangLoader. If not, see <https://www.gnu.org/licenses/>. |
16
|
|
|
* |
17
|
|
|
* Copyright (c) 2020 Vincent Quatrevieux |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
package fr.arakne.swflangloader.parser; |
21
|
|
|
|
22
|
|
|
import com.google.gson.Gson; |
23
|
|
|
import com.google.gson.JsonSyntaxException; |
24
|
|
|
|
25
|
|
|
import java.lang.reflect.Type; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Map variable assignation |
29
|
|
|
*/ |
30
|
|
|
final public class MapAssignationType implements AssignationType { |
31
|
1 |
|
final static private Gson GSON = new Gson(); |
32
|
|
|
|
33
|
|
|
final private Type keyType; |
34
|
|
|
final private Class<?> type; |
35
|
|
|
|
36
|
1 |
|
public MapAssignationType(Type keyType, Class<?> type) { |
37
|
1 |
|
this.keyType = keyType; |
38
|
1 |
|
this.type = type; |
39
|
1 |
|
} |
40
|
|
|
|
41
|
|
|
@Override |
42
|
|
|
public Assignation parseAssociative(String varName, String key, String value) { |
43
|
|
|
try { |
44
|
1 |
|
return new Assignation( |
45
|
|
|
varName, |
46
|
1 |
|
GSON.fromJson(key, keyType), |
47
|
1 |
|
GSON.fromJson(value, type) |
48
|
|
|
); |
49
|
1 |
|
} catch (JsonSyntaxException e) { |
50
|
1 |
|
return Assignation.NULL; |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|