Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
roswalt committed Aug 21, 2019
2 parents 2ae4688 + 758f02e commit a82460b
Show file tree
Hide file tree
Showing 14 changed files with 318 additions and 174 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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

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

- Java Decompiler projects home page: [http://java-decompiler.github.io](http://java-decompiler.github.io)
- JD-GUI source code: [https://github.com/java-decompiler/jd-gui](https://github.com/java-decompiler/jd-gui)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,15 +291,17 @@ protected void match(Indexes indexes, String indexName, String pattern,
if (matchedEntries == null) {
Map<String, Collection> index = indexes.getIndex(indexName);

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,15 @@
import javax.swing.*;
import javax.xml.stream.*;
import java.awt.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.io.*;
import java.net.URL;
import java.util.*;
import java.util.List;
import java.util.Map;
import java.util.Stack;
import java.util.jar.Manifest;

public class ConfigurationXmlPersisterProvider implements ConfigurationPersister {
protected static final String ERROR_BACKGROUND_COLOR = "JdGuiPreferences.errorBackgroundColor";
protected static final String JD_CORE_VERSION = "JdGuiPreferences.jdCoreVersion";

protected static final File FILE = getConfigFile();

Expand Down Expand Up @@ -57,6 +56,7 @@ protected static File getConfigFile() {
return new File(Constants.CONFIG_FILENAME);
}

@Override
public Configuration load() {
// Default values
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Expand Down Expand Up @@ -170,9 +170,31 @@ public Configuration load() {
config.getPreferences().put(ERROR_BACKGROUND_COLOR, "0xFF6666");
}

config.getPreferences().put(JD_CORE_VERSION, getJdCoreVersion());

return config;
}

protected String getJdCoreVersion() {
try {
Enumeration<URL> enumeration = ConfigurationXmlPersisterProvider.class.getClassLoader().getResources("META-INF/MANIFEST.MF");

while (enumeration.hasMoreElements()) {
try (InputStream is = enumeration.nextElement().openStream()) {
String attribute = new Manifest(is).getMainAttributes().getValue("JD-Core-Version");
if (attribute != null) {
return attribute;
}
}
}
} catch (IOException e) {
assert ExceptionUtil.printStackTrace(e);
}

return "SNAPSHOT";
}

@Override
public void save(Configuration configuration) {
Point l = configuration.getMainWindowLocation();
Dimension s = configuration.getMainWindowSize();
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/org/jd/gui/view/AboutView.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public AboutView(JFrame mainFrame) {
hbox.add(Box.createHorizontalGlue());

hbox = Box.createHorizontalBox();
hbox.add(new JLabel("Copyright © 2008-2019 Emmanuel Dupuy"));
hbox.add(new JLabel("Copyright © 2008, 2019 Emmanuel Dupuy"));
hbox.add(Box.createHorizontalGlue());
subvbox.add(hbox);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@ public SearchInConstantPoolsView(
if (selectedTreeNode != null) {
selectedTypeCallback.accept(selectedTreeNode.getUri(), searchInConstantPoolsEnterTextField.getText(), getFlags());
}
searchInConstantPoolsDialog.setVisible(false);
}
};
searchInConstantPoolsOpenButton.addActionListener(searchInConstantPoolsOpenActionListener);
Expand Down
9 changes: 3 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ apply plugin: 'edu.sc.seis.launch4j'
apply plugin: 'nebula.ospackage'

// Common configuration //
rootProject.version='1.5.2'
rootProject.ext.set('jdCoreVersion', '1.0.3')
rootProject.version='1.6.3'
rootProject.ext.set('jdCoreVersion', '1.0.7')
targetCompatibility = '1.8'

allprojects {
Expand All @@ -31,10 +31,7 @@ allprojects {
}

repositories {
mavenCentral()
maven {
url 'https://raw.github.com/java-decompiler/mvn-repo/master'
}
jcenter()
}

configurations {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public void index(API api, Container.Entry entry, Indexes indexes) {
}
}

@SuppressWarnings("unchecked")
protected static void index(API api, Container.Entry entry, Indexes indexes, Map<String, Collection> packageDeclarationIndex) {
for (Container.Entry e : entry.getChildren()) {
if (e.isDirectory()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,43 +16,23 @@
import org.jd.gui.util.io.NewlineOutputStream;

import java.io.*;
import java.net.URL;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.jar.Manifest;

public class ClassFileSourceSaverProvider extends AbstractSourceSaverProvider {
protected static final String ESCAPE_UNICODE_CHARACTERS = "ClassFileDecompilerPreferences.escapeUnicodeCharacters";
protected static final String REALIGN_LINE_NUMBERS = "ClassFileDecompilerPreferences.realignLineNumbers";
protected static final String WRITE_LINE_NUMBERS = "ClassFileSaverPreferences.writeLineNumbers";
protected static final String WRITE_METADATA = "ClassFileSaverPreferences.writeMetadata";
protected static final String REALIGN_LINE_NUMBERS = "ClassFileDecompilerPreferences.realignLineNumbers";
protected static final String WRITE_LINE_NUMBERS = "ClassFileSaverPreferences.writeLineNumbers";
protected static final String WRITE_METADATA = "ClassFileSaverPreferences.writeMetadata";
protected static final String JD_CORE_VERSION = "JdGuiPreferences.jdCoreVersion";

protected static final ClassFileToJavaSourceDecompiler DECOMPILER = new ClassFileToJavaSourceDecompiler();

protected ContainerLoader loader = new ContainerLoader();
protected LineNumberStringBuilderPrinter printer = new LineNumberStringBuilderPrinter();
protected String jdCoreVersion = "SNAPSHOT";

public ClassFileSourceSaverProvider() {
try {
Enumeration<URL> enumeration = ClassFileSourceSaverProvider.class.getClassLoader().getResources("META-INF/MANIFEST.MF");

while (enumeration.hasMoreElements()) {
try (InputStream is = enumeration.nextElement().openStream()) {
String attribute = new Manifest(is).getMainAttributes().getValue("JD-Core-Version");
if (attribute != null) {
jdCoreVersion = attribute;
}
}
}
} catch (IOException e) {
assert ExceptionUtil.printStackTrace(e);
}
}

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

Expand Down Expand Up @@ -144,7 +124,7 @@ public void saveContent(API api, Controller controller, Listener listener, Path
}
// Add JD-Core version
stringBuffer.append("\n * JD-Core Version: ");
stringBuffer.append(jdCoreVersion);
stringBuffer.append(preferences.get(JD_CORE_VERSION));
stringBuffer.append("\n */");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,99 +8,99 @@
package org.jd.gui.util.decompiler;

public class LineNumberStringBuilderPrinter extends StringBuilderPrinter {
protected boolean showLineNumbers = false;

protected int maxLineNumber = 0;
protected int digitCount = 0;

protected String lineNumberBeginPrefix;
protected String lineNumberEndPrefix;
protected String unknownLineNumberPrefix;

public void setShowLineNumbers(boolean showLineNumbers) { this.showLineNumbers = showLineNumbers; }

protected int printDigit(int dcv, int lineNumber, int divisor, int left) {
if (digitCount >= dcv) {
if (lineNumber < divisor) {
append(' ');
} else {
int e = (lineNumber-left) / divisor;
append((char)('0' + e));
left += e*divisor;
}
}

return left;
}

// --- Printer --- //
@Override
public void start(int maxLineNumber, int majorVersion, int minorVersion) {
super.start(maxLineNumber, majorVersion, minorVersion);

if (showLineNumbers) {
this.maxLineNumber = maxLineNumber;

if (maxLineNumber > 0) {
digitCount = 1;
unknownLineNumberPrefix = " ";
int maximum = 9;

while (maximum < maxLineNumber) {
digitCount++;
unknownLineNumberPrefix += ' ';
maximum = maximum*10 + 9;
}

lineNumberBeginPrefix = "/* ";
lineNumberEndPrefix = " */ ";
} else {
unknownLineNumberPrefix = "";
lineNumberBeginPrefix = "";
lineNumberEndPrefix = "";
}
} else {
this.maxLineNumber = 0;
unknownLineNumberPrefix = "";
lineNumberBeginPrefix = "";
lineNumberEndPrefix = "";
}
}

@Override public void startLine(int lineNumber) {
if (maxLineNumber > 0) {
append(lineNumberBeginPrefix);

if (lineNumber == UNKNOWN_LINE_NUMBER) {
append(unknownLineNumberPrefix);
} else {
int left = 0;

left = printDigit(5, lineNumber, 10000, left);
left = printDigit(4, lineNumber, 1000, left);
left = printDigit(3, lineNumber, 100, left);
left = printDigit(2, lineNumber, 10, left);
append((char)('0' + (lineNumber-left)));
}

append(lineNumberEndPrefix);
}

for (int i=0; i<indentationCount; i++) {
append(TAB);
}
}
@Override public void extraLine(int count) {
if (realignmentLineNumber) {
while (count-- > 0) {
if (maxLineNumber > 0) {
append(lineNumberBeginPrefix);
append(unknownLineNumberPrefix);
append(lineNumberEndPrefix);
}

append(NEWLINE);
}
}
}
protected boolean showLineNumbers = false;

protected int maxLineNumber = 0;
protected int digitCount = 0;

protected String lineNumberBeginPrefix;
protected String lineNumberEndPrefix;
protected String unknownLineNumberPrefix;

public void setShowLineNumbers(boolean showLineNumbers) { this.showLineNumbers = showLineNumbers; }

protected int printDigit(int dcv, int lineNumber, int divisor, int left) {
if (digitCount >= dcv) {
if (lineNumber < divisor) {
stringBuffer.append(' ');
} else {
int e = (lineNumber-left) / divisor;
stringBuffer.append((char)('0' + e));
left += e*divisor;
}
}

return left;
}

// --- Printer --- //
@Override
public void start(int maxLineNumber, int majorVersion, int minorVersion) {
super.start(maxLineNumber, majorVersion, minorVersion);

if (showLineNumbers) {
this.maxLineNumber = maxLineNumber;

if (maxLineNumber > 0) {
digitCount = 1;
unknownLineNumberPrefix = " ";
int maximum = 9;

while (maximum < maxLineNumber) {
digitCount++;
unknownLineNumberPrefix += ' ';
maximum = maximum*10 + 9;
}

lineNumberBeginPrefix = "/* ";
lineNumberEndPrefix = " */ ";
} else {
unknownLineNumberPrefix = "";
lineNumberBeginPrefix = "";
lineNumberEndPrefix = "";
}
} else {
this.maxLineNumber = 0;
unknownLineNumberPrefix = "";
lineNumberBeginPrefix = "";
lineNumberEndPrefix = "";
}
}

@Override public void startLine(int lineNumber) {
if (maxLineNumber > 0) {
stringBuffer.append(lineNumberBeginPrefix);

if (lineNumber == UNKNOWN_LINE_NUMBER) {
stringBuffer.append(unknownLineNumberPrefix);
} else {
int left = 0;

left = printDigit(5, lineNumber, 10000, left);
left = printDigit(4, lineNumber, 1000, left);
left = printDigit(3, lineNumber, 100, left);
left = printDigit(2, lineNumber, 10, left);
stringBuffer.append((char)('0' + (lineNumber-left)));
}

stringBuffer.append(lineNumberEndPrefix);
}

for (int i=0; i<indentationCount; i++) {
stringBuffer.append(TAB);
}
}
@Override public void extraLine(int count) {
if (realignmentLineNumber) {
while (count-- > 0) {
if (maxLineNumber > 0) {
stringBuffer.append(lineNumberBeginPrefix);
stringBuffer.append(unknownLineNumberPrefix);
stringBuffer.append(lineNumberEndPrefix);
}

stringBuffer.append(NEWLINE);
}
}
}
}
Loading

0 comments on commit a82460b

Please sign in to comment.