Skip to content

Commit

Permalink
Revert "🦄 refactor(Android): Add support to Optional, Stream, `Zo…
Browse files Browse the repository at this point in the history
…nedDateTime` for Android"

This reverts commit 8d47fb6.
  • Loading branch information
caoccao committed Feb 27, 2022
1 parent 8d47fb6 commit a44ae2e
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 7 deletions.
7 changes: 3 additions & 4 deletions android/javet-android/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021-2022. caoccao.com Sam Cao
* Copyright 2021. caoccao.com Sam Cao
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -55,9 +55,8 @@ android {
}

dependencies {
// https://developer.android.com/studio/write/java8-support
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:1.1.5")
implementation("androidx.appcompat:appcompat:1.4.1")
implementation("androidx.appcompat:appcompat:1.3.1")
implementation("org.threeten:threetenbp:1.5.1")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.3")
androidTestImplementation("androidx.test.espresso:espresso-core:3.4.0")
Expand Down
1 change: 0 additions & 1 deletion docs/release_notes/release_notes_1_1.html
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,6 @@ <h1>Release Notes 1.1.x<a class="headerlink" href="#release-notes-1-1-x" title="
<h2>1.1.1<a class="headerlink" href="#id1" title="Permalink to this headline">¶</a></h2>
<ul class="simple">
<li><p>Enhanced createV8ValueArrayBuffer with ByteBuffer</p></li>
<li><p>Added support to <cite>Optional</cite>, <cite>Stream</cite>, <cite>ZonedDateTime</cite> for Android</p></li>
</ul>
</div>
<div class="section" id="v8-v9-8">
Expand Down
1 change: 0 additions & 1 deletion docs/release_notes/release_notes_1_1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ Release Notes 1.1.x
-------------

* Enhanced createV8ValueArrayBuffer with ByteBuffer
* Added support to `Optional`, `Stream`, `ZonedDateTime` for Android

1.1.0 V8 v9.8
-------------
Expand Down
2 changes: 1 addition & 1 deletion docs/searchindex.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions docs/tutorial/basic/installation.html
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,8 @@ <h3>Android<a class="headerlink" href="#android" title="Permalink to this headli
<ul class="simple">
<li><p>Only V8 mode is supported for Android. Supporting Node.js mode implies huge amount of work, but is not mission impossible. Please contact the maintainer for detail.</p></li>
<li><p>If you need Node.js features on Android, please refer to project <a class="reference external" href="https://github.com/caoccao/Javenode">Javenode</a>.</p></li>
<li><p><a class="reference external" href="https://developer.android.com/reference/java/time/ZonedDateTime">ZonedDateTime</a> (since ABI 26) is polyfilled by <code class="docutils literal notranslate"><span class="pre">org.threeten.bp.ZonedDateTime</span></code> so that Javet can work well with low ABI version.</p></li>
<li><p><cite>Stream</cite> and <cite>Optional</cite> are not supported because they are not available with ABI version 23-24.</p></li>
<li><p>If you need ABI version 21/22, please use Javet v1.0.x or contact the maintainer for details.</p></li>
</ul>
</div>
Expand Down
2 changes: 2 additions & 0 deletions docs/tutorial/basic/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,6 @@ Android x86_64 Yes (ABI >= 23)

* Only V8 mode is supported for Android. Supporting Node.js mode implies huge amount of work, but is not mission impossible. Please contact the maintainer for detail.
* If you need Node.js features on Android, please refer to project `Javenode <https://github.com/caoccao/Javenode>`_.
* `ZonedDateTime <https://developer.android.com/reference/java/time/ZonedDateTime>`_ (since ABI 26) is polyfilled by ``org.threeten.bp.ZonedDateTime`` so that Javet can work well with low ABI version.
* `Stream` and `Optional` are not supported because they are not available with ABI version 23-24.
* If you need ABI version 21/22, please use Javet v1.0.x or contact the maintainer for details.
10 changes: 10 additions & 0 deletions scripts/python/patch_android_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,19 @@ class PatchAndroidBuild(object):
def __init__(self) -> None:
self._line_separator = '\n'
self._patch_dict = {
'java.time.': 'org.threeten.bp.',
'.getParameterCount()': '.getParameterTypes().length',
}
self._comment_list = [
'import java.util.Optional;',
'import java.util.OptionalDouble;',
'import java.util.OptionalInt;',
'import java.util.OptionalLong;',
'import java.util.stream.BaseStream;',
'import java.util.stream.DoubleStream;',
'import java.util.stream.IntStream;',
'import java.util.stream.LongStream;',
'import java.util.stream.Stream;',
'import javax.management.ListenerNotFoundException;',
'import javax.management.Notification;',
'import javax.management.NotificationEmitter;',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ private static Object convert(IJavetConverter converter, Class<?> expectedClass,
} else if (expectedClass == char.class) {
return config.getDefaultChar();
}
/* if not defined ANDROID */
} else if (expectedClass == Optional.class) {
return Optional.empty();
} else if (expectedClass == OptionalInt.class) {
Expand All @@ -91,6 +92,7 @@ private static Object convert(IJavetConverter converter, Class<?> expectedClass,
return DoubleStream.empty();
} else if (expectedClass == LongStream.class) {
return LongStream.empty();
/* end if */
}
} else if (expectedClass.isAssignableFrom(v8Value.getClass())) {
// Skip assignable
Expand Down Expand Up @@ -257,6 +259,7 @@ private static Object convert(IJavetConverter converter, Class<?> expectedClass,
return convertedString.length() > 0 ?
convertedString.charAt(0) : converter.getConfig().getDefaultChar();
}
/* if not defined ANDROID */
} else if (expectedClass == Optional.class) {
return Optional.of(convertedObject);
} else if (expectedClass == OptionalInt.class) {
Expand Down Expand Up @@ -291,6 +294,7 @@ private static Object convert(IJavetConverter converter, Class<?> expectedClass,
if (doubleStream != null) {
return doubleStream;
}
/* end if */
}
}
} catch (Throwable ignored) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ protected <T extends V8Value> T toV8Value(
v8Value = v8ValueArray;
v8Scope.setEscapable();
}
/* if not defined ANDROID */
} else if (object instanceof BaseStream) {
try (V8Scope v8Scope = v8Runtime.getV8Scope()) {
V8ValueArray v8ValueArray = v8Scope.createV8ValueArray();
Expand All @@ -443,6 +444,7 @@ protected <T extends V8Value> T toV8Value(
v8Value = v8ValueArray;
v8Scope.setEscapable();
}
/* end if */
} else if (object instanceof IJavetEntityFunction) {
final IJavetEntityFunction javetEntityFunction = (IJavetEntityFunction) object;
String sourceCode = javetEntityFunction.getJSFunctionType().isUserDefined() ?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ protected <T extends V8Value> T toV8Value(
v8Value = v8Runtime.createV8ValueInteger((Byte) object);
} else if (object instanceof Character) {
v8Value = v8Runtime.createV8ValueString(((Character) object).toString());
/* if not defined ANDROID */
} else if (object instanceof Optional) {
Optional<?> optional = (Optional<?>) object;
v8Value = optional.isPresent() ? toV8Value(v8Runtime, optional.get(), depth) : v8Runtime.createV8ValueNull();
Expand All @@ -125,6 +126,7 @@ protected <T extends V8Value> T toV8Value(
} else if (object instanceof OptionalLong) {
OptionalLong optional = (OptionalLong) object;
v8Value = optional.isPresent() ? toV8Value(v8Runtime, optional.getAsLong(), depth) : v8Runtime.createV8ValueNull();
/* end if */
} else {
v8Value = v8Runtime.createV8ValueUndefined();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,15 @@ public static String getMethodNameFromLambda(Serializable lambda) {
* @return the method name set
* @since 0.9.13
*/
/* if not defined ANDROID */
public static Set<String> getMethodNameSetFromLambdas(Serializable... lambdas) {
return Stream.of(Objects.requireNonNull(lambdas))
.filter(Objects::nonNull)
.map(JavetReflectionUtils::getMethodNameFromLambda)
.filter(Objects::nonNull)
.collect(Collectors.toSet());
}
/* end if */

/**
* Safe set accessible.
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/caoccao/javet/utils/JavetTypeUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ public static Object toApproximatePrimitive(Class<?> expectedClass, Object objec
* @return the double stream
* @since 0.9.13
*/
/* if not defined ANDROID */
public static DoubleStream toDoubleStream(Object object) {
if (object instanceof double[]) {
return DoubleStream.of((double[]) object);
Expand All @@ -149,6 +150,7 @@ public static DoubleStream toDoubleStream(Object object) {
}
return null;
}
/* end if */

/**
* To exact primitive object.
Expand Down Expand Up @@ -193,6 +195,7 @@ public static Object toExactPrimitive(Class<?> expectedClass, Object object) {
* @return the int stream
* @since 0.9.13
*/
/* if not defined ANDROID */
public static IntStream toIntStream(Object object) {
if (object instanceof int[]) {
return IntStream.of((int[]) object);
Expand All @@ -204,6 +207,7 @@ public static IntStream toIntStream(Object object) {
}
return null;
}
/* end if */

/**
* Convert object to long stream.
Expand All @@ -212,6 +216,7 @@ public static IntStream toIntStream(Object object) {
* @return the long stream
* @since 0.9.13
*/
/* if not defined ANDROID */
public static LongStream toLongStream(Object object) {
if (object instanceof long[]) {
return LongStream.of((long[]) object);
Expand All @@ -223,6 +228,7 @@ public static LongStream toLongStream(Object object) {
}
return null;
}
/* end if */

/**
* Convert object to stream.
Expand All @@ -231,6 +237,7 @@ public static LongStream toLongStream(Object object) {
* @return the stream
* @since 0.9.13
*/
/* if not defined ANDROID */
public static Stream<?> toStream(Object object) {
if (object.getClass().isArray()) {
if (object instanceof int[]) {
Expand Down Expand Up @@ -282,4 +289,5 @@ public static Stream<?> toStream(Object object) {
}
return null;
}
/* end if */
}

0 comments on commit a44ae2e

Please sign in to comment.