Minor: Use Kotlin reflection in usage printing and update test data
This commit is contained in:
@@ -16,14 +16,17 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.cli.common;
|
package org.jetbrains.kotlin.cli.common;
|
||||||
|
|
||||||
|
import com.intellij.util.containers.ContainerUtil;
|
||||||
|
import kotlin.jvm.JvmClassMappingKt;
|
||||||
|
import kotlin.reflect.KCallable;
|
||||||
|
import kotlin.reflect.KClass;
|
||||||
|
import kotlin.reflect.KProperty1;
|
||||||
import kotlin.text.StringsKt;
|
import kotlin.text.StringsKt;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.kotlin.cli.common.arguments.Argument;
|
import org.jetbrains.kotlin.cli.common.arguments.Argument;
|
||||||
import org.jetbrains.kotlin.cli.common.arguments.CommonToolArguments;
|
import org.jetbrains.kotlin.cli.common.arguments.CommonToolArguments;
|
||||||
import org.jetbrains.kotlin.cli.common.arguments.ParseCommandLineArgumentsKt;
|
import org.jetbrains.kotlin.cli.common.arguments.ParseCommandLineArgumentsKt;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
|
|
||||||
public class Usage {
|
public class Usage {
|
||||||
// The magic number 29 corresponds to the similar padding width in javac and scalac command line compilers
|
// The magic number 29 corresponds to the similar padding width in javac and scalac command line compilers
|
||||||
private static final int OPTION_NAME_PADDING_WIDTH = 29;
|
private static final int OPTION_NAME_PADDING_WIDTH = 29;
|
||||||
@@ -33,10 +36,10 @@ public class Usage {
|
|||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
appendln(sb, "Usage: " + tool.executableScriptFileName() + " <options> <source files>");
|
appendln(sb, "Usage: " + tool.executableScriptFileName() + " <options> <source files>");
|
||||||
appendln(sb, "where " + (arguments.getExtraHelp() ? "advanced" : "possible") + " options include:");
|
appendln(sb, "where " + (arguments.getExtraHelp() ? "advanced" : "possible") + " options include:");
|
||||||
for (Class<?> clazz = arguments.getClass(); clazz != null; clazz = clazz.getSuperclass()) {
|
KClass<? extends CommonToolArguments> kClass = JvmClassMappingKt.getKotlinClass(arguments.getClass());
|
||||||
for (Method method : clazz.getDeclaredMethods()) {
|
for (KCallable<?> callable : kClass.getMembers()) {
|
||||||
propertyUsage(sb, method, arguments.getExtraHelp());
|
if (!(callable instanceof KProperty1)) continue;
|
||||||
}
|
propertyUsage(sb, (KProperty1) callable, arguments.getExtraHelp());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (arguments.getExtraHelp()) {
|
if (arguments.getExtraHelp()) {
|
||||||
@@ -47,8 +50,8 @@ public class Usage {
|
|||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void propertyUsage(@NotNull StringBuilder sb, @NotNull Method method, boolean extraHelp) {
|
private static void propertyUsage(@NotNull StringBuilder sb, @NotNull KProperty1 property, boolean extraHelp) {
|
||||||
Argument argument = method.getAnnotation(Argument.class);
|
Argument argument = ContainerUtil.findInstance(property.getAnnotations(), Argument.class);
|
||||||
if (argument == null) return;
|
if (argument == null) return;
|
||||||
|
|
||||||
if (extraHelp != ParseCommandLineArgumentsKt.isAdvanced(argument)) return;
|
if (extraHelp != ParseCommandLineArgumentsKt.isAdvanced(argument)) return;
|
||||||
|
|||||||
+5
-5
@@ -1,11 +1,11 @@
|
|||||||
Usage: kotlin-dce-js <options> <source files>
|
Usage: kotlin-dce-js <options> <source files>
|
||||||
where possible options include:
|
where possible options include:
|
||||||
-output-dir <path> Output directory
|
|
||||||
-keep <fully.qualified.name[,]>
|
-keep <fully.qualified.name[,]>
|
||||||
List of fully-qualified names of declarations that shouldn't be eliminated
|
List of fully-qualified names of declarations that shouldn't be eliminated
|
||||||
-help (-h) Print a synopsis of standard options
|
-output-dir <path> Output directory
|
||||||
-X Print a synopsis of advanced options
|
-X Print a synopsis of advanced options
|
||||||
-version Display compiler version
|
-help (-h) Print a synopsis of standard options
|
||||||
-verbose Enable verbose logging output
|
|
||||||
-nowarn Generate no warnings
|
-nowarn Generate no warnings
|
||||||
OK
|
-verbose Enable verbose logging output
|
||||||
|
-version Display compiler version
|
||||||
|
OK
|
||||||
|
|||||||
+11
-11
@@ -1,19 +1,19 @@
|
|||||||
Usage: kotlinc-js <options> <source files>
|
Usage: kotlinc-js <options> <source files>
|
||||||
where advanced options include:
|
where advanced options include:
|
||||||
-Xtyped-arrays Translate primitive arrays to JS typed arrays
|
|
||||||
-Xfriend-modules-disabled Disable internal declaration export
|
|
||||||
-Xfriend-modules=<path> Paths to friend modules
|
-Xfriend-modules=<path> Paths to friend modules
|
||||||
-Xno-inline Disable method inlining
|
-Xfriend-modules-disabled Disable internal declaration export
|
||||||
-Xrepeat=<count> Repeat compilation (for performance analysis)
|
-Xtyped-arrays Translate primitive arrays to JS typed arrays
|
||||||
-Xskip-metadata-version-check Load classes with bad metadata version anyway (incl. pre-release classes)
|
|
||||||
-Xallow-kotlin-package Allow compiling code in package 'kotlin'
|
-Xallow-kotlin-package Allow compiling code in package 'kotlin'
|
||||||
-Xreport-output-files Report source to output files mapping
|
|
||||||
-Xplugin=<path> Load plugins from the given classpath
|
|
||||||
-Xmulti-platform Enable experimental language support for multi-platform projects
|
|
||||||
-Xno-check-impl Do not check presence of 'impl' modifier in multi-platform projects
|
|
||||||
-Xintellij-plugin-root=<path> Path to the kotlin-compiler.jar or directory where IntelliJ configuration files can be found
|
|
||||||
-Xcoroutines={enable|warn|error}
|
-Xcoroutines={enable|warn|error}
|
||||||
Enable coroutines or report warnings or errors on declarations and use sites of 'suspend' modifier
|
Enable coroutines or report warnings or errors on declarations and use sites of 'suspend' modifier
|
||||||
|
-Xintellij-plugin-root=<path> Path to the kotlin-compiler.jar or directory where IntelliJ configuration files can be found
|
||||||
|
-Xmulti-platform Enable experimental language support for multi-platform projects
|
||||||
|
-Xno-check-impl Do not check presence of 'impl' modifier in multi-platform projects
|
||||||
|
-Xno-inline Disable method inlining
|
||||||
|
-Xplugin=<path> Load plugins from the given classpath
|
||||||
|
-Xrepeat=<count> Repeat compilation (for performance analysis)
|
||||||
|
-Xreport-output-files Report source to output files mapping
|
||||||
|
-Xskip-metadata-version-check Load classes with bad metadata version anyway (incl. pre-release classes)
|
||||||
|
|
||||||
Advanced options are non-standard and may be changed or removed without any notice.
|
Advanced options are non-standard and may be changed or removed without any notice.
|
||||||
OK
|
OK
|
||||||
|
|||||||
Vendored
+15
-15
@@ -1,29 +1,29 @@
|
|||||||
Usage: kotlinc-js <options> <source files>
|
Usage: kotlinc-js <options> <source files>
|
||||||
where possible options include:
|
where possible options include:
|
||||||
-output <path> Output file path
|
|
||||||
-no-stdlib Don't use bundled Kotlin stdlib
|
|
||||||
-libraries <path> Paths to Kotlin libraries with .meta.js and .kjsm files, separated by system path separator
|
-libraries <path> Paths to Kotlin libraries with .meta.js and .kjsm files, separated by system path separator
|
||||||
|
-main {call,noCall} Whether a main function should be called
|
||||||
|
-meta-info Generate .meta.js and .kjsm files with metadata. Use to create a library
|
||||||
|
-module-kind { plain, amd, commonjs, umd }
|
||||||
|
Kind of a module generated by compiler
|
||||||
|
-no-stdlib Don't use bundled Kotlin stdlib
|
||||||
|
-output <path> Output file path
|
||||||
|
-output-postfix <path> Path to file which will be added to the end of output file
|
||||||
|
-output-prefix <path> Path to file which will be added to the beginning of output file
|
||||||
-source-map Generate source map
|
-source-map Generate source map
|
||||||
|
-source-map-embed-sources { always, never, inlining }
|
||||||
|
Embed source files into source map
|
||||||
-source-map-prefix Prefix for paths in a source map
|
-source-map-prefix Prefix for paths in a source map
|
||||||
-source-map-source-roots <path>
|
-source-map-source-roots <path>
|
||||||
Base directories which are used to calculate relative paths to source files in source map
|
Base directories which are used to calculate relative paths to source files in source map
|
||||||
-source-map-embed-sources { always, never, inlining }
|
|
||||||
Embed source files into source map
|
|
||||||
-meta-info Generate .meta.js and .kjsm files with metadata. Use to create a library
|
|
||||||
-target { v5 } Generate JS files for specific ECMA version
|
-target { v5 } Generate JS files for specific ECMA version
|
||||||
-module-kind { plain, amd, commonjs, umd }
|
|
||||||
Kind of a module generated by compiler
|
|
||||||
-main {call,noCall} Whether a main function should be called
|
|
||||||
-output-prefix <path> Path to file which will be added to the beginning of output file
|
|
||||||
-output-postfix <path> Path to file which will be added to the end of output file
|
|
||||||
-language-version <version> Provide source compatibility with specified language version
|
|
||||||
-api-version <version> Allow to use declarations only from the specified version of bundled libraries
|
-api-version <version> Allow to use declarations only from the specified version of bundled libraries
|
||||||
|
-X Print a synopsis of advanced options
|
||||||
|
-help (-h) Print a synopsis of standard options
|
||||||
-kotlin-home <path> Path to Kotlin compiler home directory, used for runtime libraries discovery
|
-kotlin-home <path> Path to Kotlin compiler home directory, used for runtime libraries discovery
|
||||||
|
-language-version <version> Provide source compatibility with specified language version
|
||||||
-P plugin:<pluginId>:<optionName>=<value>
|
-P plugin:<pluginId>:<optionName>=<value>
|
||||||
Pass an option to a plugin
|
Pass an option to a plugin
|
||||||
-help (-h) Print a synopsis of standard options
|
|
||||||
-X Print a synopsis of advanced options
|
|
||||||
-version Display compiler version
|
|
||||||
-verbose Enable verbose logging output
|
|
||||||
-nowarn Generate no warnings
|
-nowarn Generate no warnings
|
||||||
|
-verbose Enable verbose logging output
|
||||||
|
-version Display compiler version
|
||||||
OK
|
OK
|
||||||
|
|||||||
+23
-23
@@ -1,38 +1,38 @@
|
|||||||
Usage: kotlinc-jvm <options> <source files>
|
Usage: kotlinc-jvm <options> <source files>
|
||||||
where advanced options include:
|
where advanced options include:
|
||||||
-Xmodule-path=<path> Paths where to find Java 9+ modules
|
-Xadd-compiler-builtins Add definitions of built-in declarations to the compilation classpath (useful with -no-stdlib)
|
||||||
-Xadd-modules=<module[,]> Root modules to resolve in addition to the initial modules,
|
-Xadd-modules=<module[,]> Root modules to resolve in addition to the initial modules,
|
||||||
or all modules on the module path if <module> is ALL-MODULE-PATH
|
or all modules on the module path if <module> is ALL-MODULE-PATH
|
||||||
-Xno-call-assertions Don't generate not-null assertion after each invocation of method returning not-null
|
|
||||||
-Xno-param-assertions Don't generate not-null assertions on parameters of methods accessible from Java
|
|
||||||
-Xno-optimize Disable optimizations
|
|
||||||
-Xreport-perf Report detailed performance statistics
|
|
||||||
-Xbuild-file=<path> Path to the .xml build file to compile
|
-Xbuild-file=<path> Path to the .xml build file to compile
|
||||||
-Xmultifile-parts-inherit Compile multifile classes as a hierarchy of parts and facade
|
|
||||||
-Xskip-runtime-version-check Allow Kotlin runtime libraries of incompatible versions in the classpath
|
|
||||||
-Xuse-old-class-files-reading Use old class files reading implementation (may slow down the build and should be used in case of problems with the new implementation)
|
|
||||||
-Xdump-declarations-to=<path> Path to JSON file to dump Java to Kotlin declaration mappings
|
-Xdump-declarations-to=<path> Path to JSON file to dump Java to Kotlin declaration mappings
|
||||||
-Xsingle-module Combine modules for source files and binary dependencies into a single module
|
-Xmultifile-parts-inherit Compile multifile classes as a hierarchy of parts and facade
|
||||||
-Xadd-compiler-builtins Add definitions of built-in declarations to the compilation classpath (useful with -no-stdlib)
|
-Xmodule-path=<path> Paths where to find Java 9+ modules
|
||||||
-Xload-builtins-from-dependencies
|
|
||||||
Load definitions of built-in declarations from module dependencies, instead of from the compiler
|
|
||||||
-Xscript-resolver-environment=<key=value[,]>
|
|
||||||
Script resolver environment in key-value pairs (the value could be quoted and escaped)
|
|
||||||
-Xuse-javac Use javac for Java source and class files analysis
|
|
||||||
-Xjavac-arguments=<option[,]> Java compiler arguments
|
-Xjavac-arguments=<option[,]> Java compiler arguments
|
||||||
-Xjsr305-annotations={ignore|enable}
|
-Xjsr305-annotations={ignore|enable}
|
||||||
Specify global behavior for JSR-305 nullability annotations: ignore, or treat as other supported nullability annotations
|
Specify global behavior for JSR-305 nullability annotations: ignore, or treat as other supported nullability annotations
|
||||||
-Xno-inline Disable method inlining
|
-Xload-builtins-from-dependencies
|
||||||
-Xrepeat=<count> Repeat compilation (for performance analysis)
|
Load definitions of built-in declarations from module dependencies, instead of from the compiler
|
||||||
-Xskip-metadata-version-check Load classes with bad metadata version anyway (incl. pre-release classes)
|
-Xno-call-assertions Don't generate not-null assertion after each invocation of method returning not-null
|
||||||
|
-Xno-optimize Disable optimizations
|
||||||
|
-Xno-param-assertions Don't generate not-null assertions on parameters of methods accessible from Java
|
||||||
|
-Xreport-perf Report detailed performance statistics
|
||||||
|
-Xscript-resolver-environment=<key=value[,]>
|
||||||
|
Script resolver environment in key-value pairs (the value could be quoted and escaped)
|
||||||
|
-Xsingle-module Combine modules for source files and binary dependencies into a single module
|
||||||
|
-Xskip-runtime-version-check Allow Kotlin runtime libraries of incompatible versions in the classpath
|
||||||
|
-Xuse-javac Use javac for Java source and class files analysis
|
||||||
|
-Xuse-old-class-files-reading Use old class files reading implementation (may slow down the build and should be used in case of problems with the new implementation)
|
||||||
-Xallow-kotlin-package Allow compiling code in package 'kotlin'
|
-Xallow-kotlin-package Allow compiling code in package 'kotlin'
|
||||||
-Xreport-output-files Report source to output files mapping
|
|
||||||
-Xplugin=<path> Load plugins from the given classpath
|
|
||||||
-Xmulti-platform Enable experimental language support for multi-platform projects
|
|
||||||
-Xno-check-impl Do not check presence of 'impl' modifier in multi-platform projects
|
|
||||||
-Xintellij-plugin-root=<path> Path to the kotlin-compiler.jar or directory where IntelliJ configuration files can be found
|
|
||||||
-Xcoroutines={enable|warn|error}
|
-Xcoroutines={enable|warn|error}
|
||||||
Enable coroutines or report warnings or errors on declarations and use sites of 'suspend' modifier
|
Enable coroutines or report warnings or errors on declarations and use sites of 'suspend' modifier
|
||||||
|
-Xintellij-plugin-root=<path> Path to the kotlin-compiler.jar or directory where IntelliJ configuration files can be found
|
||||||
|
-Xmulti-platform Enable experimental language support for multi-platform projects
|
||||||
|
-Xno-check-impl Do not check presence of 'impl' modifier in multi-platform projects
|
||||||
|
-Xno-inline Disable method inlining
|
||||||
|
-Xplugin=<path> Load plugins from the given classpath
|
||||||
|
-Xrepeat=<count> Repeat compilation (for performance analysis)
|
||||||
|
-Xreport-output-files Report source to output files mapping
|
||||||
|
-Xskip-metadata-version-check Load classes with bad metadata version anyway (incl. pre-release classes)
|
||||||
|
|
||||||
Advanced options are non-standard and may be changed or removed without any notice.
|
Advanced options are non-standard and may be changed or removed without any notice.
|
||||||
OK
|
OK
|
||||||
|
|||||||
Vendored
+10
-10
@@ -1,26 +1,26 @@
|
|||||||
Usage: kotlinc-jvm <options> <source files>
|
Usage: kotlinc-jvm <options> <source files>
|
||||||
where possible options include:
|
where possible options include:
|
||||||
-d <directory|jar> Destination for generated class files
|
|
||||||
-classpath (-cp) <path> Paths where to find user class files
|
-classpath (-cp) <path> Paths where to find user class files
|
||||||
|
-d <directory|jar> Destination for generated class files
|
||||||
-include-runtime Include Kotlin runtime in to resulting .jar
|
-include-runtime Include Kotlin runtime in to resulting .jar
|
||||||
|
-java-parameters Generate metadata for Java 1.8 reflection on method parameters
|
||||||
-jdk-home <path> Path to JDK home directory to include into classpath, if differs from default JAVA_HOME
|
-jdk-home <path> Path to JDK home directory to include into classpath, if differs from default JAVA_HOME
|
||||||
|
-jvm-target <version> Target version of the generated JVM bytecode (1.6 or 1.8), default is 1.6
|
||||||
|
-module-name Module name
|
||||||
-no-jdk Don't include Java runtime into classpath
|
-no-jdk Don't include Java runtime into classpath
|
||||||
-no-stdlib Don't include Kotlin runtime into classpath
|
|
||||||
-no-reflect Don't include Kotlin reflection implementation into classpath
|
-no-reflect Don't include Kotlin reflection implementation into classpath
|
||||||
|
-no-stdlib Don't include Kotlin runtime into classpath
|
||||||
-script Evaluate the script file
|
-script Evaluate the script file
|
||||||
-script-templates <fully qualified class name[,]>
|
-script-templates <fully qualified class name[,]>
|
||||||
Script definition template classes
|
Script definition template classes
|
||||||
-module-name Module name
|
|
||||||
-jvm-target <version> Target version of the generated JVM bytecode (1.6 or 1.8), default is 1.6
|
|
||||||
-java-parameters Generate metadata for Java 1.8 reflection on method parameters
|
|
||||||
-language-version <version> Provide source compatibility with specified language version
|
|
||||||
-api-version <version> Allow to use declarations only from the specified version of bundled libraries
|
-api-version <version> Allow to use declarations only from the specified version of bundled libraries
|
||||||
|
-X Print a synopsis of advanced options
|
||||||
|
-help (-h) Print a synopsis of standard options
|
||||||
-kotlin-home <path> Path to Kotlin compiler home directory, used for runtime libraries discovery
|
-kotlin-home <path> Path to Kotlin compiler home directory, used for runtime libraries discovery
|
||||||
|
-language-version <version> Provide source compatibility with specified language version
|
||||||
-P plugin:<pluginId>:<optionName>=<value>
|
-P plugin:<pluginId>:<optionName>=<value>
|
||||||
Pass an option to a plugin
|
Pass an option to a plugin
|
||||||
-help (-h) Print a synopsis of standard options
|
|
||||||
-X Print a synopsis of advanced options
|
|
||||||
-version Display compiler version
|
|
||||||
-verbose Enable verbose logging output
|
|
||||||
-nowarn Generate no warnings
|
-nowarn Generate no warnings
|
||||||
|
-verbose Enable verbose logging output
|
||||||
|
-version Display compiler version
|
||||||
OK
|
OK
|
||||||
|
|||||||
Reference in New Issue
Block a user