Skip to content
This repository was archived by the owner on Jul 3, 2024. It is now read-only.

Commit fa6fea6

Browse files
committed
Apply spotless
1 parent 8d95bac commit fa6fea6

File tree

111 files changed

+3415
-4349
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+3415
-4349
lines changed

src/main/java/codechicken/lib/asm/ASMBlock.java

Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
package codechicken.lib.asm;
22

3+
import static org.objectweb.asm.tree.AbstractInsnNode.*;
4+
35
import com.google.common.collect.BiMap;
46
import com.google.common.collect.HashBiMap;
57
import com.google.common.collect.ImmutableMap;
8+
import java.util.*;
9+
import java.util.Map.Entry;
610
import org.objectweb.asm.tree.AbstractInsnNode;
711
import org.objectweb.asm.tree.InsnList;
812
import org.objectweb.asm.tree.JumpInsnNode;
913
import org.objectweb.asm.tree.LabelNode;
1014

11-
import java.util.*;
12-
import java.util.Map.Entry;
13-
14-
import static org.objectweb.asm.tree.AbstractInsnNode.*;
15-
16-
public class ASMBlock
17-
{
15+
public class ASMBlock {
1816
public InsnListSection list;
1917
private BiMap<String, LabelNode> labels;
2018

@@ -37,8 +35,7 @@ public ASMBlock() {
3735

3836
public LabelNode getOrAdd(String s) {
3937
LabelNode l = get(s);
40-
if (l == null)
41-
labels.put(s, l = new LabelNode());
38+
if (l == null) labels.put(s, l = new LabelNode());
4239
return l;
4340
}
4441

@@ -51,8 +48,8 @@ public void replaceLabels(Map<LabelNode, LabelNode> labelMap, Set<LabelNode> use
5148
switch (insn.getType()) {
5249
case LABEL:
5350
AbstractInsnNode insn2 = insn.clone(labelMap);
54-
if (insn2 == insn)//identity mapping
55-
continue;
51+
if (insn2 == insn) // identity mapping
52+
continue;
5653
if (usedLabels.contains(insn2))
5754
throw new IllegalStateException("LabelNode cannot be a part of two InsnLists");
5855
list.replace(insn, insn2);
@@ -64,10 +61,9 @@ public void replaceLabels(Map<LabelNode, LabelNode> labelMap, Set<LabelNode> use
6461
list.replace(insn, insn.clone(labelMap));
6562
}
6663

67-
for(Entry<LabelNode, LabelNode> entry : labelMap.entrySet()) {
64+
for (Entry<LabelNode, LabelNode> entry : labelMap.entrySet()) {
6865
String key = labels.inverse().get(entry.getKey());
69-
if(key != null)
70-
labels.put(key, entry.getValue());
66+
if (key != null) labels.put(key, entry.getValue());
7167
}
7268
}
7369

@@ -77,29 +73,25 @@ public void replaceLabels(Map<LabelNode, LabelNode> labelMap) {
7773

7874
public void replaceLabel(String s, LabelNode l) {
7975
LabelNode old = get(s);
80-
if (old != null)
81-
replaceLabels(ImmutableMap.of(old, l));
76+
if (old != null) replaceLabels(ImmutableMap.of(old, l));
8277
}
8378

8479
/**
8580
* Pulls all common labels from other into this
8681
* @return this
8782
*/
8883
public ASMBlock mergeLabels(ASMBlock other) {
89-
if(labels.isEmpty() || other.labels.isEmpty())
90-
return this;
84+
if (labels.isEmpty() || other.labels.isEmpty()) return this;
9185

92-
//common labels, give them our nodes
86+
// common labels, give them our nodes
9387
HashMap<LabelNode, LabelNode> labelMap = list.identityLabelMap();
94-
for(Entry<String, LabelNode> entry : other.labels.entrySet()) {
88+
for (Entry<String, LabelNode> entry : other.labels.entrySet()) {
9589
LabelNode old = labels.get(entry.getKey());
96-
if(old != null)
97-
labelMap.put(old, entry.getValue());
90+
if (old != null) labelMap.put(old, entry.getValue());
9891
}
9992
HashSet<LabelNode> usedLabels = new HashSet<LabelNode>();
10093
for (AbstractInsnNode insn = other.list.list.getFirst(); insn != null; insn = insn.getNext())
101-
if(insn.getType() == LABEL)
102-
usedLabels.add((LabelNode) insn);
94+
if (insn.getType() == LABEL) usedLabels.add((LabelNode) insn);
10395

10496
replaceLabels(labelMap, usedLabels);
10597
return this;
@@ -118,50 +110,50 @@ public ASMBlock copy() {
118110
BiMap<String, LabelNode> labels = HashBiMap.create();
119111
Map<LabelNode, LabelNode> labelMap = list.cloneLabels();
120112

121-
for(Entry<String, LabelNode> entry : this.labels.entrySet())
113+
for (Entry<String, LabelNode> entry : this.labels.entrySet())
122114
labels.put(entry.getKey(), labelMap.get(entry.getValue()));
123115

124116
return new ASMBlock(list.copy(labelMap), labels);
125117
}
126118

127119
public ASMBlock applyLabels(InsnListSection list2) {
128-
if(labels.isEmpty())
129-
return new ASMBlock(list2);
120+
if (labels.isEmpty()) return new ASMBlock(list2);
130121

131122
Set<LabelNode> cFlowLabels1 = labels.values();
132123
Set<LabelNode> cFlowLabels2 = InsnComparator.getControlFlowLabels(list2);
133124
ASMBlock block = new ASMBlock(list2);
134125

135126
HashMap<LabelNode, LabelNode> labelMap = new HashMap<LabelNode, LabelNode>();
136127

137-
for(int i = 0, k = 0; i < list.size() && k < list2.size(); ) {
128+
for (int i = 0, k = 0; i < list.size() && k < list2.size(); ) {
138129
AbstractInsnNode insn1 = list.get(i);
139-
if(!InsnComparator.insnImportant(insn1, cFlowLabels1)) {
130+
if (!InsnComparator.insnImportant(insn1, cFlowLabels1)) {
140131
i++;
141132
continue;
142133
}
143134

144135
AbstractInsnNode insn2 = list2.get(k);
145-
if(!InsnComparator.insnImportant(insn2, cFlowLabels2)) {
136+
if (!InsnComparator.insnImportant(insn2, cFlowLabels2)) {
146137
k++;
147138
continue;
148139
}
149140

150-
if(insn1.getOpcode() != insn2.getOpcode())
151-
throw new IllegalArgumentException("Lists do not match:\n"+list+"\n\n"+list2);
141+
if (insn1.getOpcode() != insn2.getOpcode())
142+
throw new IllegalArgumentException("Lists do not match:\n" + list + "\n\n" + list2);
152143

153-
switch(insn1.getType()) {
144+
switch (insn1.getType()) {
154145
case LABEL:
155146
labelMap.put((LabelNode) insn1, (LabelNode) insn2);
156147
break;
157148
case JUMP_INSN:
158149
labelMap.put(((JumpInsnNode) insn1).label, ((JumpInsnNode) insn2).label);
159150
break;
160151
}
161-
i++; k++;
152+
i++;
153+
k++;
162154
}
163155

164-
for(Entry<String, LabelNode> entry : labels.entrySet())
156+
for (Entry<String, LabelNode> entry : labels.entrySet())
165157
block.labels.put(entry.getKey(), labelMap.get(entry.getValue()));
166158

167159
return block;
@@ -170,4 +162,4 @@ public ASMBlock applyLabels(InsnListSection list2) {
170162
public InsnList rawListCopy() {
171163
return list.copy().list;
172164
}
173-
}
165+
}

src/main/java/codechicken/lib/asm/ASMHelper.java

Lines changed: 74 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
import codechicken.lib.config.ConfigFile;
44
import codechicken.lib.config.DefaultingConfigFile;
5+
import java.io.File;
6+
import java.io.IOException;
7+
import java.io.InputStream;
8+
import java.io.PrintWriter;
9+
import java.util.ArrayList;
10+
import java.util.List;
11+
import java.util.Map;
512
import org.apache.logging.log4j.LogManager;
613
import org.apache.logging.log4j.Logger;
714
import org.objectweb.asm.ClassReader;
@@ -12,48 +19,35 @@
1219
import org.objectweb.asm.util.Textifier;
1320
import org.objectweb.asm.util.TraceClassVisitor;
1421

15-
import java.io.File;
16-
import java.io.IOException;
17-
import java.io.InputStream;
18-
import java.io.PrintWriter;
19-
import java.util.ArrayList;
20-
import java.util.List;
21-
import java.util.Map;
22-
23-
public class ASMHelper
24-
{
22+
public class ASMHelper {
2523
public static ConfigFile config = loadConfig();
2624
public static Logger logger = LogManager.getLogger("CCL ASM");
2725

2826
private static ConfigFile loadConfig() {
29-
try {//weak reference for environments without FML
30-
File mcDir = (File)((Object[])Class.forName("cpw.mods.fml.relauncher.FMLInjectionData").getMethod("data").invoke(null))[6];
27+
try { // weak reference for environments without FML
28+
File mcDir = (File) ((Object[]) Class.forName("cpw.mods.fml.relauncher.FMLInjectionData")
29+
.getMethod("data")
30+
.invoke(null))
31+
[6];
3132
File file = new File(mcDir, "config/CodeChickenLib.cfg");
32-
if(ObfMapping.obfuscated)
33-
return new DefaultingConfigFile(file);
34-
else
35-
return new ConfigFile(file).setComment("CodeChickenLib development configuration file.");
33+
if (ObfMapping.obfuscated) return new DefaultingConfigFile(file);
34+
else return new ConfigFile(file).setComment("CodeChickenLib development configuration file.");
3635
} catch (Exception ignored) {
37-
return null;//no config for these systems
36+
return null; // no config for these systems
3837
}
3938
}
4039

41-
public static interface Acceptor
42-
{
40+
public static interface Acceptor {
4341
public void accept(ClassVisitor cv) throws IOException;
4442
}
4543

4644
public static MethodNode findMethod(ObfMapping methodmap, ClassNode cnode) {
47-
for (MethodNode mnode : cnode.methods)
48-
if (methodmap.matches(mnode))
49-
return mnode;
45+
for (MethodNode mnode : cnode.methods) if (methodmap.matches(mnode)) return mnode;
5046
return null;
5147
}
5248

5349
public static FieldNode findField(ObfMapping fieldmap, ClassNode cnode) {
54-
for (FieldNode fnode : cnode.fields)
55-
if (fieldmap.matches(fnode))
56-
return fnode;
50+
for (FieldNode fnode : cnode.fields) if (fieldmap.matches(fnode)) return fnode;
5751
return null;
5852
}
5953

@@ -86,23 +80,24 @@ public static InsnList cloneInsnList(Map<LabelNode, LabelNode> labelMap, InsnLis
8680
return new InsnListSection(list).copy(labelMap).list;
8781
}
8882

89-
public static List<TryCatchBlockNode> cloneTryCatchBlocks(Map<LabelNode, LabelNode> labelMap, List<TryCatchBlockNode> tcblocks) {
83+
public static List<TryCatchBlockNode> cloneTryCatchBlocks(
84+
Map<LabelNode, LabelNode> labelMap, List<TryCatchBlockNode> tcblocks) {
9085
ArrayList<TryCatchBlockNode> clone = new ArrayList<TryCatchBlockNode>();
9186
for (TryCatchBlockNode node : tcblocks)
9287
clone.add(new TryCatchBlockNode(
93-
labelMap.get(node.start),
94-
labelMap.get(node.end),
95-
labelMap.get(node.handler),
96-
node.type));
88+
labelMap.get(node.start), labelMap.get(node.end), labelMap.get(node.handler), node.type));
9789

9890
return clone;
9991
}
10092

101-
public static List<LocalVariableNode> cloneLocals(Map<LabelNode, LabelNode> labelMap, List<LocalVariableNode> locals) {
93+
public static List<LocalVariableNode> cloneLocals(
94+
Map<LabelNode, LabelNode> labelMap, List<LocalVariableNode> locals) {
10295
ArrayList<LocalVariableNode> clone = new ArrayList<LocalVariableNode>(locals.size());
10396
for (LocalVariableNode node : locals)
10497
clone.add(new LocalVariableNode(
105-
node.name, node.desc, node.signature,
98+
node.name,
99+
node.desc,
100+
node.signature,
106101
labelMap.get(node.start),
107102
labelMap.get(node.end),
108103
node.index));
@@ -114,8 +109,7 @@ public static void copy(MethodNode src, MethodNode dst) {
114109
Map<LabelNode, LabelNode> labelMap = cloneLabels(src.instructions);
115110
dst.instructions = cloneInsnList(labelMap, src.instructions);
116111
dst.tryCatchBlocks = cloneTryCatchBlocks(labelMap, src.tryCatchBlocks);
117-
if (src.localVariables != null)
118-
dst.localVariables = cloneLocals(labelMap, src.localVariables);
112+
if (src.localVariables != null) dst.localVariables = cloneLocals(labelMap, src.localVariables);
119113
dst.visibleAnnotations = src.visibleAnnotations;
120114
dst.invisibleAnnotations = src.invisibleAnnotations;
121115
dst.visitMaxs(src.maxStack, src.maxLocals);
@@ -130,7 +124,8 @@ public static int getLocal(List<LocalVariableNode> list, String name) {
130124
for (LocalVariableNode node : list) {
131125
if (node.name.equals(name)) {
132126
if (found >= 0)
133-
throw new RuntimeException("Duplicate local variable: " + name + " not coded to handle this scenario.");
127+
throw new RuntimeException(
128+
"Duplicate local variable: " + name + " not coded to handle this scenario.");
134129

135130
found = node.index;
136131
}
@@ -140,24 +135,21 @@ public static int getLocal(List<LocalVariableNode> list, String name) {
140135

141136
public static void replaceMethod(MethodNode original, MethodNode replacement) {
142137
original.instructions.clear();
143-
if (original.localVariables != null)
144-
original.localVariables.clear();
145-
if (original.tryCatchBlocks != null)
146-
original.tryCatchBlocks.clear();
138+
if (original.localVariables != null) original.localVariables.clear();
139+
if (original.tryCatchBlocks != null) original.tryCatchBlocks.clear();
147140
replacement.accept(original);
148141
}
149142

150-
public static void dump(Acceptor acceptor, File file, boolean filterImportant, boolean sortLocals, boolean textify) {
143+
public static void dump(
144+
Acceptor acceptor, File file, boolean filterImportant, boolean sortLocals, boolean textify) {
151145
try {
152-
if(!file.getParentFile().exists())
153-
file.getParentFile().mkdirs();
154-
if(!file.exists())
155-
file.createNewFile();
146+
if (!file.getParentFile().exists()) file.getParentFile().mkdirs();
147+
if (!file.exists()) file.createNewFile();
156148

157149
PrintWriter pout = new PrintWriter(file);
158150
ClassVisitor cv = new TraceClassVisitor(null, textify ? new Textifier() : new ASMifier(), pout);
159-
if(filterImportant) cv = new ImportantInsnVisitor(cv);
160-
if(sortLocals) cv = new LocalVariablesSorterVisitor(cv);
151+
if (filterImportant) cv = new ImportantInsnVisitor(cv);
152+
if (sortLocals) cv = new LocalVariablesSorterVisitor(cv);
161153
acceptor.accept(cv);
162154
pout.close();
163155
} catch (IOException e) {
@@ -166,36 +158,50 @@ public static void dump(Acceptor acceptor, File file, boolean filterImportant, b
166158
}
167159

168160
public static void dump(Acceptor acceptor, File file, boolean filterImportant, boolean sortLocals) {
169-
dump(acceptor, file, filterImportant, sortLocals, config.getTag("textify").getBooleanValue(true));
161+
dump(
162+
acceptor,
163+
file,
164+
filterImportant,
165+
sortLocals,
166+
config.getTag("textify").getBooleanValue(true));
170167
}
171168

172169
public static void dump(final byte[] bytes, File file, boolean filterImportant, boolean sortLocals) {
173-
dump(new Acceptor()
174-
{
175-
@Override
176-
public void accept(ClassVisitor cv) {
177-
new ClassReader(bytes).accept(cv, ClassReader.EXPAND_FRAMES);
178-
}
179-
}, file, filterImportant, sortLocals);
170+
dump(
171+
new Acceptor() {
172+
@Override
173+
public void accept(ClassVisitor cv) {
174+
new ClassReader(bytes).accept(cv, ClassReader.EXPAND_FRAMES);
175+
}
176+
},
177+
file,
178+
filterImportant,
179+
sortLocals);
180180
}
181181

182182
public static void dump(final InputStream is, File file, boolean filterImportant, boolean sortLocals) {
183-
dump(new Acceptor()
184-
{
185-
@Override
186-
public void accept(ClassVisitor cv) throws IOException {
187-
new ClassReader(is).accept(cv, ClassReader.EXPAND_FRAMES);
188-
}
189-
}, file, filterImportant, sortLocals);
183+
dump(
184+
new Acceptor() {
185+
@Override
186+
public void accept(ClassVisitor cv) throws IOException {
187+
new ClassReader(is).accept(cv, ClassReader.EXPAND_FRAMES);
188+
}
189+
},
190+
file,
191+
filterImportant,
192+
sortLocals);
190193
}
191194

192195
public static void dump(final ClassNode cnode, File file, boolean filterImportant, boolean sortLocals) {
193-
dump(new Acceptor()
194-
{
195-
@Override
196-
public void accept(ClassVisitor cv) {
197-
cnode.accept(cv);
198-
}
199-
}, file, filterImportant, sortLocals);
196+
dump(
197+
new Acceptor() {
198+
@Override
199+
public void accept(ClassVisitor cv) {
200+
cnode.accept(cv);
201+
}
202+
},
203+
file,
204+
filterImportant,
205+
sortLocals);
200206
}
201207
}

0 commit comments

Comments
 (0)