Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
# Conflicts:
#	services/src/main/java/org/jd/gui/service/indexer/ZipFileIndexerProvider.java
#	services/src/main/resources/META-INF/services/org.jd.gui.spi.ContainerFactory
#	services/src/main/resources/META-INF/services/org.jd.gui.spi.FileLoader
  • Loading branch information
roswalt committed Jun 13, 2019
2 parents b3ef034 + 515fca8 commit 2ae4688
Show file tree
Hide file tree
Showing 36 changed files with 786 additions and 299 deletions.
4 changes: 2 additions & 2 deletions api/src/main/java/org/jd/gui/spi/TreeNodeFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
import java.util.regex.Pattern;

public interface TreeNodeFactory {
String[] getSelectors();
String[] getSelectors();

Pattern getPathPattern();

<T extends DefaultMutableTreeNode & ContainerEntryGettable & UriGettable> T make(API api, Container.Entry entry);
<T extends DefaultMutableTreeNode & ContainerEntryGettable & UriGettable> T make(API api, Container.Entry entry);
}
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,10 @@ protected HashSet<Container.Entry> getOuterEntries(Set<Container.Entry> matching
}

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

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

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

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

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

if ((flags & SearchInConstantPoolsView.SEARCH_TYPE_STRING) != 0) {
if ((flags & SearchInConstantPoolsView.SEARCH_STRING) != 0) {
if (declarations || references)
match(indexes, "strings", pattern,
SearchInConstantPoolsController::matchWithChar,
SearchInConstantPoolsController::matchWithString, matchingEntries);
}

if ((flags & SearchInConstantPoolsView.SEARCH_MODULE) != 0) {
if (declarations)
match(indexes, "javaModuleDeclarations", pattern,
SearchInConstantPoolsController::matchWithChar,
SearchInConstantPoolsController::matchWithString, matchingEntries);
if (references)
match(indexes, "javaModuleReferences", pattern,
SearchInConstantPoolsController::matchWithChar,
SearchInConstantPoolsController::matchWithString, matchingEntries);
}
}

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

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

if (matchedTypes == null) {
if (matchedEntries == null) {
Map<String, Collection> index = indexes.getIndex(indexName);

if (patternLength == 1) {
matchedTypes = matchWithCharFunction.apply(pattern.charAt(0), index);
matchedEntries = matchWithCharFunction.apply(pattern.charAt(0), index);
} else {
String lastKey = key.substring(0, key.length() - 1);
Map<String, Collection> lastMatchedTypes = cache.get(lastKey);
if (lastMatchedTypes != null) {
matchedTypes = matchWithStringFunction.apply(pattern, lastMatchedTypes);
matchedEntries = matchWithStringFunction.apply(pattern, lastMatchedTypes);
} else {
matchedTypes = matchWithStringFunction.apply(pattern, index);
matchedEntries = matchWithStringFunction.apply(pattern, index);
}
}

// Cache matchingEntries
cache.put(key, matchedTypes);
cache.put(key, matchedEntries);
}

if (matchedTypes != null) {
for (Collection<Container.Entry> entries : matchedTypes.values()) {
if (matchedEntries != null) {
for (Collection<Container.Entry> entries : matchedEntries.values()) {
matchingEntries.addAll(entries);
}
}
Expand All @@ -306,7 +317,7 @@ protected void match(Indexes indexes, String indexName, String pattern,

protected static Map<String, Collection> matchTypeEntriesWithChar(char c, Map<String, Collection> index) {
if ((c == '*') || (c == '?')) {
return Collections.emptyMap();
return index;
} else {
Map<String, Collection> map = new HashMap<>();

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

protected static Map<String, Collection> matchWithChar(char c, Map<String, Collection> index) {
if ((c == '*') || (c == '?')) {
return Collections.emptyMap();
return index;
} else {
Map<String, Collection> map = new HashMap<>();

for (String typeName : index.keySet()) {
if (!typeName.isEmpty() && (typeName.charAt(0) == c)) {
map.put(typeName, index.get(typeName));
for (String key : index.keySet()) {
if (!key.isEmpty() && (key.charAt(0) == c)) {
map.put(key, index.get(key));
}
}

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

for (String typeName : index.keySet()) {
if (p.matcher(typeName).matches()) {
map.put(typeName, index.get(typeName));
for (String key : index.keySet()) {
if (p.matcher(key).matches()) {
map.put(key, index.get(key));
}
}

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

if ((flags & SearchInConstantPoolsView.SEARCH_TYPE_DECLARATION) != 0)
if ((flags & SearchInConstantPoolsView.SEARCH_DECLARATION) != 0)
sbPattern.append('d');
if ((flags & SearchInConstantPoolsView.SEARCH_TYPE_REFERENCE) != 0)
if ((flags & SearchInConstantPoolsView.SEARCH_REFERENCE) != 0)
sbPattern.append('r');
if ((flags & SearchInConstantPoolsView.SEARCH_TYPE_TYPE) != 0)
if ((flags & SearchInConstantPoolsView.SEARCH_TYPE) != 0)
sbPattern.append('t');
if ((flags & SearchInConstantPoolsView.SEARCH_TYPE_CONSTRUCTOR) != 0)
if ((flags & SearchInConstantPoolsView.SEARCH_CONSTRUCTOR) != 0)
sbPattern.append('c');
if ((flags & SearchInConstantPoolsView.SEARCH_TYPE_METHOD) != 0)
if ((flags & SearchInConstantPoolsView.SEARCH_METHOD) != 0)
sbPattern.append('m');
if ((flags & SearchInConstantPoolsView.SEARCH_TYPE_FIELD) != 0)
if ((flags & SearchInConstantPoolsView.SEARCH_FIELD) != 0)
sbPattern.append('f');
if ((flags & SearchInConstantPoolsView.SEARCH_TYPE_STRING) != 0)
if ((flags & SearchInConstantPoolsView.SEARCH_STRING) != 0)
sbPattern.append('s');
if ((flags & SearchInConstantPoolsView.SEARCH_MODULE) != 0)
sbPattern.append('M');

// TODO In a future release, add 'highlightScope' to display search results in correct type and inner-type
// def type = TypeFactoryService.instance.get(entry)?.make(api, entry, null)
Expand Down
25 changes: 13 additions & 12 deletions app/src/main/java/org/jd/gui/util/net/UriUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,25 @@ public class UriUtil {
* file://codebase/a/b/c/D$E.class => file://codebase/a/b/c/D.class#typeDeclaration=D$E
*/
public static URI createURI(API api, Collection<Future<Indexes>> collectionOfFutureIndexes, Container.Entry entry, String query, String fragment) {
TypeFactory typeFactory = TypeFactoryService.getInstance().get(entry);
URI uri = entry.getUri();

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

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

try {
return new URI(uri.getScheme(), uri.getHost(), path, query, fragment);
} catch (URISyntaxException e) {
assert ExceptionUtil.printStackTrace(e);
if (type != null) {
path = getOuterPath(collectionOfFutureIndexes, entry, type);
}
}
}

return null;
return new URI(uri.getScheme(), uri.getHost(), path, query, fragment);
} catch (URISyntaxException e) {
assert ExceptionUtil.printStackTrace(e);
return uri;
}
}

@SuppressWarnings("unchecked")
Expand Down
34 changes: 20 additions & 14 deletions app/src/main/java/org/jd/gui/view/SearchInConstantPoolsView.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@
public class SearchInConstantPoolsView<T extends DefaultMutableTreeNode & ContainerEntryGettable & UriGettable> {
protected static final ContainerComparator CONTAINER_COMPARATOR = new ContainerComparator();

public static final int SEARCH_TYPE_TYPE = 1;
public static final int SEARCH_TYPE_CONSTRUCTOR = 2;
public static final int SEARCH_TYPE_METHOD = 4;
public static final int SEARCH_TYPE_FIELD = 8;
public static final int SEARCH_TYPE_STRING = 16;
public static final int SEARCH_TYPE_DECLARATION = 32;
public static final int SEARCH_TYPE_REFERENCE = 64;
public static final int SEARCH_TYPE = 1;
public static final int SEARCH_CONSTRUCTOR = 2;
public static final int SEARCH_METHOD = 4;
public static final int SEARCH_FIELD = 8;
public static final int SEARCH_STRING = 16;
public static final int SEARCH_MODULE = 32;
public static final int SEARCH_DECLARATION = 64;
public static final int SEARCH_REFERENCE = 128;

protected API api;
protected Set<URI> accepted = new HashSet<>();
Expand All @@ -56,6 +57,7 @@ public class SearchInConstantPoolsView<T extends DefaultMutableTreeNode & Contai
protected JCheckBox searchInConstantPoolsCheckBoxConstructor;
protected JCheckBox searchInConstantPoolsCheckBoxMethod;
protected JCheckBox searchInConstantPoolsCheckBoxString;
protected JCheckBox searchInConstantPoolsCheckBoxModule;
protected JCheckBox searchInConstantPoolsCheckBoxDeclarations;
protected JCheckBox searchInConstantPoolsCheckBoxReferences;
protected Tree searchInConstantPoolsTree;
Expand Down Expand Up @@ -159,6 +161,8 @@ public SearchInConstantPoolsView(
subsubpanel.setLayout(new GridLayout(2, 1));
subsubpanel.add(searchInConstantPoolsCheckBoxString = new JCheckBox("String Constant"));
searchInConstantPoolsCheckBoxString.addItemListener(checkBoxListener);
subsubpanel.add(searchInConstantPoolsCheckBoxModule = new JCheckBox("Java Module"));
searchInConstantPoolsCheckBoxModule.addItemListener(checkBoxListener);
subhbox.add(subsubpanel);

subpanel = new JPanel();
Expand Down Expand Up @@ -338,19 +342,21 @@ public int getFlags() {
int flags = 0;

if (searchInConstantPoolsCheckBoxType.isSelected())
flags += SEARCH_TYPE_TYPE;
flags += SEARCH_TYPE;
if (searchInConstantPoolsCheckBoxConstructor.isSelected())
flags += SEARCH_TYPE_CONSTRUCTOR;
flags += SEARCH_CONSTRUCTOR;
if (searchInConstantPoolsCheckBoxMethod.isSelected())
flags += SEARCH_TYPE_METHOD;
flags += SEARCH_METHOD;
if (searchInConstantPoolsCheckBoxField.isSelected())
flags += SEARCH_TYPE_FIELD;
flags += SEARCH_FIELD;
if (searchInConstantPoolsCheckBoxString.isSelected())
flags += SEARCH_TYPE_STRING;
flags += SEARCH_STRING;
if (searchInConstantPoolsCheckBoxModule.isSelected())
flags += SEARCH_MODULE;
if (searchInConstantPoolsCheckBoxDeclarations.isSelected())
flags += SEARCH_TYPE_DECLARATION;
flags += SEARCH_DECLARATION;
if (searchInConstantPoolsCheckBoxReferences.isSelected())
flags += SEARCH_TYPE_REFERENCE;
flags += SEARCH_REFERENCE;

return flags;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,21 +144,22 @@ public boolean openUri(URI uri) {
pageChangedListenersEnabled = false;
// Search & display main tab
T page = showPage(uri);

if (page != null) {
if (!uri.equals(page.getUri()) && (page instanceof UriOpenable)) {
if (page instanceof UriOpenable) {
// Enable page changed event
pageChangedListenersEnabled = true;
// Search & display sub tab
return ((UriOpenable)page).openUri(uri);
}
return true;
} else {
return false;
}
} finally {
// Enable page changed event
pageChangedListenersEnabled = true;
}

return false;
}

// --- PageChangedListener --- //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ public void mouseClicked(MouseEvent e) {
tabbedPanel.setMinimumSize(new Dimension(150, 10));
tabbedPanel.tabbedPane.addChangeListener(e -> pageChanged());

setLayout(new BorderLayout());
setLayout(new BorderLayout());

JSplitPane splitter = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(tree), tabbedPanel);
JSplitPane splitter = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(tree), tabbedPanel);
splitter.setResizeWeight(0.2);

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

if ((baseNode != null) && showPage(uri, baseUri, baseNode)) {
DefaultMutableTreeNode node = searchTreeNode(uri, baseNode);
if (this.uri.equals(baseUri)) {
return true;
} else {
DefaultMutableTreeNode node = searchTreeNode(baseUri, (DefaultMutableTreeNode) tree.getModel().getRoot());

if (showPage(uri, baseUri, node)) {
DefaultMutableTreeNode childNode = searchTreeNode(uri, node);
if (childNode != null) {
node = childNode;
}
}

if (node != null) {
try {
// Disable tree node changed listener
treeNodeChangedEnabled = false;
// Populate and expand node
if (!(node instanceof PageCreator) && (node instanceof TreeNodeExpandable)) {
((TreeNodeExpandable) node).populateTreeNode(api);
tree.expandPath(new TreePath(node.getPath()));
}
// Select tree node
TreePath treePath = new TreePath(node.getPath());
tree.setSelectionPath(treePath);
Expand All @@ -247,8 +260,8 @@ public boolean openUri(URI uri) {
// Enable tree node changed listener
treeNodeChangedEnabled = true;
}
return true;
}
return true;
}
} catch (URISyntaxException e) {
assert ExceptionUtil.printStackTrace(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

import java.nio.file.Path;

public class JmodContainer extends GenericContainer {
public JmodContainer(API api, Container.Entry parentEntry, Path rootPath) {
public class JavaModuleContainer extends GenericContainer {
public JavaModuleContainer(API api, Container.Entry parentEntry, Path rootPath) {
super(api, parentEntry, rootPath);
}

Expand Down
Loading

0 comments on commit 2ae4688

Please sign in to comment.