001/*
002 * SonarQube
003 * Copyright (C) 2009-2017 SonarSource SA
004 * mailto:info AT sonarsource DOT com
005 *
006 * This program is free software; you can redistribute it and/or
007 * modify it under the terms of the GNU Lesser General Public
008 * License as published by the Free Software Foundation; either
009 * version 3 of the License, or (at your option) any later version.
010 *
011 * This program is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014 * Lesser General Public License for more details.
015 *
016 * You should have received a copy of the GNU Lesser General Public License
017 * along with this program; if not, write to the Free Software Foundation,
018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
019 */
020package org.sonar.api.batch.sensor.highlighting;
021
022import org.sonar.api.batch.fs.InputFile;
023import org.sonar.api.batch.fs.TextRange;
024
025/**
026 * This builder is used to define syntax highlighting (aka code coloration) on files.
027 * 
028 * Example:
029 * 
030 * <pre>
031 *   sensorContext.newHighlighting().onFile(inputFile)
032 *     .highlight(1, 10, 1, 15, KEYWORD)
033 *     .highlight(1, 16, 1, 18, STRING)
034 *     // Add more highlight if needed
035 *     .save();
036 *     
037 * </pre>
038 * 
039 * @since 5.1
040 */
041public interface NewHighlighting {
042
043  /**
044   * The file the highlighting belongs to.
045   */
046  NewHighlighting onFile(InputFile inputFile);
047
048  /**
049   * Call this method to indicate the type of text in a range.
050   * @param startOffset Starting position in file for this type of text. Beginning of a file starts with offset '0'.
051   * @param endOffset End position in file for this type of text.
052   * @param typeOfText see {@link TypeOfText} values.
053   * @deprecated since 5.6 Only supported to ease migration from old API. Please prefer other {@code highlight()} methods.
054   */
055  @Deprecated
056  NewHighlighting highlight(int startOffset, int endOffset, TypeOfText typeOfText);
057
058  /**
059   * Call this method to indicate the type of text in a range.
060   * @param range Range of text to highlight. See for example {@link InputFile#newRange(int, int, int, int)}.
061   * @param typeOfText see {@link TypeOfText} values.
062   * @since 5.6
063   */
064  NewHighlighting highlight(TextRange range, TypeOfText typeOfText);
065
066  /**
067   * Shortcut to avoid calling {@link InputFile#newRange(int, int, int, int)}
068   * @param typeOfText see {@link TypeOfText} values.
069   * @since 5.6
070   */
071  NewHighlighting highlight(int startLine, int startLineOffset, int endLine, int endLineOffset, TypeOfText typeOfText);
072
073  /**
074   * Call this method only once when your are done with defining highlighting of the file. It is not supported to save highlighting twice for the same file.
075   * @throws IllegalStateException if you have defined overlapping highlighting
076   */
077  void save();
078}