Details
-
Bug
-
Status: Resolved
-
Resolution: Done
-
None
-
None
-
None
-
None
-
Operating System: Windows
Platform: PC
-
91
Description
The new builder
public Set<org.opendaylight.yangtools.yang.model.api.Module> parseYangModels(File yangFile,File directory)
loads all yang files in the directory, not just those needed to parse the file.
This will not scale when we have large numbers of files.
Below shows the key code I used to build the list (I have omitted the antlr related code, but happy to attach that if it helps).
===============================================================
I'm not saying my code is any good, just showing it can be done.
===============================================================
>>> So my call in main was.
Set<Module> modules = parser.parseYangModels(getAllYangFiles(yangFileStr, dirStr));
>>>and here are the methods
// parse the imports in the main file
public List<File> getAllYangFiles(final String fileName, final String dirStr) throws IOException {
assert fileName != null;
assert dirStr != null;
imports = new HashSet<String>(127);
List<File> files = new ArrayList<File>();
files.add(new File(dirStr + File.separator + fileName + YANG_FILE_EXTENSION)); // add the main file
getYangImports(fileName, dirStr); // recursively get the file imports
Iterator<String> i = imports.iterator();
while (i.hasNext())
{ files.add(new File(dirStr + File.separator + i.next()+ YANG_FILE_EXTENSION)); } return files;
}
// recursively parse the imported yang files
public void getYangImports(final String fileName, final String dirStr) throws IOException {
assert fileName != null;
assert dirStr != null;
Set<String> fileImports = getYangFileImports(fileName, dirStr);
if (!fileImports.isEmpty()) { // have some imports !
Iterator<String> i = fileImports.iterator();
String importStr;
while (i.hasNext()) {
importStr = i.next();
if (!imports.contains(importStr))
}
}
}
// get the import statements in each file
public Set<String> getYangFileImports(final String fileName, final String dirStr) throws IOException