langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/ModuleFinder.java
author jlahoda
Thu, 15 Jun 2017 13:44:42 +0200
changeset 45504 ea7475564d07
parent 44294 724ad5bc5e1b
permissions -rw-r--r--
8170326: Inconsistencies between code, compiler.properties and comments Summary: Converting uses of Log and JCDiagnostic.Factory methods to use CompilerProperties instead of plain Strings, fixing inconsistencies, adding crules analyzer to ensure CompilerProperties are used whenever possible. Reviewed-by: mcimadamore
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
44289
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
     2
 * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
36526
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
package com.sun.tools.javac.code;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    26
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    27
import java.io.IOException;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    28
import java.util.Arrays;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    29
import java.util.HashMap;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    30
import java.util.Iterator;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    31
import java.util.Map;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    32
import java.util.NoSuchElementException;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    33
import java.util.Set;
41254
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 36526
diff changeset
    34
import java.util.function.Function;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    35
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    36
import javax.tools.JavaFileManager;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    37
import javax.tools.JavaFileManager.Location;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    38
import javax.tools.JavaFileObject;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    39
import javax.tools.JavaFileObject.Kind;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    40
import javax.tools.StandardLocation;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    41
44289
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
    42
import com.sun.tools.javac.code.Symbol.ClassSymbol;
41254
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 36526
diff changeset
    43
import com.sun.tools.javac.code.Symbol.Completer;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    44
import com.sun.tools.javac.code.Symbol.CompletionFailure;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    45
import com.sun.tools.javac.code.Symbol.ModuleSymbol;
41254
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 36526
diff changeset
    46
import com.sun.tools.javac.jvm.ModuleNameReader;
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 36526
diff changeset
    47
import com.sun.tools.javac.jvm.ModuleNameReader.BadClassFile;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    48
import com.sun.tools.javac.resources.CompilerProperties.Errors;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    49
import com.sun.tools.javac.resources.CompilerProperties.Fragments;
41254
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 36526
diff changeset
    50
import com.sun.tools.javac.util.Assert;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    51
import com.sun.tools.javac.util.Context;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    52
import com.sun.tools.javac.util.JCDiagnostic;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    53
import com.sun.tools.javac.util.JCDiagnostic.Fragment;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    54
import com.sun.tools.javac.util.List;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    55
import com.sun.tools.javac.util.ListBuffer;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    56
import com.sun.tools.javac.util.Log;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    57
import com.sun.tools.javac.util.Name;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    58
import com.sun.tools.javac.util.Names;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    59
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    60
import static com.sun.tools.javac.code.Kinds.Kind.*;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    61
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    62
/**
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    63
 *  This class provides operations to locate module definitions
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    64
 *  from the source and class files on the paths provided to javac.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    65
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    66
 *  <p><b>This is NOT part of any supported API.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    67
 *  If you write code that depends on this, you do so at your own risk.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    68
 *  This code and its internal interfaces are subject to change or
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    69
 *  deletion without notice.</b>
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    70
 */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    71
public class ModuleFinder {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    72
    /** The context key for the module finder. */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    73
    protected static final Context.Key<ModuleFinder> moduleFinderKey = new Context.Key<>();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    74
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    75
    /** The log to use for verbose output. */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    76
    private final Log log;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    77
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    78
    /** The symbol table. */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    79
    private final Symtab syms;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    80
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    81
    /** The name table. */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    82
    private final Names names;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    83
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    84
    private final ClassFinder classFinder;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    85
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    86
    /** Access to files
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    87
     */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    88
    private final JavaFileManager fileManager;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    89
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    90
    private final JCDiagnostic.Factory diags;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    91
41254
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 36526
diff changeset
    92
    private ModuleNameReader moduleNameReader;
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 36526
diff changeset
    93
44289
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
    94
    public ModuleNameFromSourceReader moduleNameFromSourceReader;
41254
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 36526
diff changeset
    95
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    96
    /** Get the ModuleFinder instance for this invocation. */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    97
    public static ModuleFinder instance(Context context) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    98
        ModuleFinder instance = context.get(moduleFinderKey);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    99
        if (instance == null)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   100
            instance = new ModuleFinder(context);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   101
        return instance;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   102
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   103
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   104
    /** Construct a new module finder. */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   105
    protected ModuleFinder(Context context) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   106
        context.put(moduleFinderKey, this);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   107
        names = Names.instance(context);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   108
        syms = Symtab.instance(context);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   109
        fileManager = context.get(JavaFileManager.class);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   110
        log = Log.instance(context);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   111
        classFinder = ClassFinder.instance(context);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   112
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   113
        diags = JCDiagnostic.Factory.instance(context);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   114
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   115
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   116
    class ModuleLocationIterator implements Iterator<Set<Location>> {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   117
        StandardLocation outer;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   118
        Set<Location> next = null;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   119
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   120
        Iterator<StandardLocation> outerIter = Arrays.asList(
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   121
                StandardLocation.MODULE_SOURCE_PATH,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   122
                StandardLocation.UPGRADE_MODULE_PATH,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   123
                StandardLocation.SYSTEM_MODULES,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   124
                StandardLocation.MODULE_PATH
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   125
        ).iterator();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   126
        Iterator<Set<Location>> innerIter = null;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   127
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   128
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   129
        public boolean hasNext() {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   130
            while (next == null) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   131
                while (innerIter == null || !innerIter.hasNext()) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   132
                    if (outerIter.hasNext()) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   133
                        outer = outerIter.next();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   134
                        try {
42261
bb52b5514ad5 8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents: 41254
diff changeset
   135
                            innerIter = fileManager.listLocationsForModules(outer).iterator();
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   136
                        } catch (IOException e) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   137
                            System.err.println("error listing module locations for " + outer + ": " + e);  // FIXME
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   138
                        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   139
                    } else
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   140
                        return false;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   141
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   142
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   143
                if (innerIter.hasNext())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   144
                    next = innerIter.next();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   145
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   146
            return true;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   147
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   148
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   149
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   150
        public Set<Location> next() {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   151
            hasNext();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   152
            if (next != null) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   153
                Set<Location> result = next;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   154
                next = null;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   155
                return result;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   156
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   157
            throw new NoSuchElementException();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   158
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   159
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   160
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   161
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   162
    ModuleLocationIterator moduleLocationIterator = new ModuleLocationIterator();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   163
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   164
    public ModuleSymbol findModule(Name name) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   165
        return findModule(syms.enterModule(name));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   166
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   167
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   168
    public ModuleSymbol findModule(ModuleSymbol msym) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   169
        if (msym.kind != ERR && msym.sourceLocation == null && msym.classLocation == null) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   170
            // fill in location
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   171
            List<ModuleSymbol> list = scanModulePath(msym);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   172
            if (list.isEmpty()) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   173
                msym.kind = ERR;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   174
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   175
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   176
        if (msym.kind != ERR && msym.module_info.sourcefile == null && msym.module_info.classfile == null) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   177
            // fill in module-info
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   178
            findModuleInfo(msym);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   179
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   180
        return msym;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   181
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   182
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   183
    public List<ModuleSymbol> findAllModules() {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   184
        List<ModuleSymbol> list = scanModulePath(null);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   185
        for (ModuleSymbol msym: list) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   186
            if (msym.kind != ERR && msym.module_info.sourcefile == null && msym.module_info.classfile == null) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   187
                // fill in module-info
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   188
                findModuleInfo(msym);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   189
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   190
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   191
        return list;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   192
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   193
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   194
    public ModuleSymbol findSingleModule() {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   195
        try {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   196
            JavaFileObject src_fo = getModuleInfoFromLocation(StandardLocation.SOURCE_PATH, Kind.SOURCE);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   197
            JavaFileObject class_fo = getModuleInfoFromLocation(StandardLocation.CLASS_OUTPUT, Kind.CLASS);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   198
            JavaFileObject fo = (src_fo == null) ? class_fo
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   199
                    : (class_fo == null) ? src_fo
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   200
                            : classFinder.preferredFileObject(src_fo, class_fo);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   201
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   202
            ModuleSymbol msym;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   203
            if (fo == null) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   204
                msym = syms.unnamedModule;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   205
            } else {
44289
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   206
                msym = readModule(fo);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   207
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   208
44289
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   209
            if (msym.patchLocation == null) {
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   210
                msym.classLocation = StandardLocation.CLASS_OUTPUT;
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   211
            } else {
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   212
                msym.patchOutputLocation = StandardLocation.CLASS_OUTPUT;
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   213
            }
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   214
            return msym;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   215
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   216
        } catch (IOException e) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   217
            throw new Error(e); // FIXME
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   218
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   219
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   220
44289
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   221
    private ModuleSymbol readModule(JavaFileObject fo) throws IOException {
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   222
        Name name;
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   223
        switch (fo.getKind()) {
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   224
            case SOURCE:
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   225
                name = moduleNameFromSourceReader.readModuleName(fo);
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   226
                if (name == null) {
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   227
                    JCDiagnostic diag =
45504
ea7475564d07 8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents: 44294
diff changeset
   228
                        diags.fragment(Fragments.FileDoesNotContainModule);
44289
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   229
                    ClassSymbol errModuleInfo = syms.defineClass(names.module_info, syms.errModule);
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   230
                    throw new ClassFinder.BadClassFile(errModuleInfo, fo, diag, diags);
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   231
                }
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   232
                break;
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   233
            case CLASS:
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   234
                try {
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   235
                    name = names.fromString(readModuleName(fo));
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   236
                } catch (BadClassFile | IOException ex) {
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   237
                    //fillIn will report proper errors:
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   238
                    name = names.error;
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   239
                }
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   240
                break;
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   241
            default:
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   242
                Assert.error();
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   243
                name = names.error;
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   244
                break;
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   245
        }
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   246
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   247
        ModuleSymbol msym = syms.enterModule(name);
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   248
        msym.module_info.classfile = fo;
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   249
        if (fileManager.hasLocation(StandardLocation.PATCH_MODULE_PATH) && name != names.error) {
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   250
            msym.patchLocation = fileManager.getLocationForModule(StandardLocation.PATCH_MODULE_PATH, name.toString());
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   251
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   252
            if (msym.patchLocation != null) {
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   253
                JavaFileObject patchFO = getModuleInfoFromLocation(StandardLocation.CLASS_OUTPUT, Kind.CLASS);
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   254
                patchFO = preferredFileObject(getModuleInfoFromLocation(msym.patchLocation, Kind.CLASS), patchFO);
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   255
                patchFO = preferredFileObject(getModuleInfoFromLocation(msym.patchLocation, Kind.SOURCE), patchFO);
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   256
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   257
                if (patchFO != null) {
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   258
                    msym.module_info.classfile = patchFO;
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   259
                }
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   260
            }
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   261
        }
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   262
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   263
        msym.completer = Completer.NULL_COMPLETER;
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   264
        classFinder.fillIn(msym.module_info);
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   265
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   266
        return msym;
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   267
    }
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   268
41254
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 36526
diff changeset
   269
    private String readModuleName(JavaFileObject jfo) throws IOException, ModuleNameReader.BadClassFile {
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 36526
diff changeset
   270
        if (moduleNameReader == null)
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 36526
diff changeset
   271
            moduleNameReader = new ModuleNameReader();
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 36526
diff changeset
   272
        return moduleNameReader.readModuleName(jfo);
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 36526
diff changeset
   273
    }
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 36526
diff changeset
   274
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   275
    private JavaFileObject getModuleInfoFromLocation(Location location, Kind kind) throws IOException {
44289
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   276
        if (location == null || !fileManager.hasLocation(location))
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   277
            return null;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   278
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   279
        return fileManager.getJavaFileForInput(location,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   280
                                               names.module_info.toString(),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   281
                                               kind);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   282
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   283
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   284
    private List<ModuleSymbol> scanModulePath(ModuleSymbol toFind) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   285
        ListBuffer<ModuleSymbol> results = new ListBuffer<>();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   286
        Map<Name, Location> namesInSet = new HashMap<>();
43772
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 42261
diff changeset
   287
        boolean multiModuleMode = fileManager.hasLocation(StandardLocation.MODULE_SOURCE_PATH);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   288
        while (moduleLocationIterator.hasNext()) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   289
            Set<Location> locns = (moduleLocationIterator.next());
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   290
            namesInSet.clear();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   291
            for (Location l: locns) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   292
                try {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   293
                    Name n = names.fromString(fileManager.inferModuleName(l));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   294
                    if (namesInSet.put(n, l) == null) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   295
                        ModuleSymbol msym = syms.enterModule(n);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   296
                        if (msym.sourceLocation != null || msym.classLocation != null) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   297
                            // module has already been found, so ignore this instance
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   298
                            continue;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   299
                        }
43772
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 42261
diff changeset
   300
                        if (fileManager.hasLocation(StandardLocation.PATCH_MODULE_PATH) &&
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 42261
diff changeset
   301
                            msym.patchLocation == null) {
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 42261
diff changeset
   302
                            msym.patchLocation =
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 42261
diff changeset
   303
                                    fileManager.getLocationForModule(StandardLocation.PATCH_MODULE_PATH,
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 42261
diff changeset
   304
                                                                     msym.name.toString());
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 42261
diff changeset
   305
                            if (msym.patchLocation != null &&
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 42261
diff changeset
   306
                                multiModuleMode &&
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 42261
diff changeset
   307
                                fileManager.hasLocation(StandardLocation.CLASS_OUTPUT)) {
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 42261
diff changeset
   308
                                msym.patchOutputLocation =
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 42261
diff changeset
   309
                                        fileManager.getLocationForModule(StandardLocation.CLASS_OUTPUT,
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 42261
diff changeset
   310
                                                                         msym.name.toString());
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 42261
diff changeset
   311
                            }
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 42261
diff changeset
   312
                        }
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   313
                        if (moduleLocationIterator.outer == StandardLocation.MODULE_SOURCE_PATH) {
44289
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   314
                            msym.sourceLocation = l;
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   315
                            if (fileManager.hasLocation(StandardLocation.CLASS_OUTPUT)) {
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   316
                                msym.classLocation =
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   317
                                        fileManager.getLocationForModule(StandardLocation.CLASS_OUTPUT,
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   318
                                                                         msym.name.toString());
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   319
                            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   320
                        } else {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   321
                            msym.classLocation = l;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   322
                        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   323
                        if (moduleLocationIterator.outer == StandardLocation.SYSTEM_MODULES ||
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   324
                            moduleLocationIterator.outer == StandardLocation.UPGRADE_MODULE_PATH) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   325
                            msym.flags_field |= Flags.SYSTEM_MODULE;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   326
                        }
43772
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 42261
diff changeset
   327
                        if (toFind == null ||
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 42261
diff changeset
   328
                            (toFind == msym && (msym.sourceLocation != null || msym.classLocation != null))) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   329
                            // Note: cannot return msym directly, because we must finish
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   330
                            // processing this set first
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   331
                            results.add(msym);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   332
                        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   333
                    } else {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   334
                        log.error(Errors.DuplicateModuleOnPath(
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   335
                                getDescription(moduleLocationIterator.outer), n));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   336
                    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   337
                } catch (IOException e) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   338
                    // skip location for now?  log error?
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   339
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   340
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   341
            if (toFind != null && results.nonEmpty())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   342
                return results.toList();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   343
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   344
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   345
        return results.toList();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   346
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   347
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   348
    private void findModuleInfo(ModuleSymbol msym) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   349
        try {
44289
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   350
            JavaFileObject fo;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   351
44289
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   352
            fo = getModuleInfoFromLocation(msym.patchOutputLocation, Kind.CLASS);
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   353
            fo = preferredFileObject(getModuleInfoFromLocation(msym.patchLocation, Kind.CLASS), fo);
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   354
            fo = preferredFileObject(getModuleInfoFromLocation(msym.patchLocation, Kind.SOURCE), fo);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   355
44289
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   356
            if (fo == null) {
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   357
                fo = getModuleInfoFromLocation(msym.classLocation, Kind.CLASS);
44294
724ad5bc5e1b 8176743: tools/javac/modules/MOptionTest.java test fails on Mac
jlahoda
parents: 44289
diff changeset
   358
                fo = preferredFileObject(getModuleInfoFromLocation(msym.sourceLocation, Kind.SOURCE), fo);
44289
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   359
            }
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   360
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   361
            if (fo == null) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   362
                String moduleName = msym.sourceLocation == null && msym.classLocation != null ?
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   363
                    fileManager.inferModuleName(msym.classLocation) : null;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   364
                if (moduleName != null) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   365
                    msym.module_info.classfile = null;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   366
                    msym.flags_field |= Flags.AUTOMATIC_MODULE;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   367
                } else {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   368
                    msym.kind = ERR;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   369
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   370
            } else {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   371
                msym.module_info.classfile = fo;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   372
                msym.module_info.completer = new Symbol.Completer() {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   373
                    @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   374
                    public void complete(Symbol sym) throws CompletionFailure {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   375
                        classFinder.fillIn(msym.module_info);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   376
                    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   377
                    @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   378
                    public String toString() {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   379
                        return "ModuleInfoCompleter";
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   380
                    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   381
                };
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   382
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   383
        } catch (IOException e) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   384
            msym.kind = ERR;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   385
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   386
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   387
44289
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   388
    private JavaFileObject preferredFileObject(JavaFileObject fo1, JavaFileObject fo2) {
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   389
        if (fo1 == null) return fo2;
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   390
        if (fo2 == null) return fo1;
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   391
        return classFinder.preferredFileObject(fo1, fo2);
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   392
    }
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   393
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   394
    Fragment getDescription(StandardLocation l) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   395
        switch (l) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   396
            case MODULE_PATH: return Fragments.LocnModule_path;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   397
            case MODULE_SOURCE_PATH: return Fragments.LocnModule_source_path;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   398
            case SYSTEM_MODULES: return Fragments.LocnSystem_modules;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   399
            case UPGRADE_MODULE_PATH: return Fragments.LocnUpgrade_module_path;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   400
            default:
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   401
                throw new AssertionError();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   402
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   403
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   404
44289
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   405
    public interface ModuleNameFromSourceReader {
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43772
diff changeset
   406
        public Name readModuleName(JavaFileObject file);
41254
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 36526
diff changeset
   407
    }
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 36526
diff changeset
   408
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   409
}