]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3893 First symbol API version
authorJean-Baptiste Vilain <jean-baptiste.vilain@sonarsource.com>
Tue, 16 Apr 2013 07:26:46 +0000 (09:26 +0200)
committerJean-Baptiste Vilain <jean-baptiste.vilain@sonarsource.com>
Tue, 16 Apr 2013 07:26:46 +0000 (09:26 +0200)
sonar-batch/src/main/java/org/sonar/batch/scan/source/SyntaxHighlightingRuleSet.java
sonar-core/src/main/java/org/sonar/core/source/jdbc/SnapshotDataDto.java
sonar-plugin-api/src/main/java/org/sonar/api/scan/source/Symbol.java [new file with mode: 0644]
sonar-plugin-api/src/main/java/org/sonar/api/scan/source/SymbolPerspective.java [new file with mode: 0644]

index 6de5677588d471b282ae30d5b15a40c8edc03efe..dd567ffbf9231b84fce18062143d5563eec5bdc9 100644 (file)
@@ -61,12 +61,12 @@ public class SyntaxHighlightingRuleSet {
     public Builder registerHighlightingRule(int startOffset, int endOffset, String typeOfText) {
       if (ruleConflictsWithExistingRules(startOffset, endOffset)) {
         String errorMsg = String.format("Cannot register highlighting rule for characters from %s to %s as it " +
-                "overlaps at least one existing rule", startOffset, endOffset);
+          "overlaps at least one existing rule", startOffset, endOffset);
         LoggerFactory.getLogger(SyntaxHighlightingRuleSet.class).error(errorMsg);
         throw new UnsupportedOperationException(errorMsg);
       }
       SyntaxHighlightingRule syntaxHighlightingRule = SyntaxHighlightingRule.create(startOffset, endOffset,
-              typeOfText);
+        typeOfText);
       this.syntaxHighlightingRuleSet.add(syntaxHighlightingRule);
       return this;
     }
@@ -77,24 +77,24 @@ public class SyntaxHighlightingRuleSet {
 
     private boolean ruleConflictsWithExistingRules(final int startOffset, final int endOffset) {
       Collection<SyntaxHighlightingRule> conflictingRules = Collections2
-              .filter(syntaxHighlightingRuleSet, new Predicate<SyntaxHighlightingRule>() {
-                @Override
-                public boolean apply(@Nullable SyntaxHighlightingRule syntaxHighlightingRule) {
-
-                  if (syntaxHighlightingRule != null) {
-                    boolean overlapsStartBoundary = startOffset < syntaxHighlightingRule.getStartPosition()
-                            && endOffset >= syntaxHighlightingRule.getStartPosition() + 1
-                            && endOffset < syntaxHighlightingRule.getEndPosition();
-
-                    boolean overlapsEndBoundary = startOffset > syntaxHighlightingRule.getStartPosition()
-                            && startOffset < syntaxHighlightingRule.getEndPosition()
-                            && endOffset > syntaxHighlightingRule.getEndPosition();
-
-                    return overlapsStartBoundary || overlapsEndBoundary;
-                  }
-                  return false;
-                }
-              });
+        .filter(syntaxHighlightingRuleSet, new Predicate<SyntaxHighlightingRule>() {
+          @Override
+          public boolean apply(@Nullable SyntaxHighlightingRule syntaxHighlightingRule) {
+
+            if (syntaxHighlightingRule != null) {
+              boolean overlapsStartBoundary = startOffset < syntaxHighlightingRule.getStartPosition()
+                && endOffset >= syntaxHighlightingRule.getStartPosition() + 1
+                && endOffset < syntaxHighlightingRule.getEndPosition();
+
+              boolean overlapsEndBoundary = startOffset > syntaxHighlightingRule.getStartPosition()
+                && startOffset < syntaxHighlightingRule.getEndPosition()
+                && endOffset > syntaxHighlightingRule.getEndPosition();
+
+              return overlapsStartBoundary || overlapsEndBoundary;
+            }
+            return false;
+          }
+        });
       return !conflictingRules.isEmpty();
     }
   }
@@ -110,11 +110,11 @@ public class SyntaxHighlightingRuleSet {
 
     for (SyntaxHighlightingRule highlightingRule : orderedRules) {
       serializedRules.append(highlightingRule.getStartPosition())
-              .append(FIELD_SEPARATOR)
-              .append(highlightingRule.getEndPosition())
-              .append(FIELD_SEPARATOR)
-              .append(highlightingRule.getTextType())
-              .append(RULE_SEPARATOR);
+        .append(FIELD_SEPARATOR)
+        .append(highlightingRule.getEndPosition())
+        .append(FIELD_SEPARATOR)
+        .append(highlightingRule.getTextType())
+        .append(RULE_SEPARATOR);
     }
 
     return serializedRules.toString();
index 7a8669eed108e3e5b159cde9f11f7647d8073acf..847ac49e1b536607cbec616c3527a688f8769d98 100644 (file)
@@ -70,30 +70,4 @@ public class SnapshotDataDto {
   public void setDataType(String dataType) {
     this.dataType = dataType;
   }
-
-  @Override
-  public boolean equals(Object o) {
-    if (this == o) return true;
-    if (o == null || getClass() != o.getClass()) return false;
-
-    SnapshotDataDto that = (SnapshotDataDto) o;
-
-    if (id != that.id) return false;
-    if (resourceId != that.resourceId) return false;
-    if (snapshotId != that.snapshotId) return false;
-    if (data != null ? !data.equals(that.data) : that.data != null) return false;
-    if (dataType != null ? !dataType.equals(that.dataType) : that.dataType != null) return false;
-
-    return true;
-  }
-
-  @Override
-  public int hashCode() {
-    int result = (int) (id ^ (id >>> 32));
-    result = 31 * result + (int) (snapshotId ^ (snapshotId >>> 32));
-    result = 31 * result + (int) (resourceId ^ (resourceId >>> 32));
-    result = 31 * result + (data != null ? data.hashCode() : 0);
-    result = 31 * result + (dataType != null ? dataType.hashCode() : 0);
-    return result;
-  }
 }
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/scan/source/Symbol.java b/sonar-plugin-api/src/main/java/org/sonar/api/scan/source/Symbol.java
new file mode 100644 (file)
index 0000000..a5d7c17
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
+ */
+
+package org.sonar.api.scan.source;
+
+public interface Symbol {
+
+  public int getDeclarationStartOffset();
+
+  public int getDeclarationEndOffset();
+
+  public String getFullyQualifiedName();
+}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/scan/source/SymbolPerspective.java b/sonar-plugin-api/src/main/java/org/sonar/api/scan/source/SymbolPerspective.java
new file mode 100644 (file)
index 0000000..7c1248d
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
+ */
+
+package org.sonar.api.scan.source;
+
+import org.sonar.api.component.Perspective;
+
+/**
+ * @since 3.6
+ */
+public interface SymbolPerspective extends Perspective {
+
+  interface SymbolBuilder {
+
+    SymbolBuilder setDeclaration(int startOffset, int endOffset);
+
+    SymbolBuilder setFullyQualifiedName(String fullyQualifiedName);
+
+    Symbol build();
+  }
+
+  interface ReferencesBuilder {
+
+    ReferencesBuilder addReference(int startOffset);
+  }
+
+  SymbolPerspective begin();
+
+  SymbolBuilder newSymbol();
+
+  ReferencesBuilder declareReferences(Symbol symbol);
+
+  void end();
+}
+
+
+