1 26 27 package org.objectweb.util.browser.plugin.java.reflect; 28 29 import java.lang.reflect.Modifier ; 30 import java.util.HashMap ; 31 import java.util.Map ; 32 33 41 public class ClassVisibility { 42 43 49 50 public static Map config_ = initMap(); 51 52 53 public static final String DEFAULT_CONFIG = "_default_config_"; 54 55 61 67 73 77 public static boolean hasToBeAdded(int modifier, ClassVisibilityConfig config, String type){ 78 boolean addElement = false; 79 80 if (((Modifier.isPrivate(modifier) && config.get(type + "." + ClassVisibilityConfig.PRIVATE)) || (Modifier.isProtected(modifier) && config.get(type + "." + ClassVisibilityConfig.PROTECTED)) || (Modifier.isPublic(modifier) && config.get(type + "." + ClassVisibilityConfig.PUBLIC)))||(!Modifier.isPrivate(modifier) && !Modifier.isProtected(modifier) && !Modifier.isPublic(modifier) && config.get(type + "." + ClassVisibilityConfig.PACKAGE))) { 81 if (Modifier.isStatic(modifier) && Modifier.isFinal(modifier) && config.get(type + "." + ClassVisibilityConfig.STATIC) && config.get(type + "." + ClassVisibilityConfig.FINAL)) 82 addElement = true; 83 else if (Modifier.isStatic(modifier) && !Modifier.isFinal(modifier) && config.get(type + "." + ClassVisibilityConfig.STATIC)) 84 addElement = true; 85 else if (Modifier.isFinal(modifier) && !Modifier.isStatic(modifier) && config.get(type + "." + ClassVisibilityConfig.FINAL)) 86 addElement = true; 87 else if (Modifier.isAbstract(modifier) && config.get(type + "." + ClassVisibilityConfig.ABSTRACT)) 88 addElement = true; 89 else if (!Modifier.isStatic(modifier) && !Modifier.isFinal(modifier) && !Modifier.isAbstract(modifier)) 90 addElement = true; 91 } 92 93 return addElement; 94 } 95 96 109 public static String getTypeName(Class theClass){ 110 if(theClass!=null){ 111 StringBuffer name = new StringBuffer (); 112 int dimension = 0; 113 if(theClass.isArray()){ 114 while (theClass.isArray()) { 115 dimension++; 116 theClass = theClass.getComponentType(); 117 } 118 } 119 if(theClass.isPrimitive()) { 120 name.append(theClass.getName()); 121 } else { 122 if (theClass.getName().lastIndexOf('.')!=-1) 123 name.append(theClass.getName().substring(theClass.getName().lastIndexOf('.') + 1)); 124 else 125 name.append(theClass.getName()); 126 } 127 for(int i=0 ; i<dimension ; i++) 128 name.append("[]"); 129 return name.toString(); 130 } 131 return ""; 132 } 133 134 138 public static Map initMap(){ 139 config_ = new HashMap (); 140 config_.put(DEFAULT_CONFIG, createNewDefaultConfig()); 141 return config_; 142 } 143 144 153 public static ClassVisibilityConfig createNewDefaultConfig(){ 154 ClassVisibilityConfig defaultConfig = new ClassVisibilityConfig(); 155 defaultConfig.put(ClassVisibilityConfig.ATTRIBUTE + "." + ClassVisibilityConfig.PUBLIC, true); 156 defaultConfig.put(ClassVisibilityConfig.ATTRIBUTE + "." + ClassVisibilityConfig.STATIC, true); 157 defaultConfig.put(ClassVisibilityConfig.ATTRIBUTE + "." + ClassVisibilityConfig.FINAL, true); 158 defaultConfig.put(ClassVisibilityConfig.ATTRIBUTE + "." + ClassVisibilityConfig.TYPE, true); 159 defaultConfig.put(ClassVisibilityConfig.ATTRIBUTE + "." + ClassVisibilityConfig.DECLARING_CLASS, true); 160 defaultConfig.put(ClassVisibilityConfig.METHOD + "." + ClassVisibilityConfig.PUBLIC, true); 161 defaultConfig.put(ClassVisibilityConfig.METHOD + "." + ClassVisibilityConfig.STATIC, true); 162 defaultConfig.put(ClassVisibilityConfig.METHOD + "." + ClassVisibilityConfig.ABSTRACT, true); 163 defaultConfig.put(ClassVisibilityConfig.METHOD + "." + ClassVisibilityConfig.PARAMS, true); 164 defaultConfig.put(ClassVisibilityConfig.METHOD + "." + ClassVisibilityConfig.RETURN_TYPE, true); 165 defaultConfig.put(ClassVisibilityConfig.METHOD + "." + ClassVisibilityConfig.DECLARING_CLASS, true); 166 defaultConfig.put(ClassVisibilityConfig.INNER_CLASS + "." + ClassVisibilityConfig.PUBLIC, true); 167 defaultConfig.put(ClassVisibilityConfig.INNER_CLASS + "." + ClassVisibilityConfig.STATIC, true); 168 defaultConfig.put(ClassVisibilityConfig.INNER_CLASS + "." + ClassVisibilityConfig.FINAL, true); 169 defaultConfig.put(ClassVisibilityConfig.INNER_CLASS + "." + ClassVisibilityConfig.DECLARING_CLASS, true); 170 return defaultConfig; 171 } 172 173 } | Popular Tags |