1 21 22 package org.apache.derby.iapi.services.classfile; 23 24 import java.util.Enumeration ; 25 import java.util.HashSet ; 26 import java.util.StringTokenizer ; 27 import org.apache.derby.iapi.services.classfile.VMDescriptor; 28 29 36 37 38 class ClassEnumeration implements Enumeration { 39 ClassHolder cpt; 40 Enumeration inner; 41 CONSTANT_Index_info position; 42 HashSet foundClasses; 43 Enumeration classList; 44 45 ClassEnumeration( ClassHolder cpt, 46 Enumeration e, 47 Enumeration methods, 48 Enumeration fields) 49 { 50 this.cpt = cpt; 51 inner = e; 52 foundClasses = new HashSet (30, 0.8f); 53 findMethodReferences(methods, foundClasses); 54 findFieldReferences(fields, foundClasses); 55 findClassReferences(foundClasses); 56 classList = java.util.Collections.enumeration(foundClasses); 57 58 } 59 60 public boolean hasMoreElements() { 61 return classList.hasMoreElements(); 62 } 63 64 private void findClassReferences(HashSet foundClasses) 66 { 67 68 ConstantPoolEntry item; 69 CONSTANT_Index_info ref; 70 71 72 while (inner.hasMoreElements()) 73 { 74 item = (ConstantPoolEntry) inner.nextElement(); 75 if (item == null) 76 continue; 77 if (item.getTag() == VMDescriptor.CONSTANT_Class) 78 { 79 ref = (CONSTANT_Index_info) item; 80 81 String className = cpt.className(ref.getIndex()); 82 83 if (className.startsWith("[")) 86 { 87 distillClasses(className, foundClasses); 88 continue; 89 } 90 91 94 if (className.length() > 1) 95 { 96 if (className.startsWith("java")) 98 { 99 continue; 101 } 102 103 foundClasses.add(className); 104 } 105 } 106 } 107 108 } 109 110 private void findMethodReferences( Enumeration methods, 111 HashSet foundClasses) 112 { 113 while (methods.hasMoreElements()) 114 { 115 ClassMember member = (ClassMember) methods.nextElement(); 116 String description = member.getDescriptor(); 117 distillClasses(description, foundClasses); 118 } 119 } 120 121 private void findFieldReferences( Enumeration fields, 122 HashSet foundClasses) 123 { 124 while (fields.hasMoreElements()) 125 { 126 ClassMember member = (ClassMember) fields.nextElement(); 127 String description = member.getDescriptor(); 128 distillClasses(description, foundClasses); 129 } 130 } 131 132 void distillClasses(String fieldOrMethodSig, HashSet foundClasses) 133 { 134 if (fieldOrMethodSig == null || fieldOrMethodSig.length() < 1) 135 { 136 return; 138 } 139 140 if (fieldOrMethodSig.charAt(0) != '(') 141 { 142 145 int classNameStart = fieldOrMethodSig.indexOf('L'); 146 147 if (classNameStart == -1) 148 { 149 return; 151 } 152 153 String fieldType = 156 fieldOrMethodSig.substring(classNameStart + 1).replace('/', '.'); 157 158 if (fieldType.endsWith(";")) 161 { 162 fieldType = fieldType.substring(0,fieldType.length()-1); 163 } 164 165 if (fieldType.startsWith("java")) 166 { 167 return; } 170 171 foundClasses.add(fieldType); 172 return; 173 } 174 else 175 { 176 StringTokenizer tokens = new StringTokenizer (fieldOrMethodSig, "();["); 178 while (tokens.hasMoreElements()) 179 { 180 String aToken = (String ) tokens.nextToken(); 181 int classNameStart = aToken.indexOf('L'); 185 if (classNameStart != -1) 186 { 187 distillClasses(aToken, foundClasses); 188 } 189 else 190 { 191 continue; 192 } 193 } 194 } 195 } 196 197 public Object nextElement() { 198 return classList.nextElement(); 199 } 200 201 } 202 | Popular Tags |