From 71b97ad9af2ba00f153139c28b5c2ccdc139e67a Mon Sep 17 00:00:00 2001 From: Julien HENRY Date: Thu, 12 May 2016 11:44:19 +0200 Subject: [PATCH] SONAR-7512 Backport ability to use line/offset on Symbolizable API --- .../main/java/org/sonar/api/source/Symbolizable.java | 10 ++++++++++ .../org/sonar/batch/source/DefaultSymbolizable.java | 10 ++++++++++ .../batch/source/DeprecatedDefaultSymbolTable.java | 12 ++++++++++++ 3 files changed, 32 insertions(+) diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/source/Symbolizable.java b/sonar-plugin-api/src/main/java/org/sonar/api/source/Symbolizable.java index 98177598ef1..507c1c7186f 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/source/Symbolizable.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/source/Symbolizable.java @@ -41,6 +41,11 @@ public interface Symbolizable extends Perspective { */ Symbol newSymbol(int fromOffset, int toOffset); + /** + * @since 5.6 + */ + Symbol newSymbol(int startLine, int startLineOffset, int endLine, int endLineOffset); + /** * Creates a new reference for a symbol. * The length of the reference is assumed to be the same as the symbol's length. @@ -55,6 +60,11 @@ public interface Symbolizable extends Perspective { */ void newReference(Symbol symbol, int fromOffset, int toOffset); + /** + * @since 5.6 + */ + void newReference(Symbol symbol, int startLine, int startLineOffset, int endLine, int endLineOffset); + /** * Creates a {@link SymbolTable} containing all symbols and references previously created in this file. */ 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 04c7f560e9e..a2a380c71e6 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 @@ -40,6 +40,11 @@ public class DefaultSymbolizable implements Symbolizable { return NO_OP_SYMBOL; } + @Override + public Symbol newSymbol(int startLine, int startLineOffset, int endLine, int endLineOffset) { + return NO_OP_SYMBOL; + } + @Override public void newReference(Symbol symbol, int fromOffset) { // Do nothing @@ -50,6 +55,11 @@ public class DefaultSymbolizable implements Symbolizable { // Do nothing } + @Override + public void newReference(Symbol symbol, int startLine, int startLineOffset, int endLine, int endLineOffset) { + // Do nothing + } + @Override public SymbolTable build() { return NO_OP_SYMBOL_TABLE; 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 index a902b017e8c..78ab4ec11ff 100644 --- 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 @@ -59,6 +59,13 @@ public class DeprecatedDefaultSymbolTable implements Symbolizable.SymbolTable { return new DeprecatedDefaultSymbol(symbolTable.newSymbol(fromOffset, toOffset), toOffset - fromOffset); } + @Override + public Symbol newSymbol(int startLine, int startLineOffset, int endLine, int endLineOffset) { + // This is wrong in case of multiline symbol bu I assume references will be added using start and end offsets so length is useless. + int length = endLineOffset - startLineOffset; + return new DeprecatedDefaultSymbol(symbolTable.newSymbol(startLine, startLineOffset, endLine, endLineOffset), length); + } + @Override public void newReference(Symbol symbol, int fromOffset) { ((DeprecatedDefaultSymbol) symbol).getWrapped().newReference(fromOffset, fromOffset + ((DeprecatedDefaultSymbol) symbol).getLength()); @@ -69,6 +76,11 @@ public class DeprecatedDefaultSymbolTable implements Symbolizable.SymbolTable { ((DeprecatedDefaultSymbol) symbol).getWrapped().newReference(fromOffset, toOffset); } + @Override + public void newReference(Symbol symbol, int startLine, int startLineOffset, int endLine, int endLineOffset) { + ((DeprecatedDefaultSymbol) symbol).getWrapped().newReference(startLine, startLineOffset, endLine, endLineOffset); + } + @Override public Symbolizable.SymbolTable build() { return new DeprecatedDefaultSymbolTable(symbolTable); -- 2.39.5