1/*
2 * Copyright (C) 2015 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#ifndef AAPT_PROGUARD_RULES_H
18#define AAPT_PROGUARD_RULES_H
19
20#include "Resource.h"
21#include "Source.h"
22#include "XmlDom.h"
23
24#include <map>
25#include <ostream>
26#include <set>
27#include <string>
28
29namespace aapt {
30namespace proguard {
31
32class KeepSet {
33public:
34    inline void addClass(const SourceLine& source, const std::u16string& className) {
35        mKeepSet[className].insert(source);
36    }
37
38    inline void addMethod(const SourceLine& source, const std::u16string& methodName) {
39        mKeepMethodSet[methodName].insert(source);
40    }
41
42private:
43    friend bool writeKeepSet(std::ostream* out, const KeepSet& keepSet);
44
45    std::map<std::u16string, std::set<SourceLine>> mKeepSet;
46    std::map<std::u16string, std::set<SourceLine>> mKeepMethodSet;
47};
48
49bool collectProguardRulesForManifest(const Source& source, xml::Node* node, KeepSet* keepSet);
50bool collectProguardRules(ResourceType type, const Source& source, xml::Node* node,
51                          KeepSet* keepSet);
52
53bool writeKeepSet(std::ostream* out, const KeepSet& keepSet);
54
55} // namespace proguard
56} // namespace aapt
57
58#endif // AAPT_PROGUARD_RULES_H
59