Skip to content

Updating reflect.lite to the new kotlinx.metadata.jvm #19

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

Merged
merged 74 commits into from
Aug 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
8e3daed
Migrate project to gradle
mvicsokolova Jan 12, 2022
6c0aa0d
Initial commit: introduced basic API consistent with reflect-full
mvicsokolova Jan 12, 2022
8c02d69
All the reflect interfaces copied from the stdlib.
mvicsokolova Jan 17, 2022
315d2a0
Implementation of reflect API via descriptors
mvicsokolova Jan 25, 2022
c42939c
Descriptors for reflection entities
mvicsokolova Feb 14, 2022
04d7b75
Update kotlinx-metadata-jvm to 0.4.2
mvicsokolova Feb 16, 2022
1184613
Consistent way to delegate KClass implementation to ClassDescriptor
mvicsokolova Feb 16, 2022
3f84f57
Some tests for parameter and type api
mvicsokolova Feb 16, 2022
7876740
Update Kotlin to 1.7.10
mvicsokolova Jul 18, 2022
5dc9c07
Support inherited class members
mvicsokolova Jul 18, 2022
a5276f0
KCallable: call, callBy
mvicsokolova Jul 18, 2022
d02ab87
Copy source notes
mvicsokolova Jul 19, 2022
bb632b9
Class member properties implemented: KProperty0<V>, KProperty1<T, V>
mvicsokolova Jul 22, 2022
8fe9422
Java to Kotlin reflection mapping: kotlinClass, kotlinFunction, kotli…
mvicsokolova Jul 25, 2022
50f0005
Kotlin to Java reflection: KProperty<*>.javaField
mvicsokolova Jul 25, 2022
0864056
Fix tests for KProperty accessors
mvicsokolova Jul 26, 2022
3e6788f
some test fixes
mvicsokolova Jul 26, 2022
d9a8667
KProperty:
mvicsokolova Jul 27, 2022
ee59510
Kotlin -> Java reflection mapping
mvicsokolova Jul 27, 2022
497d751
Test for private fields access: comparing the behaviour of reflect.li…
mvicsokolova Jul 27, 2022
1d9c683
Moved unsupported tests to the separate directory
mvicsokolova Jul 27, 2022
c031353
Lazy initialization for callable descriptors
mvicsokolova Jul 27, 2022
54c7e08
Support overridden properties
mvicsokolova Jul 27, 2022
73b6f47
More tests for KCallable<*>.call
mvicsokolova Jul 27, 2022
f54ac16
More tests for top-level and extension functions
mvicsokolova Jul 27, 2022
9bd29fe
Easy optional parameters supported
mvicsokolova Jul 28, 2022
2bfa10f
Added java.lang.String as a primitive type for optional parameters
mvicsokolova Jul 28, 2022
9fd5a56
More tests for callBy
mvicsokolova Jul 28, 2022
de05b75
Update kotlin to 1.7.10
mvicsokolova Jul 28, 2022
90a9918
Code cleanup WIP
mvicsokolova Jul 28, 2022
3c0365d
move more unsupported tests to unusedTestData
mvicsokolova Jul 29, 2022
13627f9
Some visibility fixes and refactoring
mvicsokolova Jul 29, 2022
f067ce4
Fixed creation default caller creation + manyMaskArguments test
mvicsokolova Aug 1, 2022
910a0c9
More tests for KCallable<*>.callBy
mvicsokolova Aug 1, 2022
414a973
KCallable<*>.callBy tests: WA for bound receiver use-cases
mvicsokolova Aug 1, 2022
4c35c36
KCallable<*>.parameters: more tests added
mvicsokolova Aug 3, 2022
83284b8
KProperty.isAccessible: more tests added
mvicsokolova Aug 3, 2022
0c8c97e
More tests for KProperty
mvicsokolova Aug 3, 2022
29ff391
Tests for ReflectionMapping (javaMethod, kotlinFunction, javaConstruc…
mvicsokolova Aug 4, 2022
827bfdc
Tests for ReflectionMapping (javaMethod, kotlinProperty)
mvicsokolova Aug 4, 2022
30458e9
Tests for ReflectionMapping (javaType), fixed types of callable param…
mvicsokolova Aug 4, 2022
7fa40f2
More tests for ReflectionMapping (javaType)
mvicsokolova Aug 6, 2022
8fededb
More tests for ReflectJvmMapping
mvicsokolova Aug 6, 2022
542ea8b
Fix defaultPrimitiveValue
mvicsokolova Aug 6, 2022
83726b2
Tests for properties
mvicsokolova Aug 6, 2022
e42791b
KCallables.callSuspend implementation
mvicsokolova Aug 8, 2022
d261679
Deprecate Class<T>.toLiteKClass() from test utils and replace it with…
mvicsokolova Aug 8, 2022
02659c1
Get rid of ReflectProperties and replac with lazy initialization
mvicsokolova Aug 8, 2022
61a186f
ReflectJvmMapping class name
mvicsokolova Aug 8, 2022
c87de55
Add KClass<T>.primaryConstructor to the API
mvicsokolova Aug 8, 2022
d0b9bf5
Fixed visibility modifiers of some declarations to be internal
mvicsokolova Aug 9, 2022
e3aac87
Fixed bug in `KClass<T>.primaryConstructor` and added a test
mvicsokolova Aug 10, 2022
65677da
Added JvmClassMapping class file with API for mapping Java to Kotlin …
mvicsokolova Aug 10, 2022
eacc252
Use `Class<T>.kotlin` and `Class<T>.kotlinPackage` API in tests
mvicsokolova Aug 10, 2022
da0fd7a
Added tests for KCallable<*>.callSuspend
mvicsokolova Aug 11, 2022
4602515
Fix `toKotlinType()` for the case of star type projection
mvicsokolova Aug 12, 2022
88d3b03
Add descriptors for Java classes
mvicsokolova Aug 22, 2022
be83ff1
Add `thisAsReceiverParameter` property to ClassDescriptor
mvicsokolova Aug 22, 2022
3e42d57
Some fixes in tests
mvicsokolova Aug 22, 2022
48f54b1
Implementation of Java class descriptor should be completed
mvicsokolova Aug 22, 2022
d355b95
Lazy initialization of ClassDescriptor properties
mvicsokolova Aug 22, 2022
63a3760
Implementation of Java descriptors
mvicsokolova Aug 23, 2022
0ac4748
Update KClass tests
mvicsokolova Aug 29, 2022
6cfff5e
Make private whatever can be private
qwwdfsad Aug 30, 2022
551c3d9
Better exception message instead of plain TODO
qwwdfsad Aug 30, 2022
6d8b4e5
Codestyle changes
qwwdfsad Aug 30, 2022
9b34b13
Revise public modifiers in root package
qwwdfsad Aug 30, 2022
13bff23
Move JvmClassMapping to its own public package kotlinx.reflect.lite.jvm
qwwdfsad Aug 30, 2022
843debe
Move ReflectJvmMapping to its own public package kotlinx.reflect.lite…
qwwdfsad Aug 30, 2022
c127e58
Cleanup build infra
qwwdfsad Aug 30, 2022
598dae3
Move corresponding declarations to full package, add -no-reflect
qwwdfsad Aug 30, 2022
27b7642
Documentation for KPackage
mvicsokolova Aug 30, 2022
989f2a4
ReflectJvmMapping: fixed KPackage creation + public modifiers
mvicsokolova Aug 30, 2022
6670c25
Update Copyright notes
mvicsokolova Aug 30, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
.idea
**/.idea/*
*.iml
.gradle
.gradletasknamecache
build
out
target
local.properties
40 changes: 40 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2016-2022 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/

plugins {
kotlin("jvm") version "1.7.10"
`java-gradle-plugin`

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it turns out that ReflectProperties.java is not needed (or can be easily rewritten in Kotlin), this won't be needed any longer, right?

`maven-publish`
}

repositories {
mavenCentral()
gradlePluginPortal()
mavenLocal()
}

dependencies {
implementation("com.google.protobuf:protobuf-java:2.6.1")
implementation("org.jetbrains.kotlin:kotlin-stdlib")
testImplementation("org.jetbrains.kotlin:kotlin-test")
implementation("org.jetbrains.kotlinx:kotlinx-metadata-jvm:0.4.2")
testImplementation("junit:junit:4.13")
}

java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

tasks.compileKotlin {
kotlinOptions {
freeCompilerArgs += listOf("-no-reflect")
}
}

publishing {
publications.create<MavenPublication>("maven") {
from(components["java"])
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use the -no-reflect flag here to make sure we don't rely on kotlin.reflect anywhere. For now, I only see import kotlin.reflect in unusedTestData and testData (the latter should be investigated if it turns out these tests were not left in testData by mistake).

10 changes: 10 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#
# Copyright 2016-2022 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
#

version=0.1.0-SNAPSHOT
group=org.jetbrains.kotlinx

kotlin_version=1.7.10
kotlinx_metadata_version=0.4.2
pluginPublishVersion=0.10.1
Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
9 changes: 9 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#
# Copyright 2016-2022 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
#

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
222 changes: 222 additions & 0 deletions gradlew
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
#!/bin/sh

#
# Copyright 2016-2022 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
#

##############################################################################
#
# Gradle start up script for POSIX generated by Gradle.
#
# Important for running:
#
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
# noncompliant, but you have some other compliant shell such as ksh or
# bash, then to run this script, type that shell name before the whole
# command line, like:
#
# ksh Gradle
#
# Busybox and similar reduced shells will NOT work, because this script
# requires all of these POSIX shell features:
# * functions;
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
# * compound commands having a testable exit status, especially «case»;
# * various built-in commands including «command», «set», and «ulimit».
#
# Important for patching:
#
# (2) This script targets any POSIX shell, so it avoids extensions provided
# by Bash, Ksh, etc; in particular arrays are avoided.
#
# The "traditional" practice of packing multiple parameters into a
# space-separated string is a well documented source of bugs and security
# problems, so this is (mostly) avoided, by progressively accumulating
# options in "$@", and eventually passing that to Java.
#
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
# see the in-line comments for details.
#
# There are tweaks for specific operating systems such as AIX, CygWin,
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
#
##############################################################################

# Attempt to set APP_HOME

# Resolve links: $0 may be a link
app_path=$0

# Need this for daisy-chained symlinks.
while
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
[ -h "$app_path" ]
do
ls=$( ls -ld "$app_path" )
link=${ls#*' -> '}
case $link in #(
/*) app_path=$link ;; #(
*) app_path=$APP_HOME$link ;;
esac
done

APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

APP_NAME="Gradle"
APP_BASE_NAME=${0##*/}

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

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum

warn () {
echo "$*"
} >&2

die () {
echo
echo "$*"
echo
exit 1
} >&2

# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "$( uname )" in #(
CYGWIN* ) cygwin=true ;; #(
Darwin* ) darwin=true ;; #(
MSYS* | MINGW* ) msys=true ;; #(
NONSTOP* ) nonstop=true ;;
esac

CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar


# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD=$JAVA_HOME/jre/sh/java
else
JAVACMD=$JAVA_HOME/bin/java
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi

# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
fi

# Collect all arguments for the java command, stacking in reverse order:
# * args from the command line
# * the main class name
# * -classpath
# * -D...appname settings
# * --module-path (only if needed)
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.

# For Cygwin or MSYS, switch paths to Windows format before running java
if "$cygwin" || "$msys" ; then
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )

JAVACMD=$( cygpath --unix "$JAVACMD" )

# Now convert the arguments - kludge to limit ourselves to /bin/sh
for arg do
if
case $arg in #(
-*) false ;; # don't mess with options #(
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
[ -e "$t" ] ;; #(
*) false ;;
esac
then
arg=$( cygpath --path --ignore --mixed "$arg" )
fi
# Roll the args list around exactly as many times as the number of
# args, so each arg winds up back in the position where it started, but
# possibly modified.
#
# NB: a `for` loop captures its iteration list before it begins, so
# changing the positional parameters here affects neither the number of
# iterations, nor the values presented in `arg`.
shift # remove old arg
set -- "$@" "$arg" # push replacement arg
done
fi

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.

set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
-classpath "$CLASSPATH" \
org.gradle.wrapper.GradleWrapperMain \
"$@"

# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
#
# In Bash we could simply go:
#
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
# set -- "${ARGS[@]}" "$@"
#
# but POSIX shell has neither arrays nor command substitution, so instead we
# post-process each arg (as a line of input to sed) to backslash-escape any
# character that might be a shell metacharacter, then use eval to reverse
# that process (while maintaining the separation between arguments), and wrap
# the whole thing up as a single "set" statement.
#
# This will of course break if any of these variables contains a newline or
# an unmatched quote.
#

eval "set -- $(
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
xargs -n1 |
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
tr '\n' ' '
)" '"$@"'

exec "$JAVACMD" "$@"
89 changes: 89 additions & 0 deletions gradlew.bat
Original file line number Diff line number Diff line change
@@ -0,0 +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
Loading