/** * Creates a new field mapping, attached to this class mapping, using * the given obfuscated and de-obfuscated name. * * @param obfuscatedName The obfuscated name of the field * @param deobfuscatedName The de-obfuscated name of the field * @return The field mapping */ default FieldMapping createFieldMapping(final String obfuscatedName, final String deobfuscatedName) { return this.createFieldMapping(new FieldSignature(obfuscatedName, (FieldType) null), deobfuscatedName); }
/** * Establishes whether the class mapping contains a field mapping * of the given obfuscated name. * * @param obfuscatedName The obfuscated name of the field mapping * @return {@code true} should a field mapping of the given * obfuscated name exists in the class mapping; * {@code false} otherwise */ default boolean hasFieldMapping(final String obfuscatedName) { return this.hasFieldMapping(new FieldSignature(obfuscatedName, (FieldType) null)); }
/** * Creates a new field signature with the given name and * decoded type descriptor. * * @param name The name of the field * @param type The raw type of the field * @return The new field signature */ public static FieldSignature of(String name, String type) { return new FieldSignature(name, FieldType.of(type)); }
/** * Gets, or creates should it not exist, a field mapping of the * given signature. * * @param obfuscatedName The obfuscated name of the field mapping * @param obfuscatedDescriptor The obfuscated descriptor of the field mapping * @return The field mapping * @since 0.4.0 */ default FieldMapping getOrCreateFieldMapping(final String obfuscatedName, final String obfuscatedDescriptor) { return this.getOrCreateFieldMapping(new FieldSignature(obfuscatedName, FieldType.of(obfuscatedDescriptor))); }
private void readClass(final ClassMapping mapping) throws IOException { mapping.setDeobfuscatedName(this.stream.readUTF()); final int classCount = this.stream.readInt(); for (int i = 0; i < classCount; i++) { this.readClass(mapping.getOrCreateInnerClassMapping(this.stream.readUTF())); } final int fieldCount = this.stream.readInt(); for (int i = 0; i < fieldCount; i++) { final FieldMapping field; final String obf = this.stream.readUTF(); // has type info // todo: clean this up (introduce more convenience methods to ClassMapping) if (this.stream.readBoolean()) { field = mapping.getOrCreateFieldMapping(new FieldSignature(obf, FieldType.of(this.stream.readUTF()))); } else { field = mapping.getOrCreateFieldMapping(obf); } field.setDeobfuscatedName(this.stream.readUTF()); } final int methodCount = this.stream.readInt(); for (int i = 0; i < methodCount; i++) { mapping.getOrCreateMethodMapping(this.stream.readUTF(), this.stream.readUTF()) .setDeobfuscatedName(this.stream.readUTF()); } }
@Override public Optional<FieldMapping> computeFieldMapping(FieldSignature signature) { // If the field type is not provided, lookup up only the field name if (!signature.getType().isPresent()) { return this.getFieldMapping(signature.getName()); } // Otherwise, look up the signature as-is, but attempt falling back to a signature without type // Note: We cannot use fieldsByName here, because we'd eventually return FieldMappings with the wrong type return Optional.ofNullable(this.fields.computeIfAbsent(signature, (sig) -> { final FieldMapping mapping = this.fields.get(new FieldSignature(sig.getName())); return mapping != null ? this.getMappings().getModelFactory().createFieldMapping(mapping.getParent(), sig, mapping.getDeobfuscatedName()) : null; })); }