01: package soot.dava.toolkits.base.renamer;
02:
03: import java.util.Iterator;
04:
05: import soot.ArrayType;
06: import soot.Type;
07: import soot.util.IterableSet;
08:
09: public class RemoveFullyQualifiedName {
10:
11: public static boolean containsMultiple(Iterator it,
12: String qualifiedName, Type t) {
13: /*
14: * The fully qualified name might contain [] in the end if the type is an ArrayType
15: */
16: if (t != null) {
17: if (t instanceof ArrayType) {
18: if (qualifiedName.indexOf('[') >= 0)
19: qualifiedName = qualifiedName.substring(0,
20: qualifiedName.indexOf('['));
21:
22: }
23: }
24: //get last name
25: String className = getClassName(qualifiedName);
26:
27: int count = 0;
28: while (it.hasNext()) {
29: String tempName = getClassName((String) it.next());
30: if (tempName.equals(className))
31: count++;
32: }
33: if (count > 1)
34: return true;
35: return false;
36: }
37:
38: /*
39: * Method finds the last . and returns the className after that
40: * if no dot is found (shouldnt happen) then the name is simply returned back
41: */
42: public static String getClassName(String qualifiedName) {
43: if (qualifiedName.lastIndexOf('.') > -1)
44: return qualifiedName.substring(qualifiedName
45: .lastIndexOf('.') + 1);
46:
47: return qualifiedName;
48: }
49:
50: public static String getReducedName(IterableSet importList,
51: String qualifiedName, Type t) {
52: //if two explicit imports dont import the same class we can remove explicit qualification
53: if (!containsMultiple(importList.iterator(), qualifiedName, t))
54: return getClassName(qualifiedName);
55: return qualifiedName;
56: }
57: }
|