Skip to content

Commit b5a3e47

Browse files
authored
Merge pull request #3 from noties/F/34
Android 34
2 parents 1cb48e3 + 24f76bf commit b5a3e47

23 files changed

+415
-234
lines changed

.run/Enhance.run.xml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
<component name="ProjectRunConfigurationManager">
22
<configuration default="false" name="Enhance" type="Application" factoryName="Application" nameIsGenerated="true">
3-
<option name="ALTERNATIVE_JRE_PATH" value="azul-13" />
4-
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="true" />
5-
<option name="MAIN_CLASS_NAME" value="ru.noties.enhance.Enhance" />
3+
<option name="MAIN_CLASS_NAME" value="io.noties.enhance.Enhance" />
64
<module name="enhance.main" />
7-
<option name="PROGRAM_PARAMETERS" value="-sdk 33 -format google" />
5+
<option name="PROGRAM_PARAMETERS" value="-sdk 34 -format google" />
6+
<option name="VM_PARAMETERS" value="--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED" />
87
<extension name="coverage">
98
<pattern>
10-
<option name="PATTERN" value="ru.noties.enhance.*" />
9+
<option name="PATTERN" value="io.noties.enhance.*" />
1110
<option name="ENABLED" value="true" />
1211
</pattern>
1312
</extension>

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
# CHANGELOG
22

3+
# 34
4+
Applied new version-name strategy - now version equals latest supported Android SDK platform
5+
### Added
6+
* Upside Down Cake (34)
7+
8+
### Changed
9+
* Updated code structure, moved to `io.noties` package (no change for clients)
10+
11+
12+
# 1.3.0
13+
### Added
14+
* Android S_V2 (32)
15+
* Tiramisu (33)
16+
17+
318
# 1.2.0
419
### Added
520
* Android 12, SDK 31 API version

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,22 @@ java -jar enhance.jar -sdk 26 -sp "/Users/not_me/android/sdk"
6565

6666
If you would like to restore unmodified copy of source code you can find it: `{your-home-directory}/.enhance-backup/android-{sdk}`
6767

68+
## Formatting on JDK 17
69+
Formatting is done with the [google-java-format](https://github.com/google/google-java-format) library
70+
which requires access to the internals of the JDK. This is why on JDK-17 in order to format
71+
the sources additional commandline arguments are required:
72+
73+
```bash
74+
java \
75+
--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \
76+
--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED \
77+
--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED \
78+
--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED \
79+
--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED \
80+
--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED \
81+
-jar enhance-34-all.jar -sdk 34 -format google
82+
```
83+
6884
## Thanks
6985

7086
Big kudos to the maintainers of amazing [javaparser](https://github.com/javaparser/javaparser)!

build.gradle

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
plugins {
2+
// https://github.com/johnrengelman/shadow
23
id 'com.github.johnrengelman.shadow' version '7.1.2'
34
id 'java'
45
id 'application'
56
}
67

7-
group 'ru.noties'
8-
version '1.3.0'
8+
group 'io.noties'
9+
version '34'
910

10-
sourceCompatibility = JavaVersion.VERSION_1_8
11-
targetCompatibility = JavaVersion.VERSION_1_8
11+
sourceCompatibility = JavaVersion.VERSION_11
12+
targetCompatibility = JavaVersion.VERSION_11
1213

13-
mainClassName = 'ru.noties.enhance.Enhance'
14+
mainClassName = 'io.noties.enhance.Enhance'
1415

1516
repositories {
1617
jcenter()
@@ -21,14 +22,15 @@ dependencies {
2122
implementation 'com.google.code.findbugs:jsr305:3.0.2'
2223

2324
// https://github.com/javaparser/javaparser
24-
implementation 'com.github.javaparser:javaparser-core:3.24.8'
25+
implementation 'com.github.javaparser:javaparser-core:3.25.5'
2526

2627
// https://github.com/google/google-java-format
27-
implementation 'com.google.googlejavaformat:google-java-format:1.5'
28+
implementation 'com.google.googlejavaformat:google-java-format:1.18.1'
2829

2930
implementation 'commons-cli:commons-cli:1.4'
30-
implementation 'commons-io:commons-io:2.6'
31-
testImplementation 'junit:junit:4.12'
31+
implementation 'commons-io:commons-io:2.7'
32+
33+
testImplementation 'junit:junit:4.13.1'
3234
}
3335

3436
wrapper {
@@ -37,13 +39,13 @@ wrapper {
3739
}
3840

3941
afterEvaluate {
40-
final def folder = new File(rootDir, '/gen/ru/noties/enhance')
42+
final def folder = new File(rootDir, '/gen/io/noties/enhance')
4143
if (!folder.exists()) {
4244
folder.mkdirs()
4345
}
4446
final def file = new File(folder, 'EnhanceVersion.java')
4547
file.write("""
46-
package ru.noties.enhance;
48+
package io.noties.enhance;
4749
class EnhanceVersion { static final String NAME = \"${version}\"; }
4850
""")
4951
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package io.noties.enhance;
2+
3+
import javax.annotation.Nonnull;
4+
import javax.annotation.Nullable;
5+
import java.util.EnumMap;
6+
import java.util.List;
7+
8+
public enum Api {
9+
SDK_1(1, "1.0", "(initial)"),
10+
SDK_2(2, "1.1", "(initial)"),
11+
SDK_3(3, "1.5", "Cupcake"),
12+
SDK_4(4, "1.6", "Donut"),
13+
SDK_5(5, "2.0", "Eclair"),
14+
SDK_6(6, "2.0.1", "Eclair"),
15+
SDK_7(7, "2.1", "Eclair"),
16+
SDK_8(8, "2.2", "Froyo"),
17+
SDK_9(9, "2.3", "Gingerbread"),
18+
SDK_10(10, "2.3.3", "Gingerbread"),
19+
SDK_11(11, "3.0", "Honeycomb"),
20+
SDK_12(12, "3.1", "Honeycomb"),
21+
SDK_13(13, "3.2", "Honeycomb"),
22+
SDK_14(14, "4.0", "Ice Scream Sandwich"),
23+
SDK_15(15, "4.0.3", "Ice Scream Sandwich"),
24+
SDK_16(16, "4.1", "Jelly Bean"),
25+
SDK_17(17, "4.2", "Jelly Bean"),
26+
SDK_18(18, "4.3", "Jelly Bean"),
27+
SDK_19(19, "4.4", "Kitkat"),
28+
SDK_20(20, "4.4W", "Kitkat"),
29+
SDK_21(21, "5.0", "Lollipop"),
30+
SDK_22(22, "5.1", "Lollipop"),
31+
SDK_23(23, "6.0", "Marshmallow"),
32+
SDK_24(24, "7.0", "Nougat"),
33+
SDK_25(25, "7.1", "Nougat"),
34+
SDK_26(26, "8.0", "Oreo"),
35+
SDK_27(27, "8.1", "Oreo"),
36+
SDK_28(28, "9.0", "Pie"),
37+
SDK_29(29, "10", "Android Q"),
38+
SDK_30(30, "11", "Android R"),
39+
SDK_31(31, "12", "Android S"),
40+
SDK_32(32, "12", "Android S_V2"),
41+
SDK_33(33, "13", "Tiramisu"),
42+
SDK_34(34, "14", "Upside Down Cake")
43+
;
44+
45+
public final int sdkInt;
46+
public final String versionName;
47+
public final String codeName;
48+
49+
Api(int sdkInt, @Nonnull String versionName, @Nonnull String codeName) {
50+
this.sdkInt = sdkInt;
51+
this.versionName = versionName;
52+
this.codeName = codeName;
53+
}
54+
55+
@Override
56+
public String toString() {
57+
return "Api.SDK{" +
58+
"sdkInt=" + sdkInt +
59+
", versionName='" + versionName + '\'' +
60+
", codeName='" + codeName + '\'' +
61+
'}';
62+
}
63+
64+
private static final List<Api> VALUES = List.of(values());
65+
66+
@Nonnull
67+
public static Api latest() {
68+
return VALUES.get(VALUES.size() - 1);
69+
}
70+
71+
@Nullable
72+
public static Api of(int sdkInt) {
73+
// NB! we assume that it starts at 1
74+
// so, SDK_1 is at 0, SDK_2 at 1, etc
75+
final int ordinal = sdkInt - 1;
76+
if (ordinal < 0 || ordinal >= VALUES.size()) {
77+
return null;
78+
}
79+
return VALUES.get(ordinal);
80+
}
81+
}

src/main/java/ru/noties/enhance/ApiInfo.java renamed to src/main/java/io/noties/enhance/ApiInfo.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
package ru.noties.enhance;
1+
package io.noties.enhance;
2+
3+
import javax.annotation.Nullable;
24

35
public class ApiInfo {
46

5-
public final ApiVersion since;
6-
public final ApiVersion deprecated;
7+
@Nullable
8+
public final Integer since;
9+
@Nullable public final Integer deprecated;
710

8-
public ApiInfo(ApiVersion since, ApiVersion deprecated) {
11+
public ApiInfo(@Nullable Integer since, @Nullable Integer deprecated) {
912
this.since = since;
1013
this.deprecated = deprecated;
1114
}

src/main/java/ru/noties/enhance/ApiInfoStore.java renamed to src/main/java/io/noties/enhance/ApiInfoStore.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package ru.noties.enhance;
1+
package io.noties.enhance;
22

33
import javax.annotation.Nonnull;
44
import javax.annotation.Nullable;
@@ -13,12 +13,12 @@ public static ApiInfoStore create(@Nonnull File apiVersions) {
1313
return new ApiInfoStoreImpl(apiVersions);
1414
}
1515

16-
static class TypeVersion extends ApiInfo {
16+
public static class TypeVersion extends ApiInfo {
1717

1818
final Map<String, ApiInfo> fields = new HashMap<>(3);
1919
final Map<String, ApiInfo> methods = new HashMap<>(3);
2020

21-
TypeVersion(ApiVersion since, ApiVersion deprecated) {
21+
TypeVersion(@Nullable Integer since, @Nullable Integer deprecated) {
2222
super(since, deprecated);
2323
}
2424
}

src/main/java/ru/noties/enhance/ApiInfoStoreImpl.java renamed to src/main/java/io/noties/enhance/ApiInfoStoreImpl.java

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package ru.noties.enhance;
1+
package io.noties.enhance;
22

33
import org.w3c.dom.Document;
44
import org.w3c.dom.Element;
@@ -156,17 +156,17 @@ private static void methods(@Nonnull TypeVersion version, @Nonnull Element paren
156156
private static boolean isEmpty(@Nonnull TypeVersion version) {
157157
return version.since == null
158158
&& version.deprecated == null
159-
&& version.fields.size() == 0
160-
&& version.methods.size() == 0;
159+
&& version.fields.isEmpty()
160+
&& version.methods.isEmpty();
161161
}
162162

163163
@Nullable
164164
private static ApiInfo apiInfo(@Nonnull Element element) {
165165

166166
final ApiInfo apiInfo;
167167

168-
final ApiVersion since = apiVersion(element.getAttribute(SINCE));
169-
final ApiVersion deprecated = apiVersion(element.getAttribute(DEPRECATED));
168+
final Integer since = apiVersion(element.getAttribute(SINCE));
169+
final Integer deprecated = apiVersion(element.getAttribute(DEPRECATED));
170170

171171
if (since == null
172172
&& deprecated == null) {
@@ -179,21 +179,19 @@ private static ApiInfo apiInfo(@Nonnull Element element) {
179179
}
180180

181181
@Nullable
182-
private static ApiVersion apiVersion(@Nullable String value) {
183-
final ApiVersion version;
184-
if (value == null
185-
|| value.length() == 0) {
186-
version = null;
187-
} else {
188-
int sdk;
189-
try {
190-
sdk = Integer.parseInt(value);
191-
} catch (NumberFormatException e) {
192-
sdk = 0;
193-
}
194-
version = ApiVersion.of(sdk);
182+
private static Integer apiVersion(@Nullable String value) {
183+
if (value == null || value.isEmpty()) {
184+
return null;
185+
}
186+
187+
try {
188+
return Integer.parseInt(value);
189+
} catch (NumberFormatException e) {
190+
//noinspection CallToPrintStackTrace
191+
e.printStackTrace();
195192
}
196-
return version;
193+
194+
return null;
197195
}
198196

199197
private static final Pattern RE = Pattern.compile("L\\w+[/\\w]+[/$](\\w+);");
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package io.noties.enhance;
2+
3+
import javax.annotation.Nonnull;
4+
5+
public abstract class ApiVersionFormatter {
6+
7+
@Nonnull
8+
public static ApiVersionFormatter create() {
9+
return new Impl();
10+
}
11+
12+
@Nonnull
13+
public abstract String format(int version);
14+
15+
16+
private static class Impl extends ApiVersionFormatter {
17+
18+
@Nonnull
19+
@Override
20+
public String format(int version) {
21+
final Api api = Api.of(version);
22+
if (api != null) {
23+
// for example - @since 5.1 Lollipop (22)
24+
return api.versionName + " " + api.codeName + " (" + api.sdkInt + ")";
25+
}
26+
return "unknown (" + version + ")";
27+
}
28+
}
29+
}

src/main/java/ru/noties/enhance/ByteCodeSignature.java renamed to src/main/java/io/noties/enhance/ByteCodeSignature.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package ru.noties.enhance;
1+
package io.noties.enhance;
22

33
import com.github.javaparser.ast.body.CallableDeclaration;
44
import com.github.javaparser.ast.body.MethodDeclaration;

0 commit comments

Comments
 (0)