@@ -24,10 +24,13 @@ bool LocationManager::inMainFile(const Location &location) const {
24
24
}
25
25
26
26
bool LocationManager::isImported (const Location &location) const {
27
+ if (location.getPath ().empty ()) {
28
+ return false ;
29
+ }
27
30
for (auto it = config.begin (); it != config.end (); ++it) {
28
- json libObject = it.value ();
29
- for (const auto &header : libObject[ " headers " ]) {
30
- if (equal (header , location)) {
31
+ json lib = it.value ();
32
+ for (const auto &object : lib[ " objects " ]) {
33
+ if (equal (object , location)) {
31
34
return true ;
32
35
}
33
36
}
@@ -36,41 +39,63 @@ bool LocationManager::isImported(const Location &location) const {
36
39
}
37
40
38
41
bool LocationManager::equal (json header, const Location &location) const {
39
- std::string headerName = getHeaderName (header);
40
- return endsWith (location.getPath (), headerName);
42
+ for (const std::string &headerName : getHeaderNames (header)) {
43
+ if (endsWith (location.getPath (), " /" + headerName)) {
44
+ return true ;
45
+ }
46
+ }
47
+ return false ;
41
48
}
42
49
43
- std::string
44
- LocationManager::getContainingObject ( const Location &location ) const {
50
+ std::string LocationManager::getImportedType ( const Location &location,
51
+ const std::string &name ) const {
45
52
for (auto it = config.begin (); it != config.end (); ++it) {
46
- json libObject = it.value ();
47
- for (const json &header : libObject[" headers" ]) {
48
- if (equal (header, location)) {
49
- return getContainingObject (libObject, header);
53
+ json lib = it.value ();
54
+ for (const json &object : lib[" objects" ]) {
55
+ if (equal (object, location)) {
56
+ std::string scalaObject = getContainingObject (lib, object);
57
+ if (lib.find (" names" ) != lib.end ()) {
58
+ /* name mapping */
59
+ json names = lib[" names" ];
60
+ if (names.find (name) != names.end ()) {
61
+ return scalaObject + " ." +
62
+ names[name].get <std::string>();
63
+ }
64
+ }
65
+ return scalaObject + " ." + handleReservedWords (name);
50
66
}
51
67
}
52
68
}
53
69
throw std::logic_error (" Location: " + location.getPath () +
54
70
" does not belong to any known library" );
55
71
}
56
72
57
- std::string LocationManager::getHeaderName (const json &header) const {
73
+ std::vector<std::string>
74
+ LocationManager::getHeaderNames (const json &header) const {
75
+ std::vector<std::string> headerNames;
58
76
if (header.is_string ()) {
59
- return header.get <std::string>();
60
- } else {
61
- return header[" header" ].get <std::string>();
77
+ headerNames.push_back (header.get <std::string>());
78
+ } else if (header.is_object ()) {
79
+ if (header.find (" header" ) != header.end ()) {
80
+ headerNames.push_back (header[" header" ].get <std::string>());
81
+ } else {
82
+ for (const json &h : header[" headers" ]) {
83
+ headerNames.push_back (h.get <std::string>());
84
+ }
85
+ }
62
86
}
87
+ return headerNames;
63
88
}
64
89
65
- std::string LocationManager::getContainingObject (const json &libObject ,
90
+ std::string LocationManager::getContainingObject (const json &lib ,
66
91
const json &header) const {
67
92
std::string package;
68
93
std::string name;
69
- if (libObject .find (" package" ) != libObject .end ()) {
70
- package = libObject [" package" ].get <std::string>();
94
+ if (lib .find (" package" ) != lib .end ()) {
95
+ package = lib [" package" ].get <std::string>();
71
96
}
72
- if (libObject .find (" name" ) != libObject .end ()) {
73
- package = libObject [" name" ].get <std::string>();
97
+ if (lib .find (" name" ) != lib .end ()) {
98
+ package = lib [" name" ].get <std::string>();
74
99
}
75
100
if (header.is_object ()) {
76
101
/* override default values */
@@ -83,7 +108,9 @@ std::string LocationManager::getContainingObject(const json &libObject,
83
108
}
84
109
if (name.empty ()) {
85
110
/* extract object name from header name */
86
- name = getHeaderName (header);
111
+ std::vector<std::string> names = getHeaderNames (header);
112
+ assert (names.size () == 1 );
113
+ name = names[0 ];
87
114
auto slashPos = name.find_last_of (' /' );
88
115
if (slashPos != std::string::npos) {
89
116
name = name.substr (slashPos + 1 , name.length ());
0 commit comments