Debian Codegraph @

build-system/manifest-merger/src/main/java/com/android/manifmerger/Selector.java

raw
1 /*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package com.android.manifmerger;
18
19 import com.android.annotations.NonNull;
20 import com.android.annotations.concurrency.Immutable;
21 import com.google.common.base.Optional;
22 import com.google.common.base.Preconditions;
23
24 /**
25 * Represents a selector to be able to identify manifest file xml elements.
26 */
27 @Immutable
28 public class Selector {
29
30 /**
31 * local name for tools:selector attributes.
32 */
33 public static final String SELECTOR_LOCAL_NAME = "selector";
34
35 @NonNull private final String mPackageName;
36
37 public Selector(@NonNull String packageName) {
38 mPackageName = Preconditions.checkNotNull(packageName);
39 }
40
41 /**
42 * Returns true if the passed element is "selected" by this selector. If so, any action this
43 * selector decorated will be applied to the element.
44 */
45 boolean appliesTo(@NonNull XmlElement element) {
46 Optional<XmlAttribute> packageName = element.getDocument().getPackage();
47 return packageName.isPresent() && mPackageName.equals(packageName.get().getValue());
48 }
49
50 /**
51 * Returns true if the passed resolver can resolve this selector, false otherwise.
52 */
53 boolean isResolvable(@NonNull KeyResolver<String> resolver) {
54 return resolver.resolve(mPackageName) != null;
55 }
56
57 @NonNull
58 @Override
59 public String toString() {
60 return mPackageName;
61 }
62 }