/** * 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 method mapping, from the given parameters. * * @param parentClass The class mapping, this mapping belongs to * @param signature The signature * @param deobfuscatedName The de-obfuscated name */ public MethodMappingImpl(final ClassMapping parentClass, final MethodSignature signature, final String deobfuscatedName) { super(parentClass, signature.getName(), deobfuscatedName); this.signature = signature; }
@Override protected StringJoiner buildToString() { return super.buildToString() .add("type=" + this.type); }
@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; })); }
/** * 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)); }
/** * Creates a method signature, with the given raw string that contains the * method name and descriptor concatenated. * * @param nameAndDescriptor The method name and descriptor * @return The new method signature */ public static MethodSignature of(final String nameAndDescriptor) { int methodIndex = nameAndDescriptor.indexOf('('); return of(nameAndDescriptor.substring(0, methodIndex), nameAndDescriptor.substring(methodIndex)); }
/** * Creates a method signature, with the given method name and raw descriptor. * * @param name The method name * @param descriptor The method's raw descriptor * @return The new method signature */ public static MethodSignature of(final String name, final String descriptor) { return new MethodSignature(name, MethodDescriptor.of(descriptor)); }
/** * Gets the {@link MethodDescriptor} of the method. * * @return The method descriptor * @see MethodSignature#getDescriptor() */ default MethodDescriptor getDescriptor() { return this.getSignature().getDescriptor(); }
/** * Gets the {@link FieldType} of the field, if at all available. * * @return The type, wrapped in an {@link Optional} * @since 0.4.0 */ default Optional<FieldType> getType() { // First check the signature if (this.getSignature().getType().isPresent()) return this.getSignature().getType(); // Check the FieldTypeProvider return this.getMappings().getFieldTypeProvider().provide(this); }
/** * 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); }
/** * Gets, or creates should it not exist, a method mapping of the * given obfuscated name, and descriptor. * * @param obfuscatedName The obfuscated name of the method mapping * @param obfuscatedDescriptor The obfuscated descriptor of the method mapping * @return The method mapping */ default MethodMapping getOrCreateMethodMapping(final String obfuscatedName, final String obfuscatedDescriptor) { return this.getOrCreateMethodMapping(MethodSignature.of(obfuscatedName, obfuscatedDescriptor)); }
/** * 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 protected StringJoiner buildToString() { return super.buildToString() .add("descriptor=" + this.descriptor); }
/** * Creates a new method mapping, attached to this class mapping, using * the given method signature. * * @param signature The method signature * @return The method mapping */ default MethodMapping createMethodMapping(final MethodSignature signature) { return this.createMethodMapping(signature, signature.getName()); }
/** * 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 method mapping, attached to this class mapping, using * the given obfuscated method name and descriptor. * * @param obfuscatedName The obfuscated method name * @param obfuscatedDescriptor The obfuscated method descriptor * @return The method mapping */ default MethodMapping createMethodMapping(final String obfuscatedName, final String obfuscatedDescriptor) { return this.createMethodMapping(MethodSignature.of(obfuscatedName, obfuscatedDescriptor)); }
@Override default String getObfuscatedName() { return this.getSignature().getName(); }
@Override public final String toString() { return this.buildToString().toString(); }
/** * 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))); }
@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; }); }