fr.arakne.swflangloader.parser.DefaultAssignationType   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 77.78%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 20
ccs 7
cts 9
cp 0.7778
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A parseAssociative(String,String,String) 0 10 2
A parseSimple(String,String) 0 6 2
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.JsonParser;
23
import com.google.gson.JsonSyntaxException;
24
25
/**
26
 * Default (i.e. undeclared) assignation
27
 * Will parse as JsonElement
28
 */
29 1
final public class DefaultAssignationType implements AssignationType {
30
    @Override
31
    public Assignation parseSimple(String varName, String value) {
32
        try {
33 1
            return Assignation.simple(varName, JsonParser.parseString(value));
34 1
        } catch (JsonSyntaxException e) {
35 1
            return Assignation.NULL;
36
        }
37
    }
38
39
    @Override
40
    public Assignation parseAssociative(String varName, String key, String value) {
41
        try {
42 1
            return new Assignation(
43
                varName,
44 1
                JsonParser.parseString(key).getAsString(),
45 1
                JsonParser.parseString(value)
46
            );
47
        } catch (JsonSyntaxException e) {
48
            return Assignation.NULL;
49
        }
50
    }
51
}
52