Skip to content

Instantly share code, notes, and snippets.

Created February 26, 2016 04:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/0a3b451e4fe22832e6ed to your computer and use it in GitHub Desktop.
Save anonymous/0a3b451e4fe22832e6ed to your computer and use it in GitHub Desktop.
package net.runtimemap.test;
import net.runtimemap.Mapper;
import net.runtimemap.map.MappingBase;
import net.runtimemap.meta.ClassMapping;
import net.runtimemap.meta.FieldMapping;
import net.runtimemap.meta.MethodMapping;
import net.runtimemap.meta.RuntimeMappings;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
/**
* A runtime mappings annotation test.
*/
public class RuntimeMappingsTest implements MappingBase {
public static String FIELD_TEST = "Test success!";
@Override
@RuntimeMappings(
classes = {
@ClassMapping(obfuscatedName = "net.runtimemap.test.RuntimeMappingsTest", name = "org.example.CurrentRuntimeMappings")
},
methods = {
@MethodMapping(className = "org.example.CurrentRuntimeMappings", obfMethodName = "mappings", methodName = "mappingsAnnotationMethod")
},
fields = {
@FieldMapping(className = "org.example.CurrentRuntimeMappings", obfFieldName = "FIELD_TEST", fieldName = "DONE_CONSTANT")
}
)
public void mappings() {}
public static void main(String[] args) throws Exception {
// get runtime instance
Mapper mapper = Mapper.getRuntimeInstance();
// register runtime mappings
mapper.register(RuntimeMappingsTest.class);
// test
Class thisClass = mapper.getClass("org.example.CurrentRuntimeMappings");
System.out.println(thisClass == null);
Method method = mapper.getMethod("org.example.CurrentRuntimeMappings.mappingsAnnotationMethod");
System.out.println(method == null);
System.out.println(method.invoke(thisClass.newInstance(), null));
Field testField = mapper.getField("org.example.CurrentRuntimeMappings.DONE_CONSTANT");
System.out.println(testField.get(String.class));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment