use of com.google.devtools.build.lib.skylarkinterface.SkylarkCallable in project bazel by bazelbuild.
the class JavaSkylarkCommon method getDefaultJavacOpts.
@SkylarkCallable(name = "default_javac_opts", // This function is experimental for now.
documented = false, // There's only one mandatory positional,the Skylark context
mandatoryPositionals = 1, parameters = { @Param(name = "java_toolchain_attr", positional = false, named = true, type = String.class) })
public static List<String> getDefaultJavacOpts(SkylarkRuleContext skylarkRuleContext, String javaToolchainAttr) {
RuleContext ruleContext = skylarkRuleContext.getRuleContext();
ConfiguredTarget javaToolchainConfigTarget = (ConfiguredTarget) checkNotNull(skylarkRuleContext.getAttr().getValue(javaToolchainAttr));
JavaToolchainProvider toolchain = checkNotNull(javaToolchainConfigTarget.getProvider(JavaToolchainProvider.class));
return ImmutableList.copyOf(Iterables.concat(toolchain.getJavacOptions(), ruleContext.getTokenizedStringListAttr("javacopts")));
}
use of com.google.devtools.build.lib.skylarkinterface.SkylarkCallable in project bazel by bazelbuild.
the class JavaProtoSkylarkCommon method getJavacOpts.
@SkylarkCallable(name = "javac_opts", // This function is experimental for now.
documented = false, // There's only one mandatory positional,the Skylark context
mandatoryPositionals = 1, parameters = { @Param(name = "java_toolchain_attr", positional = false, named = true, type = String.class) })
public static // TODO(elenairina): Consider a nicer way of returning this, taking in a JavaToolchainProvider.
List<String> getJavacOpts(SkylarkRuleContext skylarkRuleContext, String javaToolchainAttr) {
ConfiguredTarget javaToolchainConfigTarget = (ConfiguredTarget) checkNotNull(skylarkRuleContext.getAttr().getValue(javaToolchainAttr));
JavaToolchainProvider toolchain = checkNotNull(javaToolchainConfigTarget.getProvider(JavaToolchainProvider.class));
return ImmutableList.<String>builder().addAll(toolchain.getJavacOptions()).addAll(toolchain.getCompatibleJavacOptions(JavaSemantics.PROTO_JAVACOPTS_KEY)).build();
}
use of com.google.devtools.build.lib.skylarkinterface.SkylarkCallable in project bazel by bazelbuild.
the class JavaProtoSkylarkCommon method createProtoCompileAction.
@SkylarkCallable(name = "create_java_lite_proto_compile_action", // This function is experimental for now.
documented = false, // There's 2 mandatory positional arguments, the Skylark context and the ConfiguredTarget.
mandatoryPositionals = 2, parameters = { @Param(name = "src_jar", positional = false, named = true, type = Artifact.class), @Param(name = "proto_toolchain_attr", positional = false, named = true, type = String.class), @Param(name = "flavour", positional = false, named = true, type = String.class, defaultValue = "java") })
public static void createProtoCompileAction(SkylarkRuleContext skylarkRuleContext, ConfiguredTarget target, Artifact sourceJar, String protoToolchainAttr, String flavour) {
SupportData supportData = checkNotNull(target.getProvider(ProtoSupportDataProvider.class).getSupportData());
ProtoCompileActionBuilder.registerActions(skylarkRuleContext.getRuleContext(), ImmutableList.of(new ProtoCompileActionBuilder.ToolchainInvocation(flavour, getProtoToolchainProvider(skylarkRuleContext, protoToolchainAttr), sourceJar.getExecPathString())), supportData.getDirectProtoSources(), supportData.getTransitiveImports(), supportData.getProtosInDirectDeps(), skylarkRuleContext.getLabel().getCanonicalForm(), ImmutableList.of(sourceJar), "JavaLite", true);
}
use of com.google.devtools.build.lib.skylarkinterface.SkylarkCallable in project bazel by bazelbuild.
the class SkylarkMethodDoc method getParameterString.
private String getParameterString(Method method) {
SkylarkCallable annotation = SkylarkInterfaceUtils.getSkylarkCallable(method);
int nbPositional = annotation.mandatoryPositionals();
if (annotation.parameters().length > 0 && nbPositional < 0) {
nbPositional = 0;
}
List<String> argList = new ArrayList<>();
for (int i = 0; i < nbPositional; i++) {
argList.add("arg" + i + ":" + getTypeAnchor(method.getParameterTypes()[i]));
}
boolean named = false;
for (Param param : annotation.parameters()) {
if (param.named() && !param.positional() && !named) {
named = true;
if (!argList.isEmpty()) {
argList.add("*");
}
}
argList.add(formatParameter(param));
}
return Joiner.on(", ").join(argList);
}
use of com.google.devtools.build.lib.skylarkinterface.SkylarkCallable in project bazel by bazelbuild.
the class SkylarkInterfaceUtilsTest method testGetSkylarkCallableSubclass.
@Test
public void testGetSkylarkCallableSubclass() throws Exception {
// Subclass's annotation is used.
Method method = MockClassC.class.getMethod("foo");
SkylarkCallable ann = SkylarkInterfaceUtils.getSkylarkCallable(method);
assertThat(ann).isNotNull();
assertThat(ann.doc()).isEqualTo("MockClassC#foo");
}
Aggregations