Skip to content

Commit

Permalink
bazel syntax: remove deprecated list constructors
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 280927416
Change-Id: I4ceda702eb6585c0c90cda207aced0e42a34f0fe
  • Loading branch information
adonovan authored and hsudhof committed Nov 22, 2019
1 parent 1b52634 commit dcc0990
Show file tree
Hide file tree
Showing 16 changed files with 52 additions and 38 deletions.
3 changes: 2 additions & 1 deletion java/com/google/copybara/Change.java
Expand Up @@ -34,6 +34,7 @@
import com.google.devtools.build.lib.skylarkinterface.SkylarkValue;
import com.google.devtools.build.lib.syntax.Dict;
import com.google.devtools.build.lib.syntax.Sequence;
import com.google.devtools.build.lib.syntax.StarlarkList;
import java.time.ZonedDateTime;
import java.util.Objects;
import java.util.Set;
Expand Down Expand Up @@ -146,7 +147,7 @@ public Dict<String, String> getLabelsForSkylark() {
structField = true)
public Dict<String, Sequence<String>> getLabelsAllForSkylark() {
return Dict.copyOf(
/* thread= */ null, Maps.transformValues(labels.asMap(), Sequence::createImmutable));
/* thread= */ null, Maps.transformValues(labels.asMap(), StarlarkList::immutableCopyOf));
}

/**
Expand Down
5 changes: 3 additions & 2 deletions java/com/google/copybara/ChangeMessage.java
Expand Up @@ -28,6 +28,7 @@
import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory;
import com.google.devtools.build.lib.skylarkinterface.SkylarkValue;
import com.google.devtools.build.lib.syntax.Sequence;
import com.google.devtools.build.lib.syntax.StarlarkList;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -143,9 +144,9 @@ public ImmutableListMultimap<String, String> labelsAsMultimap(){
public Sequence<String> getLabelValues(String labelName) {
ImmutableListMultimap<String, String> localLabels = labelsAsMultimap();
if (localLabels.containsKey(labelName)) {
return Sequence.createImmutable(localLabels.get(labelName));
return StarlarkList.immutableCopyOf(localLabels.get(labelName));
}
return Sequence.createImmutable(ImmutableList.of());
return StarlarkList.empty();
}


Expand Down
5 changes: 3 additions & 2 deletions java/com/google/copybara/Changes.java
Expand Up @@ -22,6 +22,7 @@
import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory;
import com.google.devtools.build.lib.skylarkinterface.SkylarkValue;
import com.google.devtools.build.lib.syntax.Sequence;
import com.google.devtools.build.lib.syntax.StarlarkList;

/** Information about the changes being imported */
@SkylarkModule(
Expand All @@ -40,8 +41,8 @@ public final class Changes implements SkylarkValue {
private final Sequence<? extends Change<?>> migrated;

public Changes(Iterable<? extends Change<?>> current, Iterable<? extends Change<?>> migrated) {
this.current = Sequence.createImmutable(current);
this.migrated = Sequence.createImmutable(migrated);
this.current = StarlarkList.immutableCopyOf(current);
this.migrated = StarlarkList.immutableCopyOf(migrated);
}

@SkylarkCallable(
Expand Down
5 changes: 3 additions & 2 deletions java/com/google/copybara/Core.java
Expand Up @@ -149,7 +149,8 @@ public com.google.devtools.build.lib.syntax.Sequence<Transformation> reverse(
}
}

return com.google.devtools.build.lib.syntax.Sequence.createImmutable(builder.build().reverse());
return com.google.devtools.build.lib.syntax.StarlarkList.immutableCopyOf(
builder.build().reverse());
}

@SuppressWarnings("unused")
Expand Down Expand Up @@ -1229,7 +1230,7 @@ public Transformation transform(
if (reverseList == null) {
try {
reverseList =
com.google.devtools.build.lib.syntax.Sequence.createImmutable(
com.google.devtools.build.lib.syntax.StarlarkList.immutableCopyOf(
ImmutableList.of(forward.reverse()));
} catch (NonReversibleValidationException e) {
throw new EvalException(
Expand Down
5 changes: 3 additions & 2 deletions java/com/google/copybara/DestinationEffect.java
Expand Up @@ -26,6 +26,7 @@
import com.google.devtools.build.lib.skylarkinterface.SkylarkPrinter;
import com.google.devtools.build.lib.skylarkinterface.SkylarkValue;
import com.google.devtools.build.lib.syntax.Sequence;
import com.google.devtools.build.lib.syntax.StarlarkList;
import java.util.Objects;
import javax.annotation.Nullable;

Expand Down Expand Up @@ -73,7 +74,7 @@ public ImmutableList<OriginRef> getOriginRefs() {
doc = "List of origin changes that were included in" + " this migration",
structField = true)
public final Sequence<? extends OriginRef> getOriginRefsSkylark() {
return Sequence.createImmutable(originRefs);
return StarlarkList.immutableCopyOf(originRefs);
}

/** Return the type of effect that happened: Create, updated, noop or error */
Expand Down Expand Up @@ -136,7 +137,7 @@ public ImmutableList<String> getErrors() {
doc = "List of errors that happened during the migration",
structField = true)
public final Sequence<String> getErrorsSkylark() {
return Sequence.createImmutable(errors);
return StarlarkList.immutableCopyOf(errors);
}

@Override
Expand Down
17 changes: 9 additions & 8 deletions java/com/google/copybara/TransformWork.java
Expand Up @@ -46,6 +46,7 @@
import com.google.devtools.build.lib.syntax.EvalException;
import com.google.devtools.build.lib.syntax.Sequence;
import com.google.devtools.build.lib.syntax.Starlark;
import com.google.devtools.build.lib.syntax.StarlarkList;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
Expand Down Expand Up @@ -206,7 +207,7 @@ public Object run(Object runnable, Location location)
PathMatcher pathMatcher = ((Glob) runnable).relativeTo(checkoutDir);

try (Stream<Path> stream = Files.walk(checkoutDir)) {
return Sequence.createImmutable(
return StarlarkList.immutableCopyOf(
stream
.filter(Files::isRegularFile)
.filter(pathMatcher::matches)
Expand Down Expand Up @@ -447,20 +448,20 @@ public Sequence<String> getAllLabels(String label) {
private Sequence<String> findLabelValues(String label, boolean all) {
Map<String, ImmutableList<String>> coreLabels = getCoreLabels();
if (coreLabels.containsKey(label)) {
return Sequence.createImmutable(coreLabels.get(label));
return StarlarkList.immutableCopyOf(coreLabels.get(label));
}
ArrayList<String> result = new ArrayList<>();
ImmutableList<LabelFinder> msgLabel = getLabelInMessage(label);
if (!msgLabel.isEmpty()) {
result.addAll(Lists.transform(msgLabel, LabelFinder::getValue));
if (!all) {
return Sequence.createImmutable(result);
return StarlarkList.immutableCopyOf(result);
}
}
ImmutableSet<String> values = metadata.getHiddenLabels().get(label);
if (!values.isEmpty()) {
if (!all) {
return Sequence.createImmutable(ImmutableList.of(Iterables.getLast(values)));
return StarlarkList.immutableCopyOf(ImmutableList.of(Iterables.getLast(values)));
} else {
result.addAll(values);
}
Expand All @@ -474,25 +475,25 @@ private Sequence<String> findLabelValues(String label, boolean all) {
if (val != null) {
result.addAll(val);
if (!all) {
return Sequence.createImmutable(result);
return StarlarkList.immutableCopyOf(result);
}
}
ImmutableList<String> revVal = change.getRevision().associatedLabel(label);
if (!revVal.isEmpty()) {
result.addAll(revVal);
if (!all) {
return Sequence.createImmutable(result);
return StarlarkList.immutableCopyOf(result);
}
}
}

// Try to find the label in the resolved reference
ImmutableList<String> resolvedRefLabel = resolvedReference.associatedLabels().get(label);
if (result.addAll(resolvedRefLabel) && !all) {
return Sequence.createImmutable(result);
return StarlarkList.immutableCopyOf(result);
}

return Sequence.createImmutable(result);
return StarlarkList.immutableCopyOf(result);
}

/**
Expand Down
Expand Up @@ -32,6 +32,7 @@
import com.google.devtools.build.lib.skylarkinterface.SkylarkValue;
import com.google.devtools.build.lib.syntax.Dict;
import com.google.devtools.build.lib.syntax.Sequence;
import com.google.devtools.build.lib.syntax.StarlarkList;
import javax.annotation.Nullable;

/** Skylark context for feedback migrations. */
Expand Down Expand Up @@ -89,7 +90,7 @@ public String getFeedbackName() {
"A list containing string representations of the entities " + "that triggered the event",
structField = true)
public Sequence<String> getRefs() {
return Sequence.createImmutable(refs);
return StarlarkList.immutableCopyOf(refs);
}

@SkylarkCallable(name = "success", doc = "Returns a successful action result.")
Expand Down
5 changes: 3 additions & 2 deletions java/com/google/copybara/feedback/FinishHookContext.java
Expand Up @@ -36,6 +36,7 @@
import com.google.devtools.build.lib.syntax.EvalException;
import com.google.devtools.build.lib.syntax.Sequence;
import com.google.devtools.build.lib.syntax.Starlark;
import com.google.devtools.build.lib.syntax.StarlarkList;
import java.util.Map;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -109,7 +110,7 @@ public Endpoint getDestination() throws EvalException {
doc = "The list of effects that happened in the destination",
structField = true)
public Sequence<DestinationEffect> getChanges() {
return Sequence.createImmutable(destinationEffects);
return StarlarkList.immutableCopyOf(destinationEffects);
}

@SkylarkCallable(name = "revision", doc = "Get the requested/resolved revision",
Expand Down Expand Up @@ -160,7 +161,7 @@ public Dict<String, Sequence<String>> getLabels() {
revision.associatedLabels().asMap().entrySet().stream()
.collect(
Collectors.toMap(
Map.Entry::getKey, e -> Sequence.createImmutable(e.getValue()))));
Map.Entry::getKey, e -> StarlarkList.immutableCopyOf(e.getValue()))));
}
}
}
3 changes: 2 additions & 1 deletion java/com/google/copybara/git/GerritEndpoint.java
Expand Up @@ -41,6 +41,7 @@
import com.google.devtools.build.lib.skylarkinterface.SkylarkValue;
import com.google.devtools.build.lib.syntax.EvalException;
import com.google.devtools.build.lib.syntax.Sequence;
import com.google.devtools.build.lib.syntax.StarlarkList;

/** Gerrit endpoint implementation for feedback migrations. */
@SuppressWarnings({"unused", "UnusedReturnValue"})
Expand Down Expand Up @@ -177,7 +178,7 @@ public Sequence<ChangeInfo> listChangesByCommit(
String commit, Sequence<?> includeResults, Location location)
throws EvalException, RepoException, ValidationException {
GerritApi gerritApi = apiSupplier.load(console);
return Sequence.createImmutable(
return StarlarkList.immutableCopyOf(
gerritApi.getChanges(
new ChangesQuery(String.format("commit:%s", commit))
.withInclude(getIncludeResults(includeResults))));
Expand Down
5 changes: 3 additions & 2 deletions java/com/google/copybara/git/GitHubEndPoint.java
Expand Up @@ -59,6 +59,7 @@
import com.google.devtools.build.lib.skylarkinterface.SkylarkValue;
import com.google.devtools.build.lib.syntax.EvalException;
import com.google.devtools.build.lib.syntax.Sequence;
import com.google.devtools.build.lib.syntax.StarlarkList;
import com.google.re2j.Pattern;
import javax.annotation.Nullable;

Expand Down Expand Up @@ -393,7 +394,7 @@ private <T> T returnNullOnNotFound(Location location, GitHubApiException e)
public Sequence<Ref> getReferences(Location location) throws EvalException {
try {
String project = GitHubUtil.getProjectNameFromUrl(url);
return Sequence.createImmutable(apiSupplier.load(console).getReferences(project));
return StarlarkList.immutableCopyOf(apiSupplier.load(console).getReferences(project));
} catch (RepoException | ValidationException | RuntimeException e) {
throw new EvalException(location, "Error calling get_references", e);
}
Expand Down Expand Up @@ -433,7 +434,7 @@ public Sequence<PullRequestComment> getPullRequestComments(Integer prNumber, Loc
throws EvalException {
try {
String project = GitHubUtil.getProjectNameFromUrl(url);
return Sequence.createImmutable(
return StarlarkList.immutableCopyOf(
apiSupplier.load(console).getPullRequestComments(project, prNumber));
} catch (RepoException | ValidationException | RuntimeException e) {
throw new EvalException(location, "Error calling get_pull_request_comments", e);
Expand Down
18 changes: 9 additions & 9 deletions java/com/google/copybara/git/GitModule.java
Expand Up @@ -36,7 +36,6 @@

import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.copybara.GeneralOptions;
import com.google.copybara.Options;
Expand Down Expand Up @@ -79,6 +78,7 @@
import com.google.devtools.build.lib.syntax.NoneType;
import com.google.devtools.build.lib.syntax.Sequence;
import com.google.devtools.build.lib.syntax.Starlark;
import com.google.devtools.build.lib.syntax.StarlarkList;
import com.google.devtools.build.lib.syntax.StarlarkThread;
import com.google.re2j.Matcher;
import com.google.re2j.Pattern;
Expand Down Expand Up @@ -124,13 +124,13 @@ public class GitModule implements LabelsAwareModule, SkylarkValue {
public GitModule(Options options) {
this.options = Preconditions.checkNotNull(options);
this.defaultGitIntegrate =
Sequence.createImmutable(
ImmutableList.of(
new GitIntegrateChanges(
DEFAULT_INTEGRATE_LABEL,
Strategy.FAKE_MERGE_AND_INCLUDE_FILES,
/*ignoreErrors=*/ true,
useNewIntegrate())));
StarlarkList.of(
/*mutability=*/ null,
new GitIntegrateChanges(
DEFAULT_INTEGRATE_LABEL,
Strategy.FAKE_MERGE_AND_INCLUDE_FILES,
/*ignoreErrors=*/ true,
useNewIntegrate()));
}

private boolean useNewIntegrate() {
Expand Down Expand Up @@ -776,7 +776,7 @@ public GitHubPROrigin githubPrOrigin(
reviewState = ReviewState.valueOf(reviewStateString);
if (reviewApproversStrings == null) {
reviewApproversStrings =
Sequence.createImmutable(ImmutableList.of("COLLABORATOR", "MEMBER", "OWNER"));
StarlarkList.of(/*mutability=*/ null, "COLLABORATOR", "MEMBER", "OWNER");
}
HashSet<AuthorAssociation> approvers = new HashSet<>();
for (String r : reviewApproversStrings) {
Expand Down
3 changes: 2 additions & 1 deletion java/com/google/copybara/git/gerritapi/ChangeInfo.java
Expand Up @@ -29,6 +29,7 @@
import com.google.devtools.build.lib.skylarkinterface.SkylarkValue;
import com.google.devtools.build.lib.syntax.Dict;
import com.google.devtools.build.lib.syntax.Sequence;
import com.google.devtools.build.lib.syntax.StarlarkList;
import java.time.ZonedDateTime;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -227,7 +228,7 @@ public List<ChangeMessageInfo> getMessages() {
+ "Only set if messages are requested.",
structField = true)
public Sequence<ChangeMessageInfo> getMessagesForSkylark() {
return Sequence.createImmutable(getMessages());
return StarlarkList.immutableCopyOf(getMessages());
}

@SkylarkCallable(
Expand Down
3 changes: 2 additions & 1 deletion java/com/google/copybara/git/gerritapi/CommitInfo.java
Expand Up @@ -25,6 +25,7 @@
import com.google.devtools.build.lib.skylarkinterface.SkylarkPrinter;
import com.google.devtools.build.lib.skylarkinterface.SkylarkValue;
import com.google.devtools.build.lib.syntax.Sequence;
import com.google.devtools.build.lib.syntax.StarlarkList;
import java.util.List;

/** https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#commit-info */
Expand Down Expand Up @@ -63,7 +64,7 @@ public List<ParentCommitInfo> getParents() {
+ "In each parent only the commit and subject fields are populated.",
structField = true)
public Sequence<ParentCommitInfo> getMessagesForSkylark() {
return Sequence.createImmutable(getParents());
return StarlarkList.immutableCopyOf(getParents());
}

@SkylarkCallable(
Expand Down
3 changes: 2 additions & 1 deletion java/com/google/copybara/git/github/api/CombinedStatus.java
Expand Up @@ -23,6 +23,7 @@
import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory;
import com.google.devtools.build.lib.skylarkinterface.SkylarkValue;
import com.google.devtools.build.lib.syntax.Sequence;
import com.google.devtools.build.lib.syntax.StarlarkList;
import java.util.List;

/**
Expand Down Expand Up @@ -72,6 +73,6 @@ public int getTotalCount() {

@SkylarkCallable(name = "statuses", doc = "List of statuses for the commit", structField = true)
public Sequence<Status> getStatuses() {
return Sequence.createImmutable(statuses);
return StarlarkList.immutableCopyOf(statuses);
}
}
3 changes: 2 additions & 1 deletion java/com/google/copybara/testing/DummyEndpoint.java
Expand Up @@ -25,6 +25,7 @@
import com.google.devtools.build.lib.skylarkinterface.SkylarkPrinter;
import com.google.devtools.build.lib.skylarkinterface.SkylarkValue;
import com.google.devtools.build.lib.syntax.Sequence;
import com.google.devtools.build.lib.syntax.StarlarkList;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -62,6 +63,6 @@ public void repr(SkylarkPrinter printer) {

@SkylarkCallable(name = "get_messages", doc = "Get the messages", structField = true)
public Sequence<String> getMessages() {
return Sequence.createImmutable(messages);
return StarlarkList.immutableCopyOf(messages);
}
}
Expand Up @@ -54,7 +54,7 @@
import com.google.copybara.util.Identity;
import com.google.copybara.util.console.Message.MessageType;
import com.google.copybara.util.console.testing.TestingConsole;
import com.google.devtools.build.lib.syntax.Sequence;
import com.google.devtools.build.lib.syntax.StarlarkList;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
Expand Down Expand Up @@ -449,7 +449,7 @@ public void testIntegratesCanBeRemoved() throws Exception {

assertThat(ImmutableList.copyOf(d.getIntegrates()))
.isEqualTo(
Sequence.createImmutable(
StarlarkList.immutableCopyOf(
ImmutableList.of(
new GitIntegrateChanges(
DEFAULT_INTEGRATE_LABEL,
Expand Down

0 comments on commit dcc0990

Please sign in to comment.