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


Java EvalException類代碼示例

本文整理匯總了Java中com.google.devtools.build.lib.syntax.EvalException的典型用法代碼示例。如果您正苦於以下問題:Java EvalException類的具體用法?Java EvalException怎麽用?Java EvalException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


EvalException類屬於com.google.devtools.build.lib.syntax包,在下文中一共展示了EvalException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: invoke

import com.google.devtools.build.lib.syntax.EvalException; //導入依賴的package包/類
@SuppressWarnings("unused")
public SkylarkList<Transformation> invoke(Core self, SkylarkList<Transformation> transforms,
    Location location)
    throws EvalException {

  ImmutableList.Builder<Transformation> builder = ImmutableList.builder();
  for (Transformation t : transforms.getContents(Transformation.class, "transformations")) {
    try {
      builder.add(t.reverse());
    } catch (NonReversibleValidationException e) {
      throw new EvalException(location, e.getMessage());
    }
  }

  return SkylarkList.createImmutable(builder.build().reverse());
}
 
開發者ID:google,項目名稱:copybara,代碼行數:17,代碼來源:Core.java

示例2: create

import com.google.devtools.build.lib.syntax.EvalException; //導入依賴的package包/類
public static MapAuthor create(Location location, Map<String, String> authorMap,
    boolean reversible, boolean noopReverse, boolean failIfNotFound,
    boolean failIfNotFoundInReverse, boolean mapAll) throws EvalException {
  ImmutableMap.Builder<String, String> authorToAuthor = ImmutableMap.builder();
  ImmutableMap.Builder<String, Author> mailToAuthor = ImmutableMap.builder();
  ImmutableMap.Builder<String, Author> nameToAuthor = ImmutableMap.builder();

  for (Entry<String, String> e : authorMap.entrySet()) {
    Author to = Author.parse(location, e.getValue());
    try {
      authorToAuthor.put(AuthorParser.parse(e.getKey()).toString(),
          to.toString());
    } catch (InvalidAuthorException ex) {
      if (e.getKey().contains("@")) {
        mailToAuthor.put(e.getKey(), to);
      } else {
        nameToAuthor.put(e.getKey(), to);
      }
    }
  }
  return new MapAuthor(location, authorToAuthor.build(), mailToAuthor.build(),
      nameToAuthor.build(), reversible, noopReverse, failIfNotFound, failIfNotFoundInReverse,
      mapAll);
}
 
開發者ID:google,項目名稱:copybara,代碼行數:25,代碼來源:MapAuthor.java

示例3: create

import com.google.devtools.build.lib.syntax.EvalException; //導入依賴的package包/類
public static ReferenceMigrator create(
    String before, String after, Pattern forward, @Nullable Pattern backward,
    ImmutableList<String> additionalLabels, Location location) throws EvalException {
  Map<String, Pattern> patterns = ImmutableMap.of("reference", forward);
  TemplateTokens beforeTokens =
      new TemplateTokens(location, before, patterns, /* repeatedGroups= */ false);
  beforeTokens.validateUnused();
  TemplateTokens afterTokens =
      new TemplateTokens(location, after, patterns, /* repeatedGroups= */ false);
  afterTokens.validateUnused();
  if (after.lastIndexOf("$1") != -1) {
    // TODO: Handle escaping
    throw new EvalException(location,
        String.format("Destination format '%s' uses the reserved token '$1'.", after));
  }
  return new ReferenceMigrator(beforeTokens, afterTokens, backward, additionalLabels);
}
 
開發者ID:google,項目名稱:copybara,代碼行數:18,代碼來源:ReferenceMigrator.java

示例4: transform

import com.google.devtools.build.lib.syntax.EvalException; //導入依賴的package包/類
@Override
public void transform(TransformWork work)
    throws IOException, ValidationException {
  Author author = null;
  // If multiple commits are included (for example on a squash for skipping a bad change),
  // last author wins.
  for (Change<?> change : work.getChanges().getCurrent()) {
    ImmutableCollection<String> labelValue = change.getLabels().get(label);
    if (!labelValue.isEmpty()) {
      try {
        author = Author.parse(/*location=*/null, Iterables.getLast(labelValue));
      } catch (EvalException e) {
        // Don't fail the migration because the label is wrong since it is very
        // difficult for a user to recover from this.
        work.getConsole().warn("Cannot restore original author: " + e.getMessage());
      }
    }
    if (!searchAllChanges) {
      break;
    }
  }
  if (author != null) {
    work.setAuthor(author);
    work.removeLabel(label, /*wholeMessage=*/true);
  }
}
 
開發者ID:google,項目名稱:copybara,代碼行數:27,代碼來源:RestoreOriginalAuthor.java

示例5: invoke

import com.google.devtools.build.lib.syntax.EvalException; //導入依賴的package包/類
public NoneType invoke(GitModule self, String name, String origin, String destination,
    SkylarkList<String> strRefSpecs, Boolean prune, Location location, Environment env)
    throws EvalException {
  GeneralOptions generalOptions = self.options.get(GeneralOptions.class);
  List<Refspec> refspecs = new ArrayList<>();

  for (String refspec : SkylarkList.castList(strRefSpecs, String.class, "refspecs")) {
    refspecs.add(Refspec.create(
        generalOptions.getEnvironment(), generalOptions.getCwd(), refspec, location));
  }
  Core.getCore(env).addMigration(location, name,
      new Mirror(generalOptions, self.options.get(GitOptions.class),
          name, origin, destination, refspecs,
          self.options.get(GitMirrorOptions.class), prune, self.mainConfigFile));
  return Runtime.NONE;
}
 
開發者ID:google,項目名稱:copybara,代碼行數:17,代碼來源:GitModule.java

示例6: getDescriptor

import com.google.devtools.build.lib.syntax.EvalException; //導入依賴的package包/類
@Override
protected DecompressorDescriptor getDescriptor(Rule rule, Path downloadPath, Path outputDirectory)
    throws RepositoryFunctionException {
  WorkspaceAttributeMapper mapper = WorkspaceAttributeMapper.of(rule);
  boolean executable = false;
  try {
    executable = (mapper.isAttributeValueExplicitlySpecified("executable")
        && mapper.get("executable", Type.BOOLEAN));
  } catch (EvalException e) {
    throw new RepositoryFunctionException(e, Transience.PERSISTENT);
  }
  return DecompressorDescriptor.builder()
      .setDecompressor(FileDecompressor.INSTANCE)
      .setTargetKind(rule.getTargetKind())
      .setTargetName(rule.getName())
      .setArchivePath(downloadPath)
      .setRepositoryPath(outputDirectory)
      .setExecutable(executable)
      .build();
}
 
開發者ID:bazelbuild,項目名稱:bazel,代碼行數:21,代碼來源:HttpFileFunction.java

示例7: SkylarkRepositoryContext

import com.google.devtools.build.lib.syntax.EvalException; //導入依賴的package包/類
/**
 * Create a new context (repository_ctx) object for a skylark repository rule ({@code rule}
 * argument).
 */
SkylarkRepositoryContext(Rule rule, Path outputDirectory, Environment environment,
    Map<String, String> env, HttpDownloader httpDownloader, Map<String, String> markerData)
    throws EvalException {
  this.rule = rule;
  this.outputDirectory = outputDirectory;
  this.env = environment;
  this.osObject = new SkylarkOS(env);
  this.httpDownloader = httpDownloader;
  this.markerData = markerData;
  WorkspaceAttributeMapper attrs = WorkspaceAttributeMapper.of(rule);
  ImmutableMap.Builder<String, Object> attrBuilder = new ImmutableMap.Builder<>();
  for (String name : attrs.getAttributeNames()) {
    if (!name.equals("$local")) {
      Object val = attrs.getObject(name);
      attrBuilder.put(
          Attribute.getSkylarkName(name),
          val == null
              ? Runtime.NONE
              // Attribute values should be type safe
              : SkylarkType.convertToSkylark(val,
                  (com.google.devtools.build.lib.syntax.Environment) null));
    }
  }
  attrObject = NativeProvider.STRUCT.create(attrBuilder.build(), "No such attribute '%s'");
}
 
開發者ID:bazelbuild,項目名稱:bazel,代碼行數:30,代碼來源:SkylarkRepositoryContext.java

示例8: repr

import com.google.devtools.build.lib.syntax.EvalException; //導入依賴的package包/類
@Override
public void repr(SkylarkPrinter printer) {
  if (isImmutable()) {
    printer.append("ctx.outputs(for ");
    printer.append(context.ruleLabelCanonicalName);
    printer.append(")");
    return;
  }
  boolean first = true;
  printer.append("ctx.outputs(");
  // Sort by field name to ensure deterministic output.
  try {
    for (String field : Ordering.natural().sortedCopy(getFieldNames())) {
      if (!first) {
        printer.append(", ");
      }
      first = false;
      printer.append(field);
      printer.append(" = ");
      printer.repr(getValue(field));
    }
    printer.append(")");
  } catch (EvalException e) {
    throw new AssertionError("mutable ctx.outputs should not throw", e);
  }
}
 
開發者ID:bazelbuild,項目名稱:bazel,代碼行數:27,代碼來源:SkylarkRuleContext.java

示例9: buildProviderPredicate

import com.google.devtools.build.lib.syntax.EvalException; //導入依賴的package包/類
/**
 * Builds a list of sets of accepted providers from Skylark list {@code obj}.
 * The list can either be a list of providers (in that case the result is a list with one
 * set) or a list of lists of providers (then the result is the list of sets).
 * @param argumentName used in error messages.
 * @param location location for error messages.
 */
static ImmutableList<ImmutableSet<SkylarkProviderIdentifier>> buildProviderPredicate(
    SkylarkList<?> obj, String argumentName, Location location) throws EvalException {
  if (obj.isEmpty()) {
    return ImmutableList.of();
  }
  boolean isListOfProviders = true;
  for (Object o : obj) {
    if (!isProvider(o)) {
      isListOfProviders = false;
      break;
    }
  }
  if (isListOfProviders) {
    return ImmutableList.of(getSkylarkProviderIdentifiers(obj, location));
  } else {
    return getProvidersList(obj, argumentName, location);
  }
}
 
開發者ID:bazelbuild,項目名稱:bazel,代碼行數:26,代碼來源:SkylarkAttr.java

示例10: checkAllUrls

import com.google.devtools.build.lib.syntax.EvalException; //導入依賴的package包/類
private static ImmutableList<String> checkAllUrls(Iterable<?> urlList) throws EvalException {
  ImmutableList.Builder<String> result = ImmutableList.builder();

  for (Object o : urlList) {
    if (!(o instanceof String)) {
      throw new EvalException(
          null,
          String.format(
              "Expected a string or sequence of strings for 'url' argument, "
                  + "but got '%s' item in the sequence",
              EvalUtils.getDataTypeName(o)));
    }
    result.add((String) o);
  }

  return result.build();
}
 
開發者ID:bazelbuild,項目名稱:bazel,代碼行數:18,代碼來源:SkylarkRepositoryContext.java

示例11: getAndValidate

import com.google.devtools.build.lib.syntax.EvalException; //導入依賴的package包/類
/**
 * Variation of {@link #get} that throws an informative exception if the attribute
 * can't be resolved due to intrinsic contradictions in the configuration.
 */
private <T> T getAndValidate(String attributeName, Type<T> type) throws EvalException  {
  SelectorList<T> selectorList = getSelectorList(attributeName, type);
  if (selectorList == null) {
    // This is a normal attribute.
    return super.get(attributeName, type);
  }

  List<T> resolvedList = new ArrayList<>();
  for (Selector<T> selector : selectorList.getSelectors()) {
    ConfigKeyAndValue<T> resolvedPath = resolveSelector(attributeName, selector);
    if (!selector.isValueSet(resolvedPath.configKey)) {
      // Use the default. We don't have access to the rule here, so pass null to
      // Attribute.getValue(). This has the result of making attributes with condition
      // predicates ineligible for "None" values. But no user-facing attributes should
      // do that anyway, so that isn't a loss.
      Attribute attr = getAttributeDefinition(attributeName);
      Verify.verify(attr.getCondition() == Predicates.<AttributeMap>alwaysTrue());
      resolvedList.add((T) attr.getDefaultValue(null));
    } else {
      resolvedList.add(resolvedPath.value);
    }
  }
  return resolvedList.size() == 1 ? resolvedList.get(0) : type.concat(resolvedList);
}
 
開發者ID:bazelbuild,項目名稱:bazel,代碼行數:29,代碼來源:ConfiguredAttributeMapper.java

示例12: getObject

import com.google.devtools.build.lib.syntax.EvalException; //導入依賴的package包/類
/**
 * Returns value for attribute without casting it to any particular type, or null on no match.
 */
@Nullable
public Object getObject(String attributeName) throws EvalException {
  Object value = rule.getAttributeContainer().getAttr(checkNotNull(attributeName));
  if (value instanceof SelectorList) {
    String message;
    if (rule.getLocation().getPath().getBaseName().equals(
        Label.WORKSPACE_FILE_NAME.getPathString())) {
      message = "select() cannot be used in WORKSPACE files";
    } else {
      message = "select() cannot be used in macros called from WORKSPACE files";
    }
    throw new EvalException(
        rule.getAttributeContainer().getAttributeLocation(attributeName), message);
  }
  return value;
}
 
開發者ID:bazelbuild,項目名稱:bazel,代碼行數:20,代碼來源:WorkspaceAttributeMapper.java

示例13: invoke

import com.google.devtools.build.lib.syntax.EvalException; //導入依賴的package包/類
@SuppressWarnings({"unchecked", "unused"})
public Label invoke(
    String labelString, Boolean relativeToCallerRepository, Location loc, Environment env)
    throws EvalException {
  Label parentLabel = null;
  if (relativeToCallerRepository) {
    parentLabel = env.getCallerLabel();
  } else {
    parentLabel = env.getGlobals().getTransitiveLabel();
  }
  try {
    if (parentLabel != null) {
      LabelValidator.parseAbsoluteLabel(labelString);
      labelString = parentLabel.getRelative(labelString).getUnambiguousCanonicalForm();
    }
    return labelCache.get(labelString);
  } catch (LabelValidator.BadLabelException | LabelSyntaxException | ExecutionException e) {
    throw new EvalException(loc, "Illegal absolute label syntax: " + labelString);
  }
}
 
開發者ID:bazelbuild,項目名稱:bazel,代碼行數:21,代碼來源:SkylarkRuleClassFunctions.java

示例14: getFileAttributeAsLabel

import com.google.devtools.build.lib.syntax.EvalException; //導入依賴的package包/類
private Label getFileAttributeAsLabel(Rule rule) throws RepositoryFunctionException {
  Label label;
  try {
    // Parse a label
    label = Label.parseAbsolute(getFileAttributeValue(rule));
  } catch (LabelSyntaxException ex) {
    throw new RepositoryFunctionException(
        new EvalException(
            rule.getLocation(),
            String.format(
                "In %s the '%s' attribute does not specify a valid label: %s",
                rule, getFileAttrName(), ex.getMessage())),
        Transience.PERSISTENT);
  }
  return label;
}
 
開發者ID:bazelbuild,項目名稱:bazel,代碼行數:17,代碼來源:NewRepositoryFileHandler.java

示例15: substitutePlaceholderIntoUnsafeTemplate

import com.google.devtools.build.lib.syntax.EvalException; //導入依賴的package包/類
private static ImmutableList<String> substitutePlaceholderIntoUnsafeTemplate(
    String unsafeTemplate, AttributeMap rule, AttributeValueGetter attributeGetter)
    throws EvalException {
  // Parse the template to get the attribute names and format string.
  ParsedTemplate parsedTemplate = ParsedTemplate.parse(unsafeTemplate);

  // Make sure all attributes are valid.
  for (String placeholder : parsedTemplate.attributeNames()) {
    if (rule.isConfigurable(placeholder)) {
      throw new EvalException(
          rule.getAttributeLocation(placeholder),
          String.format(
              "Attribute %s is configurable and cannot be used in outputs", placeholder));
    }
  }

  // Return the substituted strings.
  return parsedTemplate.substituteAttributes(rule, attributeGetter);
}
 
開發者ID:bazelbuild,項目名稱:bazel,代碼行數:20,代碼來源:ImplicitOutputsFunction.java


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