summaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2014-07-24 17:16:41 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2014-07-24 17:25:10 +0200
commit2a510a2f76d2f384deba2eec2ca6a9297c0ebc63 (patch)
treebef0154a601465671ce3a2f074da3a4d09140b37 /sonar-plugin-api
parentecea6110fad63f12345422d0e868f9b89ec6dc70 (diff)
downloadsonarqube-2a510a2f76d2f384deba2eec2ca6a9297c0ebc63.tar.gz
sonarqube-2a510a2f76d2f384deba2eec2ca6a9297c0ebc63.zip
SONAR-5389 Port symbolizable API to new batch API
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java9
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/symbol/Symbol.java33
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/symbol/SymbolTableBuilder.java48
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/symbol/internal/DefaultSymbol.java66
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/symbol/internal/package-info.java21
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/symbol/package-info.java21
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/source/Symbol.java10
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/source/Symbolizable.java3
8 files changed, 209 insertions, 2 deletions
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 ff463c6b3fb..787d2fddb3d 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
@@ -29,6 +29,7 @@ import org.sonar.api.batch.sensor.issue.Issue;
import org.sonar.api.batch.sensor.issue.IssueBuilder;
import org.sonar.api.batch.sensor.measure.Measure;
import org.sonar.api.batch.sensor.measure.MeasureBuilder;
+import org.sonar.api.batch.sensor.symbol.SymbolTableBuilder;
import org.sonar.api.config.Settings;
import javax.annotation.CheckForNull;
@@ -117,4 +118,12 @@ public interface SensorContext {
*/
HighlightingBuilder highlightingBuilder(InputFile inputFile);
+ // ------------ SYMBOL REFERENCES ------------
+
+ /**
+ * Builder to define symbol references in a file.
+ * @since 4.5
+ */
+ SymbolTableBuilder symbolTableBuilder(InputFile inputFile);
+
}
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
new file mode 100644
index 00000000000..9e1e3e8259e
--- /dev/null
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/symbol/Symbol.java
@@ -0,0 +1,33 @@
+/*
+ * 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;
+
+/**
+ * Represent a symbol in a source file.
+ * @since 4.5
+ */
+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
new file mode 100644
index 00000000000..3be82175d42
--- /dev/null
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/symbol/SymbolTableBuilder.java
@@ -0,0 +1,48 @@
+/*
+ * 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;
+
+/**
+ * Use this builder to create symbol references. For now only references
+ * in the same file are supported.
+ * @since 4.5
+ */
+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
new file mode 100644
index 00000000000..8f071278505
--- /dev/null
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/symbol/internal/DefaultSymbol.java
@@ -0,0 +1,66 @@
+/*
+ * 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 String componentKey;
+ private final int declarationStartOffset;
+ private final int declarationEndOffset;
+
+ public DefaultSymbol(String componentKey, int startOffset, int endOffset) {
+ this.componentKey = componentKey;
+ this.declarationStartOffset = startOffset;
+ this.declarationEndOffset = endOffset;
+ }
+
+ public String componentKey() {
+ return componentKey;
+ }
+
+ @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("component", componentKey)
+ .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
new file mode 100644
index 00000000000..e0ccdf1c9b3
--- /dev/null
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/symbol/internal/package-info.java
@@ -0,0 +1,21 @@
+/*
+ * 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
new file mode 100644
index 00000000000..7acf7f3b056
--- /dev/null
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/symbol/package-info.java
@@ -0,0 +1,21 @@
+/*
+ * 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 260d6c8ecd7..31702ecb065 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,15 +20,21 @@
package org.sonar.api.source;
-public interface Symbol {
+/**
+ * @deprecated since 4.5 replaced by {@link org.sonar.api.batch.sensor.symbol.Symbol}
+ */
+@Deprecated
+public interface Symbol extends org.sonar.api.batch.sensor.symbol.Symbol {
+ @Override
int getDeclarationStartOffset();
+ @Override
int getDeclarationEndOffset();
/**
* @since unused
- * @deprecated in 4.3
+ * @deprecated in 4.3 not used.
*/
@Deprecated
String getFullyQualifiedName();
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 3a49ada34df..0b7f765cfe7 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
@@ -19,13 +19,16 @@
*/
package org.sonar.api.source;
+import org.sonar.api.batch.sensor.SensorContext;
import org.sonar.api.component.Perspective;
import java.util.List;
/**
* @since 3.6
+ * @deprecated since 4.5 use {@link SensorContext#symbolTableBuilder(org.sonar.api.batch.fs.InputFile)}
*/
+@Deprecated
public interface Symbolizable extends Perspective {
interface SymbolTableBuilder {