private void parseLine()

in java/com/google/devtools/bazel/e4b/projectviews/Builder.java [95:149]


  private void parseLine(String fileName, File parentFile, String line, int linenb)
      throws ProjectViewParseException, IOException {
    if (line.isEmpty()) {
      currentSection = null;
    } else if (line.startsWith("  ")) {
      if (currentSection == null) {
        throw new ProjectViewParseException(
            "Line " + linenb + " of project view " + fileName + " is not in a section");
      }
      if (currentSection.equals("directories")) {
        directories.add(line.substring(2));
      } else if (currentSection.equals("targets")) {
        targets.add(line.substring(2));
      } else if (currentSection.equals("build_flags")) {
        buildFlags.add(line.substring(2));
      } // else ignoring other sections
    } else if (line.startsWith("import ")) {
      // imports
      String path = line.substring(7);
      if (path.startsWith("/")) {
        parseView(new File(path));
      } else {
        parseView(new File(parentFile, path));
      }
    } else if (line.contains(":")) {
      // section declaration
      line = line.trim();
      if (line.endsWith(":")) {
        currentSection = line.substring(0, line.length() - 1);
        if (currentSection.equals("java_language_level")) {
          throw new ProjectViewParseException("Line " + linenb + " of project view "
              + fileName + ": java_language_level cannot be a section name");
        }
      } else {
        int colonIndex = line.indexOf(':');
        String label = line.substring(0, colonIndex).trim();
        String value = line.substring(colonIndex + 1).trim();
        if (label.equals("directories") || label.equals("import") || label.equals("targets")
            || label.equals("build_flags")) {
          throw new ProjectViewParseException("Line " + linenb + " of project view "
              + fileName + ": " + label + " cannot be a label name");
        }
        if (label.equals("java_language_level")) {
          if (!value.matches("^[0-9]+$")) {
            throw new ProjectViewParseException("Line " + linenb + " of project view "
                + fileName + ": java_language_level should be an integer.");
          }
          javaLanguageLevel = Integer.parseInt(value);
        }
      }
    } else if (!line.trim().startsWith("#")) {
      throw new ProjectViewParseException(
          "Project view " + fileName + " contains a syntax error at line " + linenb);
    }
  }