/******************************************************************************* * Copyright (c) 2015 Jeff Martin. * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Lesser General Public * License v3.0 which accompanies this distribution, and is available at * http://www.gnu.org/licenses/lgpl.html *

* Contributors: * Jeff Martin - initial API and implementation ******************************************************************************/ package cuchaz.enigma.analysis; import cuchaz.enigma.analysis.index.JarIndex; import cuchaz.enigma.analysis.index.ReferenceIndex; import cuchaz.enigma.translation.Translator; import cuchaz.enigma.translation.representation.entry.FieldEntry; import cuchaz.enigma.translation.representation.entry.MethodDefEntry; import cuchaz.enigma.translation.representation.entry.MethodEntry; import javax.swing.tree.DefaultMutableTreeNode; public class FieldReferenceTreeNode extends DefaultMutableTreeNode implements ReferenceTreeNode { private final Translator translator; private FieldEntry entry; private EntryReference reference; public FieldReferenceTreeNode(Translator translator, FieldEntry entry) { this.translator = translator; this.entry = entry; this.reference = null; } private FieldReferenceTreeNode(Translator translator, EntryReference reference) { this.translator = translator; this.entry = reference.entry; this.reference = reference; } @Override public FieldEntry getEntry() { return this.entry; } @Override public EntryReference getReference() { return this.reference; } @Override public String toString() { if (this.reference != null) { return String.format("%s", translator.translate(this.reference.context)); } return translator.translate(entry).toString(); } public void load(JarIndex index, boolean recurse) { ReferenceIndex referenceIndex = index.getReferenceIndex(); // get all the child nodes if (this.reference == null) { for (EntryReference reference : referenceIndex.getReferencesToField(this.entry)) { add(new FieldReferenceTreeNode(translator, reference)); } } else { for (EntryReference reference : referenceIndex.getReferencesToMethod(this.reference.context)) { add(new MethodReferenceTreeNode(translator, reference)); } } if (recurse && children != null) { for (Object node : children) { if (node instanceof MethodReferenceTreeNode) { ((MethodReferenceTreeNode) node).load(index, true, false); } else if (node instanceof FieldReferenceTreeNode) { ((FieldReferenceTreeNode) node).load(index, true); } } } } }