Skip to content

Commit

Permalink
Improve some tests and the contributing doc
Browse files Browse the repository at this point in the history
  • Loading branch information
jaskarth committed Jan 22, 2024
1 parent e8387fe commit 03a12f1
Show file tree
Hide file tree
Showing 6 changed files with 193 additions and 4 deletions.
10 changes: 6 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ Welcome! Thank you for taking an interest in contributing to Vineflower.
* The [ARCHITECTURE.md](./ARCHITECTURE.md) file in the repository contains technical information on how Vineflower is structured. Reading that will greatly help with familiarizing yourself with the codebase and with PR development.
* It's highly recommended to socialize your changes first through our [social platforms](https://github.com/Vineflower) before making a pull request!
* Check out the issue tracker and roadmap! You can find good things to contribute there.
* Make sure your pull request is based off of the latest development branch in the repository. The main branch is a stable snapshot, representing the latest released version of the decompiler.

## Good things to contribute
* Fixes to bugs present in the decompiler.
* Improvements to the readability of the decompiled code.
* New feature support for the decompiler.
* Optimization, to make it run faster and use fewer resources.
Expand All @@ -17,7 +19,7 @@ Welcome! Thank you for taking an interest in contributing to Vineflower.
* More technical issues are usually found in the [Test class](https://github.com/Vineflower/vineflower/blob/master/test/org/jetbrains/java/decompiler/SingleClassesTest.java) where individual wrong tests are described with their errors.

## Code Style and guidelines
While the code inherited from FernFlower varies with its style and syntax, it's expected that pull requests stick to our established code style.
While the code inherited from Fernflower varies with its style and syntax, it's expected that pull requests stick to our established code style.
* We use UpperCamelCase for class names, camelCase for method, variable, local variable, and field names, and UPPER_SNAKE_CASE for static final fields. Please always qualify instance fields with a `this.` qualifier.
* Please try to keep pull requests small and self-contained! It makes reviewing and maintaining the patch much easier.
* Statements should always have braces around them, even if they are only 1 line in their length.
Expand All @@ -30,12 +32,12 @@ While the code inherited from FernFlower varies with its style and syntax, it's
* When contributing, you should add new tests that cover the area of code that you are targeting. Having more tests makes the decompiler more robust, so it's always appreciated.

## Resources
FernFlower is a very complex and involved bit of software, and there's a lot going on in a rather questionable structure. Naturally, understanding it all is a challenge so various resources are provided here to aid with the process.
Fernflower is a very complex and involved bit of software, and there's a lot going on in a rather questionable structure. Naturally, understanding it all is a challenge so various resources are provided here to aid with the process.
* Knowing how java bytecode works is essential. You can find the detailed description of all the opcodes [here](https://docs.oracle.com/javase/specs/jvms/se16/html/jvms-6.html#jvms-6.5) or a simple list of them [here.](https://en.wikipedia.org/wiki/Java_bytecode_instruction_listings)
* Graph theory comes up frequently in the statement analysis portion of FernFlower. It's useful knowing about [Basic Blocks](https://en.wikipedia.org/wiki/Basic_block), [Control Flow Graphs](https://en.wikipedia.org/wiki/Control-flow_graph), and [Dominators.](https://en.wikipedia.org/wiki/Dominator_(graph_theory))
* Graph theory comes up frequently in the statement analysis portion of Fernflower. It's useful knowing about [Basic Blocks](https://en.wikipedia.org/wiki/Basic_block), [Control Flow Graphs](https://en.wikipedia.org/wiki/Control-flow_graph), and [Dominators.](https://en.wikipedia.org/wiki/Dominator_(graph_theory))
* [Static Single Assignment Form](https://en.wikipedia.org/wiki/Static_single_assignment_form) is also used widely to track variables and their versions within the decompilation stages.
* The [Java Language Specification](https://docs.oracle.com/javase/specs/jls/se16/html/), while dense, is a good source of information regarding language features.
* The [ARCHITECTURE.md](./ARCHITECTURE.md) file in the repository contains important information about how FernFlower is structured.
* The [ARCHITECTURE.md](./ARCHITECTURE.md) file in the repository contains important information about how Fernflower is structured.
* The [social platforms](https://github.com/Vineflower) contains many people who have worked with the code before, so any remaining questions are best asked there.

## License
Expand Down
2 changes: 2 additions & 0 deletions test/org/jetbrains/java/decompiler/SingleClassesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,8 @@ private void registerJavaRuntime() {
register(JAVA_16_NODEBUG, "TestRecordCanonicalConstructor2");
register(JAVA_8, "TestGenericArrays");
register(JAVA_8, "TestInstanceGeneric");
// TODO: wrong cast in lambda for array
register(JAVA_8, "TestArrayGenerics");
}

private void registerLiterals() {
Expand Down
59 changes: 59 additions & 0 deletions testData/results/pkg/TestArrayGenerics.dec
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package pkg;

import java.lang.reflect.Array;
import java.util.stream.IntStream;

public class TestArrayGenerics {
private static <T> T[] myMethod(Object[] myObjects, Class<T> clazz) {
return (T[])IntStream.range(0, myObjects.length).mapToObj(i -> myObjects[i]).toArray(size -> (Object[])Array.newInstance(clazz, size));// 8 9 10
}
}

class 'pkg/TestArrayGenerics' {
method 'myMethod ([Ljava/lang/Object;Ljava/lang/Class;)[Ljava/lang/Object;' {
0 7
1 7
2 7
3 7
4 7
5 7
c 7
d 7
e 7
f 7
10 7
17 7
18 7
19 7
1a 7
1b 7
1c 7
}

method 'lambda$myMethod$0 ([Ljava/lang/Object;I)Ljava/lang/Object;' {
0 7
1 7
2 7
3 7
}

method 'lambda$myMethod$1 (Ljava/lang/Class;I)[Ljava/lang/Object;' {
0 7
1 7
2 7
3 7
4 7
5 7
6 7
7 7
8 7
9 7
a 7
b 7
}
}

Lines mapping:
8 <-> 8
9 <-> 8
10 <-> 8
96 changes: 96 additions & 0 deletions testData/results/pkg/TestItrLoop.dec
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,24 @@ public class TestItrLoop {
System.out.println(s);// 13
}
}// 15

public void test1() {
for (Object var2 : this.list) {// 18
;
}
}// 21

public void test2() {
for (String var2 : this.list) {// 24
;
}
}// 27

public void test3() {
for (String var2 : this.list) {// 30
;
}
}// 33
}

class 'pkg/TestItrLoop' {
Expand Down Expand Up @@ -44,12 +62,90 @@ class 'pkg/TestItrLoop' {
23 10
27 12
}

method 'test1 ()V' {
0 15
1 15
2 15
3 15
4 15
5 15
6 15
7 15
8 15
9 15
13 15
14 15
15 15
16 15
17 15
18 15
19 15
1d 18
}

method 'test2 ()V' {
0 21
1 21
2 21
3 21
4 21
5 21
6 21
7 21
8 21
9 21
13 21
14 21
15 21
16 21
17 21
18 21
19 21
1a 21
1b 21
1c 21
20 24
}

method 'test3 ()V' {
0 27
1 27
2 27
3 27
4 27
5 27
6 27
7 27
8 27
9 27
13 27
14 27
15 27
16 27
17 27
18 27
19 27
1a 27
1b 27
1c 27
20 30
}
}

Lines mapping:
11 <-> 10
12 <-> 10
13 <-> 11
15 <-> 13
18 <-> 16
21 <-> 19
24 <-> 22
27 <-> 25
30 <-> 28
33 <-> 31
Not mapped:
14
20
26
32
12 changes: 12 additions & 0 deletions testData/src/java8/pkg/TestArrayGenerics.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package pkg;

import java.lang.reflect.Array;
import java.util.stream.IntStream;

public class TestArrayGenerics {
private static <T> T[] myMethod(Object[] myObjects, Class<T> clazz) {
return IntStream.range(0, myObjects.length)
.mapToObj(i -> myObjects[i])
.toArray(size -> (T[]) Array.newInstance(clazz, size));
}
}
18 changes: 18 additions & 0 deletions testData/src/java8/pkg/TestItrLoop.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,22 @@ public void test() {
System.out.println(s);
}
}

public void test1() {
for (Object o : list) {

}
}

public void test2() {
for (String s : (List<String>) list) {

}
}

public void test3() {
for (String s : (Iterable<String>) list) {

}
}
}

0 comments on commit 03a12f1

Please sign in to comment.