Skip to content

Commit

Permalink
Merge from develop/1.11.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jaskarth committed Jul 11, 2024
2 parents 08ee555 + 7d12f99 commit 281c87c
Show file tree
Hide file tree
Showing 427 changed files with 15,061 additions and 3,569 deletions.
14 changes: 14 additions & 0 deletions plugins/idea-not-null/testData/results/TestIdeaNotNull.dec
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,17 @@ class 'pkg/TestIdeaNotNull' {
f 9
10 10
11 10
12 10
13 10
14 11
1d 11
1e 13
1f 13
20 13
21 13
22 13
23 13
24 13
2c 14
30 14
34 14
Expand Down Expand Up @@ -145,11 +149,15 @@ class 'pkg/TestIdeaNotNull' {
2a 33
2b 33
2c 33
2d 33
2e 33
2f 34
30 34
31 34
32 34
33 34
34 34
35 34
36 36
}

Expand All @@ -168,6 +176,8 @@ class 'pkg/TestIdeaNotNull' {
12 43
13 43
14 43
15 43
16 43
1e 44
22 44
26 44
Expand All @@ -190,6 +200,8 @@ class 'pkg/TestIdeaNotNull' {
e 53
f 53
10 53
11 53
12 53
13 54
1d 54
1e 56
Expand All @@ -200,6 +212,8 @@ class 'pkg/TestIdeaNotNull' {
23 56
24 56
25 56
26 56
27 56
2f 57
33 57
37 57
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
package org.vineflower.kotlin;

import org.jetbrains.java.decompiler.api.plugin.PluginOptions;
import org.jetbrains.java.decompiler.main.DecompilerContext;
import org.jetbrains.java.decompiler.main.extern.IFernflowerPreferences.*;

import java.util.Map;

public interface KotlinOptions {
@Name("Show public visibility")
@Description("If a construct is public, show the public keyword")
@Type(Type.BOOLEAN)
String SHOW_PUBLIC_VISIBILITY = "kt-show-public";

@Name("Decompile Kotlin")
@Name("Enable Kotlin plugin")
@Description("Decompile Kotlin classes as Kotlin instead of Java")
@Type(Type.BOOLEAN)
String DECOMPILE_KOTLIN = "kt-decompile-kotlin";
String DECOMPILE_KOTLIN = "kt-enable";

@Name("Unknown default arg string")
@Description("String to use for unknown default arguments, or empty to not indicate unknown defaults")
@Type(Type.STRING)
String UNKNOWN_DEFAULT_ARG_STRING = "kt-unknown-defaults";

static void addDefaults(PluginOptions.AddDefaults cons) {
cons.addDefault(SHOW_PUBLIC_VISIBILITY, "1");
cons.addDefault(DECOMPILE_KOTLIN, "1");
cons.addDefault(UNKNOWN_DEFAULT_ARG_STRING, "...");
}
}
139 changes: 41 additions & 98 deletions plugins/kotlin/src/main/java/org/vineflower/kotlin/KotlinWriter.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ public TextBuffer toJava(int indent) {
buffer.append(KTypes.getKotlinType(type));

switch (getAnnotationType()) {
case SINGLE_ELEMENT:
case SINGLE_ELEMENT -> {
buffer.append('(').appendPossibleNewline();
writeAnnotationValue(getParValues().get(0), buffer);
buffer.append(')');
break;
case NORMAL:
}
case NORMAL -> {
buffer.append('(').appendPossibleNewline();
boolean first = true;
for (int i = 0; i < getParValues().size(); i++) {
Expand All @@ -67,26 +67,24 @@ public TextBuffer toJava(int indent) {
writeAnnotationValue(getParValues().get(i), buffer);
}
buffer.append(')');
break;
}
}

return buffer;
}

public static void writeAnnotationValue(Exprent expr, TextBuffer buffer) {
if (expr instanceof FieldExprent) {
if (expr instanceof FieldExprent fieldExprent) {
// Enum value
FieldExprent fieldExprent = (FieldExprent) expr;
VarType type = new VarType(fieldExprent.getClassname(), true);
DecompilerContext.getImportCollector().getShortName(fieldExprent.getClassname(), true);

buffer
.append(KTypes.getKotlinType(type))
.append(".")
.append(fieldExprent.getName());
} else if (expr instanceof NewExprent) {
} else if (expr instanceof NewExprent newExprent) {
// Array value
NewExprent newExprent = (NewExprent) expr;
buffer.append('[');
boolean first = true;
for (Exprent exprent : newExprent.getLstArrayElements()) {
Expand All @@ -98,19 +96,18 @@ public static void writeAnnotationValue(Exprent expr, TextBuffer buffer) {
writeAnnotationValue(exprent, buffer);
}
buffer.append(']');
} else if (expr instanceof AnnotationExprent) {
AnnotationExprent annotationExprent = (AnnotationExprent) expr;
} else if (expr instanceof AnnotationExprent annotationExprent) {
buffer.append('@');
VarType type = new VarType(annotationExprent.getClassName(), true);
buffer.append(KTypes.getKotlinType(type));

switch (annotationExprent.getAnnotationType()) {
case SINGLE_ELEMENT:
case SINGLE_ELEMENT -> {
buffer.append('(');
writeAnnotationValue(annotationExprent.getParValues().get(0), buffer);
buffer.append(')');
break;
case NORMAL:
}
case NORMAL -> {
buffer.append('(');
boolean first = true;
for (int i = 0; i < annotationExprent.getParValues().size(); i++) {
Expand All @@ -125,10 +122,9 @@ public static void writeAnnotationValue(Exprent expr, TextBuffer buffer) {
writeAnnotationValue(annotationExprent.getParValues().get(i), buffer);
}
buffer.append(')');
break;
}
}
} else if (expr instanceof ConstExprent) {
ConstExprent constExprent = (ConstExprent) expr;
} else if (expr instanceof ConstExprent constExprent) {
if (constExprent.getConstType().equals(VarType.VARTYPE_CLASS)) {
VarType type = new VarType((String) constExprent.getValue(), true);
DecompilerContext.getImportCollector().getShortName((String) constExprent.getValue(), true);
Expand Down
Loading

0 comments on commit 281c87c

Please sign in to comment.