diff options
author | 2017-04-05 13:41:44 +0000 | |
---|---|---|
committer | 2017-04-06 10:58:37 +0200 | |
commit | 32de87e07fe4f5e6379c1f6d29be0f6fd23b5768 (patch) | |
tree | 75c133f6cdf0525deea1c69aa1f19dc7bc4bcff4 /src/main/java/com/google/devtools/build/docgen/skylark/SkylarkJavaMethodDoc.java | |
parent | b13457b1434d64ab187fb511e73f01d1f2321c1e (diff) |
Skylark documentation identifies overloaded methods by their full signature (*) instead of using duplicate method names.
(*) Technically it's not a proper method signature since it contains parameter names instead of parameter types.
PiperOrigin-RevId: 152251143
Diffstat (limited to 'src/main/java/com/google/devtools/build/docgen/skylark/SkylarkJavaMethodDoc.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/docgen/skylark/SkylarkJavaMethodDoc.java | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/src/main/java/com/google/devtools/build/docgen/skylark/SkylarkJavaMethodDoc.java b/src/main/java/com/google/devtools/build/docgen/skylark/SkylarkJavaMethodDoc.java index 31951d0373..f8f0f6b281 100644 --- a/src/main/java/com/google/devtools/build/docgen/skylark/SkylarkJavaMethodDoc.java +++ b/src/main/java/com/google/devtools/build/docgen/skylark/SkylarkJavaMethodDoc.java @@ -13,11 +13,13 @@ // limitations under the License. package com.google.devtools.build.docgen.skylark; +import com.google.common.base.Joiner; import com.google.common.collect.ImmutableList; import com.google.devtools.build.lib.skylarkinterface.Param; import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable; import com.google.devtools.build.lib.util.StringUtilities; import java.lang.reflect.Method; +import java.util.ArrayList; import java.util.List; /** @@ -30,6 +32,8 @@ public final class SkylarkJavaMethodDoc extends SkylarkMethodDoc { private final SkylarkCallable callable; private final ImmutableList<SkylarkParamDoc> params; + private boolean isOverloaded; + public SkylarkJavaMethodDoc(SkylarkModuleDoc module, Method method, SkylarkCallable callable) { this.module = module; @@ -56,7 +60,27 @@ public final class SkylarkJavaMethodDoc extends SkylarkMethodDoc { @Override public String getName() { - return name; + // Normally we refer to methods by their name, e.g. "foo" for method foo(arg1, arg2). + // However, if a method is overloaded, the name is no longer unique, which forces us to append + // the names of the method parameters in order to get a unique value. + // In this case, the return value for the previous example would be "foo(arg1, arg2)". + + // We decided against ALWAYS returning the full name since we didn't want to pollute the + // TOC of documentation pages too much. This comes at the cost of inconsistency and more + // complex code. + return isOverloaded ? getFullName() : name; + } + + /** + * Returns the full name of the method, consisting of + * <method name>(<name of first param>, <name of second param>, ...). + */ + private String getFullName() { + List<String> paramNames = new ArrayList<>(); + for (Param param : callable.parameters()) { + paramNames.add(param.name()); + } + return String.format("%s(%s)", name, Joiner.on(", ").join(paramNames)); } @Override @@ -81,4 +105,8 @@ public final class SkylarkJavaMethodDoc extends SkylarkMethodDoc { public List<SkylarkParamDoc> getParams() { return params; } + + public void setOverloaded(boolean isOverloaded) { + this.isOverloaded = isOverloaded; + } } |