Skip to content

Commit b71cc56

Browse files
author
emmanue1
committed
Add full Java module support
1 parent 9fbddd5 commit b71cc56

29 files changed

+721
-284
lines changed

app/src/main/java/org/jd/gui/controller/SearchInConstantPoolsController.java

Lines changed: 43 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,10 @@ protected HashSet<Container.Entry> getOuterEntries(Set<Container.Entry> matching
211211
}
212212

213213
protected void filter(Indexes indexes, String pattern, int flags, Set<Container.Entry> matchingEntries) {
214-
boolean declarations = ((flags & SearchInConstantPoolsView.SEARCH_TYPE_DECLARATION) != 0);
215-
boolean references = ((flags & SearchInConstantPoolsView.SEARCH_TYPE_REFERENCE) != 0);
214+
boolean declarations = ((flags & SearchInConstantPoolsView.SEARCH_DECLARATION) != 0);
215+
boolean references = ((flags & SearchInConstantPoolsView.SEARCH_REFERENCE) != 0);
216216

217-
if ((flags & SearchInConstantPoolsView.SEARCH_TYPE_TYPE) != 0) {
217+
if ((flags & SearchInConstantPoolsView.SEARCH_TYPE) != 0) {
218218
if (declarations)
219219
match(indexes, "typeDeclarations", pattern,
220220
SearchInConstantPoolsController::matchTypeEntriesWithChar,
@@ -225,7 +225,7 @@ protected void filter(Indexes indexes, String pattern, int flags, Set<Container.
225225
SearchInConstantPoolsController::matchTypeEntriesWithString, matchingEntries);
226226
}
227227

228-
if ((flags & SearchInConstantPoolsView.SEARCH_TYPE_CONSTRUCTOR) != 0) {
228+
if ((flags & SearchInConstantPoolsView.SEARCH_CONSTRUCTOR) != 0) {
229229
if (declarations)
230230
match(indexes, "constructorDeclarations", pattern,
231231
SearchInConstantPoolsController::matchTypeEntriesWithChar,
@@ -236,7 +236,7 @@ protected void filter(Indexes indexes, String pattern, int flags, Set<Container.
236236
SearchInConstantPoolsController::matchTypeEntriesWithString, matchingEntries);
237237
}
238238

239-
if ((flags & SearchInConstantPoolsView.SEARCH_TYPE_METHOD) != 0) {
239+
if ((flags & SearchInConstantPoolsView.SEARCH_METHOD) != 0) {
240240
if (declarations)
241241
match(indexes, "methodDeclarations", pattern,
242242
SearchInConstantPoolsController::matchWithChar,
@@ -247,7 +247,7 @@ protected void filter(Indexes indexes, String pattern, int flags, Set<Container.
247247
SearchInConstantPoolsController::matchWithString, matchingEntries);
248248
}
249249

250-
if ((flags & SearchInConstantPoolsView.SEARCH_TYPE_FIELD) != 0) {
250+
if ((flags & SearchInConstantPoolsView.SEARCH_FIELD) != 0) {
251251
if (declarations)
252252
match(indexes, "fieldDeclarations", pattern,
253253
SearchInConstantPoolsController::matchWithChar,
@@ -258,12 +258,23 @@ protected void filter(Indexes indexes, String pattern, int flags, Set<Container.
258258
SearchInConstantPoolsController::matchWithString, matchingEntries);
259259
}
260260

261-
if ((flags & SearchInConstantPoolsView.SEARCH_TYPE_STRING) != 0) {
261+
if ((flags & SearchInConstantPoolsView.SEARCH_STRING) != 0) {
262262
if (declarations || references)
263263
match(indexes, "strings", pattern,
264264
SearchInConstantPoolsController::matchWithChar,
265265
SearchInConstantPoolsController::matchWithString, matchingEntries);
266266
}
267+
268+
if ((flags & SearchInConstantPoolsView.SEARCH_MODULE) != 0) {
269+
if (declarations)
270+
match(indexes, "javaModuleDeclarations", pattern,
271+
SearchInConstantPoolsController::matchWithChar,
272+
SearchInConstantPoolsController::matchWithString, matchingEntries);
273+
if (references)
274+
match(indexes, "javaModuleReferences", pattern,
275+
SearchInConstantPoolsController::matchWithChar,
276+
SearchInConstantPoolsController::matchWithString, matchingEntries);
277+
}
267278
}
268279

269280
@SuppressWarnings("unchecked")
@@ -275,29 +286,29 @@ protected void match(Indexes indexes, String indexName, String pattern,
275286

276287
if (patternLength > 0) {
277288
String key = String.valueOf(indexes.hashCode()) + "***" + indexName + "***" + pattern;
278-
Map<String, Collection> matchedTypes = cache.get(key);
289+
Map<String, Collection> matchedEntries = cache.get(key);
279290

280-
if (matchedTypes == null) {
291+
if (matchedEntries == null) {
281292
Map<String, Collection> index = indexes.getIndex(indexName);
282293

283294
if (patternLength == 1) {
284-
matchedTypes = matchWithCharFunction.apply(pattern.charAt(0), index);
295+
matchedEntries = matchWithCharFunction.apply(pattern.charAt(0), index);
285296
} else {
286297
String lastKey = key.substring(0, key.length() - 1);
287298
Map<String, Collection> lastMatchedTypes = cache.get(lastKey);
288299
if (lastMatchedTypes != null) {
289-
matchedTypes = matchWithStringFunction.apply(pattern, lastMatchedTypes);
300+
matchedEntries = matchWithStringFunction.apply(pattern, lastMatchedTypes);
290301
} else {
291-
matchedTypes = matchWithStringFunction.apply(pattern, index);
302+
matchedEntries = matchWithStringFunction.apply(pattern, index);
292303
}
293304
}
294305

295306
// Cache matchingEntries
296-
cache.put(key, matchedTypes);
307+
cache.put(key, matchedEntries);
297308
}
298309

299-
if (matchedTypes != null) {
300-
for (Collection<Container.Entry> entries : matchedTypes.values()) {
310+
if (matchedEntries != null) {
311+
for (Collection<Container.Entry> entries : matchedEntries.values()) {
301312
matchingEntries.addAll(entries);
302313
}
303314
}
@@ -306,7 +317,7 @@ protected void match(Indexes indexes, String indexName, String pattern,
306317

307318
protected static Map<String, Collection> matchTypeEntriesWithChar(char c, Map<String, Collection> index) {
308319
if ((c == '*') || (c == '?')) {
309-
return Collections.emptyMap();
320+
return index;
310321
} else {
311322
Map<String, Collection> map = new HashMap<>();
312323

@@ -345,13 +356,13 @@ protected static Map<String, Collection> matchTypeEntriesWithString(String patte
345356

346357
protected static Map<String, Collection> matchWithChar(char c, Map<String, Collection> index) {
347358
if ((c == '*') || (c == '?')) {
348-
return Collections.emptyMap();
359+
return index;
349360
} else {
350361
Map<String, Collection> map = new HashMap<>();
351362

352-
for (String typeName : index.keySet()) {
353-
if (!typeName.isEmpty() && (typeName.charAt(0) == c)) {
354-
map.put(typeName, index.get(typeName));
363+
for (String key : index.keySet()) {
364+
if (!key.isEmpty() && (key.charAt(0) == c)) {
365+
map.put(key, index.get(key));
355366
}
356367
}
357368

@@ -363,9 +374,9 @@ protected static Map<String, Collection> matchWithString(String pattern, Map<Str
363374
Pattern p = createPattern(pattern);
364375
Map<String, Collection> map = new HashMap<>();
365376

366-
for (String typeName : index.keySet()) {
367-
if (p.matcher(typeName).matches()) {
368-
map.put(typeName, index.get(typeName));
377+
for (String key : index.keySet()) {
378+
if (p.matcher(key).matches()) {
379+
map.put(key, index.get(key));
369380
}
370381
}
371382

@@ -419,20 +430,22 @@ protected void onTypeSelected(URI uri, String pattern, int flags) {
419430
sbPattern.append(pattern);
420431
sbPattern.append("&highlightFlags=");
421432

422-
if ((flags & SearchInConstantPoolsView.SEARCH_TYPE_DECLARATION) != 0)
433+
if ((flags & SearchInConstantPoolsView.SEARCH_DECLARATION) != 0)
423434
sbPattern.append('d');
424-
if ((flags & SearchInConstantPoolsView.SEARCH_TYPE_REFERENCE) != 0)
435+
if ((flags & SearchInConstantPoolsView.SEARCH_REFERENCE) != 0)
425436
sbPattern.append('r');
426-
if ((flags & SearchInConstantPoolsView.SEARCH_TYPE_TYPE) != 0)
437+
if ((flags & SearchInConstantPoolsView.SEARCH_TYPE) != 0)
427438
sbPattern.append('t');
428-
if ((flags & SearchInConstantPoolsView.SEARCH_TYPE_CONSTRUCTOR) != 0)
439+
if ((flags & SearchInConstantPoolsView.SEARCH_CONSTRUCTOR) != 0)
429440
sbPattern.append('c');
430-
if ((flags & SearchInConstantPoolsView.SEARCH_TYPE_METHOD) != 0)
441+
if ((flags & SearchInConstantPoolsView.SEARCH_METHOD) != 0)
431442
sbPattern.append('m');
432-
if ((flags & SearchInConstantPoolsView.SEARCH_TYPE_FIELD) != 0)
443+
if ((flags & SearchInConstantPoolsView.SEARCH_FIELD) != 0)
433444
sbPattern.append('f');
434-
if ((flags & SearchInConstantPoolsView.SEARCH_TYPE_STRING) != 0)
445+
if ((flags & SearchInConstantPoolsView.SEARCH_STRING) != 0)
435446
sbPattern.append('s');
447+
if ((flags & SearchInConstantPoolsView.SEARCH_MODULE) != 0)
448+
sbPattern.append('M');
436449

437450
// TODO In a future release, add 'highlightScope' to display search results in correct type and inner-type
438451
// def type = TypeFactoryService.instance.get(entry)?.make(api, entry, null)

app/src/main/java/org/jd/gui/util/net/UriUtil.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,25 @@ public class UriUtil {
2626
* file://codebase/a/b/c/D$E.class => file://codebase/a/b/c/D.class#typeDeclaration=D$E
2727
*/
2828
public static URI createURI(API api, Collection<Future<Indexes>> collectionOfFutureIndexes, Container.Entry entry, String query, String fragment) {
29-
TypeFactory typeFactory = TypeFactoryService.getInstance().get(entry);
29+
URI uri = entry.getUri();
3030

31-
if (typeFactory != null) {
32-
Type type = typeFactory.make(api, entry, fragment);
31+
try {
32+
String path = uri.getPath();
33+
TypeFactory typeFactory = TypeFactoryService.getInstance().get(entry);
3334

34-
if (type != null) {
35-
URI uri = entry.getUri();
36-
String path = getOuterPath(collectionOfFutureIndexes, entry, type);
35+
if (typeFactory != null) {
36+
Type type = typeFactory.make(api, entry, fragment);
3737

38-
try {
39-
return new URI(uri.getScheme(), uri.getHost(), path, query, fragment);
40-
} catch (URISyntaxException e) {
41-
assert ExceptionUtil.printStackTrace(e);
38+
if (type != null) {
39+
path = getOuterPath(collectionOfFutureIndexes, entry, type);
4240
}
4341
}
44-
}
4542

46-
return null;
43+
return new URI(uri.getScheme(), uri.getHost(), path, query, fragment);
44+
} catch (URISyntaxException e) {
45+
assert ExceptionUtil.printStackTrace(e);
46+
return uri;
47+
}
4748
}
4849

4950
@SuppressWarnings("unchecked")

app/src/main/java/org/jd/gui/view/SearchInConstantPoolsView.java

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,14 @@
3636
public class SearchInConstantPoolsView<T extends DefaultMutableTreeNode & ContainerEntryGettable & UriGettable> {
3737
protected static final ContainerComparator CONTAINER_COMPARATOR = new ContainerComparator();
3838

39-
public static final int SEARCH_TYPE_TYPE = 1;
40-
public static final int SEARCH_TYPE_CONSTRUCTOR = 2;
41-
public static final int SEARCH_TYPE_METHOD = 4;
42-
public static final int SEARCH_TYPE_FIELD = 8;
43-
public static final int SEARCH_TYPE_STRING = 16;
44-
public static final int SEARCH_TYPE_DECLARATION = 32;
45-
public static final int SEARCH_TYPE_REFERENCE = 64;
39+
public static final int SEARCH_TYPE = 1;
40+
public static final int SEARCH_CONSTRUCTOR = 2;
41+
public static final int SEARCH_METHOD = 4;
42+
public static final int SEARCH_FIELD = 8;
43+
public static final int SEARCH_STRING = 16;
44+
public static final int SEARCH_MODULE = 32;
45+
public static final int SEARCH_DECLARATION = 64;
46+
public static final int SEARCH_REFERENCE = 128;
4647

4748
protected API api;
4849
protected Set<URI> accepted = new HashSet<>();
@@ -56,6 +57,7 @@ public class SearchInConstantPoolsView<T extends DefaultMutableTreeNode & Contai
5657
protected JCheckBox searchInConstantPoolsCheckBoxConstructor;
5758
protected JCheckBox searchInConstantPoolsCheckBoxMethod;
5859
protected JCheckBox searchInConstantPoolsCheckBoxString;
60+
protected JCheckBox searchInConstantPoolsCheckBoxModule;
5961
protected JCheckBox searchInConstantPoolsCheckBoxDeclarations;
6062
protected JCheckBox searchInConstantPoolsCheckBoxReferences;
6163
protected Tree searchInConstantPoolsTree;
@@ -159,6 +161,8 @@ public SearchInConstantPoolsView(
159161
subsubpanel.setLayout(new GridLayout(2, 1));
160162
subsubpanel.add(searchInConstantPoolsCheckBoxString = new JCheckBox("String Constant"));
161163
searchInConstantPoolsCheckBoxString.addItemListener(checkBoxListener);
164+
subsubpanel.add(searchInConstantPoolsCheckBoxModule = new JCheckBox("Java Module"));
165+
searchInConstantPoolsCheckBoxModule.addItemListener(checkBoxListener);
162166
subhbox.add(subsubpanel);
163167

164168
subpanel = new JPanel();
@@ -338,19 +342,21 @@ public int getFlags() {
338342
int flags = 0;
339343

340344
if (searchInConstantPoolsCheckBoxType.isSelected())
341-
flags += SEARCH_TYPE_TYPE;
345+
flags += SEARCH_TYPE;
342346
if (searchInConstantPoolsCheckBoxConstructor.isSelected())
343-
flags += SEARCH_TYPE_CONSTRUCTOR;
347+
flags += SEARCH_CONSTRUCTOR;
344348
if (searchInConstantPoolsCheckBoxMethod.isSelected())
345-
flags += SEARCH_TYPE_METHOD;
349+
flags += SEARCH_METHOD;
346350
if (searchInConstantPoolsCheckBoxField.isSelected())
347-
flags += SEARCH_TYPE_FIELD;
351+
flags += SEARCH_FIELD;
348352
if (searchInConstantPoolsCheckBoxString.isSelected())
349-
flags += SEARCH_TYPE_STRING;
353+
flags += SEARCH_STRING;
354+
if (searchInConstantPoolsCheckBoxModule.isSelected())
355+
flags += SEARCH_MODULE;
350356
if (searchInConstantPoolsCheckBoxDeclarations.isSelected())
351-
flags += SEARCH_TYPE_DECLARATION;
357+
flags += SEARCH_DECLARATION;
352358
if (searchInConstantPoolsCheckBoxReferences.isSelected())
353-
flags += SEARCH_TYPE_REFERENCE;
359+
flags += SEARCH_REFERENCE;
354360

355361
return flags;
356362
}

app/src/main/java/org/jd/gui/view/component/panel/MainTabbedPanel.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,21 +144,22 @@ public boolean openUri(URI uri) {
144144
pageChangedListenersEnabled = false;
145145
// Search & display main tab
146146
T page = showPage(uri);
147+
147148
if (page != null) {
148-
if (!uri.equals(page.getUri()) && (page instanceof UriOpenable)) {
149+
if (page instanceof UriOpenable) {
149150
// Enable page changed event
150151
pageChangedListenersEnabled = true;
151152
// Search & display sub tab
152153
return ((UriOpenable)page).openUri(uri);
153154
}
154155
return true;
155-
} else {
156-
return false;
157156
}
158157
} finally {
159158
// Enable page changed event
160159
pageChangedListenersEnabled = true;
161160
}
161+
162+
return false;
162163
}
163164

164165
// --- PageChangedListener --- //

app/src/main/java/org/jd/gui/view/component/panel/TreeTabbedPanel.java

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,9 @@ public void mouseClicked(MouseEvent e) {
108108
tabbedPanel.setMinimumSize(new Dimension(150, 10));
109109
tabbedPanel.tabbedPane.addChangeListener(e -> pageChanged());
110110

111-
setLayout(new BorderLayout());
111+
setLayout(new BorderLayout());
112112

113-
JSplitPane splitter = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(tree), tabbedPanel);
113+
JSplitPane splitter = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(tree), tabbedPanel);
114114
splitter.setResizeWeight(0.2);
115115

116116
add(splitter, BorderLayout.CENTER);
@@ -230,15 +230,28 @@ protected <P extends JComponent & UriGettable> void pageChanged() {
230230
public boolean openUri(URI uri) {
231231
try {
232232
URI baseUri = new URI(uri.getScheme(), uri.getHost(), uri.getPath(), null);
233-
DefaultMutableTreeNode baseNode = searchTreeNode(baseUri, (DefaultMutableTreeNode)tree.getModel().getRoot());
234233

235-
if ((baseNode != null) && showPage(uri, baseUri, baseNode)) {
236-
DefaultMutableTreeNode node = searchTreeNode(uri, baseNode);
234+
if (this.uri.equals(baseUri)) {
235+
return true;
236+
} else {
237+
DefaultMutableTreeNode node = searchTreeNode(baseUri, (DefaultMutableTreeNode) tree.getModel().getRoot());
238+
239+
if (showPage(uri, baseUri, node)) {
240+
DefaultMutableTreeNode childNode = searchTreeNode(uri, node);
241+
if (childNode != null) {
242+
node = childNode;
243+
}
244+
}
237245

238246
if (node != null) {
239247
try {
240248
// Disable tree node changed listener
241249
treeNodeChangedEnabled = false;
250+
// Populate and expand node
251+
if (!(node instanceof PageCreator) && (node instanceof TreeNodeExpandable)) {
252+
((TreeNodeExpandable) node).populateTreeNode(api);
253+
tree.expandPath(new TreePath(node.getPath()));
254+
}
242255
// Select tree node
243256
TreePath treePath = new TreePath(node.getPath());
244257
tree.setSelectionPath(treePath);
@@ -247,8 +260,8 @@ public boolean openUri(URI uri) {
247260
// Enable tree node changed listener
248261
treeNodeChangedEnabled = true;
249262
}
263+
return true;
250264
}
251-
return true;
252265
}
253266
} catch (URISyntaxException e) {
254267
assert ExceptionUtil.printStackTrace(e);

services/src/main/java/org/jd/gui/model/container/JmodContainer.java renamed to services/src/main/java/org/jd/gui/model/container/JavaModuleContainer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313
import java.nio.file.Path;
1414

15-
public class JmodContainer extends GenericContainer {
16-
public JmodContainer(API api, Container.Entry parentEntry, Path rootPath) {
15+
public class JavaModuleContainer extends GenericContainer {
16+
public JavaModuleContainer(API api, Container.Entry parentEntry, Path rootPath) {
1717
super(api, parentEntry, rootPath);
1818
}
1919

services/src/main/java/org/jd/gui/service/container/JmodContainerFactoryProvider.java renamed to services/src/main/java/org/jd/gui/service/container/JavaModuleContainerFactoryProvider.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99

1010
import org.jd.gui.api.API;
1111
import org.jd.gui.api.model.Container;
12-
import org.jd.gui.model.container.JmodContainer;
12+
import org.jd.gui.model.container.JavaModuleContainer;
1313
import org.jd.gui.spi.ContainerFactory;
1414
import org.jd.gui.util.exception.ExceptionUtil;
1515

1616
import java.nio.file.Files;
1717
import java.nio.file.InvalidPathException;
1818
import java.nio.file.Path;
1919

20-
public class JmodContainerFactoryProvider implements ContainerFactory {
20+
public class JavaModuleContainerFactoryProvider implements ContainerFactory {
2121
@Override
2222
public String getType() { return "jmod"; }
2323

@@ -38,6 +38,6 @@ public boolean accept(API api, Path rootPath) {
3838

3939
@Override
4040
public Container make(API api, Container.Entry parentEntry, Path rootPath) {
41-
return new JmodContainer(api, parentEntry, rootPath);
41+
return new JavaModuleContainer(api, parentEntry, rootPath);
4242
}
4343
}

0 commit comments

Comments
 (0)