blob: 340daa264d51cd9234c8e7963508801ba9495c66 [file] [log] [blame]
Dmitry Lomov82e03772015-11-30 12:13:22 +00001// Copyright 2015 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.packages;
16
17import com.google.devtools.build.lib.cmdline.Label;
Dmitry Lomov777845c2016-04-06 15:24:36 +000018import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
Dmitry Lomov82e03772015-11-30 12:13:22 +000019
20import java.util.Objects;
21
22/**
23 * {@link AspectClass} for aspects defined in Skylark.
24 */
Dmitry Lomov777845c2016-04-06 15:24:36 +000025@Immutable
26public final class SkylarkAspectClass implements AspectClass {
27 private final Label extensionLabel;
28 private final String exportedName;
Dmitry Lomov82e03772015-11-30 12:13:22 +000029
Dmitry Lomov777845c2016-04-06 15:24:36 +000030 public SkylarkAspectClass(Label extensionLabel, String exportedName) {
31 this.extensionLabel = extensionLabel;
32 this.exportedName = exportedName;
33 }
Dmitry Lomov82e03772015-11-30 12:13:22 +000034
Dmitry Lomov777845c2016-04-06 15:24:36 +000035 public Label getExtensionLabel() {
36 return extensionLabel;
37 }
38
39 public String getExportedName() {
40 return exportedName;
41 }
42
Dmitry Lomov82e03772015-11-30 12:13:22 +000043
44 @Override
45 public final String getName() {
46 return getExtensionLabel() + "%" + getExportedName();
47 }
48
49 @Override
50 public final boolean equals(Object o) {
51 if (this == o) {
52 return true;
53 }
54
55 if (!(o instanceof SkylarkAspectClass)) {
56 return false;
57 }
58
59 SkylarkAspectClass that = (SkylarkAspectClass) o;
60
Dmitry Lomov777845c2016-04-06 15:24:36 +000061 return extensionLabel.equals(that.extensionLabel)
62 && exportedName.equals(that.exportedName);
Dmitry Lomov82e03772015-11-30 12:13:22 +000063 }
64
65 @Override
66 public final int hashCode() {
Chris Parsonsa614c932016-03-25 22:51:51 +000067 return Objects.hash(getExtensionLabel(), getExportedName());
Dmitry Lomov82e03772015-11-30 12:13:22 +000068 }
Dmitry Lomov82e03772015-11-30 12:13:22 +000069}