Applies mappings to all classes in the given resource. Return value is the map of updated classes. @param resource Resource containing classes. @return Map of updated classes. Keys of the old names, values of the updated code.
(JavaResource resource)
| 149 | * @return Map of updated classes. Keys of the old names, values of the updated code. |
| 150 | */ |
| 151 | public Map<String, byte[]> accept(JavaResource resource) { |
| 152 | // Collect: <OldName, NewBytecode> |
| 153 | Map<String, byte[]> updated = new HashMap<>(); |
| 154 | for(Map.Entry<String, byte[]> e : resource.getClasses().entrySet()) { |
| 155 | byte[] old = e.getValue(); |
| 156 | ClassReader cr = new ClassReader(old); |
| 157 | accept(updated, cr); |
| 158 | } |
| 159 | // Update the resource's classes map |
| 160 | for(Map.Entry<String, byte[]> e : updated.entrySet()) { |
| 161 | String oldKey = e.getKey(); |
| 162 | String newKey = new ClassReader(e.getValue()).getClassName(); |
| 163 | if (!oldKey.equals(newKey)) |
| 164 | resource.getClasses().remove(oldKey); |
| 165 | resource.getClasses().put(newKey, e.getValue()); |
| 166 | } |
| 167 | // Tell the workspace we've finished renaming classes |
| 168 | workspace.onPrimaryDefinitionChanges(updated.keySet()); |
| 169 | // Update hierarchy graph |
| 170 | workspace.getHierarchyGraph().refresh(); |
| 171 | // Update saved mappings |
| 172 | workspace.updateAggregateMappings(getMappings(), updated.keySet()); |
| 173 | return updated; |
| 174 | } |
| 175 | |
| 176 | /** |
| 177 | * Applies mappings to the given class and puts the modified bytecode in the map. |