aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2016-05-10 14:48:31 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2016-05-10 16:25:05 +0200
commit08aef06a32939cea56269e111969178bd19f74ac (patch)
treefb72a9868f6f42e01b9b85d127f0f99ca9168b89 /sonar-scanner-engine
parent5ae4a897295e5ce2b265fb6ea9784fb11128008f (diff)
downloadsonarqube-08aef06a32939cea56269e111969178bd19f74ac.tar.gz
sonarqube-08aef06a32939cea56269e111969178bd19f74ac.zip
SONAR-7512 New symbol reference API
Diffstat (limited to 'sonar-scanner-engine')
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/batch/sensor/DefaultSensorContext.java12
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/batch/sensor/DefaultSensorStorage.java22
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/batch/sensor/noop/NoOpNewSymbolTable.java75
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/batch/source/DefaultSymbolTable.java123
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/batch/source/DefaultSymbolizable.java5
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/batch/source/DeprecatedDefaultSymbol.java (renamed from sonar-scanner-engine/src/main/java/org/sonar/batch/source/DefaultSymbol.java)25
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/batch/source/DeprecatedDefaultSymbolTable.java78
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/batch/source/DefaultSymbolizableTest.java9
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/batch/source/DeprecatedDefaultSymbolTableTest.java (renamed from sonar-scanner-engine/src/test/java/org/sonar/batch/source/DefaultSymbolTableTest.java)34
9 files changed, 205 insertions, 178 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/sensor/DefaultSensorContext.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/sensor/DefaultSensorContext.java
index 48dde9fd12d..f8a88f24b63 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/batch/sensor/DefaultSensorContext.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/batch/sensor/DefaultSensorContext.java
@@ -37,14 +37,18 @@ 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.NewSymbolTable;
+import org.sonar.api.batch.sensor.symbol.internal.DefaultSymbolTable;
import org.sonar.api.config.Settings;
import org.sonar.api.utils.Version;
import org.sonar.batch.sensor.noop.NoOpNewCpdTokens;
import org.sonar.batch.sensor.noop.NoOpNewHighlighting;
+import org.sonar.batch.sensor.noop.NoOpNewSymbolTable;
public class DefaultSensorContext implements SensorContext {
private static final NoOpNewHighlighting NO_OP_NEW_HIGHLIGHTING = new NoOpNewHighlighting();
+ private static final NoOpNewSymbolTable NO_OP_NEW_SYMBOL_TABLE = new NoOpNewSymbolTable();
private static final NoOpNewCpdTokens NO_OP_NEW_CPD_TOKENS = new NoOpNewCpdTokens();
private final Settings settings;
@@ -110,6 +114,14 @@ public class DefaultSensorContext implements SensorContext {
}
@Override
+ public NewSymbolTable newSymbolTable() {
+ if (analysisMode.isIssues()) {
+ return NO_OP_NEW_SYMBOL_TABLE;
+ }
+ return new DefaultSymbolTable(sensorStorage);
+ }
+
+ @Override
public NewCoverage newCoverage() {
return new DefaultCoverage(sensorStorage);
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/sensor/DefaultSensorStorage.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/sensor/DefaultSensorStorage.java
index ce3ae500bd1..e80a5627c41 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/batch/sensor/DefaultSensorStorage.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/batch/sensor/DefaultSensorStorage.java
@@ -45,12 +45,12 @@ import org.sonar.api.batch.sensor.internal.SensorStorage;
import org.sonar.api.batch.sensor.issue.Issue;
import org.sonar.api.batch.sensor.measure.Measure;
import org.sonar.api.batch.sensor.measure.internal.DefaultMeasure;
+import org.sonar.api.batch.sensor.symbol.internal.DefaultSymbolTable;
import org.sonar.api.config.Settings;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.Metric;
import org.sonar.api.resources.File;
import org.sonar.api.resources.Resource;
-import org.sonar.api.source.Symbol;
import org.sonar.api.utils.KeyValueFormat;
import org.sonar.api.utils.SonarException;
import org.sonar.batch.cpd.deprecated.DefaultCpdBlockIndexer;
@@ -62,7 +62,6 @@ import org.sonar.batch.report.ReportPublisher;
import org.sonar.batch.report.ScannerReportUtils;
import org.sonar.batch.scan.measure.MeasureCache;
import org.sonar.batch.sensor.coverage.CoverageExclusions;
-import org.sonar.batch.source.DefaultSymbol;
import org.sonar.duplications.block.Block;
import org.sonar.duplications.internal.pmd.PmdBlockChunker;
import org.sonar.scanner.protocol.output.ScannerReport;
@@ -199,22 +198,23 @@ public class DefaultSensorStorage implements SensorStorage {
Iterables.transform(highlighting.getSyntaxHighlightingRuleSet(), new BuildSyntaxHighlighting()));
}
- public void store(DefaultInputFile inputFile, Map<Symbol, Set<TextRange>> referencesBySymbol) {
+ @Override
+ public void store(DefaultSymbolTable symbolTable) {
ScannerReportWriter writer = reportPublisher.getWriter();
- writer.writeComponentSymbols(componentCache.get(inputFile).batchId(),
- Iterables.transform(referencesBySymbol.entrySet(), new Function<Map.Entry<Symbol, Set<TextRange>>, ScannerReport.Symbol>() {
+ writer.writeComponentSymbols(componentCache.get(symbolTable.inputFile()).batchId(),
+ Iterables.transform(symbolTable.getReferencesBySymbol().entrySet(), new Function<Map.Entry<TextRange, Set<TextRange>>, ScannerReport.Symbol>() {
private ScannerReport.Symbol.Builder builder = ScannerReport.Symbol.newBuilder();
private ScannerReport.TextRange.Builder rangeBuilder = ScannerReport.TextRange.newBuilder();
@Override
- public ScannerReport.Symbol apply(Map.Entry<Symbol, Set<TextRange>> input) {
+ public ScannerReport.Symbol apply(Map.Entry<TextRange, Set<TextRange>> input) {
builder.clear();
rangeBuilder.clear();
- DefaultSymbol symbol = (DefaultSymbol) input.getKey();
- builder.setDeclaration(rangeBuilder.setStartLine(symbol.range().start().line())
- .setStartOffset(symbol.range().start().lineOffset())
- .setEndLine(symbol.range().end().line())
- .setEndOffset(symbol.range().end().lineOffset())
+ TextRange declaration = input.getKey();
+ builder.setDeclaration(rangeBuilder.setStartLine(declaration.start().line())
+ .setStartOffset(declaration.start().lineOffset())
+ .setEndLine(declaration.end().line())
+ .setEndOffset(declaration.end().lineOffset())
.build());
for (TextRange reference : input.getValue()) {
builder.addReference(rangeBuilder.setStartLine(reference.start().line())
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/sensor/noop/NoOpNewSymbolTable.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/sensor/noop/NoOpNewSymbolTable.java
new file mode 100644
index 00000000000..46e8ed22e29
--- /dev/null
+++ b/sonar-scanner-engine/src/main/java/org/sonar/batch/sensor/noop/NoOpNewSymbolTable.java
@@ -0,0 +1,75 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.
+ */
+package org.sonar.batch.sensor.noop;
+
+import org.sonar.api.batch.fs.InputFile;
+import org.sonar.api.batch.fs.TextRange;
+import org.sonar.api.batch.sensor.symbol.NewSymbol;
+import org.sonar.api.batch.sensor.symbol.NewSymbolTable;
+
+public class NoOpNewSymbolTable implements NewSymbolTable, NewSymbol {
+ @Override
+ public void save() {
+ // Do nothing
+ }
+
+ @Override
+ public NoOpNewSymbolTable onFile(InputFile inputFile) {
+ // Do nothing
+ return this;
+ }
+
+ @Override
+ public NewSymbol newSymbol(int startOffset, int endOffset) {
+ // Do nothing
+ return this;
+ }
+
+ @Override
+ public NewSymbol newSymbol(int startLine, int startLineOffset, int endLine, int endLineOffset) {
+ // Do nothing
+ return this;
+ }
+
+ @Override
+ public NewSymbol newSymbol(TextRange range) {
+ // Do nothing
+ return this;
+ }
+
+ @Override
+ public NewSymbol newReference(int startLine, int startLineOffset, int endLine, int endLineOffset) {
+ // Do nothing
+ return this;
+ }
+
+ @Override
+ public NewSymbol newReference(int startOffset, int endOffset) {
+ // Do nothing
+ return this;
+ }
+
+ @Override
+ public NewSymbol newReference(TextRange range) {
+ // Do nothing
+ return this;
+ }
+
+}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/source/DefaultSymbolTable.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/source/DefaultSymbolTable.java
deleted file mode 100644
index f4ecc8e3761..00000000000
--- a/sonar-scanner-engine/src/main/java/org/sonar/batch/source/DefaultSymbolTable.java
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact 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.
- */
-package org.sonar.batch.source;
-
-import java.util.ArrayList;
-import java.util.Comparator;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeSet;
-import org.sonar.api.batch.fs.TextRange;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
-import org.sonar.api.source.Symbol;
-import org.sonar.api.source.Symbolizable;
-
-public class DefaultSymbolTable implements Symbolizable.SymbolTable {
-
- private Map<Symbol, Set<TextRange>> referencesBySymbol;
-
- private DefaultSymbolTable(Map<Symbol, Set<TextRange>> referencesBySymbol) {
- this.referencesBySymbol = referencesBySymbol;
- }
-
- public Map<Symbol, Set<TextRange>> getReferencesBySymbol() {
- return referencesBySymbol;
- }
-
- @Override
- public List<Symbol> symbols() {
- List<Symbol> result = new ArrayList<>();
- for (Symbol symbol : referencesBySymbol.keySet()) {
- result.add((Symbol) symbol);
- }
- return result;
- }
-
- @Override
- public List<Integer> references(Symbol symbol) {
- throw new UnsupportedOperationException("references");
- }
-
- public static class Builder implements Symbolizable.SymbolTableBuilder {
-
- private static final class FakeSymbol implements Symbol {
- @Override
- public String getFullyQualifiedName() {
- return null;
- }
-
- @Override
- public int getDeclarationStartOffset() {
- return 0;
- }
-
- @Override
- public int getDeclarationEndOffset() {
- return 0;
- }
- }
-
- private final Map<Symbol, Set<TextRange>> referencesBySymbol = new LinkedHashMap<>();
- private final DefaultInputFile inputFile;
-
- public Builder(DefaultInputFile inputFile) {
- this.inputFile = inputFile;
- }
-
- @Override
- public Symbol newSymbol(int fromOffset, int toOffset) {
- TextRange declarationRange = inputFile.newRange(fromOffset, toOffset);
- DefaultSymbol symbol = new DefaultSymbol(declarationRange, toOffset - fromOffset);
- referencesBySymbol.put(symbol, new TreeSet<>(new Comparator<TextRange>() {
- @Override
- public int compare(TextRange o1, TextRange o2) {
- return o1.start().compareTo(o2.start());
- }
- }));
- return symbol;
- }
-
- @Override
- public void newReference(Symbol symbol, int fromOffset) {
- newReference(symbol, fromOffset, fromOffset + ((DefaultSymbol) symbol).getLength());
- }
-
- @Override
- public void newReference(Symbol symbol, int fromOffset, int toOffset) {
- if (!referencesBySymbol.containsKey(symbol)) {
- throw new UnsupportedOperationException("Cannot add reference to a symbol in another file");
- }
- TextRange referenceRange = inputFile.newRange(fromOffset, toOffset);
-
- if (referenceRange.overlap(((DefaultSymbol) symbol).range())) {
- throw new UnsupportedOperationException("Cannot add reference (" + fromOffset + ") overlapping " + symbol + " in " + inputFile.key());
- }
- referencesBySymbol.get(symbol).add(referenceRange);
- }
-
- @Override
- public Symbolizable.SymbolTable build() {
- return new DefaultSymbolTable(referencesBySymbol);
- }
-
- }
-}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/source/DefaultSymbolizable.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/source/DefaultSymbolizable.java
index cddeabb9683..04c7f560e9e 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/batch/source/DefaultSymbolizable.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/batch/source/DefaultSymbolizable.java
@@ -23,6 +23,7 @@ import java.util.Collections;
import java.util.List;
import org.sonar.api.batch.AnalysisMode;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
+import org.sonar.api.batch.sensor.symbol.internal.DefaultSymbolTable;
import org.sonar.api.source.Symbol;
import org.sonar.api.source.Symbolizable;
import org.sonar.batch.sensor.DefaultSensorStorage;
@@ -99,7 +100,7 @@ public class DefaultSymbolizable implements Symbolizable {
if (analysisMode.isIssues()) {
return NO_OP_SYMBOL_TABLE_BUILDER;
}
- return new DefaultSymbolTable.Builder(inputFile);
+ return new DeprecatedDefaultSymbolTable.Builder(new DefaultSymbolTable(sensorStorage).onFile(inputFile));
}
@Override
@@ -108,6 +109,6 @@ public class DefaultSymbolizable implements Symbolizable {
// No need for symbols in issues mode
return;
}
- sensorStorage.store(inputFile, ((DefaultSymbolTable) symbolTable).getReferencesBySymbol());
+ ((DeprecatedDefaultSymbolTable) symbolTable).getWrapped().save();
}
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/source/DefaultSymbol.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/source/DeprecatedDefaultSymbol.java
index a317bfb2de8..e63dc70b141 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/batch/source/DefaultSymbol.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/batch/source/DeprecatedDefaultSymbol.java
@@ -19,18 +19,15 @@
*/
package org.sonar.batch.source;
-import com.google.common.base.Objects;
-import org.sonar.api.batch.fs.TextRange;
+import org.sonar.api.batch.sensor.symbol.NewSymbol;
-import java.io.Serializable;
+public class DeprecatedDefaultSymbol implements org.sonar.api.source.Symbol {
-public class DefaultSymbol implements org.sonar.api.source.Symbol, Serializable {
+ private final NewSymbol wrapped;
+ private final int length;
- private TextRange range;
- private int length;
-
- public DefaultSymbol(TextRange range, int length) {
- this.range = range;
+ public DeprecatedDefaultSymbol(NewSymbol newSymbol, int length) {
+ this.wrapped = newSymbol;
this.length = length;
}
@@ -49,18 +46,12 @@ public class DefaultSymbol implements org.sonar.api.source.Symbol, Serializable
throw new UnsupportedOperationException("getFullyQualifiedName");
}
- public TextRange range() {
- return range;
+ public NewSymbol getWrapped() {
+ return wrapped;
}
public int getLength() {
return length;
}
- @Override
- public String toString() {
- return Objects.toStringHelper("Symbol")
- .add("range", range)
- .toString();
- }
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/source/DeprecatedDefaultSymbolTable.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/source/DeprecatedDefaultSymbolTable.java
new file mode 100644
index 00000000000..a902b017e8c
--- /dev/null
+++ b/sonar-scanner-engine/src/main/java/org/sonar/batch/source/DeprecatedDefaultSymbolTable.java
@@ -0,0 +1,78 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.
+ */
+package org.sonar.batch.source;
+
+import java.util.List;
+import org.sonar.api.batch.sensor.symbol.internal.DefaultSymbolTable;
+import org.sonar.api.source.Symbol;
+import org.sonar.api.source.Symbolizable;
+
+public class DeprecatedDefaultSymbolTable implements Symbolizable.SymbolTable {
+
+ private final DefaultSymbolTable wrapped;
+
+ public DeprecatedDefaultSymbolTable(DefaultSymbolTable wrapped) {
+ this.wrapped = wrapped;
+ }
+
+ public DefaultSymbolTable getWrapped() {
+ return wrapped;
+ }
+
+ @Override
+ public List<Symbol> symbols() {
+ throw new UnsupportedOperationException("symbols");
+ }
+
+ @Override
+ public List<Integer> references(Symbol symbol) {
+ throw new UnsupportedOperationException("references");
+ }
+
+ public static class Builder implements Symbolizable.SymbolTableBuilder {
+
+ private final DefaultSymbolTable symbolTable;
+
+ public Builder(DefaultSymbolTable symbolTable) {
+ this.symbolTable = symbolTable;
+ }
+
+ @Override
+ public Symbol newSymbol(int fromOffset, int toOffset) {
+ return new DeprecatedDefaultSymbol(symbolTable.newSymbol(fromOffset, toOffset), toOffset - fromOffset);
+ }
+
+ @Override
+ public void newReference(Symbol symbol, int fromOffset) {
+ ((DeprecatedDefaultSymbol) symbol).getWrapped().newReference(fromOffset, fromOffset + ((DeprecatedDefaultSymbol) symbol).getLength());
+ }
+
+ @Override
+ public void newReference(Symbol symbol, int fromOffset, int toOffset) {
+ ((DeprecatedDefaultSymbol) symbol).getWrapped().newReference(fromOffset, toOffset);
+ }
+
+ @Override
+ public Symbolizable.SymbolTable build() {
+ return new DeprecatedDefaultSymbolTable(symbolTable);
+ }
+
+ }
+}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/source/DefaultSymbolizableTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/source/DefaultSymbolizableTest.java
index f19a4b04099..a6dde755b35 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/batch/source/DefaultSymbolizableTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/batch/source/DefaultSymbolizableTest.java
@@ -21,18 +21,17 @@ package org.sonar.batch.source;
import com.google.common.base.Strings;
import java.io.StringReader;
-import java.util.Map;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.sonar.api.batch.AnalysisMode;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
import org.sonar.api.batch.fs.internal.FileMetadata;
+import org.sonar.api.batch.sensor.symbol.internal.DefaultSymbolTable;
import org.sonar.api.source.Symbol;
import org.sonar.api.source.Symbolizable;
import org.sonar.batch.sensor.DefaultSensorStorage;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@@ -58,9 +57,9 @@ public class DefaultSymbolizableTest {
symbolPerspective.setSymbolTable(symbolTable);
- ArgumentCaptor<Map> argCaptor = ArgumentCaptor.forClass(Map.class);
- verify(sensorStorage).store(eq(inputFile), argCaptor.capture());
+ ArgumentCaptor<DefaultSymbolTable> argCaptor = ArgumentCaptor.forClass(DefaultSymbolTable.class);
+ verify(sensorStorage).store(argCaptor.capture());
// Map<Symbol, Set<TextRange>>
- assertThat(argCaptor.getValue().keySet()).hasSize(2);
+ assertThat(argCaptor.getValue().getReferencesBySymbol().keySet()).hasSize(2);
}
}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/source/DefaultSymbolTableTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/source/DeprecatedDefaultSymbolTableTest.java
index 86c7b7b316d..e8b6d6df380 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/batch/source/DefaultSymbolTableTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/batch/source/DeprecatedDefaultSymbolTableTest.java
@@ -19,23 +19,23 @@
*/
package org.sonar.batch.source;
-import org.sonar.api.batch.fs.TextRange;
import com.google.common.base.Strings;
-
import java.io.StringReader;
import java.util.Set;
-
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
+import org.sonar.api.batch.fs.TextRange;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
import org.sonar.api.batch.fs.internal.FileMetadata;
+import org.sonar.api.batch.sensor.symbol.internal.DefaultSymbolTable;
import org.sonar.api.source.Symbol;
import org.sonar.api.source.Symbolizable;
+
import static org.assertj.core.api.Assertions.assertThat;
-public class DefaultSymbolTableTest {
+public class DeprecatedDefaultSymbolTableTest {
@Rule
public ExpectedException throwable = ExpectedException.none();
@@ -50,30 +50,31 @@ public class DefaultSymbolTableTest {
@Test
public void should_order_symbol_and_references() {
- Symbolizable.SymbolTableBuilder symbolTableBuilder = new DefaultSymbolTable.Builder(inputFile);
+ Symbolizable.SymbolTableBuilder symbolTableBuilder = new DeprecatedDefaultSymbolTable.Builder(new DefaultSymbolTable(null).onFile(inputFile));
Symbol firstSymbol = symbolTableBuilder.newSymbol(10, 20);
symbolTableBuilder.newReference(firstSymbol, 32);
Symbol secondSymbol = symbolTableBuilder.newSymbol(84, 92);
symbolTableBuilder.newReference(secondSymbol, 124);
Symbol thirdSymbol = symbolTableBuilder.newSymbol(55, 62);
symbolTableBuilder.newReference(thirdSymbol, 70);
- Symbolizable.SymbolTable symbolTable = symbolTableBuilder.build();
- assertThat(symbolTable.symbols()).containsExactly(firstSymbol, secondSymbol, thirdSymbol);
+ DeprecatedDefaultSymbolTable symbolTable = (DeprecatedDefaultSymbolTable) symbolTableBuilder.build();
+
+ assertThat(symbolTable.getWrapped().getReferencesBySymbol().keySet()).containsExactly(range(10, 20), range(84, 92), range(55, 62));
}
@Test
public void variable_length_references() {
- Symbolizable.SymbolTableBuilder symbolTableBuilder = new DefaultSymbolTable.Builder(inputFile);
+ Symbolizable.SymbolTableBuilder symbolTableBuilder = new DeprecatedDefaultSymbolTable.Builder(new DefaultSymbolTable(null).onFile(inputFile));
Symbol firstSymbol = symbolTableBuilder.newSymbol(10, 20);
symbolTableBuilder.newReference(firstSymbol, 32);
symbolTableBuilder.newReference(firstSymbol, 44, 47);
- DefaultSymbolTable symbolTable = (DefaultSymbolTable) symbolTableBuilder.build();
+ DeprecatedDefaultSymbolTable symbolTable = (DeprecatedDefaultSymbolTable) symbolTableBuilder.build();
- assertThat(symbolTable.symbols()).containsExactly(firstSymbol);
+ assertThat(symbolTable.getWrapped().getReferencesBySymbol().keySet()).containsExactly(range(10, 20));
- Set<TextRange> references = symbolTable.getReferencesBySymbol().get(firstSymbol);
+ Set<TextRange> references = symbolTable.getWrapped().getReferencesBySymbol().get(range(10, 20));
assertThat(references).containsExactly(range(32, 42), range(44, 47));
}
@@ -83,18 +84,11 @@ public class DefaultSymbolTableTest {
@Test
public void should_reject_reference_conflicting_with_declaration() {
- throwable.expect(UnsupportedOperationException.class);
+ throwable.expect(IllegalArgumentException.class);
- Symbolizable.SymbolTableBuilder symbolTableBuilder = new DefaultSymbolTable.Builder(inputFile);
+ Symbolizable.SymbolTableBuilder symbolTableBuilder = new DeprecatedDefaultSymbolTable.Builder(new DefaultSymbolTable(null).onFile(inputFile));
Symbol symbol = symbolTableBuilder.newSymbol(10, 20);
symbolTableBuilder.newReference(symbol, 15);
}
- @Test
- public void test_toString() throws Exception {
- Symbolizable.SymbolTableBuilder symbolTableBuilder = new DefaultSymbolTable.Builder(inputFile);
- Symbol symbol = symbolTableBuilder.newSymbol(10, 20);
-
- assertThat(symbol.toString()).isEqualTo("Symbol{range=Range[from [line=2, lineOffset=3] to [line=3, lineOffset=6]]}");
- }
}