/** * Creates a new field mapping, from the given parameters. * * @param parentClass The class mapping, this mapping belongs to * @param signature The obfuscated signature * @param deobfuscatedName The de-obfuscated name */ public FieldMappingImpl(final ClassMapping parentClass, final FieldSignature signature, final String deobfuscatedName) { super(parentClass, signature.getName(), deobfuscatedName); this.signature = signature; }
/** * Creates a new field mapping, attached to this class mapping, using * the given obfuscated name. * * @param signature The signature of the field * @return The field mapping * @since 0.4.0 */ default FieldMapping createFieldMapping(final FieldSignature signature) { return this.createFieldMapping(signature, signature.getName()); }
@Override default String getObfuscatedName() { return this.getSignature().getName(); }
@Override public FieldMapping createFieldMapping(final FieldSignature signature, final String deobfuscatedName) { return this.fields.compute(signature, (sig, existingMapping) -> { if (existingMapping != null) return existingMapping.setDeobfuscatedName(deobfuscatedName); final FieldMapping mapping = this.getMappings().getModelFactory().createFieldMapping(this, sig, deobfuscatedName); this.fieldsByName.put(sig.getName(), mapping); return mapping; }); }
@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; })); }