Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply ForgeFlower's patches #8

Merged
merged 69 commits into from May 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
f2fda31
use more high-level methods to copy arrays instead of low-level crypt…
cdracm Nov 12, 2020
74837d4
Avoid set.removeAll(list)
amaembo Dec 2, 2020
188028a
Fix NPE inside `ExceptionRangeCFG::toString()` for `finally` exceptio…
Maccimo Dec 18, 2020
7379fe5
[java] API cleanup: remove unused API which was deprecated for a long…
chashnikov Jan 15, 2021
a179cb5
java 11 migration: explicit -> diamond for anonymous classes
akozlova Jan 16, 2021
4cfa056
[java-decompiler] aligning language level with the main project; bump…
trespasserw Jan 18, 2021
5b6f5ad
IDEA-245329: Handle CONSTANT_Module and CONSTANT_Package
leonardosnt Feb 11, 2021
5f3502e
[java decompiler] minor refactoring + cleanup (duplicates; dependenci…
trespasserw Feb 11, 2021
5b38107
[java decompiler] separating `module-info` sections
trespasserw Feb 12, 2021
6120e0d
Cleanup (formatting)
trespasserw Feb 12, 2021
0adc278
[java decompiler] supporting `package-info`
trespasserw Feb 12, 2021
1b97854
[java decompiler] skipping generated `module-info` statements
trespasserw Feb 12, 2021
87a5b1a
Unused assignments removed, misc other fixes
amaembo Apr 5, 2021
eda2c43
use jdk9+ Map.entry API instead of AbstractMap.SimpleImmutableEntry
develar Apr 12, 2021
d2cebcb
Avoid assignment used as condition
amaembo Apr 13, 2021
b54f30b
Git filter and setup, backport to Java 8
LexManos Apr 12, 2017
5e5a69c
Test Framework upgrades
LexManos Apr 12, 2017
4a1a9e2
Fix initializers for anon and synthetic classes
LexManos Apr 12, 2017
086c87e
Fix field initalizers
LexManos Apr 12, 2017
62139f2
Fix output discrepancies based on running JVM
LexManos Apr 12, 2017
d7662f3
Convert Exprent.bytecode to a BitMap.
LexManos Apr 12, 2017
247e026
Enhance switch on enum and string output
LexManos Apr 16, 2017
d8b87b8
Make methods hold a reference to their declaring class
zml2008 Mar 31, 2021
1ae86fb
Reintroduce DotExporter for debugging purposes
LexManos Apr 13, 2017
cf3b13a
LVT Fixes and Support for Enhanced For loop detection.
LexManos Apr 12, 2017
00e2e18
Rework of Generics system for better output
LexManos Apr 15, 2017
9257ee7
Improvements to var++ and var--
LexManos Apr 14, 2017
062cd73
JAD Style variable naming
LexManos Apr 12, 2017
b7c522b
Fix primitive un/boxing issues.
LexManos May 11, 2017
796620b
Add Minecraft test framework
LexManos Apr 19, 2017
62235af
Add better debug logging
LexManos Sep 25, 2017
6d55656
Add new command line argument -sef SkipExtraFiles: To skip copying no…
LexManos Dec 12, 2017
7d81231
Bugfix: Fix invalid logic in ExprUtils. https://github.com/MinecraftF…
LexManos Feb 22, 2018
d84467d
Enhance Generic Invocations Temporarily.
LexManos Feb 17, 2018
450459a
Add -cfg argument Used to specify a text file with additional command…
LexManos Apr 7, 2018
558faab
Add support for destination to be a zip file if there is only one inp…
LexManos Jul 20, 2018
671be0a
Add a metadata file named 'fernflower_abstract_parameter_names.txt' t…
LexManos Jul 20, 2018
418c6d0
Synthetic getClass cleanup
JDLogic Jul 26, 2018
7462b9c
Fix shortname imports that are shadowed by super class inner classes
JDLogic Jul 27, 2018
3af5ca6
Give nicer output for float and double literals
Pokechu22 Aug 3, 2018
1057c48
Add try with resource support
JDLogic Aug 7, 2018
7d444df
Prioritize self and enclosing class when encountering inconsistent In…
LexManos Sep 12, 2018
89fd5aa
Fix ambiguous lambdas
JDLogic Sep 20, 2018
c43c76f
Improve inferred generic types
JDLogic Apr 30, 2019
ac3cdae
Improve stack var processor output
JDLogic Aug 26, 2019
ca573f9
Fix finally processor instruction comparison
JDLogic Jan 12, 2020
7a1cf37
Simple lambda syntax support, --isl=0 to disable.
JDLogic Dec 20, 2019
dcaed37
Add explicit cast to invocations of java/nio/Buffer functions.
LexManos Apr 15, 2020
df5da21
Revert change to FieldExprent#getExprentUse
covers1624 Jun 7, 2020
61f69fb
Add -only argument It will filter what classes are decompiled from th…
LexManos Jun 10, 2020
7936934
Fix local variables incorrectly merging.
LexManos Jun 16, 2020
75cf7a0
Do not rebuild variable names in lambdas.
LexManos Jun 17, 2020
e580a07
Add toString to MethodDescriptor
LexManos Jun 17, 2020
a76032e
Fix compile and assignment exprent
jaskarth Apr 21, 2021
2453eac
[PATCH] Fix many NPEs and IOOBEs
jaskarth Apr 21, 2021
fd4cffe
Fix tests
jaskarth Apr 21, 2021
a91c9ed
Add test archiving action
jaskarth Apr 21, 2021
ff80e8b
Add multi release jar support
jaskarth Apr 22, 2021
4472554
Remove release arg
jaskarth Apr 22, 2021
2c9c53d
Fix wrong float behavior
jaskarth Apr 22, 2021
920ee0c
Fix deadlock with bitwise operations
jaskarth Apr 23, 2021
1b3adeb
Extract method call into local variable
jaskarth Apr 23, 2021
19c596e
Fix casts where parameter is subset
jaskarth Apr 24, 2021
c343eb8
Fix linemapping bug with foreach loops
jaskarth Apr 24, 2021
6a021b1
Tiny optimizations for speed and allocation reduction
jaskarth Apr 24, 2021
f066c84
cleaned up test todos, more documentation
jaskarth Apr 24, 2021
6f63e6e
Fix more tests
jaskarth Apr 24, 2021
b2c293b
Add new tests
jaskarth Apr 26, 2021
0ec234d
Remove duplicated test
jaskarth Apr 27, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
43 changes: 42 additions & 1 deletion .gitattributes
@@ -1 +1,42 @@
*.dec text
# Convert line endings to linux for files detected as text
# and leave all files detected as binary untouched.
* text eol=lf

#
# The above will handle all files NOT found below
#
# These files are text and should be normalized (Convert crlf => lf)
*.css text
*.df text
*.htm text
*.html text
*.java text
*.js text
*.json text
*.jsp text
*.jspf text
*.jspx text
*.properties text
*.sh text
*.tld text
*.txt text
*.tag text
*.tagx text
*.xml text
*.yml text
*.dec text

# These files are binary and should be left untouched
# (binary is a macro for -text -diff)
*.class binary
*.dll binary
*.ear binary
*.gif binary
*.ico binary
*.jar binary
*.jpg binary
*.jpeg binary
*.png binary
*.so binary
*.war binary

8 changes: 8 additions & 0 deletions .github/workflows/build.yml
Expand Up @@ -13,3 +13,11 @@ jobs:
- uses: actions/checkout@v1
- uses: gradle/wrapper-validation-action@v1
- run: ./gradlew build --stacktrace
- name: Archive test results
if: "${{ always() }}"
uses: actions/upload-artifact@v2
with:
name: "test-results-${{ matrix.os }}"
path: |
build/reports/
*/build/reports/
40 changes: 32 additions & 8 deletions build.gradle
@@ -1,4 +1,4 @@
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
apply plugin: 'java'
apply plugin: 'maven-publish'

Expand All @@ -18,17 +18,46 @@ version = version + (ENV.GITHUB_ACTIONS ? "" : "+local")
sourceSets {
main.java.srcDirs 'src'
test.java.srcDirs 'test'
// We need specific java9+ versions of certain classes, so we have a separate source set for them
java9.java.srcDirs 'java9'
}

repositories { mavenCentral() }

dependencies {
testCompile 'junit:junit:4.12'
testCompile 'org.assertj:assertj-core:3.12.2'

// Java 9 classes need the main source set
java9Implementation sourceSets.main.output
}

java.toolchain {
languageVersion = JavaLanguageVersion.of(8)
}

tasks.withType(JavaCompile) {
options.deprecation = true
}

// Compile the java 9 classes
compileJava9Java {
javaCompiler = javaToolchains.compilerFor {
languageVersion = JavaLanguageVersion.of(9)
}
}

jar {
// put the java 9 source set into the jar to make a multi-release jar
into('META-INF/versions/9') {
from sourceSets.java9.output
}

manifest {
attributes 'Main-Class': 'org.jetbrains.java.decompiler.main.decompiler.ConsoleDecompiler'
attributes (
'Multi-Release': 'true',
'Main-Class': 'org.jetbrains.java.decompiler.main.decompiler.ConsoleDecompiler'
)
}
}

Expand All @@ -39,11 +68,6 @@ task sourceJar(type:Jar) {

tasks.withType(JavaCompile).configureEach {
it.options.encoding = "UTF-8"

// Target JDK 8
if (JavaVersion.current().isJava9Compatible()) {
it.options.release = 8
}
}

publishing {
Expand All @@ -66,4 +90,4 @@ publishing {
}
}
}
}
}
178 changes: 89 additions & 89 deletions gradlew.bat
@@ -1,89 +1,89 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem

@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################

@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"

@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome

set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.

goto fail

:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto execute

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.

goto fail

:execute
@rem Setup the command line

set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar


@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*

:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd

:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1

:mainEnd
if "%OS%"=="Windows_NT" endlocal

:omega
81 changes: 81 additions & 0 deletions java9/org/jetbrains/java/decompiler/util/ClasspathScanner.java
@@ -0,0 +1,81 @@
// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.java.decompiler.util;

import java.lang.module.*;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.nio.ByteBuffer;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Stream;

import org.jetbrains.java.decompiler.main.DecompilerContext;
import org.jetbrains.java.decompiler.main.extern.IFernflowerLogger.Severity;
import org.jetbrains.java.decompiler.struct.StructContext;

public class ClasspathScanner {

public static void addAllClasspath(StructContext ctx) {
Set<String> found = new HashSet<String>();
String[] props = { System.getProperty("java.class.path"), System.getProperty("sun.boot.class.path") };
for (String prop : props) {
if (prop == null)
continue;

for (final String path : prop.split(File.pathSeparator)) {
File file = new File(path);
if (found.contains(file.getAbsolutePath()))
continue;

if (file.exists() && (file.getName().endsWith(".class") || file.getName().endsWith(".jar"))) {
DecompilerContext.getLogger().writeMessage("Adding File to context from classpath: " + file, Severity.INFO);
ctx.addSpace(file, false);
found.add(file.getAbsolutePath());
}
}
}

addAllModulePath(ctx);
}

private static void addAllModulePath(StructContext ctx) {
for (ModuleReference module : ModuleFinder.ofSystem().findAll()) {
String name = module.descriptor().name();
try {
ModuleReader reader = module.open();
DecompilerContext.getLogger().writeMessage("Reading Module: " + name, Severity.INFO);
reader.list().forEach(cls -> {
if (!cls.endsWith(".class") || cls.contains("module-info.class"))
return;

DecompilerContext.getLogger().writeMessage(" " + cls, Severity.INFO);
try {
Optional<ByteBuffer> bb = reader.read(cls);
if (!bb.isPresent()) {
DecompilerContext.getLogger().writeMessage(" Error Reading Class: " + cls, Severity.ERROR);
return;
}

byte[] data;
if (bb.get().hasArray()) {
data = bb.get().array();
} else {
data = new byte[bb.get().remaining()];
bb.get().get(data);
}
ctx.addData(name, cls, data, false);
} catch (IOException e) {
DecompilerContext.getLogger().writeMessage(" Error Reading Class: " + cls, e);
}
});
reader.close();
} catch (IOException e) {
DecompilerContext.getLogger().writeMessage("Error loading module " + name, e);
}
}
}
}
2 changes: 1 addition & 1 deletion src/org/jetbrains/java/decompiler/code/CodeConstants.java
@@ -1,4 +1,4 @@
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.java.decompiler.code;

@SuppressWarnings({"unused", "SpellCheckingInspection"})
Expand Down