text: "use strict";
  Object.defineProperty(exports, "__esModule", { value: true });
  /*
   * SonarTS
   * Copyright (C) 2017-2017 SonarSource SA
   * mailto:info AT sonarsource DOT com
   *
   * This program is free software; you can redistribute it and/or
   * modify it under the terms of the GNU Lesser General Public
   * License as published by the Free Software Foundation; either
   * version 3 of the License, or (at your option) any later version.
   *
   * This program is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   * Lesser General Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public License
   * along with this program; if not, write to the Free Software Foundation,
   * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
   */
  const ts = require("typescript");
  const navigation_1 = require("../utils/navigation");
  const sonar_utils_1 = require("./sonar-utils");
  function getHighlighting(sourceFile) {
      const highlights = [];
      const tokens = navigation_1.toTokens(sourceFile);
      tokens.forEach(token => {
          // KEYWORDS
          if (isKeyword(token)) {
              highlights.push(highlight(token, "keyword"));
          }
          // COMMENTS
          navigation_1.getComments(token).forEach(comment => {
              highlights.push(highlightComment(comment, navigation_1.getText(comment, token.getSourceFile()).startsWith("/**") ? "structured_comment" : "comment", token.getSourceFile()));
          });
          // STRINGS
          const isString = navigation_1.is(token, ts.SyntaxKind.StringLiteral, ts.SyntaxKind.NoSubstitutionTemplateLiteral, ts.SyntaxKind.TemplateHead, ts.SyntaxKind.TemplateMiddle, ts.SyntaxKind.TemplateTail);
          if (isString) {
              highlights.push(highlight(token, "string"));
          }
          // NUMBERS
          if (navigation_1.is(token, ts.SyntaxKind.NumericLiteral)) {
              highlights.push(highlight(token, "constant"));
          }
      });
      return { highlights };
  }
  exports.default = getHighlighting;
  function isKeyword(node) {
      return node.kind >= ts.SyntaxKind.BreakKeyword && node.kind <= ts.SyntaxKind.OfKeyword;
  }
  function highlight(node, highlightKind) {
      const startPosition = navigation_1.lineAndCharacter(node.getStart(), node.getSourceFile());
      const endPosition = navigation_1.lineAndCharacter(node.getEnd(), node.getSourceFile());
      return {
          startLine: sonar_utils_1.toSonarLine(startPosition.line),
          startCol: startPosition.character,
          endLine: sonar_utils_1.toSonarLine(endPosition.line),
          endCol: endPosition.character,
          textType: highlightKind,
      };
  }
  function highlightComment(comment, highlightKind, file) {
      const startPosition = file.getLineAndCharacterOfPosition(comment.pos);
      const endPosition = file.getLineAndCharacterOfPosition(comment.end);
      return {
          startLine: sonar_utils_1.toSonarLine(startPosition.line),
          startCol: startPosition.character,
          endLine: sonar_utils_1.toSonarLine(endPosition.line),
          endCol: endPosition.character,
          textType: highlightKind,
      };
  }
  //# sourceMappingURL=highlighter.js.map