From de08304be81c812b2d1b712dce2c6fc9530aab39 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Thu, 3 Apr 2014 16:42:54 +0200 Subject: [PATCH] Deprecated the unused Symbol#getFullyQualifiedName() and improve exception message --- .../org/sonar/batch/source/DefaultSymbol.java | 16 ++++++++++------ .../sonar/batch/source/DefaultSymbolTable.java | 4 ++-- .../batch/source/DefaultSymbolTableTest.java | 10 ++++++++-- .../main/java/org/sonar/api/source/Symbol.java | 5 +++++ 4 files changed, 25 insertions(+), 10 deletions(-) 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 index da0d4193e72..629633a05de 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/source/DefaultSymbol.java +++ b/sonar-batch/src/main/java/org/sonar/batch/source/DefaultSymbol.java @@ -20,20 +20,17 @@ package org.sonar.batch.source; +import com.google.common.base.Objects; import org.sonar.api.source.Symbol; -import javax.annotation.Nullable; - public class DefaultSymbol implements Symbol { private final int declarationStartOffset; private final int declarationEndOffset; - private final String fullyQualifiedName; - public DefaultSymbol(int startOffset, int endOffset, @Nullable String fullyQualifiedName) { + public DefaultSymbol(int startOffset, int endOffset) { this.declarationStartOffset = startOffset; this.declarationEndOffset = endOffset; - this.fullyQualifiedName = fullyQualifiedName; } public int getDeclarationStartOffset() { @@ -45,6 +42,13 @@ public class DefaultSymbol implements Symbol { } public String getFullyQualifiedName() { - return fullyQualifiedName; + 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 b49c87ec98d..0d66c31b8f1 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 @@ -66,7 +66,7 @@ public class DefaultSymbolTable implements Symbolizable.SymbolTable { @Override public Symbol newSymbol(int fromOffset, int toOffset) { - Symbol symbol = new DefaultSymbol(fromOffset, toOffset, null); + Symbol symbol = new DefaultSymbol(fromOffset, toOffset); referencesBySymbol.put(symbol, symbol.getDeclarationStartOffset()); return symbol; } @@ -74,7 +74,7 @@ public class DefaultSymbolTable implements Symbolizable.SymbolTable { @Override public void newReference(Symbol symbol, int fromOffset) { if (fromOffset >= symbol.getDeclarationStartOffset() && fromOffset < symbol.getDeclarationEndOffset()) { - throw new UnsupportedOperationException("Cannot add reference overlapping the symbol declaration"); + throw new UnsupportedOperationException("Cannot add reference (" + fromOffset + ") overlapping " + symbol); } referencesBySymbol.put(symbol, fromOffset); } diff --git a/sonar-batch/src/test/java/org/sonar/batch/source/DefaultSymbolTableTest.java b/sonar-batch/src/test/java/org/sonar/batch/source/DefaultSymbolTableTest.java index b39a347d113..2e65c12473b 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/source/DefaultSymbolTableTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/source/DefaultSymbolTableTest.java @@ -35,7 +35,6 @@ public class DefaultSymbolTableTest { @Test public void should_order_symbol_and_references() throws Exception { - Symbolizable.SymbolTableBuilder symbolTableBuilder = new DefaultSymbolTable.Builder(); Symbol firstSymbol = symbolTableBuilder.newSymbol(10, 20); symbolTableBuilder.newReference(firstSymbol, 32); @@ -53,11 +52,18 @@ public class DefaultSymbolTableTest { @Test public void should_reject_reference_conflicting_with_declaration() throws Exception { - throwable.expect(UnsupportedOperationException.class); Symbolizable.SymbolTableBuilder symbolTableBuilder = new DefaultSymbolTable.Builder(); Symbol symbol = symbolTableBuilder.newSymbol(10, 20); symbolTableBuilder.newReference(symbol, 15); } + + @Test + public void test_toString() throws Exception { + Symbolizable.SymbolTableBuilder symbolTableBuilder = new DefaultSymbolTable.Builder(); + Symbol symbol = symbolTableBuilder.newSymbol(10, 20); + + assertThat(symbol.toString()).isEqualTo("Symbol{offset=10-20}"); + } } 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 32ef2a51541..260d6c8ecd7 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 @@ -26,5 +26,10 @@ public interface Symbol { int getDeclarationEndOffset(); + /** + * @since unused + * @deprecated in 4.3 + */ + @Deprecated String getFullyQualifiedName(); } -- 2.39.5