@@ -24,10 +24,13 @@ bool LocationManager::inMainFile(const Location &location) const {
2424}
2525
2626bool LocationManager::isImported (const Location &location) const {
27+ if (location.getPath ().empty ()) {
28+ return false ;
29+ }
2730 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)) {
3134 return true ;
3235 }
3336 }
@@ -36,41 +39,63 @@ bool LocationManager::isImported(const Location &location) const {
3639}
3740
3841bool 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 ;
4148}
4249
43- std::string
44- LocationManager::getContainingObject ( const Location &location ) const {
50+ std::string LocationManager::getImportedType ( const Location &location,
51+ const std::string &name ) const {
4552 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);
5066 }
5167 }
5268 }
5369 throw std::logic_error (" Location: " + location.getPath () +
5470 " does not belong to any known library" );
5571}
5672
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;
5876 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+ }
6286 }
87+ return headerNames;
6388}
6489
65- std::string LocationManager::getContainingObject (const json &libObject ,
90+ std::string LocationManager::getContainingObject (const json &lib ,
6691 const json &header) const {
6792 std::string package;
6893 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>();
7196 }
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>();
7499 }
75100 if (header.is_object ()) {
76101 /* override default values */
@@ -83,7 +108,9 @@ std::string LocationManager::getContainingObject(const json &libObject,
83108 }
84109 if (name.empty ()) {
85110 /* 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 ];
87114 auto slashPos = name.find_last_of (' /' );
88115 if (slashPos != std::string::npos) {
89116 name = name.substr (slashPos + 1 , name.length ());
0 commit comments