]> source.dussan.org Git - sonarqube.git/commitdiff
Deprecated the unused Symbol#getFullyQualifiedName() and improve exception message
authorSimon Brandhof <simon.brandhof@gmail.com>
Thu, 3 Apr 2014 14:42:54 +0000 (16:42 +0200)
committerSimon Brandhof <simon.brandhof@gmail.com>
Thu, 3 Apr 2014 14:42:54 +0000 (16:42 +0200)
sonar-batch/src/main/java/org/sonar/batch/source/DefaultSymbol.java
sonar-batch/src/main/java/org/sonar/batch/source/DefaultSymbolTable.java
sonar-batch/src/test/java/org/sonar/batch/source/DefaultSymbolTableTest.java
sonar-plugin-api/src/main/java/org/sonar/api/source/Symbol.java

index da0d4193e72d03726329841f89726f5bd338116a..629633a05deb63ceffa327aff0ab87d3f6e8aecf 100644 (file)
 
 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();
   }
 }
index b49c87ec98df17c36337257b840b13e4756bd53c..0d66c31b8f178ec67d2c818654334852a9d7bb63 100644 (file)
@@ -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);
     }
index b39a347d1136fb0ee8d67a01ed6be9b9b61df255..2e65c12473b0ac83971a677f2536b44be35ad82c 100644 (file)
@@ -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}");
+  }
 }
index 32ef2a515411e197775b5e61027125af125586a8..260d6c8ecd71991a767db72999104a5c39edccf7 100644 (file)
@@ -26,5 +26,10 @@ public interface Symbol {
 
   int getDeclarationEndOffset();
 
+  /**
+   * @since unused
+   * @deprecated in 4.3
+   */
+  @Deprecated
   String getFullyQualifiedName();
 }