aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api
diff options
context:
space:
mode:
authorStephane Gamard <stephane.gamard@searchbox.com>2014-07-25 15:45:59 +0200
committerStephane Gamard <stephane.gamard@searchbox.com>2014-07-25 15:45:59 +0200
commitc799e9745bb3f33e7146b870853ede4eb05a8a1f (patch)
treeaae7295086e4d37937ac70686d7beaa3293febd3 /sonar-plugin-api
parent83d4e04cfd57d992e0f67da2cfe06260e413408f (diff)
parent5de168c51c20ef298d1257cc91517eeca9db7d9c (diff)
downloadsonarqube-c799e9745bb3f33e7146b870853ede4eb05a8a1f.tar.gz
sonarqube-c799e9745bb3f33e7146b870853ede4eb05a8a1f.zip
Merge branch 'master' into SONAR-4898
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java18
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/highlighting/HighlightingBuilder.java78
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/highlighting/package-info.java21
-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/rules/Rule.java4
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/source/Highlightable.java3
-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
12 files changed, 322 insertions, 4 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 234b3865ca3..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
@@ -24,10 +24,12 @@ import org.sonar.api.batch.fs.FileSystem;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.measure.Metric;
import org.sonar.api.batch.rule.ActiveRules;
+import org.sonar.api.batch.sensor.highlighting.HighlightingBuilder;
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;
@@ -108,4 +110,20 @@ public interface SensorContext {
*/
boolean addIssue(Issue issue);
+ // ------------ HIGHLIGHTING ------------
+
+ /**
+ * Builder to define highlighting of a file.
+ * @since 4.5
+ */
+ 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/highlighting/HighlightingBuilder.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/highlighting/HighlightingBuilder.java
new file mode 100644
index 00000000000..db8d5c46e93
--- /dev/null
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/highlighting/HighlightingBuilder.java
@@ -0,0 +1,78 @@
+/*
+ * 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.highlighting;
+
+
+/**
+ * This builder is used to define syntax highlighting (aka code coloration) on files.
+ * @since 4.5
+ */
+public interface HighlightingBuilder {
+
+ /**
+ * See sonar-colorizer.css
+ */
+ enum TypeOfText {
+ ANNOTATION("a"),
+ CONSTANT("c"),
+ JAVADOC("j"),
+ CLASSIC_COMMENT("cd"),
+ CPP_DOC("cppd"),
+ KEYWORD("k"),
+ STRING("s"),
+ KEYWORD_LIGHT("h"),
+ PREPROCESS_DIRECTIVE("p");
+
+ private final String cssClass;
+
+ private TypeOfText(String cssClass) {
+ this.cssClass = cssClass;
+ }
+
+ public static TypeOfText forCssClass(String cssClass) {
+ for (TypeOfText typeOfText : TypeOfText.values()) {
+ if (typeOfText.cssClass().equals(cssClass)) {
+ return typeOfText;
+ }
+ }
+ throw new IllegalArgumentException("No TypeOfText for CSS class " + cssClass);
+ }
+
+ /**
+ * For internal use
+ */
+ public String cssClass() {
+ return cssClass;
+ }
+ }
+
+ /**
+ * Call this method to indicate the type of text in a range.
+ * @param startOffset Starting position in file for this type of text. Beginning of a file starts with offset '0'.
+ * @param endOffset End position in file for this type of text.
+ * @param typeOfText see {@link TypeOfText} values.
+ */
+ HighlightingBuilder highlight(int startOffset, int endOffset, TypeOfText typeOfText);
+
+ /**
+ * Call this method only once when your are done with defining highlighting of the file.
+ */
+ void done();
+}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/highlighting/package-info.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/highlighting/package-info.java
new file mode 100644
index 00000000000..b4d89fb5783
--- /dev/null
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/highlighting/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.highlighting;
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/rules/Rule.java b/sonar-plugin-api/src/main/java/org/sonar/api/rules/Rule.java
index 45328b52e49..006eb0866cd 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/rules/Rule.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/rules/Rule.java
@@ -48,6 +48,7 @@ import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
+
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@@ -195,7 +196,6 @@ public class Rule {
this.id = id;
}
- @CheckForNull
public String getName() {
return name;
}
@@ -203,7 +203,7 @@ public class Rule {
/**
* Sets the rule name
*/
- public Rule setName(@Nullable String name) {
+ public Rule setName(String name) {
this.name = removeNewLineCharacters(name);
return this;
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/source/Highlightable.java b/sonar-plugin-api/src/main/java/org/sonar/api/source/Highlightable.java
index 0ab229be03c..6d5bd6bd14d 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/source/Highlightable.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/source/Highlightable.java
@@ -19,11 +19,14 @@
*/
package org.sonar.api.source;
+import org.sonar.api.batch.sensor.SensorContext;
import org.sonar.api.component.Perspective;
/**
* @since 3.6
+ * @deprecated since 4.5 use {@link SensorContext#highlightingBuilder(org.sonar.api.batch.fs.InputFile)}
*/
+@Deprecated
public interface Highlightable extends Perspective {
interface HighlightingBuilder {
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 {