aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/skydoc/rendering/RuleInfo.java
diff options
context:
space:
mode:
authorGravatar cparsons <cparsons@google.com>2018-06-26 13:47:28 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-06-26 13:49:42 -0700
commit5d85e75601b1c82bbc1358d399afa3e07e87a766 (patch)
tree33a4b7a558e517f3abfa81bd081999758fabd6b1 /src/main/java/com/google/devtools/build/skydoc/rendering/RuleInfo.java
parent06b4928a5d005f6738f1ad43783c1167c2ab20a3 (diff)
Initial check-in of skydoc rewrite.
This skydoc rewrite uses an actual skylark interpreter with a faked build API (implementing the actual build API that Bazel uses). There's a lot left to do here, this is a barebones start. For example, this does not yet handle: - load() statements - non-global build API elements (e.g. apple_common) - output of any rule information other than attribute names - markdown output format RELNOTES: None. PiperOrigin-RevId: 202187207
Diffstat (limited to 'src/main/java/com/google/devtools/build/skydoc/rendering/RuleInfo.java')
-rw-r--r--src/main/java/com/google/devtools/build/skydoc/rendering/RuleInfo.java58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/main/java/com/google/devtools/build/skydoc/rendering/RuleInfo.java b/src/main/java/com/google/devtools/build/skydoc/rendering/RuleInfo.java
new file mode 100644
index 0000000000..0d8a150dfc
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/skydoc/rendering/RuleInfo.java
@@ -0,0 +1,58 @@
+// Copyright 2018 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.devtools.build.skydoc.rendering;
+
+import com.google.common.base.Joiner;
+import com.google.common.base.Strings;
+import com.google.devtools.build.lib.events.Location;
+import java.util.Collection;
+
+/**
+ * Stores information about a skylark rule definition.
+ */
+public class RuleInfo {
+
+ private final Location location;
+ private final String docString;
+ private final Collection<String> attrNames;
+
+ public RuleInfo(Location location, String docString, Collection<String> attrNames) {
+ this.location = location;
+ this.docString = docString;
+ this.attrNames = attrNames;
+ }
+
+ public Location getLocation() {
+ return location;
+ }
+
+ public String getDocString() {
+ return docString;
+ }
+
+ public Collection<String> getAttrNames() {
+ return attrNames;
+ }
+
+ public String getDescription() {
+ StringBuilder stringBuilder = new StringBuilder();
+ if (!Strings.isNullOrEmpty(docString)) {
+ stringBuilder.append(docString);
+ stringBuilder.append("\n");
+ }
+ Joiner.on(",").appendTo(stringBuilder, attrNames);
+ return stringBuilder.toString();
+ }
+}