Dmitry Lomov | 654717f | 2017-03-02 14:39:52 +0000 | [diff] [blame] | 1 | // 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. |
| 14 | package com.google.devtools.build.lib.packages; |
| 15 | |
| 16 | import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; |
| 17 | import com.google.devtools.build.lib.events.Location; |
cparsons | 56fbc99 | 2018-05-01 16:08:53 -0700 | [diff] [blame] | 18 | import com.google.devtools.build.lib.skylarkbuildapi.ProviderApi; |
brandjon | d331fa7 | 2017-12-28 07:38:31 -0800 | [diff] [blame] | 19 | import com.google.devtools.build.lib.syntax.ClassObject; |
Dmitry Lomov | 654717f | 2017-03-02 14:39:52 +0000 | [diff] [blame] | 20 | |
| 21 | /** |
cparsons | 4ebf6c0 | 2018-08-17 14:49:36 -0700 | [diff] [blame] | 22 | * Declared Provider (a constructor for {@link InfoInterface}). |
Dmitry Lomov | 654717f | 2017-03-02 14:39:52 +0000 | [diff] [blame] | 23 | * |
dslomov | de965ac | 2017-07-31 21:07:51 +0200 | [diff] [blame] | 24 | * <p>Declared providers can be declared either natively ({@link NativeProvider} or in Skylark |
| 25 | * {@link SkylarkProvider}. |
Dmitry Lomov | 654717f | 2017-03-02 14:39:52 +0000 | [diff] [blame] | 26 | * |
dslomov | de965ac | 2017-07-31 21:07:51 +0200 | [diff] [blame] | 27 | * <p>{@link Provider} serves both as "type identifier" for declared provider instances and as a |
brandjon | a60c6a4 | 2017-12-21 05:53:21 -0800 | [diff] [blame] | 28 | * function that can be called to construct a provider. To the Skylark user, there are "providers" |
| 29 | * and "provider instances"; the former is a Java instance of this class, and the latter is a Java |
cparsons | 4ebf6c0 | 2018-08-17 14:49:36 -0700 | [diff] [blame] | 30 | * instance of {@link InfoInterface}. |
Dmitry Lomov | 654717f | 2017-03-02 14:39:52 +0000 | [diff] [blame] | 31 | * |
dslomov | de965ac | 2017-07-31 21:07:51 +0200 | [diff] [blame] | 32 | * <p>Prefer to use {@link Key} as a serializable identifier of {@link Provider}. In particular, |
| 33 | * {@link Key} should be used in all data structures exposed to Skyframe. |
Dmitry Lomov | 654717f | 2017-03-02 14:39:52 +0000 | [diff] [blame] | 34 | */ |
Dmitry Lomov | 654717f | 2017-03-02 14:39:52 +0000 | [diff] [blame] | 35 | @Immutable |
cparsons | 56fbc99 | 2018-05-01 16:08:53 -0700 | [diff] [blame] | 36 | public interface Provider extends ProviderApi { |
Dmitry Lomov | 654717f | 2017-03-02 14:39:52 +0000 | [diff] [blame] | 37 | |
Dmitry Lomov | 654717f | 2017-03-02 14:39:52 +0000 | [diff] [blame] | 38 | /** |
dslomov | de965ac | 2017-07-31 21:07:51 +0200 | [diff] [blame] | 39 | * Has this {@link Provider} been exported? All native providers are always exported. Skylark |
| 40 | * providers are exported if they are assigned to top-level name in a Skylark module. |
Dmitry Lomov | 654717f | 2017-03-02 14:39:52 +0000 | [diff] [blame] | 41 | */ |
cparsons | 2415cb4 | 2018-05-01 10:32:30 -0700 | [diff] [blame] | 42 | boolean isExported(); |
Dmitry Lomov | 654717f | 2017-03-02 14:39:52 +0000 | [diff] [blame] | 43 | |
dslomov | de965ac | 2017-07-31 21:07:51 +0200 | [diff] [blame] | 44 | /** Returns a serializable representation of this {@link Provider}. */ |
cparsons | 2415cb4 | 2018-05-01 10:32:30 -0700 | [diff] [blame] | 45 | Key getKey(); |
Dmitry Lomov | 654717f | 2017-03-02 14:39:52 +0000 | [diff] [blame] | 46 | |
dslomov | de965ac | 2017-07-31 21:07:51 +0200 | [diff] [blame] | 47 | /** Returns a name of this {@link Provider} that should be used in error messages. */ |
cparsons | 2415cb4 | 2018-05-01 10:32:30 -0700 | [diff] [blame] | 48 | String getPrintableName(); |
Dmitry Lomov | 654717f | 2017-03-02 14:39:52 +0000 | [diff] [blame] | 49 | |
| 50 | /** |
brandjon | d331fa7 | 2017-12-28 07:38:31 -0800 | [diff] [blame] | 51 | * Returns an error message format string for instances to use for their {@link |
| 52 | * ClassObject#getErrorMessageForUnknownField(String)}. |
Dmitry Lomov | 654717f | 2017-03-02 14:39:52 +0000 | [diff] [blame] | 53 | * |
brandjon | d331fa7 | 2017-12-28 07:38:31 -0800 | [diff] [blame] | 54 | * <p>The format string must contain one {@code '%s'} placeholder for the field name. |
Dmitry Lomov | 654717f | 2017-03-02 14:39:52 +0000 | [diff] [blame] | 55 | */ |
cparsons | 2415cb4 | 2018-05-01 10:32:30 -0700 | [diff] [blame] | 56 | default String getErrorMessageFormatForUnknownField() { |
| 57 | return String.format("'%s' object has no attribute '%%s'", getPrintableName()); |
Dmitry Lomov | 654717f | 2017-03-02 14:39:52 +0000 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | /** |
cparsons | 2415cb4 | 2018-05-01 10:32:30 -0700 | [diff] [blame] | 61 | * Returns the location at which provider was defined. |
Dmitry Lomov | 654717f | 2017-03-02 14:39:52 +0000 | [diff] [blame] | 62 | */ |
cparsons | 2415cb4 | 2018-05-01 10:32:30 -0700 | [diff] [blame] | 63 | Location getLocation(); |
Dmitry Lomov | 654717f | 2017-03-02 14:39:52 +0000 | [diff] [blame] | 64 | |
dslomov | de965ac | 2017-07-31 21:07:51 +0200 | [diff] [blame] | 65 | /** A serializable representation of {@link Provider}. */ |
Dmitry Lomov | 654717f | 2017-03-02 14:39:52 +0000 | [diff] [blame] | 66 | public abstract static class Key {} |
| 67 | } |