janakr | ae52720 | 2018-02-14 13:44:30 -0800 | [diff] [blame] | 1 | // 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 | |
| 15 | package com.google.devtools.build.lib.analysis; |
| 16 | |
| 17 | import com.google.auto.value.AutoValue; |
| 18 | import com.google.devtools.build.lib.cmdline.Label; |
janakr | ae52720 | 2018-02-14 13:44:30 -0800 | [diff] [blame] | 19 | import com.google.devtools.build.lib.packages.Target; |
| 20 | import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; |
adonovan | 450c7ad | 2020-09-14 13:00:21 -0700 | [diff] [blame] | 21 | import net.starlark.java.syntax.Location; |
janakr | ae52720 | 2018-02-14 13:44:30 -0800 | [diff] [blame] | 22 | |
| 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 |
| 31 | public 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 | } |