Mapper improved

This commit is contained in:
Michael Wain 2025-01-09 21:26:27 +03:00
parent 2fc08152b1
commit 5977af51b7
4 changed files with 21 additions and 2 deletions

View File

@ -6,7 +6,7 @@
<groupId>com.alterdekim.game</groupId>
<artifactId>actionScriptDecompiler</artifactId>
<version>0.0.3</version>
<version>0.0.4</version>
<packaging>jar</packaging>
<name>SWFDissect</name>

View File

@ -9,4 +9,6 @@ import java.lang.annotation.Target;
@Target(ElementType.FIELD)
public @interface FlashField {
String name() default "";
boolean useCustomConverter() default false;
Class<? extends FlashFieldConverter> converter() default FlashFieldConverter.None.class;
}

View File

@ -0,0 +1,11 @@
package com.alterdekim.flash.decompiler.mapper;
public abstract class FlashFieldConverter {
public abstract Object convert(Object o);
public abstract static class None extends FlashFieldConverter {
public None() {
}
}
}

View File

@ -4,6 +4,7 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.tuple.Pair;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.Map;
@ -21,8 +22,13 @@ public class FlashMapper {
Field f = p.getLeft();
String name = p.getRight();
f.setAccessible(true);
if( f.isAnnotationPresent(FlashField.class) && f.getAnnotation(FlashField.class).useCustomConverter()) {
f.set(result, f.getAnnotation(FlashField.class).converter().getDeclaredConstructor().newInstance().convert(m.get(name)));
return;
}
f.set(result, m.get(name));
} catch (IllegalAccessException e) {
} catch (IllegalAccessException | NoSuchMethodException | InstantiationException |
InvocationTargetException e) {
log.error("FlashMapper valueSet error: {}", e.getMessage());
}
});