From: Julien HENRY Date: Fri, 20 Feb 2015 10:09:49 +0000 (+0100) Subject: SONAR-5931 Cleanup symbol reference API X-Git-Tag: 5.1-RC1~141 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=38357bb24905509dd775e40bdf09e40aec6af39c;p=sonarqube.git SONAR-5931 Cleanup symbol reference API --- diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/SymbolReferencesSensor.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/SymbolReferencesSensor.java index 5cc2ea832f9..118fe828243 100644 --- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/SymbolReferencesSensor.java +++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/SymbolReferencesSensor.java @@ -26,8 +26,9 @@ import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.sensor.Sensor; import org.sonar.api.batch.sensor.SensorContext; import org.sonar.api.batch.sensor.SensorDescriptor; -import org.sonar.api.batch.sensor.symbol.Symbol; -import org.sonar.api.batch.sensor.symbol.SymbolTableBuilder; +import org.sonar.api.component.ResourcePerspectives; +import org.sonar.api.source.Symbol; +import org.sonar.api.source.Symbolizable; import org.sonar.api.utils.log.Logger; import org.sonar.api.utils.log.Loggers; import org.sonar.xoo.Xoo; @@ -42,6 +43,12 @@ import java.util.List; */ public class SymbolReferencesSensor implements Sensor { + private ResourcePerspectives perspectives; + + public SymbolReferencesSensor(ResourcePerspectives perspectives) { + this.perspectives = perspectives; + } + private static final Logger LOG = Loggers.get(SymbolReferencesSensor.class); private static final String SYMBOL_EXTENSION = ".symbol"; @@ -54,7 +61,9 @@ public class SymbolReferencesSensor implements Sensor { try { List lines = FileUtils.readLines(symbolFile, context.fileSystem().encoding().name()); int lineNumber = 0; - SymbolTableBuilder symbolTableBuilder = context.symbolTableBuilder(inputFile); + Symbolizable symbolizable = perspectives.as(Symbolizable.class, inputFile); + + Symbolizable.SymbolTableBuilder symbolTableBuilder = symbolizable.newSymbolTableBuilder(); for (String line : lines) { lineNumber++; if (StringUtils.isBlank(line) || line.startsWith("#")) { @@ -62,14 +71,14 @@ public class SymbolReferencesSensor implements Sensor { } processLine(symbolFile, lineNumber, symbolTableBuilder, line); } - symbolTableBuilder.done(); + symbolizable.setSymbolTable(symbolTableBuilder.build()); } catch (IOException e) { throw new IllegalStateException(e); } } } - private void processLine(File symbolFile, int lineNumber, SymbolTableBuilder symbolTableBuilder, String line) { + private void processLine(File symbolFile, int lineNumber, Symbolizable.SymbolTableBuilder symbolTableBuilder, String line) { try { Iterator split = Splitter.on(",").split(line).iterator(); int startOffset = Integer.parseInt(split.next()); diff --git a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/SymbolReferencesSensorTest.java b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/SymbolReferencesSensorTest.java index 5673221a46e..332629c8469 100644 --- a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/SymbolReferencesSensorTest.java +++ b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/SymbolReferencesSensorTest.java @@ -28,8 +28,9 @@ import org.sonar.api.batch.fs.internal.DefaultFileSystem; import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.batch.sensor.SensorContext; import org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor; -import org.sonar.api.batch.sensor.symbol.Symbol; -import org.sonar.api.batch.sensor.symbol.SymbolTableBuilder; +import org.sonar.api.component.ResourcePerspectives; +import org.sonar.api.source.Symbol; +import org.sonar.api.source.Symbolizable; import java.io.File; import java.io.IOException; @@ -47,11 +48,13 @@ public class SymbolReferencesSensorTest { @Rule public TemporaryFolder temp = new TemporaryFolder(); private File baseDir; + private ResourcePerspectives perspectives; @Before public void prepare() throws IOException { baseDir = temp.newFolder(); - sensor = new SymbolReferencesSensor(); + perspectives = mock(ResourcePerspectives.class); + sensor = new SymbolReferencesSensor(perspectives); fileSystem = new DefaultFileSystem(baseDir.toPath()); when(context.fileSystem()).thenReturn(fileSystem); } @@ -74,8 +77,10 @@ public class SymbolReferencesSensorTest { FileUtils.write(symbol, "1,4,7\n12,15,23\n\n#comment"); DefaultInputFile inputFile = new DefaultInputFile("foo", "src/foo.xoo").setLanguage("xoo"); fileSystem.add(inputFile); - SymbolTableBuilder symbolTableBuilder = mock(SymbolTableBuilder.class); - when(context.symbolTableBuilder(inputFile)).thenReturn(symbolTableBuilder); + Symbolizable symbolizable = mock(Symbolizable.class); + when(perspectives.as(Symbolizable.class, inputFile)).thenReturn(symbolizable); + Symbolizable.SymbolTableBuilder symbolTableBuilder = mock(Symbolizable.SymbolTableBuilder.class); + when(symbolizable.newSymbolTableBuilder()).thenReturn(symbolTableBuilder); Symbol symbol1 = mock(Symbol.class); when(symbolTableBuilder.newSymbol(1, 4)).thenReturn(symbol1); diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/SourceDataFactory.java b/sonar-batch/src/main/java/org/sonar/batch/index/SourceDataFactory.java index edea3a94051..0b7d9414f35 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/index/SourceDataFactory.java +++ b/sonar-batch/src/main/java/org/sonar/batch/index/SourceDataFactory.java @@ -27,9 +27,9 @@ import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.batch.sensor.duplication.Duplication; import org.sonar.api.batch.sensor.duplication.internal.DefaultDuplication; import org.sonar.api.batch.sensor.highlighting.internal.SyntaxHighlightingRule; -import org.sonar.api.batch.sensor.symbol.Symbol; import org.sonar.api.measures.CoreMetrics; import org.sonar.api.measures.Measure; +import org.sonar.api.source.Symbol; import org.sonar.api.utils.DateUtils; import org.sonar.api.utils.KeyValueFormat; import org.sonar.batch.duplication.DuplicationCache; diff --git a/sonar-batch/src/main/java/org/sonar/batch/mediumtest/TaskResult.java b/sonar-batch/src/main/java/org/sonar/batch/mediumtest/TaskResult.java index 8c07b72e5a6..6d2eeabcc73 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/mediumtest/TaskResult.java +++ b/sonar-batch/src/main/java/org/sonar/batch/mediumtest/TaskResult.java @@ -31,10 +31,10 @@ import org.sonar.api.batch.sensor.duplication.Duplication; import org.sonar.api.batch.sensor.highlighting.TypeOfText; import org.sonar.api.batch.sensor.highlighting.internal.SyntaxHighlightingRule; import org.sonar.api.batch.sensor.measure.internal.DefaultMeasure; -import org.sonar.api.batch.sensor.symbol.Symbol; import org.sonar.api.issue.Issue; import org.sonar.api.issue.internal.DefaultIssue; import org.sonar.api.measures.Measure; +import org.sonar.api.source.Symbol; import org.sonar.batch.dependency.DependencyCache; import org.sonar.batch.duplication.DuplicationCache; import org.sonar.batch.highlighting.SyntaxHighlightingData; diff --git a/sonar-batch/src/main/java/org/sonar/batch/sensor/DefaultSensorContext.java b/sonar-batch/src/main/java/org/sonar/batch/sensor/DefaultSensorContext.java index 73a05a177b5..130e8c10c63 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/sensor/DefaultSensorContext.java +++ b/sonar-batch/src/main/java/org/sonar/batch/sensor/DefaultSensorContext.java @@ -21,8 +21,6 @@ package org.sonar.batch.sensor; import org.sonar.api.batch.AnalysisMode; import org.sonar.api.batch.fs.FileSystem; -import org.sonar.api.batch.fs.InputFile; -import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.batch.rule.ActiveRules; import org.sonar.api.batch.sensor.SensorContext; import org.sonar.api.batch.sensor.dependency.NewDependency; @@ -36,10 +34,8 @@ import org.sonar.api.batch.sensor.issue.NewIssue; import org.sonar.api.batch.sensor.issue.internal.DefaultIssue; import org.sonar.api.batch.sensor.measure.NewMeasure; import org.sonar.api.batch.sensor.measure.internal.DefaultMeasure; -import org.sonar.api.batch.sensor.symbol.SymbolTableBuilder; import org.sonar.api.config.Settings; import org.sonar.batch.index.ComponentDataCache; -import org.sonar.batch.symbol.DefaultSymbolTableBuilder; import java.io.Serializable; @@ -97,11 +93,6 @@ public class DefaultSensorContext implements SensorContext { return new DefaultHighlighting(sensorStorage); } - @Override - public SymbolTableBuilder symbolTableBuilder(InputFile inputFile) { - return new DefaultSymbolTableBuilder(((DefaultInputFile) inputFile).key(), componentDataCache); - } - @Override public NewDuplication newDuplication() { return new DefaultDuplication(sensorStorage); diff --git a/sonar-batch/src/main/java/org/sonar/batch/source/DefaultSymbol.java b/sonar-batch/src/main/java/org/sonar/batch/source/DefaultSymbol.java new file mode 100644 index 00000000000..0bca8bd9997 --- /dev/null +++ b/sonar-batch/src/main/java/org/sonar/batch/source/DefaultSymbol.java @@ -0,0 +1,58 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube 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. + * + * SonarQube 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. + */ + +package org.sonar.batch.source; + +import com.google.common.base.Objects; + +import java.io.Serializable; + +public class DefaultSymbol implements org.sonar.api.source.Symbol, Serializable { + + private final int declarationStartOffset; + private final int declarationEndOffset; + + public DefaultSymbol(int startOffset, int endOffset) { + this.declarationStartOffset = startOffset; + this.declarationEndOffset = endOffset; + } + + @Override + public int getDeclarationStartOffset() { + return declarationStartOffset; + } + + @Override + public int getDeclarationEndOffset() { + return declarationEndOffset; + } + + @Override + public String getFullyQualifiedName() { + return null; + } + + @Override + public String toString() { + return Objects.toStringHelper("Symbol") + .add("offset", String.format("%d-%d", declarationStartOffset, declarationEndOffset)) + .toString(); + } +} diff --git a/sonar-batch/src/main/java/org/sonar/batch/source/DefaultSymbolTable.java b/sonar-batch/src/main/java/org/sonar/batch/source/DefaultSymbolTable.java index b4ce0c15878..18b3e06df6b 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/source/DefaultSymbolTable.java +++ b/sonar-batch/src/main/java/org/sonar/batch/source/DefaultSymbolTable.java @@ -20,7 +20,6 @@ package org.sonar.batch.source; -import org.sonar.api.batch.sensor.symbol.internal.DefaultSymbol; import org.sonar.api.source.Symbol; import org.sonar.api.source.Symbolizable; @@ -46,7 +45,7 @@ public class DefaultSymbolTable implements Symbolizable.SymbolTable { @Override public List symbols() { List result = new ArrayList(); - for (org.sonar.api.batch.sensor.symbol.Symbol symbol : referencesBySymbol.keySet()) { + for (Symbol symbol : referencesBySymbol.keySet()) { result.add((Symbol) symbol); } return result; diff --git a/sonar-batch/src/main/java/org/sonar/batch/symbol/DefaultSymbolTableBuilder.java b/sonar-batch/src/main/java/org/sonar/batch/symbol/DefaultSymbolTableBuilder.java index 72d4c050eb4..fc33c337b52 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/symbol/DefaultSymbolTableBuilder.java +++ b/sonar-batch/src/main/java/org/sonar/batch/symbol/DefaultSymbolTableBuilder.java @@ -20,10 +20,9 @@ package org.sonar.batch.symbol; -import org.sonar.api.batch.sensor.symbol.Symbol; -import org.sonar.api.batch.sensor.symbol.SymbolTableBuilder; -import org.sonar.api.batch.sensor.symbol.internal.DefaultSymbol; +import org.sonar.api.source.Symbol; import org.sonar.batch.index.ComponentDataCache; +import org.sonar.batch.source.DefaultSymbol; import org.sonar.core.source.SnapshotDataTypes; import java.io.Serializable; @@ -33,7 +32,7 @@ import java.util.Map; import java.util.Set; import java.util.TreeSet; -public class DefaultSymbolTableBuilder implements SymbolTableBuilder { +public class DefaultSymbolTableBuilder { private final String componentKey; private final ComponentDataCache cache; @@ -44,14 +43,12 @@ public class DefaultSymbolTableBuilder implements SymbolTableBuilder { this.cache = cache; } - @Override public Symbol newSymbol(int fromOffset, int toOffset) { org.sonar.api.source.Symbol symbol = new DefaultSymbol(fromOffset, toOffset); referencesBySymbol.put(symbol, new TreeSet()); return symbol; } - @Override public void newReference(Symbol symbol, int fromOffset) { if (!referencesBySymbol.containsKey(symbol)) { throw new UnsupportedOperationException("Cannot add reference to a symbol in another file"); @@ -66,7 +63,6 @@ public class DefaultSymbolTableBuilder implements SymbolTableBuilder { return new SymbolData(referencesBySymbol); } - @Override public void done() { cache.setData(componentKey, SnapshotDataTypes.SYMBOL_HIGHLIGHTING, build()); } diff --git a/sonar-batch/src/main/java/org/sonar/batch/symbol/SymbolData.java b/sonar-batch/src/main/java/org/sonar/batch/symbol/SymbolData.java index baf897c6d1b..616429242ca 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/symbol/SymbolData.java +++ b/sonar-batch/src/main/java/org/sonar/batch/symbol/SymbolData.java @@ -20,7 +20,7 @@ package org.sonar.batch.symbol; -import org.sonar.api.batch.sensor.symbol.Symbol; +import org.sonar.api.source.Symbol; import org.sonar.batch.index.Data; import java.util.Collection; diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/SourceDataFactoryTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/SourceDataFactoryTest.java index d6e07f67f5f..131ba214571 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/index/SourceDataFactoryTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/index/SourceDataFactoryTest.java @@ -34,6 +34,7 @@ import org.sonar.api.batch.sensor.highlighting.TypeOfText; import org.sonar.api.measures.CoreMetrics; import org.sonar.api.measures.Measure; import org.sonar.api.measures.Metric; +import org.sonar.api.source.Symbol; import org.sonar.batch.duplication.DuplicationCache; import org.sonar.batch.highlighting.SyntaxHighlightingData; import org.sonar.batch.highlighting.SyntaxHighlightingDataBuilder; @@ -324,10 +325,10 @@ public class SourceDataFactoryTest { @Test public void applySymbolReferences() throws Exception { DefaultSymbolTableBuilder symbolBuilder = new DefaultSymbolTableBuilder(inputFile.key(), null); - org.sonar.api.batch.sensor.symbol.Symbol s1 = symbolBuilder.newSymbol(1, 2); + Symbol s1 = symbolBuilder.newSymbol(1, 2); symbolBuilder.newReference(s1, 4); symbolBuilder.newReference(s1, 11); - org.sonar.api.batch.sensor.symbol.Symbol s2 = symbolBuilder.newSymbol(4, 6); + Symbol s2 = symbolBuilder.newSymbol(4, 6); symbolBuilder.newReference(s2, 0); symbolBuilder.newReference(s2, 7); when(componentDataCache.getData(inputFile.key(), SnapshotDataTypes.SYMBOL_HIGHLIGHTING)).thenReturn(symbolBuilder.build()); @@ -344,10 +345,10 @@ public class SourceDataFactoryTest { @Test public void applySymbolReferences_declaration_order_is_not_important() throws Exception { DefaultSymbolTableBuilder symbolBuilder = new DefaultSymbolTableBuilder(inputFile.key(), null); - org.sonar.api.batch.sensor.symbol.Symbol s2 = symbolBuilder.newSymbol(4, 6); + Symbol s2 = symbolBuilder.newSymbol(4, 6); symbolBuilder.newReference(s2, 7); symbolBuilder.newReference(s2, 0); - org.sonar.api.batch.sensor.symbol.Symbol s1 = symbolBuilder.newSymbol(1, 2); + Symbol s1 = symbolBuilder.newSymbol(1, 2); symbolBuilder.newReference(s1, 11); symbolBuilder.newReference(s1, 4); when(componentDataCache.getData(inputFile.key(), SnapshotDataTypes.SYMBOL_HIGHLIGHTING)).thenReturn(symbolBuilder.build()); diff --git a/sonar-batch/src/test/java/org/sonar/batch/symbol/DefaultSymbolTableBuilderTest.java b/sonar-batch/src/test/java/org/sonar/batch/symbol/DefaultSymbolTableBuilderTest.java index 8e125a74d04..05961573725 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/symbol/DefaultSymbolTableBuilderTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/symbol/DefaultSymbolTableBuilderTest.java @@ -24,8 +24,7 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.mockito.ArgumentCaptor; -import org.sonar.api.batch.sensor.symbol.Symbol; -import org.sonar.api.batch.sensor.symbol.SymbolTableBuilder; +import org.sonar.api.source.Symbol; import org.sonar.batch.index.ComponentDataCache; import org.sonar.core.source.SnapshotDataTypes; @@ -46,7 +45,7 @@ public class DefaultSymbolTableBuilderTest { @Test public void should_write_symbol_and_references() throws Exception { ComponentDataCache componentDataCache = mock(ComponentDataCache.class); - SymbolTableBuilder symbolTableBuilder = new DefaultSymbolTableBuilder("foo", componentDataCache); + DefaultSymbolTableBuilder symbolTableBuilder = new DefaultSymbolTableBuilder("foo", componentDataCache); Symbol firstSymbol = symbolTableBuilder.newSymbol(10, 20); symbolTableBuilder.newReference(firstSymbol, 32); Symbol secondSymbol = symbolTableBuilder.newSymbol(84, 92); @@ -72,7 +71,7 @@ public class DefaultSymbolTableBuilderTest { public void should_serialize_unused_symbol() throws Exception { ComponentDataCache componentDataCache = mock(ComponentDataCache.class); - SymbolTableBuilder symbolTableBuilder = new DefaultSymbolTableBuilder("foo", componentDataCache); + DefaultSymbolTableBuilder symbolTableBuilder = new DefaultSymbolTableBuilder("foo", componentDataCache); symbolTableBuilder.newSymbol(10, 20); symbolTableBuilder.done(); @@ -87,7 +86,7 @@ public class DefaultSymbolTableBuilderTest { throwable.expect(UnsupportedOperationException.class); ComponentDataCache componentDataCache = mock(ComponentDataCache.class); - SymbolTableBuilder symbolTableBuilder = new DefaultSymbolTableBuilder("foo", componentDataCache); + DefaultSymbolTableBuilder symbolTableBuilder = new DefaultSymbolTableBuilder("foo", componentDataCache); Symbol symbol = symbolTableBuilder.newSymbol(10, 20); symbolTableBuilder.newReference(symbol, 15); } @@ -97,10 +96,10 @@ public class DefaultSymbolTableBuilderTest { throwable.expect(UnsupportedOperationException.class); ComponentDataCache componentDataCache = mock(ComponentDataCache.class); - SymbolTableBuilder symbolTableBuilder = new DefaultSymbolTableBuilder("foo", componentDataCache); + DefaultSymbolTableBuilder symbolTableBuilder = new DefaultSymbolTableBuilder("foo", componentDataCache); Symbol symbol = symbolTableBuilder.newSymbol(10, 20); - SymbolTableBuilder symbolTableBuilder2 = new DefaultSymbolTableBuilder("foo2", componentDataCache); + DefaultSymbolTableBuilder symbolTableBuilder2 = new DefaultSymbolTableBuilder("foo2", componentDataCache); Symbol symbol2 = symbolTableBuilder2.newSymbol(30, 40); symbolTableBuilder.newReference(symbol2, 15); diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java index b07a14560a2..91c039763fc 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java @@ -22,7 +22,6 @@ package org.sonar.api.batch.sensor; import org.sonar.api.batch.AnalysisMode; import org.sonar.api.batch.CpdMapping; import org.sonar.api.batch.fs.FileSystem; -import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.rule.ActiveRules; import org.sonar.api.batch.sensor.dependency.NewDependency; import org.sonar.api.batch.sensor.duplication.NewDuplication; @@ -31,7 +30,6 @@ import org.sonar.api.batch.sensor.issue.Issue; import org.sonar.api.batch.sensor.issue.NewIssue; import org.sonar.api.batch.sensor.measure.Measure; import org.sonar.api.batch.sensor.measure.NewMeasure; -import org.sonar.api.batch.sensor.symbol.SymbolTableBuilder; import org.sonar.api.config.Settings; import java.io.Serializable; @@ -85,10 +83,7 @@ public interface SensorContext { // ------------ SYMBOL REFERENCES ------------ - /** - * Builder to define symbol references in a file. - */ - SymbolTableBuilder symbolTableBuilder(InputFile inputFile); + // TODO // ------------ DUPLICATIONS ------------ diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/symbol/Symbol.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/symbol/Symbol.java deleted file mode 100644 index 72f0bf92980..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/symbol/Symbol.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube 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. - * - * SonarQube 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. - */ - -package org.sonar.api.batch.sensor.symbol; - -import com.google.common.annotations.Beta; - -/** - * Represent a symbol in a source file. Experimental, do not use - * @since 4.5 - */ -@Beta -public interface Symbol { - - int getDeclarationStartOffset(); - - int getDeclarationEndOffset(); - -} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/symbol/SymbolTableBuilder.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/symbol/SymbolTableBuilder.java deleted file mode 100644 index e9ebd8c72fc..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/symbol/SymbolTableBuilder.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube 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. - * - * SonarQube 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. - */ -package org.sonar.api.batch.sensor.symbol; - -import com.google.common.annotations.Beta; - -/** - * Experimental, do not use. - *

- * Use this builder to create symbol references. For now only references - * in the same file are supported. - * @since 4.5 - */ -@Beta -public interface SymbolTableBuilder { - - /** - * Create a new symbol. - * @param fromOffset Starting offset in a file for the symbol declaration. File starts at offset '0'. - * @param toOffset Ending offset of symbol declaration. - * @return a new Symbol that can be used later in {@link #newReference(Symbol, int)} - */ - Symbol newSymbol(int fromOffset, int toOffset); - - /** - * Records that a {@link Symbol} is referenced at another location in the same file. - * @param symbol Symbol previously created with {@link #newSymbol(int, int)} - * @param fromOffset Starting offset of the place symbol is referenced. No need for end offset here since we assume it is same length. - */ - void newReference(Symbol symbol, int fromOffset); - - /** - * Call this method only once when your are done with defining symbols of the file. - */ - void done(); -} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/symbol/internal/DefaultSymbol.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/symbol/internal/DefaultSymbol.java deleted file mode 100644 index 8fe4b83529f..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/symbol/internal/DefaultSymbol.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube 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. - * - * SonarQube 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. - */ - -package org.sonar.api.batch.sensor.symbol.internal; - -import com.google.common.base.Objects; -import org.sonar.api.batch.sensor.symbol.Symbol; - -import java.io.Serializable; - -public class DefaultSymbol implements Symbol, org.sonar.api.source.Symbol, Serializable { - - private final int declarationStartOffset; - private final int declarationEndOffset; - - public DefaultSymbol(int startOffset, int endOffset) { - this.declarationStartOffset = startOffset; - this.declarationEndOffset = endOffset; - } - - @Override - public int getDeclarationStartOffset() { - return declarationStartOffset; - } - - @Override - public int getDeclarationEndOffset() { - return declarationEndOffset; - } - - @Override - public String getFullyQualifiedName() { - return null; - } - - @Override - public String toString() { - return Objects.toStringHelper("Symbol") - .add("offset", String.format("%d-%d", declarationStartOffset, declarationEndOffset)) - .toString(); - } -} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/symbol/internal/package-info.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/symbol/internal/package-info.java deleted file mode 100644 index e0ccdf1c9b3..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/symbol/internal/package-info.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube 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. - * - * SonarQube 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. - */ -@javax.annotation.ParametersAreNonnullByDefault -package org.sonar.api.batch.sensor.symbol.internal; diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/symbol/package-info.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/symbol/package-info.java deleted file mode 100644 index 7acf7f3b056..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/symbol/package-info.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube 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. - * - * SonarQube 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. - */ -@javax.annotation.ParametersAreNonnullByDefault -package org.sonar.api.batch.sensor.symbol; diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/source/Symbol.java b/sonar-plugin-api/src/main/java/org/sonar/api/source/Symbol.java index 9aa8ae26900..dd4c7d40883 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/source/Symbol.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/source/Symbol.java @@ -20,12 +20,10 @@ package org.sonar.api.source; -public interface Symbol extends org.sonar.api.batch.sensor.symbol.Symbol { +public interface Symbol { - @Override int getDeclarationStartOffset(); - @Override int getDeclarationEndOffset(); /**