src/jdk.compiler/share/classes/com/sun/tools/javac/code/Directive.java
author jjg
Wed, 03 Jan 2018 11:10:56 -0800
changeset 48427 b08405cc467a
parent 47216 71c04702a3d5
permissions -rw-r--r--
8193125: javac should not compile a module if it requires java.base with modifiers Reviewed-by: vromero
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
48427
b08405cc467a 8193125: javac should not compile a module if it requires java.base with modifiers
jjg
parents: 47216
diff changeset
     2
 * Copyright (c) 2009, 2018, 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
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    26
package com.sun.tools.javac.code;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    27
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    28
import java.util.Collections;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    29
import java.util.EnumSet;
48427
b08405cc467a 8193125: javac should not compile a module if it requires java.base with modifiers
jjg
parents: 47216
diff changeset
    30
import java.util.Locale;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    31
import java.util.Set;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    32
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    33
import javax.lang.model.element.ModuleElement;
44062
9a579f258574 8175118: Revisit modeling of module directives
jjg
parents: 43767
diff changeset
    34
import javax.lang.model.element.ModuleElement.DirectiveVisitor;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    35
48427
b08405cc467a 8193125: javac should not compile a module if it requires java.base with modifiers
jjg
parents: 47216
diff changeset
    36
import com.sun.tools.javac.api.Messages;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    37
import com.sun.tools.javac.code.Symbol.ClassSymbol;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    38
import com.sun.tools.javac.code.Symbol.ModuleSymbol;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    39
import com.sun.tools.javac.code.Symbol.PackageSymbol;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    40
import com.sun.tools.javac.util.DefinedBy;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    41
import com.sun.tools.javac.util.DefinedBy.Api;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    42
import com.sun.tools.javac.util.List;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    43
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    44
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    45
/**
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    46
 *  Root class for the directives that may appear in module compilation units.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    47
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    48
 *  <p><b>This is NOT part of any supported API.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    49
 *  If you write code that depends on this, you do so at your own risk.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    50
 *  This code and its internal interfaces are subject to change or
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    51
 *  deletion without notice.</b>
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    52
 */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    53
public abstract class Directive implements ModuleElement.Directive {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    54
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    55
    /** Flags for RequiresDirective. */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    56
    public enum RequiresFlag {
43767
9cff98a149cb 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42407
diff changeset
    57
        TRANSITIVE(0x0020),
9cff98a149cb 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42407
diff changeset
    58
        STATIC_PHASE(0x0040),
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    59
        SYNTHETIC(0x1000),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    60
        MANDATED(0x8000),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    61
        EXTRA(0x10000);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    62
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    63
        // overkill? move to ClassWriter?
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    64
        public static int value(Set<RequiresFlag> s) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    65
            int v = 0;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    66
            for (RequiresFlag f: s)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    67
                v |= f.value;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    68
            return v;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    69
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    70
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    71
        RequiresFlag(int value) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    72
            this.value = value;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    73
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    74
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    75
        public final int value;
48427
b08405cc467a 8193125: javac should not compile a module if it requires java.base with modifiers
jjg
parents: 47216
diff changeset
    76
b08405cc467a 8193125: javac should not compile a module if it requires java.base with modifiers
jjg
parents: 47216
diff changeset
    77
        @Override
b08405cc467a 8193125: javac should not compile a module if it requires java.base with modifiers
jjg
parents: 47216
diff changeset
    78
        public String toString() {
b08405cc467a 8193125: javac should not compile a module if it requires java.base with modifiers
jjg
parents: 47216
diff changeset
    79
            return String.format("ACC_%s (0x%04x", name(), value);
b08405cc467a 8193125: javac should not compile a module if it requires java.base with modifiers
jjg
parents: 47216
diff changeset
    80
        }
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    81
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    82
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
    83
    /** Flags for ExportsDirective. */
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
    84
    public enum ExportsFlag {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
    85
        SYNTHETIC(0x1000),
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
    86
        MANDATED(0x8000);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
    87
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
    88
        // overkill? move to ClassWriter?
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
    89
        public static int value(Set<ExportsFlag> s) {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
    90
            int v = 0;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
    91
            for (ExportsFlag f: s)
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
    92
                v |= f.value;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
    93
            return v;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
    94
        }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
    95
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
    96
        ExportsFlag(int value) {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
    97
            this.value = value;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
    98
        }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
    99
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   100
        public final int value;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   101
    }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   102
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   103
    /**
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   104
     * 'exports' Package ';'
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   105
     * 'exports' Package 'to' ModuleList ';'
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   106
     */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   107
    public static class ExportsDirective extends Directive
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   108
            implements ModuleElement.ExportsDirective {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   109
        public final PackageSymbol packge;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   110
        public final List<ModuleSymbol> modules;
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   111
        public final Set<ExportsFlag> flags;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   112
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   113
        public ExportsDirective(PackageSymbol packge, List<ModuleSymbol> modules) {
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   114
            this(packge, modules, EnumSet.noneOf(ExportsFlag.class));
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   115
        }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   116
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   117
        public ExportsDirective(PackageSymbol packge, List<ModuleSymbol> modules, Set<ExportsFlag> flags) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   118
            this.packge = packge;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   119
            this.modules = modules;
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   120
            this.flags = flags;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   121
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   122
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   123
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   124
        public ModuleElement.DirectiveKind getKind() {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   125
            return ModuleElement.DirectiveKind.EXPORTS;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   126
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   127
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   128
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   129
        public PackageSymbol getPackage() {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   130
            return packge;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   131
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   132
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   133
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   134
        public java.util.List<ModuleSymbol> getTargetModules() {
37946
e420b9f05aaf 8156950: NPE while accessing ExportsDirectives.getTargetModules
ksrini
parents: 36526
diff changeset
   135
            return modules == null
e420b9f05aaf 8156950: NPE while accessing ExportsDirectives.getTargetModules
ksrini
parents: 36526
diff changeset
   136
                    ? null
e420b9f05aaf 8156950: NPE while accessing ExportsDirectives.getTargetModules
ksrini
parents: 36526
diff changeset
   137
                    : Collections.unmodifiableList(modules);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   138
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   139
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   140
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   141
        public String toString() {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   142
            if (modules == null)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   143
                return "Exports[" + packge + "]";
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   144
            else
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   145
                return "Exports[" + packge + ":" + modules + "]";
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   146
        }
44062
9a579f258574 8175118: Revisit modeling of module directives
jjg
parents: 43767
diff changeset
   147
9a579f258574 8175118: Revisit modeling of module directives
jjg
parents: 43767
diff changeset
   148
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
9a579f258574 8175118: Revisit modeling of module directives
jjg
parents: 43767
diff changeset
   149
        public <R, P> R accept(DirectiveVisitor<R, P> v, P p) {
9a579f258574 8175118: Revisit modeling of module directives
jjg
parents: 43767
diff changeset
   150
            return v.visitExports(this, p);
9a579f258574 8175118: Revisit modeling of module directives
jjg
parents: 43767
diff changeset
   151
        }
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   152
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   153
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   154
    /** Flags for OpensDirective. */
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   155
    public enum OpensFlag {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   156
        SYNTHETIC(0x1000),
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   157
        MANDATED(0x8000);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   158
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   159
        // overkill? move to ClassWriter?
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   160
        public static int value(Set<OpensFlag> s) {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   161
            int v = 0;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   162
            for (OpensFlag f: s)
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   163
                v |= f.value;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   164
            return v;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   165
        }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   166
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   167
        OpensFlag(int value) {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   168
            this.value = value;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   169
        }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   170
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   171
        public final int value;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   172
    }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   173
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   174
    /**
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   175
     * 'opens' Package ';'
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   176
     * 'opens' Package 'to' ModuleList ';'
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   177
     */
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   178
    public static class OpensDirective extends Directive
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   179
            implements ModuleElement.OpensDirective {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   180
        public final PackageSymbol packge;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   181
        public final List<ModuleSymbol> modules;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   182
        public final Set<OpensFlag> flags;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   183
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   184
        public OpensDirective(PackageSymbol packge, List<ModuleSymbol> modules) {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   185
            this(packge, modules, EnumSet.noneOf(OpensFlag.class));
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   186
        }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   187
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   188
        public OpensDirective(PackageSymbol packge, List<ModuleSymbol> modules, Set<OpensFlag> flags) {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   189
            this.packge = packge;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   190
            this.modules = modules;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   191
            this.flags = flags;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   192
        }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   193
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   194
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   195
        public ModuleElement.DirectiveKind getKind() {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   196
            return ModuleElement.DirectiveKind.OPENS;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   197
        }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   198
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   199
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   200
        public PackageSymbol getPackage() {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   201
            return packge;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   202
        }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   203
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   204
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   205
        public java.util.List<ModuleSymbol> getTargetModules() {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   206
            return modules == null
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   207
                    ? null
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   208
                    : Collections.unmodifiableList(modules);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   209
        }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   210
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   211
        @Override
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   212
        public String toString() {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   213
            if (modules == null)
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   214
                return "Opens[" + packge + "]";
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   215
            else
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   216
                return "Opens[" + packge + ":" + modules + "]";
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   217
        }
44062
9a579f258574 8175118: Revisit modeling of module directives
jjg
parents: 43767
diff changeset
   218
9a579f258574 8175118: Revisit modeling of module directives
jjg
parents: 43767
diff changeset
   219
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
9a579f258574 8175118: Revisit modeling of module directives
jjg
parents: 43767
diff changeset
   220
        public <R, P> R accept(DirectiveVisitor<R, P> v, P p) {
9a579f258574 8175118: Revisit modeling of module directives
jjg
parents: 43767
diff changeset
   221
            return v.visitOpens(this, p);
9a579f258574 8175118: Revisit modeling of module directives
jjg
parents: 43767
diff changeset
   222
        }
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   223
    }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   224
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   225
    /**
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   226
     * 'provides' ServiceName 'with' QualifiedIdentifer ';'
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   227
     */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   228
    public static class ProvidesDirective extends Directive
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   229
            implements ModuleElement.ProvidesDirective {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   230
        public final ClassSymbol service;
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   231
        public final List<ClassSymbol> impls;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   232
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   233
        public ProvidesDirective(ClassSymbol service, List<ClassSymbol> impls) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   234
            this.service = service;
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   235
            this.impls = impls;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   236
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   237
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   238
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   239
        public ModuleElement.DirectiveKind getKind() {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   240
            return ModuleElement.DirectiveKind.PROVIDES;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   241
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   242
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   243
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   244
        public ClassSymbol getService() {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   245
            return service;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   246
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   247
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   248
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   249
        public List<ClassSymbol> getImplementations() {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   250
            return impls;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   251
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   252
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   253
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   254
        public String toString() {
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   255
            return "Provides[" + service + "," + impls + "]";
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   256
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   257
44062
9a579f258574 8175118: Revisit modeling of module directives
jjg
parents: 43767
diff changeset
   258
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
9a579f258574 8175118: Revisit modeling of module directives
jjg
parents: 43767
diff changeset
   259
        public <R, P> R accept(DirectiveVisitor<R, P> v, P p) {
9a579f258574 8175118: Revisit modeling of module directives
jjg
parents: 43767
diff changeset
   260
            return v.visitProvides(this, p);
9a579f258574 8175118: Revisit modeling of module directives
jjg
parents: 43767
diff changeset
   261
        }
9a579f258574 8175118: Revisit modeling of module directives
jjg
parents: 43767
diff changeset
   262
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   263
        // TODO: delete?
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   264
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   265
        public boolean equals(Object obj) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   266
            if (!(obj instanceof ProvidesDirective)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   267
                return false;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   268
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   269
            ProvidesDirective other = (ProvidesDirective)obj;
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   270
            return service == other.service && impls.equals(other.impls);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   271
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   272
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   273
        // TODO: delete?
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   274
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   275
        public int hashCode() {
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   276
            return service.hashCode() * 31 + impls.hashCode() * 37;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   277
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   278
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   279
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   280
    /**
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   281
     * 'requires' ('static' | 'transitive')* ModuleName ';'
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   282
     */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   283
    public static class RequiresDirective extends Directive
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   284
            implements ModuleElement.RequiresDirective {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   285
        public final ModuleSymbol module;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   286
        public final Set<RequiresFlag> flags;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   287
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   288
        public RequiresDirective(ModuleSymbol module) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   289
            this(module, EnumSet.noneOf(RequiresFlag.class));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   290
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   291
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   292
        public RequiresDirective(ModuleSymbol module, Set<RequiresFlag> flags) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   293
            this.module = module;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   294
            this.flags = flags;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   295
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   296
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   297
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   298
        public ModuleElement.DirectiveKind getKind() {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   299
            return ModuleElement.DirectiveKind.REQUIRES;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   300
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   301
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   302
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   303
        public boolean isStatic() {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   304
            return flags.contains(RequiresFlag.STATIC_PHASE);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   305
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   306
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   307
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   308
        public boolean isTransitive() {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   309
            return flags.contains(RequiresFlag.TRANSITIVE);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   310
        }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   311
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   312
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   313
        public ModuleSymbol getDependency() {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   314
            return module;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   315
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   316
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   317
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   318
        public String toString() {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   319
            return "Requires[" + flags + "," + module + "]";
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   320
        }
44062
9a579f258574 8175118: Revisit modeling of module directives
jjg
parents: 43767
diff changeset
   321
9a579f258574 8175118: Revisit modeling of module directives
jjg
parents: 43767
diff changeset
   322
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
9a579f258574 8175118: Revisit modeling of module directives
jjg
parents: 43767
diff changeset
   323
        public <R, P> R accept(DirectiveVisitor<R, P> v, P p) {
9a579f258574 8175118: Revisit modeling of module directives
jjg
parents: 43767
diff changeset
   324
            return v.visitRequires(this, p);
9a579f258574 8175118: Revisit modeling of module directives
jjg
parents: 43767
diff changeset
   325
        }
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   326
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   327
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   328
    /**
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   329
     * 'uses' ServiceName ';'
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   330
     */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   331
    public static class UsesDirective extends Directive
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   332
            implements ModuleElement.UsesDirective {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   333
        public final ClassSymbol service;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   334
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   335
        public UsesDirective(ClassSymbol service) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   336
            this.service = service;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   337
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   338
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   339
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   340
        public ModuleElement.DirectiveKind getKind() {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   341
            return ModuleElement.DirectiveKind.USES;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   342
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   343
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   344
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   345
        public ClassSymbol getService() {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   346
            return service;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   347
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   348
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   349
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   350
        public String toString() {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   351
            return "Uses[" + service + "]";
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   352
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   353
44062
9a579f258574 8175118: Revisit modeling of module directives
jjg
parents: 43767
diff changeset
   354
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
9a579f258574 8175118: Revisit modeling of module directives
jjg
parents: 43767
diff changeset
   355
        public <R, P> R accept(DirectiveVisitor<R, P> v, P p) {
9a579f258574 8175118: Revisit modeling of module directives
jjg
parents: 43767
diff changeset
   356
            return v.visitUses(this, p);
9a579f258574 8175118: Revisit modeling of module directives
jjg
parents: 43767
diff changeset
   357
        }
9a579f258574 8175118: Revisit modeling of module directives
jjg
parents: 43767
diff changeset
   358
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   359
        // TODO: delete?
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   360
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   361
        public boolean equals(Object obj) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   362
            if (!(obj instanceof UsesDirective)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   363
                return false;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   364
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   365
            UsesDirective other = (UsesDirective)obj;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   366
            return service == other.service;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   367
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   368
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   369
        // TODO: delete?
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   370
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   371
        public int hashCode() {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   372
            return service.hashCode() * 31;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   373
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   374
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   375
}