/** * This adds a single file to the parser * * @param rootPath The root path to the source folder * @param relativeFilePath The relative path inside the root path to the file. The file will be * added to the map with the key of the entire relative path so that lookups from within * Sorbet do not have any ambiguity * @return 0 if success, 1 if failed */ private int addFile(String rootPath, String relativeFilePath) { try { // Open file FileInputStream file = new FileInputStream(rootPath + File.separator + relativeFilePath); // Setup parser CompilationUnit cu = JavaParser.parse(file); // Visit the file with our visitor VariableVisitor<Object> variableVisitor = new VariableVisitor<Object>(); variableVisitor.visit(cu, null); Lines lines = variableVisitor.getLines(); if (files.containsKey(relativeFilePath)) { // Already contains this file, return failed return 1; } else { files.put(relativeFilePath, lines); } } catch (FileNotFoundException e) { // File doesn't exist, return failed return 1; } catch (ParseException e) { // File isn't valid, return failed return 1; } // Return success return 0; }