Skip to content
This repository was archived by the owner on Nov 28, 2020. It is now read-only.

Commit aa1f30e

Browse files
committed
Right click -> search member refs results now show containing method body name
1 parent 2aeb467 commit aa1f30e

3 files changed

Lines changed: 41 additions & 24 deletions

File tree

src/me/coley/jremapper/gui/component/MemberSelectionMenu.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public void actionPerformed(ActionEvent e) {
5959
itemReferences.addActionListener(new ActionListener() {
6060
@Override
6161
public void actionPerformed(ActionEvent e) {
62-
DefaultMutableTreeNode root = callback.getSearcher().searchMember(mm);
62+
DefaultMutableTreeNode root = callback.getSearcher().searchMember(callback.getCurrentClass(), mm);
6363
callback.getWindow().getSearchPanel().setResults(root);
6464
}
6565
});

src/me/coley/jremapper/parse/Context.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ public class Context {
2929
private final static String ID_IMPLEMENTS = "implements";
3030
private final static String ID_EXTENDS = "extends";
3131
private final static String ID_ENUM = "enum";
32-
private final static String ID_FINAL = "final";
3332
private final static boolean debug = false;
3433
private ClassType thisType;
3534
private Map<String, String> simpleToQuantified = new HashMap<>();
@@ -324,8 +323,6 @@ private void readMember(IndexableStringReader read, String currentSimple, String
324323

325324
// Finish up the method descriptor and
326325
sbDesc.append(")" + retType);
327-
System.out.println(name + ":" + sbDesc.toString());
328-
329326
MemberMapping mm = callback.getCurrentClass().getMemberMappingWithRenaming(name, sbDesc.toString());
330327
if (mm != null) {
331328
fill(read, name, mm, read.getIndex() - nameIndex);

src/me/coley/jremapper/search/Search.java

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@
1010
import me.coley.bmf.ClassNode;
1111
import me.coley.bmf.JarReader;
1212
import me.coley.bmf.MemberNode;
13+
import me.coley.bmf.MethodNode;
1314
import me.coley.bmf.consts.*;
1415
import me.coley.bmf.mapping.ClassMapping;
1516
import me.coley.bmf.mapping.MemberMapping;
17+
import me.coley.bmf.opcode.AbstractFieldOpcode;
18+
import me.coley.bmf.opcode.AbstractMethodOpcode;
19+
import me.coley.bmf.opcode.Opcode;
1620
import me.coley.bmf.type.Type;
1721
import me.coley.bmf.util.ConstUtil;
1822
import me.coley.bmf.util.StreamUtil;
@@ -102,8 +106,7 @@ public DefaultMutableTreeNode searchClass(int mode, String text) {
102106
boolean meth = mode == CLASS_REFERENCE_METHODS;
103107
for (int i = 0; i < cn.constants.size(); i++) {
104108
Constant c = cn.constants.get(i);
105-
if (c == null || c.type != (meth ? ConstantType.METHOD : ConstantType.FIELD))
106-
continue;
109+
if (c == null || c.type != (meth ? ConstantType.METHOD : ConstantType.FIELD)) continue;
107110
if (c instanceof AbstractMemberConstant) {
108111
AbstractMemberConstant amc = (AbstractMemberConstant) c;
109112
String memberOwner = ConstUtil.getClassName(cn, amc.getClassIndex());
@@ -158,42 +161,59 @@ public DefaultMutableTreeNode searchMember(int mode, boolean methods, String tex
158161
return root;
159162
}
160163

161-
public DefaultMutableTreeNode searchMember(MemberMapping mm) {
164+
public DefaultMutableTreeNode searchMember(ClassMapping memberOwner, MemberMapping mm) {
162165
DefaultMutableTreeNode root = new DefaultMutableTreeNode(mm.toString());
163166
JarReader jar = callback.getJarReader();
164167
boolean isMethod = mm.desc.original.startsWith("(");
165168
// Sort at this stage rather than sorting the root later.
166169
// Its not worth the trouble later on.
167-
// @formatter:off
168170
for (String name : StreamUtil.listOfSortedJavaNames(jar.getClassEntries().keySet())) {
169171
ClassNode cn = jar.getClassEntries().get(name);
170172
ClassMapping cm = jar.getMapping().getMapping(name);
171173
MappingTreeNode mtn = new MappingTreeNode(cm.name.getValue(), cm);
172-
String space = isMethod ? "" : " ";
173-
cn.constants.stream()
174-
.filter(c -> c instanceof AbstractMemberConstant)
175-
.map(c -> ((AbstractMemberConstant)c))
176-
.map(c -> ((ConstNameType) cn.getConst(c.getNameTypeIndex())))
177-
.filter(c -> matchesNameDesc(cn, c, mm))
178-
.forEach(
179-
c -> mtn.add(new SearchResultTreeNode(mtn,
180-
ConstUtil.getUTF8(cn, c.getNameIndex()) + space + ConstUtil.getUTF8(cn, c.getDescIndex())))
181-
);
174+
for (MethodNode mn : cn.methods) {
175+
if (mn.code != null && mn.code.opcodes != null) {
176+
for (Opcode op : mn.code.opcodes.opcodes) {
177+
AbstractMemberConstant amc = getMemberConstantFromOpcode(cn, op, isMethod);
178+
if (amc == null) {
179+
continue;
180+
}
181+
// Check for proper owner
182+
String className = ConstUtil.getClassName(cn, amc.getClassIndex());
183+
if (className.equals(memberOwner.name.getValue())) {
184+
ConstNameType cnt = (ConstNameType) cn.getConst(amc.getNameTypeIndex());
185+
if (matchesNameDesc(cn, cnt, mm)) {
186+
mtn.add(new SearchResultTreeNode(mtn,
187+
ConstUtil.getUTF8(cn, mn.name) + " " + ConstUtil.getUTF8(cn, mn.desc)));
188+
}
189+
}
190+
}
191+
}
192+
}
182193
if (!mtn.isLeaf()) {
183194
root.add(mtn);
184195
}
185196
}
186-
// @formatter:on
187197
return root;
188198
}
189199

190-
private boolean matchesNameDesc(ClassNode cn, ConstNameType c, MemberMapping mm) {
191-
ConstUTF8 utfName = (ConstUTF8) cn.getConst(c.getNameIndex());
192-
ConstUTF8 utfDesc = (ConstUTF8) cn.getConst(c.getDescIndex());
193-
return mm.name.getValue().equals(utfName.getValue()) && mm.desc.toDesc().equals(utfDesc.getValue());
200+
private static AbstractMemberConstant getMemberConstantFromOpcode(ClassNode cn, Opcode op, boolean isMethod) {
201+
if (isMethod && op instanceof AbstractMethodOpcode) {
202+
AbstractMethodOpcode amo = (AbstractMethodOpcode) op;
203+
return (AbstractMemberConstant) cn.getConst(amo.methodIndex);
204+
} else if (!isMethod && op instanceof AbstractFieldOpcode) {
205+
AbstractFieldOpcode afo = (AbstractFieldOpcode) op;
206+
return (AbstractMemberConstant) cn.getConst(afo.fieldIndex);
207+
}
208+
return null;
209+
}
210+
211+
private static boolean matchesNameDesc(ClassNode cn, ConstNameType c, MemberMapping mm) {
212+
return mm.name.getValue().equals(ConstUtil.getUTF8(cn, c.getNameIndex()))
213+
&& mm.desc.toDesc().equals(ConstUtil.getUTF8(cn, c.getDescIndex()));
194214
}
195215

196-
private boolean isPrim(String search, boolean methods) {
216+
private static boolean isPrim(String search, boolean methods) {
197217
int l = search.length();
198218
if (methods) {
199219
return l == 3 && Type.readPrim(search.charAt(2)) != null;

0 commit comments

Comments
 (0)