blob: 7c46b63bb02e1af36cd279659e241e3be4bf303d [file] [log] [blame]
janakr93e3eea2017-03-30 22:09:37 +00001// Copyright 2017 The Bazel Authors. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14package com.google.devtools.build.lib.actions;
15
16import com.google.common.base.MoreObjects;
tomlua155b532017-11-08 20:12:47 +010017import com.google.common.base.Preconditions;
janakr93e3eea2017-03-30 22:09:37 +000018import com.google.devtools.build.lib.cmdline.Label;
janakr93e3eea2017-03-30 22:09:37 +000019import com.google.devtools.build.skyframe.SkyKey;
20
21/** Data that uniquely identifies an action. */
22public class ActionLookupData {
23 private final SkyKey actionLookupNode;
24 private final int actionIndex;
25
26 public ActionLookupData(SkyKey actionLookupNode, int actionIndex) {
27 Preconditions.checkState(
28 actionLookupNode.argument() instanceof ActionLookupValue.ActionLookupKey, actionLookupNode);
29 this.actionLookupNode = actionLookupNode;
30 this.actionIndex = actionIndex;
31 }
32
33 public SkyKey getActionLookupNode() {
34 return actionLookupNode;
35 }
36
37 /**
38 * Index of the action in question in the node keyed by {@link #getActionLookupNode}. Should be
39 * passed to {@link ActionLookupValue#getAction}.
40 */
41 public int getActionIndex() {
42 return actionIndex;
43 }
44
45 public Label getLabelForErrors() {
46 return ((ActionLookupValue.ActionLookupKey) actionLookupNode.argument()).getLabel();
47 }
48
49 @Override
50 public int hashCode() {
51 return 37 * actionLookupNode.hashCode() + actionIndex;
52 }
53
54 @Override
55 public boolean equals(Object obj) {
56 if (this == obj) {
57 return true;
58 }
59 if (!(obj instanceof ActionLookupData)) {
60 return false;
61 }
62 ActionLookupData that = (ActionLookupData) obj;
63 return this.actionIndex == that.actionIndex
64 && this.actionLookupNode.equals(that.actionLookupNode);
65 }
66
67 @Override
68 public String toString() {
69 return MoreObjects.toStringHelper(this)
70 .add("actionLookupNode", actionLookupNode)
71 .add("actionIndex", actionIndex)
72 .toString();
73 }
74}