1 20 21 package org.netbeans.modules.java.ui.nodes.elements; 22 23 import java.lang.reflect.Modifier ; 24 import org.netbeans.jmi.javamodel.*; 25 26 30 public class IconResolver implements IconStrings { 31 32 private static String getIconBaseForMethod(int modif) { 33 if (Modifier.isStatic(modif)) { 34 if (Modifier.isPrivate(modif)) 36 return METHOD_ST_PRIVATE; 37 else if (Modifier.isProtected(modif)) 38 return METHOD_ST_PROTECTED; 39 else if (Modifier.isPublic(modif)) 40 return METHOD_ST_PUBLIC; 41 else 42 return METHOD_ST_PACKAGE; 43 } 44 else { 45 if (Modifier.isPrivate(modif)) 47 return METHOD_PRIVATE; 48 else if (Modifier.isProtected(modif)) 49 return METHOD_PROTECTED; 50 else if (Modifier.isPublic(modif)) 51 return METHOD_PUBLIC; 52 else 53 return METHOD_PACKAGE; 54 } 55 } 56 57 public static String getIconBaseForMethod(Method m) { 58 return getIconBaseForMethod(m.getModifiers()); 59 } 60 61 public static String getIconBaseForAttribute(Attribute a) { 62 return getIconBaseForMethod(a.getModifiers()); 63 } 64 65 public static String getIconBaseForVariable(Variable v) { 66 return FIELD_PRIVATE; 67 } 68 69 public static String getIconBaseForField(Field f) { 70 int modif = f.getModifiers(); 71 if (!Modifier.isStatic(modif)) { 72 if (Modifier.isPrivate(modif)) 74 return FIELD_PRIVATE; 75 else if (Modifier.isProtected(modif)) 76 return FIELD_PROTECTED; 77 else if (Modifier.isPublic(modif)) 78 return FIELD_PUBLIC; 79 else 80 return FIELD_PACKAGE; 81 } 82 else { 83 if (Modifier.isPrivate(modif)) 85 return FIELD_ST_PRIVATE; 86 else if (Modifier.isProtected(modif)) 87 return FIELD_ST_PROTECTED; 88 else if (Modifier.isPublic(modif)) 89 return FIELD_ST_PUBLIC; 90 else 91 return FIELD_ST_PACKAGE; 92 } 93 } 94 95 public static String getIconBaseForInitializer(Initializer i) { 96 return Modifier.isStatic(i.getModifiers())? INITIALIZER_ST : INITIALIZER; 97 } 98 99 public static String getIconBaseForJavaClass(JavaClass c) { 100 return c.isInterface()? INTERFACE : CLASS; 101 } 102 103 public static String getIconBaseForConstructor(Constructor c) { 104 int modif = c.getModifiers(); 105 if (Modifier.isPrivate(modif)) 106 return CONSTRUCTOR_PRIVATE; 107 else if (Modifier.isProtected(modif)) 108 return CONSTRUCTOR_PROTECTED; 109 else if (Modifier.isPublic(modif)) 110 return CONSTRUCTOR_PUBLIC; 111 else 112 return CONSTRUCTOR_PACKAGE; 113 } 114 115 public static String getIconBase(Feature f) { 116 if (f instanceof Method) 117 return getIconBaseForMethod((Method) f); 118 if (f instanceof Field) 119 return getIconBaseForField((Field) f); 120 if (f instanceof Constructor) 121 return getIconBaseForConstructor((Constructor) f); 122 if (f instanceof Initializer) 123 return getIconBaseForInitializer((Initializer) f); 124 if (f instanceof JavaClass) 125 return getIconBaseForJavaClass((JavaClass) f); 126 if (f instanceof Attribute) 127 return getIconBaseForAttribute((Attribute) f); 128 if (f instanceof AnnotationType) 129 return ANNOTATION_TYPE; 130 if (f instanceof EnumConstant) 131 return ENUM_CONSTANT; 132 if (f instanceof JavaEnum) 133 return ENUM; 134 throw new IllegalArgumentException ("Unknown Feature"); } 136 } 137 | Popular Tags |