Reformatted all the code using the default intelji formatting options.

This commit is contained in:
modmuss50 2015-08-09 11:05:32 +01:00
parent 2f63a24070
commit e0ab0af822
363 changed files with 20524 additions and 23016 deletions

View file

@ -15,115 +15,115 @@ import java.util.List;
public class ClassTransformation implements IClassTransformer {
private static final String[] emptyList = {};
static String strippableDesc;
private static final String[] emptyList = {};
static String strippableDesc;
public ClassTransformation() {
strippableDesc = Type.getDescriptor(Strippable.class);
}
public ClassTransformation() {
strippableDesc = Type.getDescriptor(Strippable.class);
}
static boolean strip(ClassNode cn) {
boolean altered = false;
if (cn.methods != null) {
Iterator<MethodNode> iter = cn.methods.iterator();
while (iter.hasNext()) {
MethodNode mn = iter.next();
if (mn.visibleAnnotations != null) {
for (AnnotationNode node : mn.visibleAnnotations) {
if (checkRemove(parseAnnotation(node, strippableDesc), iter)) {
altered = true;
break;
}
}
}
}
}
if (cn.fields != null) {
Iterator<FieldNode> iter = cn.fields.iterator();
while (iter.hasNext()) {
FieldNode fn = iter.next();
if (fn.visibleAnnotations != null) {
for (AnnotationNode node : fn.visibleAnnotations) {
if (checkRemove(parseAnnotation(node, strippableDesc), iter)) {
altered = true;
break;
}
}
}
}
}
return altered;
}
static boolean strip(ClassNode cn) {
boolean altered = false;
if (cn.methods != null) {
Iterator<MethodNode> iter = cn.methods.iterator();
while (iter.hasNext()) {
MethodNode mn = iter.next();
if (mn.visibleAnnotations != null) {
for (AnnotationNode node : mn.visibleAnnotations) {
if (checkRemove(parseAnnotation(node, strippableDesc), iter)) {
altered = true;
break;
}
}
}
}
}
if (cn.fields != null) {
Iterator<FieldNode> iter = cn.fields.iterator();
while (iter.hasNext()) {
FieldNode fn = iter.next();
if (fn.visibleAnnotations != null) {
for (AnnotationNode node : fn.visibleAnnotations) {
if (checkRemove(parseAnnotation(node, strippableDesc), iter)) {
altered = true;
break;
}
}
}
}
}
return altered;
}
static AnnotationInfo parseAnnotation(AnnotationNode node, String desc) {
AnnotationInfo info = null;
if (node.desc.equals(desc)) {
info = new AnnotationInfo();
if (node.values != null) {
List<Object> values = node.values;
for (int i = 0, e = values.size(); i < e; ) {
Object k = values.get(i++);
Object v = values.get(i++);
if ("value".equals(k)) {
if (!(v instanceof List && ((List<?>) v).size() > 0 && ((List<?>) v).get(0) instanceof String)) {
continue;
}
info.values = ((List<?>) v).toArray(emptyList);
}
}
}
}
return info;
}
static AnnotationInfo parseAnnotation(AnnotationNode node, String desc) {
AnnotationInfo info = null;
if (node.desc.equals(desc)) {
info = new AnnotationInfo();
if (node.values != null) {
List<Object> values = node.values;
for (int i = 0, e = values.size(); i < e; ) {
Object k = values.get(i++);
Object v = values.get(i++);
if ("value".equals(k)) {
if (!(v instanceof List && ((List<?>) v).size() > 0 && ((List<?>) v).get(0) instanceof String)) {
continue;
}
info.values = ((List<?>) v).toArray(emptyList);
}
}
}
}
return info;
}
static boolean checkRemove(AnnotationInfo node, Iterator<? extends Object> iter) {
if (node != null) {
boolean needsRemoved = false;
String[] value = node.values;
for (int j = 0, l = value.length; j < l; ++j) {
String clazz = value[j];
String mod = clazz.substring(4);
if (clazz.startsWith("mod:")) {
int i = mod.indexOf('@');
if (i > 0) {
mod = mod.substring(0, i);
}
if (!Loader.isModLoaded(mod)) {
needsRemoved = true;
}
}
if (needsRemoved) {
break;
}
}
if (needsRemoved) {
iter.remove();
return true;
}
}
return false;
}
static boolean checkRemove(AnnotationInfo node, Iterator<? extends Object> iter) {
if (node != null) {
boolean needsRemoved = false;
String[] value = node.values;
for (int j = 0, l = value.length; j < l; ++j) {
String clazz = value[j];
String mod = clazz.substring(4);
if (clazz.startsWith("mod:")) {
int i = mod.indexOf('@');
if (i > 0) {
mod = mod.substring(0, i);
}
if (!Loader.isModLoaded(mod)) {
needsRemoved = true;
}
}
if (needsRemoved) {
break;
}
}
if (needsRemoved) {
iter.remove();
return true;
}
}
return false;
}
@Override
public byte[] transform(String name, String transformedName, byte[] bytes) {
if (bytes == null) {
return null;
}
ClassReader cr = new ClassReader(bytes);
ClassNode cn = new ClassNode();
cr.accept(cn, 0);
if (strip(cn)) {
ClassWriter cw = new ClassWriter(0);
cn.accept(cw);
bytes = cw.toByteArray();
LoadingPlugin.stripedClases++;
}
return bytes;
}
@Override
public byte[] transform(String name, String transformedName, byte[] bytes) {
if (bytes == null) {
return null;
}
ClassReader cr = new ClassReader(bytes);
ClassNode cn = new ClassNode();
cr.accept(cn, 0);
if (strip(cn)) {
ClassWriter cw = new ClassWriter(0);
cn.accept(cw);
bytes = cw.toByteArray();
LoadingPlugin.stripedClases++;
}
return bytes;
}
static class AnnotationInfo {
public String side = "NONE";
public String[] values = emptyList;
}
static class AnnotationInfo {
public String side = "NONE";
public String[] values = emptyList;
}
}

View file

@ -11,53 +11,53 @@ import java.util.Map;
@IFMLLoadingPlugin.MCVersion("1.7.10")
public class LoadingPlugin implements IFMLLoadingPlugin {
public static boolean runtimeDeobfEnabled = false;
public static int stripedClases = 0;
public static boolean runtimeDeobfEnabled = false;
public static int stripedClases = 0;
@Override
public String[] getASMTransformerClass() {
return new String[]{"techreborn.asm.ClassTransformation"};
}
@Override
public String[] getASMTransformerClass() {
return new String[]{"techreborn.asm.ClassTransformation"};
}
@Override
public String getModContainerClass() {
return DummyMod.class.getName();
}
@Override
public String getModContainerClass() {
return DummyMod.class.getName();
}
@Override
public String getSetupClass() {
return DummyMod.class.getName();
}
@Override
public String getSetupClass() {
return DummyMod.class.getName();
}
@Override
public void injectData(Map<String, Object> data) {
runtimeDeobfEnabled = (Boolean) data.get("runtimeDeobfuscationEnabled");
}
@Override
public void injectData(Map<String, Object> data) {
runtimeDeobfEnabled = (Boolean) data.get("runtimeDeobfuscationEnabled");
}
@Override
public String getAccessTransformerClass() {
return null;
}
@Override
public String getAccessTransformerClass() {
return null;
}
public static class DummyMod extends DummyModContainer implements IFMLCallHook {
public DummyMod() {
super(new ModMetadata());
ModMetadata md = getMetadata();
md.autogenerated = true;
md.modId = ModInfo.MOD_ID + "asm";
md.name = md.description = "Techreborn-ASM";
md.parent = ModInfo.MOD_ID;
md.version = "000";
}
public static class DummyMod extends DummyModContainer implements IFMLCallHook {
public DummyMod() {
super(new ModMetadata());
ModMetadata md = getMetadata();
md.autogenerated = true;
md.modId = ModInfo.MOD_ID + "asm";
md.name = md.description = "Techreborn-ASM";
md.parent = ModInfo.MOD_ID;
md.version = "000";
}
@Override
public void injectData(Map<String, Object> data) {
@Override
public void injectData(Map<String, Object> data) {
}
}
@Override
public Void call() throws Exception {
return null;
}
}
@Override
public Void call() throws Exception {
return null;
}
}
}

View file

@ -1,10 +1,6 @@
package techreborn.asm;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.annotation.*;
/**
* When used on a class, methods from referenced interfaces will not be removed <br>
@ -17,6 +13,6 @@ import java.lang.annotation.Target;
@Target({ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.TYPE})
public @interface Strippable {
public String[] value();
public String[] value();
}