Refactoring of K2JSTranslator and neighboring classes
Drop GenerationUtils Introduce MainCallParameters Generate calls to main function together with the other code in contrast to as text afterwards Enhance tests a bit
This commit is contained in:
@@ -93,8 +93,8 @@ public class K2JSCompiler extends CLICompiler<K2JSCompilerArguments, K2JSCompile
|
||||
private static ExitCode translateAndGenerateOutputFile(@NotNull PrintingMessageCollector messageCollector,
|
||||
@NotNull JetCoreEnvironment environmentForJS, @NotNull Config config, @NotNull String outputFile) {
|
||||
try {
|
||||
K2JSTranslator.translateWithCallToMainAndSaveToFile(environmentForJS.getSourceFiles(), outputFile, config,
|
||||
environmentForJS.getProject());
|
||||
K2JSTranslator.translateWithCallToMainAndSaveToFile(environmentForJS.getSourceFiles(), outputFile, config
|
||||
);
|
||||
}
|
||||
catch (Exception e) {
|
||||
messageCollector.report(CompilerMessageSeverity.ERROR, "Exception while translating:\n" + e.getMessage(),
|
||||
|
||||
@@ -29,16 +29,11 @@ public class JetMainDetector {
|
||||
private JetMainDetector() {
|
||||
}
|
||||
|
||||
public static boolean hasMain(List<JetDeclaration> declarations) {
|
||||
for (JetDeclaration declaration : declarations) {
|
||||
if (declaration instanceof JetNamedFunction) {
|
||||
if (isMain((JetNamedFunction) declaration)) return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
public static boolean hasMain(@NotNull List<JetDeclaration> declarations) {
|
||||
return findMainFunction(declarations) != null;
|
||||
}
|
||||
|
||||
public static boolean isMain(JetNamedFunction function) {
|
||||
public static boolean isMain(@NotNull JetNamedFunction function) {
|
||||
if ("main".equals(function.getName())) {
|
||||
List<JetParameter> parameters = function.getValueParameters();
|
||||
if (parameters.size() == 1) {
|
||||
@@ -52,10 +47,24 @@ public class JetMainDetector {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static JetFile getFileWithMain(@NotNull List<JetFile> files) {
|
||||
public static JetNamedFunction getMainFunction(@NotNull List<JetFile> files) {
|
||||
for (JetFile file : files) {
|
||||
if (hasMain(file.getDeclarations())) {
|
||||
return file;
|
||||
JetNamedFunction mainFunction = findMainFunction(file.getDeclarations());
|
||||
if (mainFunction != null) {
|
||||
return mainFunction;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static JetNamedFunction findMainFunction(@NotNull List<JetDeclaration> declarations) {
|
||||
for (JetDeclaration declaration : declarations) {
|
||||
if (declaration instanceof JetNamedFunction) {
|
||||
JetNamedFunction candidateFunction = (JetNamedFunction) declaration;
|
||||
if (isMain(candidateFunction)) {
|
||||
return candidateFunction;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user