Dmitry Lomov | 82e0377 | 2015-11-30 12:13:22 +0000 | [diff] [blame] | 1 | // 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 | |
| 15 | package com.google.devtools.build.lib.packages; |
| 16 | |
| 17 | import com.google.devtools.build.lib.cmdline.Label; |
Dmitry Lomov | 777845c | 2016-04-06 15:24:36 +0000 | [diff] [blame] | 18 | import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; |
Dmitry Lomov | 82e0377 | 2015-11-30 12:13:22 +0000 | [diff] [blame] | 19 | |
| 20 | import java.util.Objects; |
| 21 | |
| 22 | /** |
| 23 | * {@link AspectClass} for aspects defined in Skylark. |
| 24 | */ |
Dmitry Lomov | 777845c | 2016-04-06 15:24:36 +0000 | [diff] [blame] | 25 | @Immutable |
| 26 | public final class SkylarkAspectClass implements AspectClass { |
| 27 | private final Label extensionLabel; |
| 28 | private final String exportedName; |
Dmitry Lomov | 82e0377 | 2015-11-30 12:13:22 +0000 | [diff] [blame] | 29 | |
Dmitry Lomov | 777845c | 2016-04-06 15:24:36 +0000 | [diff] [blame] | 30 | public SkylarkAspectClass(Label extensionLabel, String exportedName) { |
| 31 | this.extensionLabel = extensionLabel; |
| 32 | this.exportedName = exportedName; |
| 33 | } |
Dmitry Lomov | 82e0377 | 2015-11-30 12:13:22 +0000 | [diff] [blame] | 34 | |
Dmitry Lomov | 777845c | 2016-04-06 15:24:36 +0000 | [diff] [blame] | 35 | public Label getExtensionLabel() { |
| 36 | return extensionLabel; |
| 37 | } |
| 38 | |
| 39 | public String getExportedName() { |
| 40 | return exportedName; |
| 41 | } |
| 42 | |
Dmitry Lomov | 82e0377 | 2015-11-30 12:13:22 +0000 | [diff] [blame] | 43 | |
| 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 Lomov | 777845c | 2016-04-06 15:24:36 +0000 | [diff] [blame] | 61 | return extensionLabel.equals(that.extensionLabel) |
| 62 | && exportedName.equals(that.exportedName); |
Dmitry Lomov | 82e0377 | 2015-11-30 12:13:22 +0000 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | @Override |
| 66 | public final int hashCode() { |
Chris Parsons | a614c93 | 2016-03-25 22:51:51 +0000 | [diff] [blame] | 67 | return Objects.hash(getExtensionLabel(), getExportedName()); |
Dmitry Lomov | 82e0377 | 2015-11-30 12:13:22 +0000 | [diff] [blame] | 68 | } |
Dmitry Lomov | 82e0377 | 2015-11-30 12:13:22 +0000 | [diff] [blame] | 69 | } |