Mapper improved
This commit is contained in:
parent
2fc08152b1
commit
5977af51b7
2
pom.xml
2
pom.xml
@ -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>
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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() {
|
||||
}
|
||||
}
|
||||
}
|
@ -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());
|
||||
}
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user