blob: d2602d2109e3960f197404d3c1c6dd29526ef795 [file] [log] [blame]
janakrae527202018-02-14 13:44:30 -08001// Copyright 2018 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.
14
15package com.google.devtools.build.lib.analysis;
16
17import com.google.auto.value.AutoValue;
18import com.google.devtools.build.lib.cmdline.Label;
janakrae527202018-02-14 13:44:30 -080019import com.google.devtools.build.lib.packages.Target;
20import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
adonovan450c7ad2020-09-14 13:00:21 -070021import net.starlark.java.syntax.Location;
janakrae527202018-02-14 13:44:30 -080022
23/**
24 * Container for some attributes of a {@link Target} that is significantly less heavyweight than an
25 * actual {@link Target} for purposes of serialization. Should still not be used indiscriminately,
26 * since {@link Location} can be quite heavy on its own and each of these wrapper objects costs 24
27 * bytes over an existing {@link Target}.
28 */
29@AutoCodec
30@AutoValue
31public abstract class LabelAndLocation {
32 @AutoCodec.Instantiator
33 static LabelAndLocation create(Label label, Location location) {
34 return new AutoValue_LabelAndLocation(label, location);
35 }
36
37 public static LabelAndLocation of(Target target) {
38 return create(target.getLabel(), target.getLocation());
39 }
40
41 public abstract Label getLabel();
42
43 public abstract Location getLocation();
44}