diff --git a/compiler/analyser.c b/compiler/analyser.c index c69a6b43..590b8914 100644 --- a/compiler/analyser.c +++ b/compiler/analyser.c @@ -895,6 +895,9 @@ static struct node * make_among(struct analyser * a, struct node * p, struct nod } x->substring = substring; if (substring != 0) substring->among = x; + + if (x->function_count > 0) ++a->among_with_function_count; + return p; } @@ -1612,6 +1615,7 @@ extern struct analyser * create_analyser(struct tokeniser * t) { a->program = 0; a->amongs = 0; a->among_count = 0; + a->among_with_function_count = 0; a->groupings = 0; a->mode = m_forward; a->modifyable = true; diff --git a/compiler/generator_java.c b/compiler/generator_java.c index f2e0a263..36fb18d2 100644 --- a/compiler/generator_java.c +++ b/compiler/generator_java.c @@ -1194,9 +1194,11 @@ static void generate_class_begin(struct generator * g) { w(g, g->options->parent_class_name); w(g, " {~+~N" "~N" - "~Mprivate static final long serialVersionUID = 1L;~N" - "~Mprivate static final java.lang.invoke.MethodHandles.Lookup methodObject = java.lang.invoke.MethodHandles.lookup();~N" - "~N"); + "~Mprivate static final long serialVersionUID = 1L;~N"); + if (g->analyser->among_with_function_count > 0) { + w(g, "~Mprivate static final java.lang.invoke.MethodHandles.Lookup methodObject = java.lang.invoke.MethodHandles.lookup();~N"); + } + w(g, "~N"); } static void generate_class_end(struct generator * g) { diff --git a/compiler/header.h b/compiler/header.h index c391d5a2..3bc845ce 100644 --- a/compiler/header.h +++ b/compiler/header.h @@ -310,6 +310,7 @@ struct analyser { struct among * amongs_end; int among_count; int amongvar_needed; /* used in reading routine definitions */ + int among_with_function_count; /* number of amongs with functions */ struct grouping * groupings; struct grouping * groupings_end; struct node * substring; /* pending 'substring' in current routine definition */