1 17 package org.apache.bcel.generic; 18 19 import org.apache.bcel.Constants; 20 import org.apache.bcel.Repository; 21 import org.apache.bcel.classfile.JavaClass; 22 23 29 public class ObjectType extends ReferenceType { 30 31 private String class_name; 33 34 37 public ObjectType(String class_name) { 38 super(Constants.T_REFERENCE, "L" + class_name.replace('.', '/') + ";"); 39 this.class_name = class_name.replace('/', '.'); 40 } 41 42 43 45 public String getClassName() { 46 return class_name; 47 } 48 49 50 52 public int hashCode() { 53 return class_name.hashCode(); 54 } 55 56 57 59 public boolean equals( Object type ) { 60 return (type instanceof ObjectType) 61 ? ((ObjectType) type).class_name.equals(class_name) 62 : false; 63 } 64 65 66 73 public boolean referencesClass() { 74 try { 75 JavaClass jc = Repository.lookupClass(class_name); 76 return jc.isClass(); 77 } catch (ClassNotFoundException e) { 78 return false; 79 } 80 } 81 82 83 90 public boolean referencesInterface() { 91 try { 92 JavaClass jc = Repository.lookupClass(class_name); 93 return !jc.isClass(); 94 } catch (ClassNotFoundException e) { 95 return false; 96 } 97 } 98 99 100 108 public boolean referencesClassExact() throws ClassNotFoundException { 109 JavaClass jc = Repository.lookupClass(class_name); 110 return jc.isClass(); 111 } 112 113 114 122 public boolean referencesInterfaceExact() throws ClassNotFoundException { 123 JavaClass jc = Repository.lookupClass(class_name); 124 return !jc.isClass(); 125 } 126 127 128 133 public boolean subclassOf( ObjectType superclass ) throws ClassNotFoundException { 134 if (this.referencesInterface() || superclass.referencesInterface()) { 135 return false; 136 } 137 return Repository.instanceOf(this.class_name, superclass.class_name); 138 } 139 140 141 146 public boolean accessibleTo( ObjectType accessor ) throws ClassNotFoundException { 147 JavaClass jc = Repository.lookupClass(class_name); 148 if (jc.isPublic()) { 149 return true; 150 } else { 151 JavaClass acc = Repository.lookupClass(accessor.class_name); 152 return acc.getPackageName().equals(jc.getPackageName()); 153 } 154 } 155 } 156 | Popular Tags |