本文整理汇总了Java中com.google.devtools.build.lib.syntax.Environment.lookup方法的典型用法代码示例。如果您正苦于以下问题:Java Environment.lookup方法的具体用法?Java Environment.lookup怎么用?Java Environment.lookup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.devtools.build.lib.syntax.Environment
的用法示例。
在下文中一共展示了Environment.lookup方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getContext
import com.google.devtools.build.lib.syntax.Environment; //导入方法依赖的package包/类
/**
* Get the PackageContext by looking up in the environment.
*/
public static PackageContext getContext(Environment env, FuncallExpression ast)
throws EvalException {
PackageContext value = (PackageContext) env.lookup(PKG_CONTEXT);
if (value == null) {
// if PKG_CONTEXT is missing, we're not called from a BUILD file. This happens if someone
// uses native.some_func() in the wrong place.
throw new EvalException(ast.getLocation(),
"The native module cannot be accessed from here. "
+ "Wrap the function in a macro and call it from a BUILD file");
}
return value;
}
示例2: getPackageContext
import com.google.devtools.build.lib.syntax.Environment; //导入方法依赖的package包/类
/** Get the {@link PackageContext} by looking up in the environment. */
public static PackageContext getPackageContext(Environment env, FuncallExpression ast)
throws EvalException {
@Nullable PackageContext value = (PackageContext) env.lookup(PACKAGE_CONTEXT);
if (value == null) {
// if package context is missing, we're not called from a build file. This happens if someone
// uses native.some_func() in the wrong place.
throw new EvalException(
ast.getLocation(),
"The native module cannot be accessed from here. "
+ "Wrap the function in a macro and call it from a BUCK file");
}
return value;
}
示例3: getParseContext
import com.google.devtools.build.lib.syntax.Environment; //导入方法依赖的package包/类
/** Get the {@link ParseContext} by looking up in the environment. */
private static ParseContext getParseContext(Environment env, FuncallExpression ast)
throws EvalException {
@Nullable ParseContext value = (ParseContext) env.lookup(PARSE_CONTEXT);
if (value == null) {
// if PARSE_CONTEXT is missing, we're not called from a build file. This happens if someone
// uses native.some_func() in the wrong place.
throw new EvalException(
ast.getLocation(),
"The native module cannot be accessed from here. "
+ "Wrap the function in a macro and call it from a BUCK file");
}
return value;
}
示例4: invoke
import com.google.devtools.build.lib.syntax.Environment; //导入方法依赖的package包/类
public String invoke(FuncallExpression ast, Environment env)
throws EvalException, ConversionException {
env.checkLoadingPhase("native.package_name", ast.getLocation());
return (String) env.lookup("PACKAGE_NAME");
}
示例5: call
import com.google.devtools.build.lib.syntax.Environment; //导入方法依赖的package包/类
@Override
@SuppressWarnings("unchecked") // the magic hidden $pkg_context variable is guaranteed
// to be a PackageContext
public Object call(Object[] args, FuncallExpression ast, Environment env)
throws EvalException, InterruptedException, ConversionException {
env.checkLoadingPhase(getName(), ast.getLocation());
if (ruleClass == null) {
throw new EvalException(ast.getLocation(),
"Invalid rule class hasn't been exported by a Skylark file");
}
for (Attribute attribute : ruleClass.getAttributes()) {
// TODO(dslomov): If a Skylark parameter extractor is specified for this aspect, its
// attributes may not be required.
for (Map.Entry<String, ImmutableSet<String>> attrRequirements :
attribute.getRequiredAspectParameters().entrySet()) {
for (String required : attrRequirements.getValue()) {
if (!ruleClass.hasAttr(required, Type.STRING)) {
throw new EvalException(definitionLocation, String.format(
"Aspect %s requires rule %s to specify attribute '%s' with type string.",
attrRequirements.getKey(),
ruleClass.getName(),
required));
}
}
}
}
BuildLangTypedAttributeValuesMap attributeValues =
new BuildLangTypedAttributeValuesMap((Map<String, Object>) args[0]);
try {
PackageContext pkgContext = (PackageContext) env.lookup(PackageFactory.PKG_CONTEXT);
if (pkgContext == null) {
throw new EvalException(ast.getLocation(),
"Cannot instantiate a rule when loading a .bzl file. Rules can only be called from "
+ "a BUILD file (possibly via a macro).");
}
RuleFactory.createAndAddRule(
pkgContext,
ruleClass,
attributeValues,
ast,
env,
pkgContext.getAttributeContainerFactory().apply(ruleClass));
return Runtime.NONE;
} catch (InvalidRuleException | NameConflictException e) {
throw new EvalException(ast.getLocation(), e.getMessage());
}
}
示例6: invoke
import com.google.devtools.build.lib.syntax.Environment; //导入方法依赖的package包/类
@SuppressWarnings("unused")
public String invoke(FuncallExpression ast, Environment env) throws EvalException {
env.checkLoadingPhase("native.package_name", ast.getLocation());
return (String) env.lookup("PACKAGE_NAME");
}