001 /*
002 * SonarQube, open source software quality management tool.
003 * Copyright (C) 2008-2014 SonarSource
004 * mailto:contact AT sonarsource DOT com
005 *
006 * SonarQube 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 * SonarQube 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 */
020 package org.sonar.batch.source;
021
022 import org.sonar.api.batch.sensor.highlighting.TypeOfText;
023
024 import org.sonar.api.component.Component;
025 import org.sonar.api.source.Highlightable;
026 import org.sonar.batch.highlighting.SyntaxHighlightingDataBuilder;
027 import org.sonar.batch.index.ComponentDataCache;
028 import org.sonar.core.source.SnapshotDataTypes;
029
030 /**
031 * @since 3.6
032 * @deprecated since 4.5 no more used in batch 2.0
033 */
034 @Deprecated
035 public class DefaultHighlightable implements Highlightable {
036
037 private final Component component;
038 private final ComponentDataCache cache;
039 private final SyntaxHighlightingDataBuilder builder;
040
041 public DefaultHighlightable(Component component, ComponentDataCache cache) {
042 this.component = component;
043 this.cache = cache;
044 this.builder = new SyntaxHighlightingDataBuilder();
045 }
046
047 @Override
048 public HighlightingBuilder newHighlighting() {
049 return new DefaultHighlightingBuilder(component.key(), cache, builder);
050 }
051
052 @Override
053 public Component component() {
054 return component;
055 }
056
057 public SyntaxHighlightingDataBuilder getHighlightingRules() {
058 return builder;
059 }
060
061 private static class DefaultHighlightingBuilder implements HighlightingBuilder {
062
063 private final SyntaxHighlightingDataBuilder builder;
064 private String componentKey;
065 private ComponentDataCache cache;
066
067 public DefaultHighlightingBuilder(String componentKey, ComponentDataCache cache, SyntaxHighlightingDataBuilder builder) {
068 this.componentKey = componentKey;
069 this.cache = cache;
070 this.builder = builder;
071 }
072
073 @Override
074 public HighlightingBuilder highlight(int startOffset, int endOffset, String typeOfText) {
075 TypeOfText type = org.sonar.api.batch.sensor.highlighting.TypeOfText.forCssClass(typeOfText);
076 builder.registerHighlightingRule(startOffset, endOffset, type);
077 return this;
078 }
079
080 @Override
081 public void done() {
082 cache.setData(componentKey, SnapshotDataTypes.SYNTAX_HIGHLIGHTING, builder.build());
083 }
084 }
085 }