• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 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.apicheck;
18 import java.util.*;
19 
20 public class PackageInfo {
21     private String mName;
22     private HashMap<String, ClassInfo> mClasses;
23     private boolean mExistsInBoth;
24     private SourcePositionInfo mPosition;
25 
PackageInfo(String name, SourcePositionInfo position)26     public PackageInfo(String name, SourcePositionInfo position) {
27         mName = name;
28         mClasses = new HashMap<String, ClassInfo>();
29         mExistsInBoth = false;
30         mPosition = position;
31     }
32 
addClass(ClassInfo cl)33     public void addClass(ClassInfo cl) {
34         mClasses.put(cl.name() , cl);
35     }
36 
allClasses()37     public HashMap<String, ClassInfo> allClasses() {
38         return mClasses;
39     }
40 
name()41     public String name() {
42         return mName;
43     }
44 
position()45     public SourcePositionInfo position() {
46         return mPosition;
47     }
48 
isConsistent(PackageInfo pInfo)49     public boolean isConsistent(PackageInfo pInfo) {
50         mExistsInBoth = true;
51         pInfo.mExistsInBoth = true;
52         boolean consistent = true;
53         for (ClassInfo cInfo : mClasses.values()) {
54             if (pInfo.mClasses.containsKey(cInfo.name())) {
55                 if (!cInfo.isConsistent(pInfo.mClasses.get(cInfo.name()))) {
56                     consistent = false;
57                 }
58             } else {
59                 Errors.error(Errors.REMOVED_CLASS, cInfo.position(),
60                         "Removed public class " + cInfo.qualifiedName());
61                 consistent = false;
62             }
63         }
64         for (ClassInfo cInfo : pInfo.mClasses.values()) {
65             if (!cInfo.isInBoth()) {
66                 Errors.error(Errors.ADDED_CLASS, cInfo.position(),
67                         "Added class " + cInfo.name() + " to package "
68                         + pInfo.name());
69                 consistent = false;
70             }
71         }
72         return consistent;
73     }
74 
isInBoth()75     public boolean isInBoth() {
76         return mExistsInBoth;
77     }
78 }
79