langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Directive.java
author mcimadamore
Mon, 05 Dec 2016 19:00:56 +0000
changeset 42416 1cfad0990b99
parent 42407 f3702cff2933
child 43767 9cff98a149cb
permissions -rw-r--r--
8170410: inference: javac doesn't implement 18.2.5 correctly Summary: javac does not generate constraints of the kind 'throws alpha' as described in the spec Reviewed-by: vromero, dlsmith
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
37946
e420b9f05aaf 8156950: NPE while accessing ExportsDirectives.getTargetModules
ksrini
parents: 36526
diff changeset
     2
 * Copyright (c) 2009, 2016, 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;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    30
import java.util.Set;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    31
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    32
import javax.lang.model.element.ModuleElement;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    33
import javax.lang.model.element.PackageElement;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    34
import javax.lang.model.element.TypeElement;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    35
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    36
import com.sun.tools.javac.code.Symbol.ClassSymbol;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    37
import com.sun.tools.javac.code.Symbol.ModuleSymbol;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    38
import com.sun.tools.javac.code.Symbol.PackageSymbol;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    39
import com.sun.tools.javac.util.DefinedBy;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    40
import com.sun.tools.javac.util.DefinedBy.Api;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    41
import com.sun.tools.javac.util.List;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    42
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
 *  Root class for the directives that may appear in module compilation units.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    46
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    47
 *  <p><b>This is NOT part of any supported API.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    48
 *  If you write code that depends on this, you do so at your own risk.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    49
 *  This code and its internal interfaces are subject to change or
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    50
 *  deletion without notice.</b>
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    51
 */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    52
public abstract class Directive implements ModuleElement.Directive {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    53
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    54
    /** Flags for RequiresDirective. */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    55
    public enum RequiresFlag {
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
    56
        TRANSITIVE(0x0010),
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
    57
        STATIC_PHASE(0x0020),
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    58
        SYNTHETIC(0x1000),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    59
        MANDATED(0x8000),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    60
        EXTRA(0x10000);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    61
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    62
        // overkill? move to ClassWriter?
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    63
        public static int value(Set<RequiresFlag> s) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    64
            int v = 0;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    65
            for (RequiresFlag f: s)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    66
                v |= f.value;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    67
            return v;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    68
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    69
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    70
        RequiresFlag(int value) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    71
            this.value = value;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    72
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    73
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    74
        public final int value;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    75
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    76
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
    77
    /** Flags for ExportsDirective. */
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
    78
    public enum ExportsFlag {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
    79
        SYNTHETIC(0x1000),
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
    80
        MANDATED(0x8000);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
    81
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
    82
        // overkill? move to ClassWriter?
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
    83
        public static int value(Set<ExportsFlag> s) {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
    84
            int v = 0;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
    85
            for (ExportsFlag f: s)
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
    86
                v |= f.value;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
    87
            return v;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
    88
        }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
    89
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
    90
        ExportsFlag(int value) {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
    91
            this.value = value;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
    92
        }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
    93
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
    94
        public final int value;
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
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    97
    /**
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    98
     * 'exports' Package ';'
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
    99
     * 'exports' Package 'to' ModuleList ';'
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   100
     */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   101
    public static class ExportsDirective extends Directive
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   102
            implements ModuleElement.ExportsDirective {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   103
        public final PackageSymbol packge;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   104
        public final List<ModuleSymbol> modules;
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   105
        public final Set<ExportsFlag> flags;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   106
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   107
        public ExportsDirective(PackageSymbol packge, List<ModuleSymbol> modules) {
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   108
            this(packge, modules, EnumSet.noneOf(ExportsFlag.class));
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   109
        }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   110
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   111
        public ExportsDirective(PackageSymbol packge, List<ModuleSymbol> modules, Set<ExportsFlag> flags) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   112
            this.packge = packge;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   113
            this.modules = modules;
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   114
            this.flags = flags;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   115
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   116
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   117
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   118
        public ModuleElement.DirectiveKind getKind() {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   119
            return ModuleElement.DirectiveKind.EXPORTS;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   120
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   121
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   122
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   123
        public PackageSymbol getPackage() {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   124
            return packge;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   125
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   126
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   127
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   128
        public java.util.List<ModuleSymbol> getTargetModules() {
37946
e420b9f05aaf 8156950: NPE while accessing ExportsDirectives.getTargetModules
ksrini
parents: 36526
diff changeset
   129
            return modules == null
e420b9f05aaf 8156950: NPE while accessing ExportsDirectives.getTargetModules
ksrini
parents: 36526
diff changeset
   130
                    ? null
e420b9f05aaf 8156950: NPE while accessing ExportsDirectives.getTargetModules
ksrini
parents: 36526
diff changeset
   131
                    : Collections.unmodifiableList(modules);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   132
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   133
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   134
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   135
        public String toString() {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   136
            if (modules == null)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   137
                return "Exports[" + packge + "]";
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   138
            else
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   139
                return "Exports[" + packge + ":" + modules + "]";
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   140
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   141
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   142
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   143
    /** Flags for OpensDirective. */
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   144
    public enum OpensFlag {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   145
        SYNTHETIC(0x1000),
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   146
        MANDATED(0x8000);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   147
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   148
        // overkill? move to ClassWriter?
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   149
        public static int value(Set<OpensFlag> s) {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   150
            int v = 0;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   151
            for (OpensFlag f: s)
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   152
                v |= f.value;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   153
            return v;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   154
        }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   155
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   156
        OpensFlag(int value) {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   157
            this.value = value;
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
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   160
        public final int value;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   161
    }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   162
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   163
    /**
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   164
     * 'opens' Package ';'
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   165
     * 'opens' Package 'to' ModuleList ';'
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
    public static class OpensDirective extends Directive
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   168
            implements ModuleElement.OpensDirective {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   169
        public final PackageSymbol packge;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   170
        public final List<ModuleSymbol> modules;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   171
        public final Set<OpensFlag> flags;
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
        public OpensDirective(PackageSymbol packge, List<ModuleSymbol> modules) {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   174
            this(packge, modules, EnumSet.noneOf(OpensFlag.class));
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   175
        }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   176
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   177
        public OpensDirective(PackageSymbol packge, List<ModuleSymbol> modules, Set<OpensFlag> flags) {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   178
            this.packge = packge;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   179
            this.modules = modules;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   180
            this.flags = flags;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   181
        }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   182
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   183
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   184
        public ModuleElement.DirectiveKind getKind() {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   185
            return ModuleElement.DirectiveKind.OPENS;
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
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   189
        public PackageSymbol getPackage() {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   190
            return packge;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   191
        }
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
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   194
        public java.util.List<ModuleSymbol> getTargetModules() {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   195
            return modules == null
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   196
                    ? null
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   197
                    : Collections.unmodifiableList(modules);
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
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   200
        @Override
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   201
        public String toString() {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   202
            if (modules == null)
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   203
                return "Opens[" + packge + "]";
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   204
            else
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   205
                return "Opens[" + packge + ":" + modules + "]";
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   206
        }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   207
    }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   208
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   209
    /**
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   210
     * 'provides' ServiceName 'with' QualifiedIdentifer ';'
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   211
     */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   212
    public static class ProvidesDirective extends Directive
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   213
            implements ModuleElement.ProvidesDirective {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   214
        public final ClassSymbol service;
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   215
        public final List<ClassSymbol> impls;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   216
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   217
        public ProvidesDirective(ClassSymbol service, List<ClassSymbol> impls) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   218
            this.service = service;
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   219
            this.impls = impls;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   220
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   221
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   222
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   223
        public ModuleElement.DirectiveKind getKind() {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   224
            return ModuleElement.DirectiveKind.PROVIDES;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   225
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   226
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   227
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   228
        public ClassSymbol getService() {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   229
            return service;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   230
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   231
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   232
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   233
        public List<ClassSymbol> getImplementations() {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   234
            return impls;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   235
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   236
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   237
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   238
        public String toString() {
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   239
            return "Provides[" + service + "," + impls + "]";
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   240
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   241
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   242
        // TODO: delete?
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   243
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   244
        public boolean equals(Object obj) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   245
            if (!(obj instanceof ProvidesDirective)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   246
                return false;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   247
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   248
            ProvidesDirective other = (ProvidesDirective)obj;
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   249
            return service == other.service && impls.equals(other.impls);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   250
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   251
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   252
        // TODO: delete?
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   253
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   254
        public int hashCode() {
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   255
            return service.hashCode() * 31 + impls.hashCode() * 37;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   256
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   257
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   258
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   259
    /**
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   260
     * 'requires' ('static' | 'transitive')* ModuleName ';'
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   261
     */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   262
    public static class RequiresDirective extends Directive
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   263
            implements ModuleElement.RequiresDirective {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   264
        public final ModuleSymbol module;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   265
        public final Set<RequiresFlag> flags;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   266
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   267
        public RequiresDirective(ModuleSymbol module) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   268
            this(module, EnumSet.noneOf(RequiresFlag.class));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   269
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   270
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   271
        public RequiresDirective(ModuleSymbol module, Set<RequiresFlag> flags) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   272
            this.module = module;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   273
            this.flags = flags;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   274
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   275
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   276
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   277
        public ModuleElement.DirectiveKind getKind() {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   278
            return ModuleElement.DirectiveKind.REQUIRES;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   279
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   280
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   281
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   282
        public boolean isStatic() {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   283
            return flags.contains(RequiresFlag.STATIC_PHASE);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   284
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   285
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   286
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   287
        public boolean isTransitive() {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   288
            return flags.contains(RequiresFlag.TRANSITIVE);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   289
        }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   290
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   291
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   292
        public ModuleSymbol getDependency() {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   293
            return module;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   294
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   295
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   296
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   297
        public String toString() {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   298
            return "Requires[" + flags + "," + module + "]";
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   299
        }
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
    /**
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   303
     * 'uses' ServiceName ';'
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   304
     */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   305
    public static class UsesDirective extends Directive
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   306
            implements ModuleElement.UsesDirective {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   307
        public final ClassSymbol service;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   308
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   309
        public UsesDirective(ClassSymbol service) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   310
            this.service = service;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   311
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   312
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   313
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   314
        public ModuleElement.DirectiveKind getKind() {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   315
            return ModuleElement.DirectiveKind.USES;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   316
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   317
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   318
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   319
        public ClassSymbol getService() {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   320
            return service;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   321
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   322
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   323
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   324
        public String toString() {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   325
            return "Uses[" + service + "]";
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   326
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   327
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   328
        // TODO: delete?
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   329
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   330
        public boolean equals(Object obj) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   331
            if (!(obj instanceof UsesDirective)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   332
                return false;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   333
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   334
            UsesDirective other = (UsesDirective)obj;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   335
            return service == other.service;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   336
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   337
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37946
diff changeset
   338
        // TODO: delete?
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   339
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   340
        public int hashCode() {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   341
            return service.hashCode() * 31;
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
}