當前位置: 首頁>>代碼示例>>Java>>正文


Java Environment.lookup方法代碼示例

本文整理匯總了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;
}
 
開發者ID:bazelbuild,項目名稱:bazel,代碼行數:16,代碼來源:PackageFactory.java

示例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;
}
 
開發者ID:facebook,項目名稱:buck,代碼行數:15,代碼來源:PackageFactory.java

示例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;
}
 
開發者ID:facebook,項目名稱:buck,代碼行數:15,代碼來源:SkylarkProjectBuildFileParser.java

示例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");
}
 
開發者ID:bazelbuild,項目名稱:bazel,代碼行數:6,代碼來源:SkylarkNativeModule.java

示例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());
  }
}
 
開發者ID:bazelbuild,項目名稱:bazel,代碼行數:50,代碼來源:SkylarkRuleClassFunctions.java

示例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");
}
 
開發者ID:facebook,項目名稱:buck,代碼行數:6,代碼來源:SkylarkNativeModule.java


注:本文中的com.google.devtools.build.lib.syntax.Environment.lookup方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。