langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Modules.java
author jlahoda
Tue, 04 Oct 2016 16:25:19 +0200
changeset 41254 08f8dbf7741e
parent 40768 8b6a878d8773
child 41931 d7c9720c4223
permissions -rw-r--r--
8152911: javac assertion error when compiling overlay sources Summary: Avoid creating ModuleSymbols with unspecified name, to avoid conflicts with predefined ModuleSymbol for the java.base module. Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     2
 * Copyright (c) 2009, 2016, Oracle and/or its affiliates. All rights reserved.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     4
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    10
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    15
 * accompanied this code).
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    16
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    20
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    23
 * questions.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    24
 */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    25
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    26
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    27
package com.sun.tools.javac.comp;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    28
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    29
import java.io.IOException;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    30
import java.util.Arrays;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    31
import java.util.Collection;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    32
import java.util.Collections;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    33
import java.util.EnumSet;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    34
import java.util.HashMap;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    35
import java.util.HashSet;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    36
import java.util.LinkedHashMap;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    37
import java.util.LinkedHashSet;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    38
import java.util.Map;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    39
import java.util.Map.Entry;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    40
import java.util.Set;
39917
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
    41
import java.util.function.Consumer;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    42
import java.util.function.Predicate;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    43
import java.util.regex.Matcher;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    44
import java.util.regex.Pattern;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    45
import java.util.stream.Stream;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    46
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    47
import javax.lang.model.SourceVersion;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    48
import javax.tools.JavaFileManager;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    49
import javax.tools.JavaFileManager.Location;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    50
import javax.tools.JavaFileObject;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    51
import javax.tools.JavaFileObject.Kind;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    52
import javax.tools.StandardLocation;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    53
39361
cd0aca7db174 8159439: javac throws NPE with Module attribute and super_class != 0
vromero
parents: 38827
diff changeset
    54
import com.sun.tools.javac.code.ClassFinder;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    55
import com.sun.tools.javac.code.Directive;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    56
import com.sun.tools.javac.code.Directive.ExportsDirective;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    57
import com.sun.tools.javac.code.Directive.RequiresDirective;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    58
import com.sun.tools.javac.code.Directive.RequiresFlag;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    59
import com.sun.tools.javac.code.Directive.UsesDirective;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    60
import com.sun.tools.javac.code.Flags;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    61
import com.sun.tools.javac.code.Kinds;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    62
import com.sun.tools.javac.code.ModuleFinder;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    63
import com.sun.tools.javac.code.Source;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    64
import com.sun.tools.javac.code.Symbol;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    65
import com.sun.tools.javac.code.Symbol.ClassSymbol;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    66
import com.sun.tools.javac.code.Symbol.Completer;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    67
import com.sun.tools.javac.code.Symbol.CompletionFailure;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    68
import com.sun.tools.javac.code.Symbol.MethodSymbol;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    69
import com.sun.tools.javac.code.Symbol.ModuleSymbol;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    70
import com.sun.tools.javac.code.Symbol.PackageSymbol;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    71
import com.sun.tools.javac.code.Symtab;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    72
import com.sun.tools.javac.code.Type;
38827
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents: 38619
diff changeset
    73
import com.sun.tools.javac.code.Types;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    74
import com.sun.tools.javac.jvm.ClassWriter;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    75
import com.sun.tools.javac.jvm.JNIWriter;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    76
import com.sun.tools.javac.main.Option;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    77
import com.sun.tools.javac.resources.CompilerProperties.Errors;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    78
import com.sun.tools.javac.resources.CompilerProperties.Warnings;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    79
import com.sun.tools.javac.tree.JCTree;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    80
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    81
import com.sun.tools.javac.tree.JCTree.JCExports;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    82
import com.sun.tools.javac.tree.JCTree.JCExpression;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    83
import com.sun.tools.javac.tree.JCTree.JCModuleDecl;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    84
import com.sun.tools.javac.tree.JCTree.JCPackageDecl;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    85
import com.sun.tools.javac.tree.JCTree.JCProvides;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    86
import com.sun.tools.javac.tree.JCTree.JCRequires;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    87
import com.sun.tools.javac.tree.JCTree.JCUses;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    88
import com.sun.tools.javac.tree.TreeInfo;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    89
import com.sun.tools.javac.util.Assert;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    90
import com.sun.tools.javac.util.Context;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    91
import com.sun.tools.javac.util.JCDiagnostic;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    92
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    93
import com.sun.tools.javac.util.List;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    94
import com.sun.tools.javac.util.ListBuffer;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    95
import com.sun.tools.javac.util.Log;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    96
import com.sun.tools.javac.util.Name;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    97
import com.sun.tools.javac.util.Names;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    98
import com.sun.tools.javac.util.Options;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    99
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   100
import static com.sun.tools.javac.code.Flags.UNATTRIBUTED;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   101
import static com.sun.tools.javac.code.Kinds.Kind.MDL;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   102
import static com.sun.tools.javac.code.TypeTag.CLASS;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   103
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   104
import com.sun.tools.javac.tree.JCTree.JCDirective;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   105
import com.sun.tools.javac.tree.JCTree.Tag;
39361
cd0aca7db174 8159439: javac throws NPE with Module attribute and super_class != 0
vromero
parents: 38827
diff changeset
   106
import com.sun.tools.javac.util.Abort;
cd0aca7db174 8159439: javac throws NPE with Module attribute and super_class != 0
vromero
parents: 38827
diff changeset
   107
import com.sun.tools.javac.util.Position;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   108
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   109
import static com.sun.tools.javac.code.Flags.ABSTRACT;
37854
a76a06106d02 8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents: 37848
diff changeset
   110
import static com.sun.tools.javac.code.Flags.ENUM;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   111
import static com.sun.tools.javac.code.Flags.PUBLIC;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   112
import static com.sun.tools.javac.tree.JCTree.Tag.MODULEDEF;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   113
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   114
/**
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   115
 *  TODO: fill in
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   116
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   117
 *  <p><b>This is NOT part of any supported API.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   118
 *  If you write code that depends on this, you do so at your own risk.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   119
 *  This code and its internal interfaces are subject to change or
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   120
 *  deletion without notice.</b>
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   121
 */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   122
public class Modules extends JCTree.Visitor {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   123
    private static final String ALL_SYSTEM = "ALL-SYSTEM";
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   124
    private static final String ALL_MODULE_PATH = "ALL-MODULE-PATH";
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   125
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   126
    private final Log log;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   127
    private final Names names;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   128
    private final Symtab syms;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   129
    private final Attr attr;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   130
    private final TypeEnvs typeEnvs;
38827
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents: 38619
diff changeset
   131
    private final Types types;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   132
    private final JavaFileManager fileManager;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   133
    private final ModuleFinder moduleFinder;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   134
    private final boolean allowModules;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   135
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   136
    public final boolean multiModuleMode;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   137
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   138
    private final String moduleOverride;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   139
37848
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36526
diff changeset
   140
    private final Name java_se;
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36526
diff changeset
   141
    private final Name java_;
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36526
diff changeset
   142
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   143
    ModuleSymbol defaultModule;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   144
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   145
    private final String addExportsOpt;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   146
    private Map<ModuleSymbol, Set<ExportsDirective>> addExports;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   147
    private final String addReadsOpt;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   148
    private Map<ModuleSymbol, Set<RequiresDirective>> addReads;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   149
    private final String addModsOpt;
40311
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   150
    private final Set<String> extraAddMods = new HashSet<>();
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   151
    private final String limitModsOpt;
40311
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   152
    private final Set<String> extraLimitMods = new HashSet<>();
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   153
39917
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   154
    private Set<ModuleSymbol> rootModules = null;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   155
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   156
    public static Modules instance(Context context) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   157
        Modules instance = context.get(Modules.class);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   158
        if (instance == null)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   159
            instance = new Modules(context);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   160
        return instance;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   161
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   162
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   163
    protected Modules(Context context) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   164
        context.put(Modules.class, this);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   165
        log = Log.instance(context);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   166
        names = Names.instance(context);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   167
        syms = Symtab.instance(context);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   168
        attr = Attr.instance(context);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   169
        typeEnvs = TypeEnvs.instance(context);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   170
        moduleFinder = ModuleFinder.instance(context);
38827
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents: 38619
diff changeset
   171
        types = Types.instance(context);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   172
        fileManager = context.get(JavaFileManager.class);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   173
        allowModules = Source.instance(context).allowModules();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   174
        Options options = Options.instance(context);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   175
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   176
        moduleOverride = options.get(Option.XMODULE);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   177
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   178
        multiModuleMode = fileManager.hasLocation(StandardLocation.MODULE_SOURCE_PATH);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   179
        ClassWriter classWriter = ClassWriter.instance(context);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   180
        classWriter.multiModuleMode = multiModuleMode;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   181
        JNIWriter jniWriter = JNIWriter.instance(context);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   182
        jniWriter.multiModuleMode = multiModuleMode;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   183
37848
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36526
diff changeset
   184
        java_se = names.fromString("java.se");
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36526
diff changeset
   185
        java_ = names.fromString("java.");
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36526
diff changeset
   186
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39917
diff changeset
   187
        addExportsOpt = options.get(Option.ADD_EXPORTS);
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39917
diff changeset
   188
        addReadsOpt = options.get(Option.ADD_READS);
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39917
diff changeset
   189
        addModsOpt = options.get(Option.ADD_MODULES);
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39917
diff changeset
   190
        limitModsOpt = options.get(Option.LIMIT_MODULES);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   191
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   192
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   193
    int depth = -1;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   194
    private void dprintln(String msg) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   195
        for (int i = 0; i < depth; i++)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   196
            System.err.print("  ");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   197
        System.err.println(msg);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   198
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   199
40311
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   200
    public void addExtraAddModules(String... extras) {
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   201
        extraAddMods.addAll(Arrays.asList(extras));
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   202
    }
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   203
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   204
    public void addExtraLimitModules(String... extras) {
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   205
        extraLimitMods.addAll(Arrays.asList(extras));
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   206
    }
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   207
39917
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   208
    boolean inInitModules;
40311
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   209
    public void initModules(List<JCCompilationUnit> trees) {
39917
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   210
        Assert.check(!inInitModules);
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   211
        try {
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   212
            inInitModules = true;
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   213
            Assert.checkNull(rootModules);
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   214
            enter(trees, modules -> {
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   215
                Assert.checkNull(rootModules);
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   216
                Assert.checkNull(allModules);
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   217
                this.rootModules = modules;
40311
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   218
                setupAllModules(); //initialize the module graph
39917
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   219
                Assert.checkNonNull(allModules);
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   220
                inInitModules = false;
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   221
            }, null);
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   222
        } finally {
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   223
            inInitModules = false;
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   224
        }
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   225
    }
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   226
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   227
    public boolean enter(List<JCCompilationUnit> trees, ClassSymbol c) {
39917
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   228
        Assert.check(rootModules != null || inInitModules || !allowModules);
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   229
        return enter(trees, modules -> {}, c);
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   230
    }
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   231
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   232
    private boolean enter(List<JCCompilationUnit> trees, Consumer<Set<ModuleSymbol>> init, ClassSymbol c) {
38619
27c0007bb28d 8152785: Remove javac -XDnoModules
vromero
parents: 37854
diff changeset
   233
        if (!allowModules) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   234
            for (JCCompilationUnit tree: trees) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   235
                tree.modle = syms.noModule;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   236
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   237
            defaultModule = syms.noModule;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   238
            return true;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   239
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   240
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   241
        int startErrors = log.nerrors;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   242
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   243
        depth++;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   244
        try {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   245
            // scan trees for module defs
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   246
            Set<ModuleSymbol> roots = enterModules(trees, c);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   247
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   248
            setCompilationUnitModules(trees, roots);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   249
39917
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   250
            init.accept(roots);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   251
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   252
            for (ModuleSymbol msym: roots) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   253
                msym.complete();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   254
            }
39361
cd0aca7db174 8159439: javac throws NPE with Module attribute and super_class != 0
vromero
parents: 38827
diff changeset
   255
        } catch (CompletionFailure ex) {
cd0aca7db174 8159439: javac throws NPE with Module attribute and super_class != 0
vromero
parents: 38827
diff changeset
   256
            log.error(JCDiagnostic.DiagnosticFlag.NON_DEFERRABLE, Position.NOPOS, "cant.access", ex.sym, ex.getDetailValue());
cd0aca7db174 8159439: javac throws NPE with Module attribute and super_class != 0
vromero
parents: 38827
diff changeset
   257
            if (ex instanceof ClassFinder.BadClassFile) throw new Abort();
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   258
        } finally {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   259
            depth--;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   260
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   261
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   262
        return (log.nerrors == startErrors);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   263
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   264
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   265
    public Completer getCompleter() {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   266
        return mainCompleter;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   267
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   268
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   269
    public ModuleSymbol getDefaultModule() {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   270
        return defaultModule;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   271
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   272
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   273
    private Set<ModuleSymbol> enterModules(List<JCCompilationUnit> trees, ClassSymbol c) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   274
        Set<ModuleSymbol> modules = new LinkedHashSet<>();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   275
        for (JCCompilationUnit tree : trees) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   276
            JavaFileObject prev = log.useSource(tree.sourcefile);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   277
            try {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   278
                enterModule(tree, c, modules);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   279
            } finally {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   280
                log.useSource(prev);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   281
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   282
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   283
        return modules;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   284
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   285
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   286
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   287
    private void enterModule(JCCompilationUnit toplevel, ClassSymbol c, Set<ModuleSymbol> modules) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   288
        boolean isModuleInfo = toplevel.sourcefile.isNameCompatible("module-info", Kind.SOURCE);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   289
        boolean isModuleDecl = toplevel.defs.nonEmpty() && toplevel.defs.head.hasTag(MODULEDEF);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   290
        if (isModuleInfo && isModuleDecl) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   291
            JCModuleDecl decl = (JCModuleDecl) toplevel.defs.head;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   292
            Name name = TreeInfo.fullName(decl.qualId);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   293
            ModuleSymbol sym;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   294
            if (c != null) {
41254
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40768
diff changeset
   295
                sym = (ModuleSymbol) c.owner;
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40768
diff changeset
   296
                Assert.checkNonNull(sym.name);
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40768
diff changeset
   297
                Name treeName = TreeInfo.fullName(decl.qualId);
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40768
diff changeset
   298
                if (sym.name != treeName) {
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40768
diff changeset
   299
                    log.error(decl.pos(), Errors.ModuleNameMismatch(name, sym.name));
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40768
diff changeset
   300
                }
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   301
            } else {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   302
                sym = syms.enterModule(name);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   303
                if (sym.module_info.sourcefile != null && sym.module_info.sourcefile != toplevel.sourcefile) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   304
                    log.error(decl.pos(), Errors.DuplicateModule(sym));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   305
                    return;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   306
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   307
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   308
            sym.completer = getSourceCompleter(toplevel);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   309
            sym.module_info.sourcefile = toplevel.sourcefile;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   310
            decl.sym = sym;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   311
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   312
            if (multiModuleMode || modules.isEmpty()) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   313
                modules.add(sym);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   314
            } else {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   315
                log.error(toplevel.pos(), Errors.TooManyModules);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   316
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   317
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   318
            Env<AttrContext> provisionalEnv = new Env<>(decl, null);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   319
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   320
            provisionalEnv.toplevel = toplevel;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   321
            typeEnvs.put(sym, provisionalEnv);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   322
        } else if (isModuleInfo) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   323
            if (multiModuleMode) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   324
                JCTree tree = toplevel.defs.isEmpty() ? toplevel : toplevel.defs.head;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   325
                log.error(tree.pos(), Errors.ExpectedModule);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   326
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   327
        } else if (isModuleDecl) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   328
            JCTree tree = toplevel.defs.head;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   329
            log.error(tree.pos(), Errors.ModuleDeclSbInModuleInfoJava);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   330
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   331
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   332
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   333
    private void setCompilationUnitModules(List<JCCompilationUnit> trees, Set<ModuleSymbol> rootModules) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   334
        // update the module for each compilation unit
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   335
        if (multiModuleMode) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   336
            checkNoAllModulePath();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   337
            for (JCCompilationUnit tree: trees) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   338
                if (tree.defs.isEmpty()) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   339
                    tree.modle = syms.unnamedModule;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   340
                    continue;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   341
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   342
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   343
                JavaFileObject prev = log.useSource(tree.sourcefile);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   344
                try {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   345
                    Location locn = getModuleLocation(tree);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   346
                    if (locn != null) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   347
                        Name name = names.fromString(fileManager.inferModuleName(locn));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   348
                        ModuleSymbol msym;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   349
                        if (tree.defs.head.hasTag(MODULEDEF)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   350
                            JCModuleDecl decl = (JCModuleDecl) tree.defs.head;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   351
                            msym = decl.sym;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   352
                            if (msym.name != name) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   353
                                log.error(decl.qualId, Errors.ModuleNameMismatch(msym.name, name));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   354
                            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   355
                        } else {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   356
                            msym = syms.enterModule(name);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   357
                        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   358
                        if (msym.sourceLocation == null) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   359
                            msym.sourceLocation = locn;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   360
                            if (fileManager.hasLocation(StandardLocation.CLASS_OUTPUT)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   361
                                msym.classLocation = fileManager.getModuleLocation(
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   362
                                        StandardLocation.CLASS_OUTPUT, msym.name.toString());
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   363
                            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   364
                        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   365
                        tree.modle = msym;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   366
                        rootModules.add(msym);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   367
                    } else {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   368
                        log.error(tree.pos(), Errors.UnnamedPkgNotAllowedNamedModules);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   369
                        tree.modle = syms.errModule;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   370
                    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   371
                } catch (IOException e) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   372
                    throw new Error(e); // FIXME
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   373
                } finally {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   374
                    log.useSource(prev);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   375
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   376
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   377
            if (syms.unnamedModule.sourceLocation == null) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   378
                syms.unnamedModule.completer = getUnnamedModuleCompleter();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   379
                syms.unnamedModule.sourceLocation = StandardLocation.SOURCE_PATH;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   380
                syms.unnamedModule.classLocation = StandardLocation.CLASS_PATH;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   381
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   382
            defaultModule = syms.unnamedModule;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   383
        } else {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   384
            if (defaultModule == null) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   385
                switch (rootModules.size()) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   386
                    case 0:
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   387
                        defaultModule = moduleFinder.findSingleModule();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   388
                        if (defaultModule == syms.unnamedModule) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   389
                            if (moduleOverride != null) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   390
                                checkNoAllModulePath();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   391
                                defaultModule = moduleFinder.findModule(names.fromString(moduleOverride));
40768
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40762
diff changeset
   392
                                defaultModule.sourceLocation = StandardLocation.SOURCE_PATH;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   393
                            } else {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   394
                                // Question: why not do findAllModules and initVisiblePackages here?
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   395
                                // i.e. body of unnamedModuleCompleter
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   396
                                defaultModule.completer = getUnnamedModuleCompleter();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   397
                                defaultModule.classLocation = StandardLocation.CLASS_PATH;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   398
                            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   399
                        } else {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   400
                            checkSpecifiedModule(trees, Errors.ModuleInfoWithXmoduleClasspath);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   401
                            checkNoAllModulePath();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   402
                            defaultModule.complete();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   403
                            // Question: why not do completeModule here?
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   404
                            defaultModule.completer = new Completer() {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   405
                                @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   406
                                public void complete(Symbol sym) throws CompletionFailure {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   407
                                    completeModule((ModuleSymbol) sym);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   408
                                }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   409
                            };
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   410
                        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   411
                        rootModules.add(defaultModule);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   412
                        break;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   413
                    case 1:
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   414
                        checkSpecifiedModule(trees, Errors.ModuleInfoWithXmoduleSourcepath);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   415
                        checkNoAllModulePath();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   416
                        defaultModule = rootModules.iterator().next();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   417
                        defaultModule.classLocation = StandardLocation.CLASS_OUTPUT;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   418
                        break;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   419
                    default:
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   420
                        Assert.error("too many modules");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   421
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   422
                defaultModule.sourceLocation = StandardLocation.SOURCE_PATH;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   423
            } else if (rootModules.size() == 1 && defaultModule == rootModules.iterator().next()) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   424
                defaultModule.complete();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   425
                defaultModule.completer = sym -> completeModule((ModuleSymbol) sym);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   426
            } else {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   427
                Assert.check(rootModules.isEmpty());
39917
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   428
                rootModules.add(defaultModule);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   429
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   430
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   431
            if (defaultModule != syms.unnamedModule) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   432
                syms.unnamedModule.completer = getUnnamedModuleCompleter();
40768
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40762
diff changeset
   433
                if (moduleOverride == null) {
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40762
diff changeset
   434
                    syms.unnamedModule.sourceLocation = StandardLocation.SOURCE_PATH;
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40762
diff changeset
   435
                }
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   436
                syms.unnamedModule.classLocation = StandardLocation.CLASS_PATH;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   437
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   438
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   439
            for (JCCompilationUnit tree: trees) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   440
                tree.modle = defaultModule;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   441
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   442
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   443
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   444
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   445
    private Location getModuleLocation(JCCompilationUnit tree) throws IOException {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   446
        switch (tree.defs.head.getTag()) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   447
            case MODULEDEF:
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   448
                return getModuleLocation(tree.sourcefile, null);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   449
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   450
            case PACKAGEDEF:
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   451
                JCPackageDecl pkg = (JCPackageDecl) tree.defs.head;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   452
                return getModuleLocation(tree.sourcefile, TreeInfo.fullName(pkg.pid));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   453
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   454
            default:
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   455
                // code in unnamed module
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   456
                return null;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   457
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   458
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   459
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   460
    private Location getModuleLocation(JavaFileObject fo, Name pkgName) throws IOException {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   461
        // For now, just check module source path.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   462
        // We may want to check source path as well.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   463
        return fileManager.getModuleLocation(StandardLocation.MODULE_SOURCE_PATH,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   464
                fo, (pkgName == null) ? null : pkgName.toString());
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   465
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   466
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   467
    private void checkSpecifiedModule(List<JCCompilationUnit> trees, JCDiagnostic.Error error) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   468
        if (moduleOverride != null) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   469
            JavaFileObject prev = log.useSource(trees.head.sourcefile);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   470
            try {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   471
                log.error(trees.head.pos(), error);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   472
            } finally {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   473
                log.useSource(prev);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   474
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   475
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   476
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   477
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   478
    private void checkNoAllModulePath() {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   479
        if (addModsOpt != null && Arrays.asList(addModsOpt.split(",")).contains(ALL_MODULE_PATH)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   480
            log.error(Errors.AddmodsAllModulePathInvalid);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   481
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   482
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   483
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   484
    private final Completer mainCompleter = new Completer() {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   485
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   486
        public void complete(Symbol sym) throws CompletionFailure {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   487
            ModuleSymbol msym = moduleFinder.findModule((ModuleSymbol) sym);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   488
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   489
            if (msym.kind == Kinds.Kind.ERR) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   490
                log.error(Errors.CantFindModule(msym));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   491
                //make sure the module is initialized:
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   492
                msym.directives = List.nil();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   493
                msym.exports = List.nil();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   494
                msym.provides = List.nil();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   495
                msym.requires = List.nil();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   496
                msym.uses = List.nil();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   497
            } else if ((msym.flags_field & Flags.AUTOMATIC_MODULE) != 0) {
39917
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   498
                setupAutomaticModule(msym);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   499
            } else {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   500
                msym.module_info.complete();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   501
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   502
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   503
            // If module-info comes from a .java file, the underlying
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   504
            // call of classFinder.fillIn will have called through the
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   505
            // source completer, to Enter, and then to Modules.enter,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   506
            // which will call completeModule.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   507
            // But, if module-info comes from a .class file, the underlying
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   508
            // call of classFinder.fillIn will just call ClassReader to read
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   509
            // the .class file, and so we call completeModule here.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   510
            if (msym.module_info.classfile == null || msym.module_info.classfile.getKind() == Kind.CLASS) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   511
                completeModule(msym);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   512
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   513
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   514
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   515
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   516
        public String toString() {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   517
            return "mainCompleter";
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   518
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   519
    };
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   520
39917
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   521
    private void setupAutomaticModule(ModuleSymbol msym) throws CompletionFailure {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   522
        try {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   523
            ListBuffer<Directive> directives = new ListBuffer<>();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   524
            ListBuffer<ExportsDirective> exports = new ListBuffer<>();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   525
            Set<String> seenPackages = new HashSet<>();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   527
            for (JavaFileObject clazz : fileManager.list(msym.classLocation, "", EnumSet.of(Kind.CLASS), true)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   528
                String binName = fileManager.inferBinaryName(msym.classLocation, clazz);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   529
                String pack = binName.lastIndexOf('.') != (-1) ? binName.substring(0, binName.lastIndexOf('.')) : ""; //unnamed package????
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   530
                if (seenPackages.add(pack)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   531
                    ExportsDirective d = new ExportsDirective(syms.enterPackage(msym, names.fromString(pack)), null);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   532
                    directives.add(d);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   533
                    exports.add(d);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   534
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   535
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   536
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   537
            msym.exports = exports.toList();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   538
            msym.provides = List.nil();
39917
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   539
            msym.requires = List.nil();
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   540
            msym.uses = List.nil();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   541
            msym.directives = directives.toList();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   542
            msym.flags_field |= Flags.ACYCLIC;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   543
        } catch (IOException ex) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   544
            throw new IllegalStateException(ex);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   545
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   546
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   547
39917
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   548
    private void completeAutomaticModule(ModuleSymbol msym) throws CompletionFailure {
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   549
        ListBuffer<Directive> directives = new ListBuffer<>();
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   550
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   551
        directives.addAll(msym.directives);
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   552
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   553
        ListBuffer<RequiresDirective> requires = new ListBuffer<>();
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   554
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   555
        for (ModuleSymbol ms : allModules()) {
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   556
            if (ms == syms.unnamedModule || ms == msym)
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   557
                continue;
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   558
            Set<RequiresFlag> flags = (ms.flags_field & Flags.AUTOMATIC_MODULE) != 0 ?
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   559
                    EnumSet.of(RequiresFlag.PUBLIC) : EnumSet.noneOf(RequiresFlag.class);
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   560
            RequiresDirective d = new RequiresDirective(ms, flags);
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   561
            directives.add(d);
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   562
            requires.add(d);
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   563
        }
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   564
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   565
        RequiresDirective requiresUnnamed = new RequiresDirective(syms.unnamedModule);
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   566
        directives.add(requiresUnnamed);
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   567
        requires.add(requiresUnnamed);
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   568
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   569
        msym.requires = requires.toList();
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   570
        msym.directives = directives.toList();
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   571
    }
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   572
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   573
    private Completer getSourceCompleter(JCCompilationUnit tree) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   574
        return new Completer() {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   575
            @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   576
            public void complete(Symbol sym) throws CompletionFailure {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   577
                ModuleSymbol msym = (ModuleSymbol) sym;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   578
                msym.flags_field |= UNATTRIBUTED;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   579
                ModuleVisitor v = new ModuleVisitor();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   580
                JavaFileObject prev = log.useSource(tree.sourcefile);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   581
                try {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   582
                    tree.defs.head.accept(v);
39917
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   583
                    checkCyclicDependencies((JCModuleDecl) tree.defs.head);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   584
                    completeModule(msym);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   585
                } finally {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   586
                    log.useSource(prev);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   587
                    msym.flags_field &= ~UNATTRIBUTED;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   588
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   589
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   590
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   591
            @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   592
            public String toString() {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   593
                return "SourceCompleter: " + tree.sourcefile.getName();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   594
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   595
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   596
        };
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   597
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   598
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   599
    class ModuleVisitor extends JCTree.Visitor {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   600
        private ModuleSymbol sym;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   601
        private final Set<ModuleSymbol> allRequires = new HashSet<>();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   602
        private final Set<PackageSymbol> allExports = new HashSet<>();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   603
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   604
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   605
        public void visitModuleDef(JCModuleDecl tree) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   606
            sym = Assert.checkNonNull(tree.sym);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   607
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   608
            sym.requires = List.nil();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   609
            sym.exports = List.nil();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   610
            tree.directives.forEach(t -> t.accept(this));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   611
            sym.requires = sym.requires.reverse();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   612
            sym.exports = sym.exports.reverse();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   613
            ensureJavaBase();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   614
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   615
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   616
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   617
        public void visitRequires(JCRequires tree) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   618
            ModuleSymbol msym = lookupModule(tree.moduleName);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   619
            if (msym.kind != MDL) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   620
                log.error(tree.moduleName.pos(), Errors.ModuleNotFound(msym));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   621
            } else if (allRequires.contains(msym)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   622
                log.error(tree.moduleName.pos(), Errors.DuplicateRequires(msym));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   623
            } else {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   624
                allRequires.add(msym);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   625
                Set<RequiresFlag> flags = EnumSet.noneOf(RequiresFlag.class);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   626
                if (tree.isPublic)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   627
                    flags.add(RequiresFlag.PUBLIC);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   628
                RequiresDirective d = new RequiresDirective(msym, flags);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   629
                tree.directive = d;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   630
                sym.requires = sym.requires.prepend(d);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   631
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   632
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   633
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   634
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   635
        public void visitExports(JCExports tree) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   636
            Name name = TreeInfo.fullName(tree.qualid);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   637
            PackageSymbol packge = syms.enterPackage(sym, name);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   638
            attr.setPackageSymbols(tree.qualid, packge);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   639
            if (!allExports.add(packge)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   640
                log.error(tree.qualid.pos(), Errors.DuplicateExports(packge));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   641
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   642
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   643
            List<ModuleSymbol> toModules = null;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   644
            if (tree.moduleNames != null) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   645
                Set<ModuleSymbol> to = new HashSet<>();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   646
                for (JCExpression n: tree.moduleNames) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   647
                    ModuleSymbol msym = lookupModule(n);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   648
                    if (msym.kind != MDL) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   649
                        log.error(n.pos(), Errors.ModuleNotFound(msym));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   650
                    } else if (!to.add(msym)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   651
                        log.error(n.pos(), Errors.DuplicateExports(msym));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   652
                    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   653
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   654
                toModules = List.from(to);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   655
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   656
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   657
            if (toModules == null || !toModules.isEmpty()) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   658
                ExportsDirective d = new ExportsDirective(packge, toModules);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   659
                tree.directive = d;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   660
                sym.exports = sym.exports.prepend(d);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   661
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   662
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   663
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   664
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   665
        public void visitProvides(JCProvides tree) { }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   666
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   667
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   668
        public void visitUses(JCUses tree) { }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   669
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   670
        private void ensureJavaBase() {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   671
            if (sym.name == names.java_base)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   672
                return;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   673
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   674
            for (RequiresDirective d: sym.requires) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   675
                if (d.module.name == names.java_base)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   676
                    return;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   677
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   678
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   679
            ModuleSymbol java_base = syms.enterModule(names.java_base);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   680
            Directive.RequiresDirective d =
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   681
                    new Directive.RequiresDirective(java_base,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   682
                            EnumSet.of(Directive.RequiresFlag.MANDATED));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   683
            sym.requires = sym.requires.prepend(d);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   684
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   685
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   686
        private ModuleSymbol lookupModule(JCExpression moduleName) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   687
            try {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   688
            Name name = TreeInfo.fullName(moduleName);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   689
            ModuleSymbol msym = moduleFinder.findModule(name);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   690
            TreeInfo.setSymbol(moduleName, msym);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   691
            return msym;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   692
            } catch (Throwable t) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   693
                System.err.println("Module " + sym + "; lookup export " + moduleName);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   694
                throw t;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   695
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   696
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   697
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   698
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   699
    public Completer getUsesProvidesCompleter() {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   700
        return sym -> {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   701
            ModuleSymbol msym = (ModuleSymbol) sym;
39917
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   702
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   703
            msym.complete();
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   704
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   705
            Env<AttrContext> env = typeEnvs.get(msym);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   706
            UsesProvidesVisitor v = new UsesProvidesVisitor(msym, env);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   707
            JavaFileObject prev = log.useSource(env.toplevel.sourcefile);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   708
            try {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   709
                env.toplevel.defs.head.accept(v);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   710
            } finally {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   711
                log.useSource(prev);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   712
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   713
        };
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   714
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   715
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   716
    class UsesProvidesVisitor extends JCTree.Visitor {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   717
        private final ModuleSymbol msym;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   718
        private final Env<AttrContext> env;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   719
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   720
        private final Set<Directive.UsesDirective> allUses = new HashSet<>();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   721
        private final Set<Directive.ProvidesDirective> allProvides = new HashSet<>();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   722
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   723
        public UsesProvidesVisitor(ModuleSymbol msym, Env<AttrContext> env) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   724
            this.msym = msym;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   725
            this.env = env;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   726
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   727
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   728
        @Override @SuppressWarnings("unchecked")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   729
        public void visitModuleDef(JCModuleDecl tree) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   730
            msym.directives = List.nil();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   731
            msym.provides = List.nil();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   732
            msym.uses = List.nil();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   733
            tree.directives.forEach(t -> t.accept(this));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   734
            msym.directives = msym.directives.reverse();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   735
            msym.provides = msym.provides.reverse();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   736
            msym.uses = msym.uses.reverse();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   737
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   738
            if (msym.requires.nonEmpty() && msym.requires.head.flags.contains(RequiresFlag.MANDATED))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   739
                msym.directives = msym.directives.prepend(msym.requires.head);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   740
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   741
            msym.directives = msym.directives.appendList(List.from(addReads.getOrDefault(msym, Collections.emptySet())));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   742
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   743
            checkForCorrectness();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   744
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   745
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   746
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   747
        public void visitExports(JCExports tree) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   748
            if (tree.directive.packge.members().isEmpty()) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   749
                log.error(tree.qualid.pos(), Errors.PackageEmptyOrNotFound(tree.directive.packge));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   750
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   751
            msym.directives = msym.directives.prepend(tree.directive);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   752
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   753
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   754
        MethodSymbol noArgsConstructor(ClassSymbol tsym) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   755
            for (Symbol sym : tsym.members().getSymbolsByName(names.init)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   756
                MethodSymbol mSym = (MethodSymbol)sym;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   757
                if (mSym.params().isEmpty()) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   758
                    return mSym;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   759
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   760
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   761
            return null;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   762
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   763
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   764
        Map<Directive.ProvidesDirective, JCProvides> directiveToTreeMap = new HashMap<>();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   765
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   766
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   767
        public void visitProvides(JCProvides tree) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   768
            Type st = attr.attribType(tree.serviceName, env, syms.objectType);
38827
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents: 38619
diff changeset
   769
            Type it = attr.attribType(tree.implName, env, syms.objectType);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   770
            ClassSymbol service = (ClassSymbol) st.tsym;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   771
            ClassSymbol impl = (ClassSymbol) it.tsym;
38827
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents: 38619
diff changeset
   772
            if (!types.isSubtype(it, st)) {
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents: 38619
diff changeset
   773
                log.error(tree.implName.pos(), Errors.ServiceImplementationMustBeSubtypeOfServiceInterface);
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents: 38619
diff changeset
   774
            }
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   775
            if ((impl.flags() & ABSTRACT) != 0) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   776
                log.error(tree.implName.pos(), Errors.ServiceImplementationIsAbstract(impl));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   777
            } else if (impl.isInner()) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   778
                log.error(tree.implName.pos(), Errors.ServiceImplementationIsInner(impl));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   779
            } else if (service.isInner()) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   780
                log.error(tree.serviceName.pos(), Errors.ServiceDefinitionIsInner(service));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   781
            } else {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   782
                MethodSymbol constr = noArgsConstructor(impl);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   783
                if (constr == null) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   784
                    log.error(tree.implName.pos(), Errors.ServiceImplementationDoesntHaveANoArgsConstructor(impl));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   785
                } else if ((constr.flags() & PUBLIC) == 0) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   786
                    log.error(tree.implName.pos(), Errors.ServiceImplementationNoArgsConstructorNotPublic(impl));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   787
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   788
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   789
            if (st.hasTag(CLASS) && it.hasTag(CLASS)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   790
                Directive.ProvidesDirective d = new Directive.ProvidesDirective(service, impl);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   791
                if (!allProvides.add(d)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   792
                    log.error(tree.pos(), Errors.DuplicateProvides(service, impl));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   793
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   794
                msym.provides = msym.provides.prepend(d);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   795
                msym.directives = msym.directives.prepend(d);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   796
                directiveToTreeMap.put(d, tree);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   797
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   798
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   799
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   800
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   801
        public void visitRequires(JCRequires tree) {
39915
5d1e0740e709 8158224: NullPointerException in com.sun.tools.javac.comp.Modules.checkCyclicDependencies when module missing
sadayapalam
parents: 39366
diff changeset
   802
            if (tree.directive != null) {
5d1e0740e709 8158224: NullPointerException in com.sun.tools.javac.comp.Modules.checkCyclicDependencies when module missing
sadayapalam
parents: 39366
diff changeset
   803
                msym.directives = msym.directives.prepend(tree.directive);
5d1e0740e709 8158224: NullPointerException in com.sun.tools.javac.comp.Modules.checkCyclicDependencies when module missing
sadayapalam
parents: 39366
diff changeset
   804
            }
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   805
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   806
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   807
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   808
        public void visitUses(JCUses tree) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   809
            Type st = attr.attribType(tree.qualid, env, syms.objectType);
37854
a76a06106d02 8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents: 37848
diff changeset
   810
            Symbol sym = TreeInfo.symbol(tree.qualid);
a76a06106d02 8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents: 37848
diff changeset
   811
            if ((sym.flags() & ENUM) != 0) {
a76a06106d02 8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents: 37848
diff changeset
   812
                log.error(tree.qualid.pos(), Errors.ServiceDefinitionIsEnum(st.tsym));
a76a06106d02 8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents: 37848
diff changeset
   813
            } else if (st.hasTag(CLASS)) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   814
                ClassSymbol service = (ClassSymbol) st.tsym;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   815
                Directive.UsesDirective d = new Directive.UsesDirective(service);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   816
                if (!allUses.add(d)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   817
                    log.error(tree.pos(), Errors.DuplicateUses(service));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   818
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   819
                msym.uses = msym.uses.prepend(d);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   820
                msym.directives = msym.directives.prepend(d);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   821
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   822
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   823
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   824
        private void checkForCorrectness() {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   825
            for (Directive.ProvidesDirective provides : allProvides) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   826
                JCProvides tree = directiveToTreeMap.get(provides);
37848
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36526
diff changeset
   827
                /* The implementation must be defined in the same module as the provides directive
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36526
diff changeset
   828
                 * (else, error)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   829
                 */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   830
                PackageSymbol implementationDefiningPackage = provides.impl.packge();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   831
                if (implementationDefiningPackage.modle != msym) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   832
                    log.error(tree.pos(), Errors.ServiceImplementationNotInRightModule(implementationDefiningPackage.modle));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   833
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   834
37848
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36526
diff changeset
   835
                /* There is no inherent requirement that module that provides a service should actually
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36526
diff changeset
   836
                 * use it itself. However, it is a pointless declaration if the service package is not
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36526
diff changeset
   837
                 * exported and there is no uses for the service.
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   838
                 */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   839
                PackageSymbol interfaceDeclaringPackage = provides.service.packge();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   840
                boolean isInterfaceDeclaredInCurrentModule = interfaceDeclaringPackage.modle == msym;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   841
                boolean isInterfaceExportedFromAReadableModule =
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   842
                        msym.visiblePackages.get(interfaceDeclaringPackage.fullname) == interfaceDeclaringPackage;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   843
                if (isInterfaceDeclaredInCurrentModule && !isInterfaceExportedFromAReadableModule) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   844
                    // ok the interface is declared in this module. Let's check if it's exported
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   845
                    boolean warn = true;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   846
                    for (ExportsDirective export : msym.exports) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   847
                        if (interfaceDeclaringPackage == export.packge) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   848
                            warn = false;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   849
                            break;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   850
                        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   851
                    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   852
                    if (warn) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   853
                        for (UsesDirective uses : msym.uses) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   854
                            if (provides.service == uses.service) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   855
                                warn = false;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   856
                                break;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   857
                            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   858
                        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   859
                    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   860
                    if (warn) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   861
                        log.warning(tree.pos(), Warnings.ServiceProvidedButNotExportedOrUsed(provides.service));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   862
                    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   863
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   864
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   865
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   866
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   867
39917
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   868
    private Set<ModuleSymbol> allModules;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   869
39917
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   870
    public Set<ModuleSymbol> allModules() {
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   871
        Assert.checkNonNull(allModules);
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   872
        return allModules;
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   873
    }
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   874
40311
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   875
    private void setupAllModules() {
39917
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   876
        Assert.checkNonNull(rootModules);
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   877
        Assert.checkNull(allModules);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   878
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   879
        Set<ModuleSymbol> observable;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   880
39917
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   881
        if (limitModsOpt == null && extraLimitMods.isEmpty()) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   882
            observable = null;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   883
        } else {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   884
            Set<ModuleSymbol> limitMods = new HashSet<>();
39917
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   885
            if (limitModsOpt != null) {
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   886
                for (String limit : limitModsOpt.split(",")) {
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   887
                    limitMods.add(syms.enterModule(names.fromString(limit)));
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   888
                }
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   889
            }
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   890
            for (String limit : extraLimitMods) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   891
                limitMods.add(syms.enterModule(names.fromString(limit)));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   892
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   893
            observable = computeTransitiveClosure(limitMods, null);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   894
            observable.addAll(rootModules);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   895
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   896
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   897
        Predicate<ModuleSymbol> observablePred = sym -> observable == null || observable.contains(sym);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   898
        Predicate<ModuleSymbol> systemModulePred = sym -> (sym.flags() & Flags.SYSTEM_MODULE) != 0;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   899
        Set<ModuleSymbol> enabledRoot = new LinkedHashSet<>();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   900
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   901
        if (rootModules.contains(syms.unnamedModule)) {
37848
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36526
diff changeset
   902
            ModuleSymbol javaSE = syms.getModule(java_se);
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36526
diff changeset
   903
            Predicate<ModuleSymbol> jdkModulePred;
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36526
diff changeset
   904
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36526
diff changeset
   905
            if (javaSE != null && (observable == null || observable.contains(javaSE))) {
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36526
diff changeset
   906
                jdkModulePred = sym -> {
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36526
diff changeset
   907
                    sym.complete();
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36526
diff changeset
   908
                    return   !sym.name.startsWith(java_)
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36526
diff changeset
   909
                           && sym.exports.stream().anyMatch(e -> e.modules == null);
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36526
diff changeset
   910
                };
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36526
diff changeset
   911
                enabledRoot.add(javaSE);
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36526
diff changeset
   912
            } else {
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36526
diff changeset
   913
                jdkModulePred = sym -> true;
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36526
diff changeset
   914
            }
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36526
diff changeset
   915
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36526
diff changeset
   916
            for (ModuleSymbol sym : new HashSet<>(syms.getAllModules())) {
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36526
diff changeset
   917
                if (systemModulePred.test(sym) && observablePred.test(sym) && jdkModulePred.test(sym)) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   918
                    enabledRoot.add(sym);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   919
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   920
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   921
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   922
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   923
        enabledRoot.addAll(rootModules);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   924
39917
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   925
        if (addModsOpt != null || !extraAddMods.isEmpty()) {
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   926
            Set<String> fullAddMods = new HashSet<>();
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   927
            fullAddMods.addAll(extraAddMods);
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   928
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   929
            if (addModsOpt != null) {
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   930
                fullAddMods.addAll(Arrays.asList(addModsOpt.split(",")));
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   931
            }
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   932
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   933
            for (String added : fullAddMods) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   934
                Stream<ModuleSymbol> modules;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   935
                switch (added) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   936
                    case ALL_SYSTEM:
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   937
                        modules = syms.getAllModules()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   938
                                      .stream()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   939
                                      .filter(systemModulePred.and(observablePred));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   940
                        break;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   941
                    case ALL_MODULE_PATH:
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   942
                        modules = syms.getAllModules()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   943
                                      .stream()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   944
                                      .filter(systemModulePred.negate().and(observablePred));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   945
                        break;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   946
                    default:
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   947
                        modules = Stream.of(syms.enterModule(names.fromString(added)));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   948
                        break;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   949
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   950
                modules.forEach(sym -> {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   951
                    enabledRoot.add(sym);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   952
                    if (observable != null)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   953
                        observable.add(sym);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   954
                });
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   955
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   956
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   957
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   958
        Set<ModuleSymbol> result = computeTransitiveClosure(enabledRoot, observable);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   959
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   960
        result.add(syms.unnamedModule);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   961
39917
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
   962
        allModules = result;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   963
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   964
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   965
    private Set<ModuleSymbol> computeTransitiveClosure(Iterable<? extends ModuleSymbol> base, Set<ModuleSymbol> observable) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   966
        List<ModuleSymbol> todo = List.nil();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   967
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   968
        for (ModuleSymbol ms : base) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   969
            todo = todo.prepend(ms);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   970
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   971
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   972
        Set<ModuleSymbol> result = new LinkedHashSet<>();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   973
        result.add(syms.java_base);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   974
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   975
        while (todo.nonEmpty()) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   976
            ModuleSymbol current = todo.head;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   977
            todo = todo.tail;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   978
            if (observable != null && !observable.contains(current))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   979
                continue;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   980
            if (!result.add(current) || current == syms.unnamedModule || ((current.flags_field & Flags.AUTOMATIC_MODULE) != 0))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   981
                continue;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   982
            current.complete();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   983
            for (RequiresDirective rd : current.requires) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   984
                todo = todo.prepend(rd.module);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   985
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   986
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   987
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   988
        return result;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   989
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   990
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   991
    public ModuleSymbol getObservableModule(Name name) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   992
        ModuleSymbol mod = syms.getModule(name);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   993
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   994
        if (allModules().contains(mod)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   995
            return mod;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   996
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   997
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   998
        return null;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   999
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1000
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1001
    private Completer getUnnamedModuleCompleter() {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1002
        moduleFinder.findAllModules();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1003
        return new Symbol.Completer() {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1004
            @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1005
            public void complete(Symbol sym) throws CompletionFailure {
41254
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40768
diff changeset
  1006
                if (inInitModules) {
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40768
diff changeset
  1007
                    sym.completer = this;
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40768
diff changeset
  1008
                    return ;
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40768
diff changeset
  1009
                }
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1010
                ModuleSymbol msym = (ModuleSymbol) sym;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1011
                Set<ModuleSymbol> allModules = allModules();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1012
                for (ModuleSymbol m : allModules) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1013
                    m.complete();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1014
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1015
                initVisiblePackages(msym, allModules);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1016
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1017
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1018
            @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1019
            public String toString() {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1020
                return "unnamedModule Completer";
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1021
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1022
        };
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1023
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1024
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1025
    private final Map<ModuleSymbol, Set<ModuleSymbol>> requiresPublicCache = new HashMap<>();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1026
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1027
    private void completeModule(ModuleSymbol msym) {
39917
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
  1028
        if (inInitModules) {
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
  1029
            msym.completer = sym -> completeModule(msym);
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
  1030
            return ;
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
  1031
        }
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
  1032
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
  1033
        if ((msym.flags_field & Flags.AUTOMATIC_MODULE) != 0) {
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
  1034
            completeAutomaticModule(msym);
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
  1035
        }
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
  1036
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1037
        Assert.checkNonNull(msym.requires);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1038
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1039
        initAddReads();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1040
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1041
        msym.requires = msym.requires.appendList(List.from(addReads.getOrDefault(msym, Collections.emptySet())));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1042
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1043
        List<RequiresDirective> requires = msym.requires;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1044
        List<RequiresDirective> previous = null;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1045
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1046
        while (requires.nonEmpty()) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1047
            if (!allModules().contains(requires.head.module)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1048
                Env<AttrContext> env = typeEnvs.get(msym);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1049
                if (env != null) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1050
                    JavaFileObject origSource = log.useSource(env.toplevel.sourcefile);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1051
                    try {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1052
                        log.error(/*XXX*/env.tree, Errors.ModuleNotFound(requires.head.module));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1053
                    } finally {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1054
                        log.useSource(origSource);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1055
                    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1056
                } else {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1057
                    Assert.check((msym.flags() & Flags.AUTOMATIC_MODULE) == 0);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1058
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1059
                if (previous != null) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1060
                    previous.tail = requires.tail;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1061
                } else {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1062
                    msym.requires.tail = requires.tail;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1063
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1064
            } else {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1065
                previous = requires;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1066
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1067
            requires = requires.tail;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1068
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1069
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1070
        Set<ModuleSymbol> readable = new LinkedHashSet<>();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1071
        Set<ModuleSymbol> requiresPublic = new HashSet<>();
39366
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 39361
diff changeset
  1072
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 39361
diff changeset
  1073
        for (RequiresDirective d : msym.requires) {
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 39361
diff changeset
  1074
            d.module.complete();
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 39361
diff changeset
  1075
            readable.add(d.module);
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 39361
diff changeset
  1076
            Set<ModuleSymbol> s = retrieveRequiresPublic(d.module);
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 39361
diff changeset
  1077
            Assert.checkNonNull(s, () -> "no entry in cache for " + d.module);
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 39361
diff changeset
  1078
            readable.addAll(s);
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 39361
diff changeset
  1079
            if (d.flags.contains(RequiresFlag.PUBLIC)) {
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 39361
diff changeset
  1080
                requiresPublic.add(d.module);
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 39361
diff changeset
  1081
                requiresPublic.addAll(s);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1082
            }
39366
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 39361
diff changeset
  1083
        }
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1084
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1085
        requiresPublicCache.put(msym, requiresPublic);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1086
        initVisiblePackages(msym, readable);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1087
        for (ExportsDirective d: msym.exports) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1088
            d.packge.modle = msym;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1089
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1090
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1091
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1092
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1093
    private Set<ModuleSymbol> retrieveRequiresPublic(ModuleSymbol msym) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1094
        Set<ModuleSymbol> requiresPublic = requiresPublicCache.get(msym);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1095
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1096
        if (requiresPublic == null) {
40762
f8883aa0053c 8160851: Remove old launcher module-related options
mchung
parents: 40604
diff changeset
  1097
            //the module graph may contain cycles involving automatic modules or --add-reads edges
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1098
            requiresPublic = new HashSet<>();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1099
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1100
            Set<ModuleSymbol> seen = new HashSet<>();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1101
            List<ModuleSymbol> todo = List.of(msym);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1102
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1103
            while (todo.nonEmpty()) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1104
                ModuleSymbol current = todo.head;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1105
                todo = todo.tail;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1106
                if (!seen.add(current))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1107
                    continue;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1108
                requiresPublic.add(current);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1109
                current.complete();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1110
                Iterable<? extends RequiresDirective> requires;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1111
                if (current != syms.unnamedModule) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1112
                    Assert.checkNonNull(current.requires, () -> current + ".requires == null; " + msym);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1113
                    requires = current.requires;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1114
                    for (RequiresDirective rd : requires) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1115
                        if (rd.isPublic())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1116
                            todo = todo.prepend(rd.module);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1117
                    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1118
                } else {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1119
                    for (ModuleSymbol mod : allModules()) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1120
                        todo = todo.prepend(mod);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1121
                    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1122
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1123
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1124
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1125
            requiresPublic.remove(msym);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1126
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1127
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1128
        return requiresPublic;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1129
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1130
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1131
    private void initVisiblePackages(ModuleSymbol msym, Collection<ModuleSymbol> readable) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1132
        initAddExports();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1133
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1134
        msym.visiblePackages = new LinkedHashMap<>();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1135
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1136
        Map<Name, ModuleSymbol> seen = new HashMap<>();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1137
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1138
        for (ModuleSymbol rm : readable) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1139
            if (rm == syms.unnamedModule)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1140
                continue;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1141
            addVisiblePackages(msym, seen, rm, rm.exports);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1142
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1143
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1144
        for (Entry<ModuleSymbol, Set<ExportsDirective>> addExportsEntry : addExports.entrySet())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1145
            addVisiblePackages(msym, seen, addExportsEntry.getKey(), addExportsEntry.getValue());
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1146
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1147
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1148
    private void addVisiblePackages(ModuleSymbol msym,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1149
                                    Map<Name, ModuleSymbol> seenPackages,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1150
                                    ModuleSymbol exportsFrom,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1151
                                    Collection<ExportsDirective> exports) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1152
        for (ExportsDirective d : exports) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1153
            if (d.modules == null || d.modules.contains(msym)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1154
                Name packageName = d.packge.fullname;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1155
                ModuleSymbol previousModule = seenPackages.get(packageName);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1156
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1157
                if (previousModule != null && previousModule != exportsFrom) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1158
                    Env<AttrContext> env = typeEnvs.get(msym);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1159
                    JavaFileObject origSource = env != null ? log.useSource(env.toplevel.sourcefile)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1160
                                                            : null;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1161
                    DiagnosticPosition pos = env != null ? env.tree.pos() : null;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1162
                    try {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1163
                        log.error(pos, Errors.PackageClashFromRequires(msym, packageName,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1164
                                                                      previousModule, exportsFrom));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1165
                    } finally {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1166
                        if (env != null)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1167
                            log.useSource(origSource);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1168
                    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1169
                    continue;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1170
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1171
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1172
                seenPackages.put(packageName, exportsFrom);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1173
                msym.visiblePackages.put(d.packge.fullname, d.packge);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1174
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1175
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1176
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1177
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1178
    private void initAddExports() {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1179
        if (addExports != null)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1180
            return;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1181
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1182
        addExports = new LinkedHashMap<>();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1183
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1184
        if (addExportsOpt == null)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1185
            return;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1186
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1187
//        System.err.println("Modules.addExports:\n   " + addExportsOpt.replace("\0", "\n   "));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1188
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1189
        Pattern ep = Pattern.compile("([^/]+)/([^=]+)=(.*)");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1190
        for (String s: addExportsOpt.split("\0+")) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1191
            if (s.isEmpty())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1192
                continue;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1193
            Matcher em = ep.matcher(s);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1194
            if (!em.matches()) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1195
                continue;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1196
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1197
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1198
            // Terminology comes from
40762
f8883aa0053c 8160851: Remove old launcher module-related options
mchung
parents: 40604
diff changeset
  1199
            //  --add-exports module/package=target,...
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1200
            // Compare to
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1201
            //  module module { exports package to target, ... }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1202
            String moduleName = em.group(1);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1203
            String packageName = em.group(2);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1204
            String targetNames = em.group(3);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1205
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1206
            ModuleSymbol msym = syms.enterModule(names.fromString(moduleName));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1207
            PackageSymbol p = syms.enterPackage(msym, names.fromString(packageName));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1208
            p.modle = msym;  // TODO: do we need this?
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1209
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1210
            List<ModuleSymbol> targetModules = List.nil();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1211
            for (String toModule : targetNames.split("[ ,]+")) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1212
                ModuleSymbol m;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1213
                if (toModule.equals("ALL-UNNAMED")) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1214
                    m = syms.unnamedModule;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1215
                } else {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1216
                    if (!SourceVersion.isName(toModule)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1217
                        // TODO: error: invalid module name
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1218
                        continue;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1219
                    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1220
                    m = syms.enterModule(names.fromString(toModule));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1221
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1222
                targetModules = targetModules.prepend(m);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1223
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1224
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1225
            Set<ExportsDirective> extra = addExports.computeIfAbsent(msym, _x -> new LinkedHashSet<>());
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1226
            ExportsDirective d = new ExportsDirective(p, targetModules);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1227
            extra.add(d);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1228
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1229
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1230
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1231
    private void initAddReads() {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1232
        if (addReads != null)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1233
            return;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1234
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1235
        addReads = new LinkedHashMap<>();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1236
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1237
        if (addReadsOpt == null)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1238
            return;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1239
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1240
//        System.err.println("Modules.addReads:\n   " + addReadsOpt.replace("\0", "\n   "));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1241
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1242
        Pattern rp = Pattern.compile("([^=]+)=(.*)");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1243
        for (String s : addReadsOpt.split("\0+")) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1244
            if (s.isEmpty())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1245
                continue;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1246
            Matcher rm = rp.matcher(s);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1247
            if (!rm.matches()) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1248
                continue;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1249
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1250
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1251
            // Terminology comes from
40762
f8883aa0053c 8160851: Remove old launcher module-related options
mchung
parents: 40604
diff changeset
  1252
            //  --add-reads target-module=source-module,...
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1253
            // Compare to
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1254
            //  module target-module { requires source-module; ... }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1255
            String targetName = rm.group(1);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1256
            String sources = rm.group(2);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1257
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1258
            ModuleSymbol msym = syms.enterModule(names.fromString(targetName));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1259
            for (String source : sources.split("[ ,]+")) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1260
                ModuleSymbol sourceModule;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1261
                if (source.equals("ALL-UNNAMED")) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1262
                    sourceModule = syms.unnamedModule;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1263
                } else {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1264
                    if (!SourceVersion.isName(source)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1265
                        // TODO: error: invalid module name
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1266
                        continue;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1267
                    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1268
                    sourceModule = syms.enterModule(names.fromString(source));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1269
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1270
                addReads.computeIfAbsent(msym, m -> new HashSet<>())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1271
                        .add(new RequiresDirective(sourceModule, EnumSet.of(RequiresFlag.EXTRA)));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1272
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1273
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1274
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1275
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1276
    private void checkCyclicDependencies(JCModuleDecl mod) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1277
        for (JCDirective d : mod.directives) {
39915
5d1e0740e709 8158224: NullPointerException in com.sun.tools.javac.comp.Modules.checkCyclicDependencies when module missing
sadayapalam
parents: 39366
diff changeset
  1278
            JCRequires rd;
5d1e0740e709 8158224: NullPointerException in com.sun.tools.javac.comp.Modules.checkCyclicDependencies when module missing
sadayapalam
parents: 39366
diff changeset
  1279
            if (!d.hasTag(Tag.REQUIRES) || (rd = (JCRequires) d).directive == null)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1280
                continue;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1281
            Set<ModuleSymbol> nonSyntheticDeps = new HashSet<>();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1282
            List<ModuleSymbol> queue = List.of(rd.directive.module);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1283
            while (queue.nonEmpty()) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1284
                ModuleSymbol current = queue.head;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1285
                queue = queue.tail;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1286
                if (!nonSyntheticDeps.add(current))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1287
                    continue;
39917
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
  1288
                current.complete();
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1289
                if ((current.flags() & Flags.ACYCLIC) != 0)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1290
                    continue;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1291
                Assert.checkNonNull(current.requires, () -> current.toString());
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1292
                for (RequiresDirective dep : current.requires) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1293
                    if (!dep.flags.contains(RequiresFlag.EXTRA))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1294
                        queue = queue.prepend(dep.module);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1295
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1296
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1297
            if (nonSyntheticDeps.contains(mod.sym)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1298
                log.error(rd.moduleName.pos(), Errors.CyclicRequires(rd.directive.module));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1299
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1300
            mod.sym.flags_field |= Flags.ACYCLIC;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1301
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1302
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1303
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1304
    // DEBUG
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1305
    private String toString(ModuleSymbol msym) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1306
        return msym.name + "["
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1307
                + "kind:" + msym.kind + ";"
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1308
                + "locn:" + toString(msym.sourceLocation) + "," + toString(msym.classLocation) + ";"
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1309
                + "info:" + toString(msym.module_info.sourcefile) + ","
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1310
                            + toString(msym.module_info.classfile) + ","
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1311
                            + msym.module_info.completer
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1312
                + "]";
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1313
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1314
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1315
    // DEBUG
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1316
    String toString(Location locn) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1317
        return (locn == null) ? "--" : locn.getName();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1318
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1319
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1320
    // DEBUG
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1321
    String toString(JavaFileObject fo) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1322
        return (fo == null) ? "--" : fo.getName();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1323
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1324
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1325
    public void newRound() {
39917
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
  1326
        rootModules = null;
c51a8950f278 8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents: 39915
diff changeset
  1327
        allModules = null;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1328
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1329
}