Skip to content

Commit a82460b

Browse files
author
roswalt
committed
2 parents 2ae4688 + 758f02e commit a82460b

File tree

14 files changed

+318
-174
lines changed

14 files changed

+318
-174
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
JD-GUI, a standalone graphical utility that displays Java sources from CLASS files.
44

5-
![](http://java-decompiler.github.io/img/screenshot17.png)
5+
![](https://raw.githubusercontent.com/java-decompiler/jd-gui/master/src/website/img/jd-gui.png)
66

77
- Java Decompiler projects home page: [http://java-decompiler.github.io](http://java-decompiler.github.io)
88
- JD-GUI source code: [https://github.com/java-decompiler/jd-gui](https://github.com/java-decompiler/jd-gui)

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -291,15 +291,17 @@ protected void match(Indexes indexes, String indexName, String pattern,
291291
if (matchedEntries == null) {
292292
Map<String, Collection> index = indexes.getIndex(indexName);
293293

294-
if (patternLength == 1) {
295-
matchedEntries = matchWithCharFunction.apply(pattern.charAt(0), index);
296-
} else {
297-
String lastKey = key.substring(0, key.length() - 1);
298-
Map<String, Collection> lastMatchedTypes = cache.get(lastKey);
299-
if (lastMatchedTypes != null) {
300-
matchedEntries = matchWithStringFunction.apply(pattern, lastMatchedTypes);
294+
if (index != null) {
295+
if (patternLength == 1) {
296+
matchedEntries = matchWithCharFunction.apply(pattern.charAt(0), index);
301297
} else {
302-
matchedEntries = matchWithStringFunction.apply(pattern, index);
298+
String lastKey = key.substring(0, key.length() - 1);
299+
Map<String, Collection> lastMatchedTypes = cache.get(lastKey);
300+
if (lastMatchedTypes != null) {
301+
matchedEntries = matchWithStringFunction.apply(pattern, lastMatchedTypes);
302+
} else {
303+
matchedEntries = matchWithStringFunction.apply(pattern, index);
304+
}
303305
}
304306
}
305307

app/src/main/java/org/jd/gui/service/configuration/ConfigurationXmlPersisterProvider.java

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,15 @@
1515
import javax.swing.*;
1616
import javax.xml.stream.*;
1717
import java.awt.*;
18-
import java.io.File;
19-
import java.io.FileInputStream;
20-
import java.io.FileOutputStream;
21-
import java.util.ArrayList;
18+
import java.io.*;
19+
import java.net.URL;
20+
import java.util.*;
2221
import java.util.List;
23-
import java.util.Map;
24-
import java.util.Stack;
22+
import java.util.jar.Manifest;
2523

2624
public class ConfigurationXmlPersisterProvider implements ConfigurationPersister {
2725
protected static final String ERROR_BACKGROUND_COLOR = "JdGuiPreferences.errorBackgroundColor";
26+
protected static final String JD_CORE_VERSION = "JdGuiPreferences.jdCoreVersion";
2827

2928
protected static final File FILE = getConfigFile();
3029

@@ -57,6 +56,7 @@ protected static File getConfigFile() {
5756
return new File(Constants.CONFIG_FILENAME);
5857
}
5958

59+
@Override
6060
public Configuration load() {
6161
// Default values
6262
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
@@ -170,9 +170,31 @@ public Configuration load() {
170170
config.getPreferences().put(ERROR_BACKGROUND_COLOR, "0xFF6666");
171171
}
172172

173+
config.getPreferences().put(JD_CORE_VERSION, getJdCoreVersion());
174+
173175
return config;
174176
}
175177

178+
protected String getJdCoreVersion() {
179+
try {
180+
Enumeration<URL> enumeration = ConfigurationXmlPersisterProvider.class.getClassLoader().getResources("META-INF/MANIFEST.MF");
181+
182+
while (enumeration.hasMoreElements()) {
183+
try (InputStream is = enumeration.nextElement().openStream()) {
184+
String attribute = new Manifest(is).getMainAttributes().getValue("JD-Core-Version");
185+
if (attribute != null) {
186+
return attribute;
187+
}
188+
}
189+
}
190+
} catch (IOException e) {
191+
assert ExceptionUtil.printStackTrace(e);
192+
}
193+
194+
return "SNAPSHOT";
195+
}
196+
197+
@Override
176198
public void save(Configuration configuration) {
177199
Point l = configuration.getMainWindowLocation();
178200
Dimension s = configuration.getMainWindowSize();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public AboutView(JFrame mainFrame) {
9797
hbox.add(Box.createHorizontalGlue());
9898

9999
hbox = Box.createHorizontalBox();
100-
hbox.add(new JLabel("Copyright © 2008-2019 Emmanuel Dupuy"));
100+
hbox.add(new JLabel("Copyright © 2008, 2019 Emmanuel Dupuy"));
101101
hbox.add(Box.createHorizontalGlue());
102102
subvbox.add(hbox);
103103

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,6 @@ public SearchInConstantPoolsView(
250250
if (selectedTreeNode != null) {
251251
selectedTypeCallback.accept(selectedTreeNode.getUri(), searchInConstantPoolsEnterTextField.getText(), getFlags());
252252
}
253-
searchInConstantPoolsDialog.setVisible(false);
254253
}
255254
};
256255
searchInConstantPoolsOpenButton.addActionListener(searchInConstantPoolsOpenActionListener);

build.gradle

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ apply plugin: 'edu.sc.seis.launch4j'
1515
apply plugin: 'nebula.ospackage'
1616

1717
// Common configuration //
18-
rootProject.version='1.5.2'
19-
rootProject.ext.set('jdCoreVersion', '1.0.3')
18+
rootProject.version='1.6.3'
19+
rootProject.ext.set('jdCoreVersion', '1.0.7')
2020
targetCompatibility = '1.8'
2121

2222
allprojects {
@@ -31,10 +31,7 @@ allprojects {
3131
}
3232

3333
repositories {
34-
mavenCentral()
35-
maven {
36-
url 'https://raw.github.com/java-decompiler/mvn-repo/master'
37-
}
34+
jcenter()
3835
}
3936

4037
configurations {

services/src/main/java/org/jd/gui/service/indexer/JavaModuleFileIndexerProvider.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public void index(API api, Container.Entry entry, Indexes indexes) {
3232
}
3333
}
3434

35+
@SuppressWarnings("unchecked")
3536
protected static void index(API api, Container.Entry entry, Indexes indexes, Map<String, Collection> packageDeclarationIndex) {
3637
for (Container.Entry e : entry.getChildren()) {
3738
if (e.isDirectory()) {

services/src/main/java/org/jd/gui/service/sourcesaver/ClassFileSourceSaverProvider.java

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,43 +16,23 @@
1616
import org.jd.gui.util.io.NewlineOutputStream;
1717

1818
import java.io.*;
19-
import java.net.URL;
2019
import java.nio.charset.Charset;
2120
import java.nio.file.Files;
2221
import java.nio.file.Path;
23-
import java.util.Enumeration;
2422
import java.util.HashMap;
2523
import java.util.Map;
26-
import java.util.jar.Manifest;
2724

2825
public class ClassFileSourceSaverProvider extends AbstractSourceSaverProvider {
2926
protected static final String ESCAPE_UNICODE_CHARACTERS = "ClassFileDecompilerPreferences.escapeUnicodeCharacters";
30-
protected static final String REALIGN_LINE_NUMBERS = "ClassFileDecompilerPreferences.realignLineNumbers";
31-
protected static final String WRITE_LINE_NUMBERS = "ClassFileSaverPreferences.writeLineNumbers";
32-
protected static final String WRITE_METADATA = "ClassFileSaverPreferences.writeMetadata";
27+
protected static final String REALIGN_LINE_NUMBERS = "ClassFileDecompilerPreferences.realignLineNumbers";
28+
protected static final String WRITE_LINE_NUMBERS = "ClassFileSaverPreferences.writeLineNumbers";
29+
protected static final String WRITE_METADATA = "ClassFileSaverPreferences.writeMetadata";
30+
protected static final String JD_CORE_VERSION = "JdGuiPreferences.jdCoreVersion";
3331

3432
protected static final ClassFileToJavaSourceDecompiler DECOMPILER = new ClassFileToJavaSourceDecompiler();
3533

3634
protected ContainerLoader loader = new ContainerLoader();
3735
protected LineNumberStringBuilderPrinter printer = new LineNumberStringBuilderPrinter();
38-
protected String jdCoreVersion = "SNAPSHOT";
39-
40-
public ClassFileSourceSaverProvider() {
41-
try {
42-
Enumeration<URL> enumeration = ClassFileSourceSaverProvider.class.getClassLoader().getResources("META-INF/MANIFEST.MF");
43-
44-
while (enumeration.hasMoreElements()) {
45-
try (InputStream is = enumeration.nextElement().openStream()) {
46-
String attribute = new Manifest(is).getMainAttributes().getValue("JD-Core-Version");
47-
if (attribute != null) {
48-
jdCoreVersion = attribute;
49-
}
50-
}
51-
}
52-
} catch (IOException e) {
53-
assert ExceptionUtil.printStackTrace(e);
54-
}
55-
}
5636

5737
@Override public String[] getSelectors() { return appendSelectors("*:file:*.class"); }
5838

@@ -144,7 +124,7 @@ public void saveContent(API api, Controller controller, Listener listener, Path
144124
}
145125
// Add JD-Core version
146126
stringBuffer.append("\n * JD-Core Version: ");
147-
stringBuffer.append(jdCoreVersion);
127+
stringBuffer.append(preferences.get(JD_CORE_VERSION));
148128
stringBuffer.append("\n */");
149129
}
150130

services/src/main/java/org/jd/gui/util/decompiler/LineNumberStringBuilderPrinter.java

Lines changed: 95 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -8,99 +8,99 @@
88
package org.jd.gui.util.decompiler;
99

1010
public class LineNumberStringBuilderPrinter extends StringBuilderPrinter {
11-
protected boolean showLineNumbers = false;
12-
13-
protected int maxLineNumber = 0;
14-
protected int digitCount = 0;
15-
16-
protected String lineNumberBeginPrefix;
17-
protected String lineNumberEndPrefix;
18-
protected String unknownLineNumberPrefix;
19-
20-
public void setShowLineNumbers(boolean showLineNumbers) { this.showLineNumbers = showLineNumbers; }
21-
22-
protected int printDigit(int dcv, int lineNumber, int divisor, int left) {
23-
if (digitCount >= dcv) {
24-
if (lineNumber < divisor) {
25-
append(' ');
26-
} else {
27-
int e = (lineNumber-left) / divisor;
28-
append((char)('0' + e));
29-
left += e*divisor;
30-
}
31-
}
32-
33-
return left;
34-
}
35-
36-
// --- Printer --- //
37-
@Override
38-
public void start(int maxLineNumber, int majorVersion, int minorVersion) {
39-
super.start(maxLineNumber, majorVersion, minorVersion);
40-
41-
if (showLineNumbers) {
42-
this.maxLineNumber = maxLineNumber;
43-
44-
if (maxLineNumber > 0) {
45-
digitCount = 1;
46-
unknownLineNumberPrefix = " ";
47-
int maximum = 9;
48-
49-
while (maximum < maxLineNumber) {
50-
digitCount++;
51-
unknownLineNumberPrefix += ' ';
52-
maximum = maximum*10 + 9;
53-
}
54-
55-
lineNumberBeginPrefix = "/* ";
56-
lineNumberEndPrefix = " */ ";
57-
} else {
58-
unknownLineNumberPrefix = "";
59-
lineNumberBeginPrefix = "";
60-
lineNumberEndPrefix = "";
61-
}
62-
} else {
63-
this.maxLineNumber = 0;
64-
unknownLineNumberPrefix = "";
65-
lineNumberBeginPrefix = "";
66-
lineNumberEndPrefix = "";
67-
}
68-
}
69-
70-
@Override public void startLine(int lineNumber) {
71-
if (maxLineNumber > 0) {
72-
append(lineNumberBeginPrefix);
73-
74-
if (lineNumber == UNKNOWN_LINE_NUMBER) {
75-
append(unknownLineNumberPrefix);
76-
} else {
77-
int left = 0;
78-
79-
left = printDigit(5, lineNumber, 10000, left);
80-
left = printDigit(4, lineNumber, 1000, left);
81-
left = printDigit(3, lineNumber, 100, left);
82-
left = printDigit(2, lineNumber, 10, left);
83-
append((char)('0' + (lineNumber-left)));
84-
}
85-
86-
append(lineNumberEndPrefix);
87-
}
88-
89-
for (int i=0; i<indentationCount; i++) {
90-
append(TAB);
91-
}
92-
}
93-
@Override public void extraLine(int count) {
94-
if (realignmentLineNumber) {
95-
while (count-- > 0) {
96-
if (maxLineNumber > 0) {
97-
append(lineNumberBeginPrefix);
98-
append(unknownLineNumberPrefix);
99-
append(lineNumberEndPrefix);
100-
}
101-
102-
append(NEWLINE);
103-
}
104-
}
105-
}
11+
protected boolean showLineNumbers = false;
12+
13+
protected int maxLineNumber = 0;
14+
protected int digitCount = 0;
15+
16+
protected String lineNumberBeginPrefix;
17+
protected String lineNumberEndPrefix;
18+
protected String unknownLineNumberPrefix;
19+
20+
public void setShowLineNumbers(boolean showLineNumbers) { this.showLineNumbers = showLineNumbers; }
21+
22+
protected int printDigit(int dcv, int lineNumber, int divisor, int left) {
23+
if (digitCount >= dcv) {
24+
if (lineNumber < divisor) {
25+
stringBuffer.append(' ');
26+
} else {
27+
int e = (lineNumber-left) / divisor;
28+
stringBuffer.append((char)('0' + e));
29+
left += e*divisor;
30+
}
31+
}
32+
33+
return left;
34+
}
35+
36+
// --- Printer --- //
37+
@Override
38+
public void start(int maxLineNumber, int majorVersion, int minorVersion) {
39+
super.start(maxLineNumber, majorVersion, minorVersion);
40+
41+
if (showLineNumbers) {
42+
this.maxLineNumber = maxLineNumber;
43+
44+
if (maxLineNumber > 0) {
45+
digitCount = 1;
46+
unknownLineNumberPrefix = " ";
47+
int maximum = 9;
48+
49+
while (maximum < maxLineNumber) {
50+
digitCount++;
51+
unknownLineNumberPrefix += ' ';
52+
maximum = maximum*10 + 9;
53+
}
54+
55+
lineNumberBeginPrefix = "/* ";
56+
lineNumberEndPrefix = " */ ";
57+
} else {
58+
unknownLineNumberPrefix = "";
59+
lineNumberBeginPrefix = "";
60+
lineNumberEndPrefix = "";
61+
}
62+
} else {
63+
this.maxLineNumber = 0;
64+
unknownLineNumberPrefix = "";
65+
lineNumberBeginPrefix = "";
66+
lineNumberEndPrefix = "";
67+
}
68+
}
69+
70+
@Override public void startLine(int lineNumber) {
71+
if (maxLineNumber > 0) {
72+
stringBuffer.append(lineNumberBeginPrefix);
73+
74+
if (lineNumber == UNKNOWN_LINE_NUMBER) {
75+
stringBuffer.append(unknownLineNumberPrefix);
76+
} else {
77+
int left = 0;
78+
79+
left = printDigit(5, lineNumber, 10000, left);
80+
left = printDigit(4, lineNumber, 1000, left);
81+
left = printDigit(3, lineNumber, 100, left);
82+
left = printDigit(2, lineNumber, 10, left);
83+
stringBuffer.append((char)('0' + (lineNumber-left)));
84+
}
85+
86+
stringBuffer.append(lineNumberEndPrefix);
87+
}
88+
89+
for (int i=0; i<indentationCount; i++) {
90+
stringBuffer.append(TAB);
91+
}
92+
}
93+
@Override public void extraLine(int count) {
94+
if (realignmentLineNumber) {
95+
while (count-- > 0) {
96+
if (maxLineNumber > 0) {
97+
stringBuffer.append(lineNumberBeginPrefix);
98+
stringBuffer.append(unknownLineNumberPrefix);
99+
stringBuffer.append(lineNumberEndPrefix);
100+
}
101+
102+
stringBuffer.append(NEWLINE);
103+
}
104+
}
105+
}
106106
}

0 commit comments

Comments
 (0)