langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Directive.java
author ksrini
Sat, 14 May 2016 08:03:03 -0700
changeset 37946 e420b9f05aaf
parent 36526 3b41f1c69604
child 42407 f3702cff2933
permissions -rw-r--r--
8156950: NPE while accessing ExportsDirectives.getTargetModules Reviewed-by: jjg
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 {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    56
        PUBLIC(0x0020),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    57
        SYNTHETIC(0x1000),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    58
        MANDATED(0x8000),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    59
        EXTRA(0x10000);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    60
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    61
        // overkill? move to ClassWriter?
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    62
        public static int value(Set<RequiresFlag> s) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    63
            int v = 0;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    64
            for (RequiresFlag f: s)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    65
                v |= f.value;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    66
            return v;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    67
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    68
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    69
        RequiresFlag(int value) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    70
            this.value = value;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    71
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    72
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    73
        public final int value;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    74
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    75
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    76
    /**
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    77
     * 'exports' Package ';'
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    78
     */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    79
    public static class ExportsDirective extends Directive
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    80
            implements ModuleElement.ExportsDirective {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    81
        public final PackageSymbol packge;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    82
        public final List<ModuleSymbol> modules;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    83
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    84
        public ExportsDirective(PackageSymbol packge, List<ModuleSymbol> modules) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    85
            this.packge = packge;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    86
            this.modules = modules;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    87
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    88
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    89
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    90
        public ModuleElement.DirectiveKind getKind() {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    91
            return ModuleElement.DirectiveKind.EXPORTS;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    92
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    93
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    94
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    95
        public PackageElement getPackage() {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    96
            return packge;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    97
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    98
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    99
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   100
        public java.util.List<? extends ModuleElement> getTargetModules() {
37946
e420b9f05aaf 8156950: NPE while accessing ExportsDirectives.getTargetModules
ksrini
parents: 36526
diff changeset
   101
            return modules == null
e420b9f05aaf 8156950: NPE while accessing ExportsDirectives.getTargetModules
ksrini
parents: 36526
diff changeset
   102
                    ? null
e420b9f05aaf 8156950: NPE while accessing ExportsDirectives.getTargetModules
ksrini
parents: 36526
diff changeset
   103
                    : Collections.unmodifiableList(modules);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   104
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   105
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   106
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   107
        public String toString() {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   108
            if (modules == null)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   109
                return "Exports[" + packge + "]";
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   110
            else
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   111
                return "Exports[" + packge + ":" + modules + "]";
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   112
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   113
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   114
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   115
    /**
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   116
     * 'provides' ServiceName 'with' QualifiedIdentifer ';'
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   117
     */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   118
    public static class ProvidesDirective extends Directive
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   119
            implements ModuleElement.ProvidesDirective {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   120
        public final ClassSymbol service;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   121
        public final ClassSymbol impl;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   122
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   123
        public ProvidesDirective(ClassSymbol service, ClassSymbol impl) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   124
            this.service = service;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   125
            this.impl = impl;
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)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   129
        public ModuleElement.DirectiveKind getKind() {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   130
            return ModuleElement.DirectiveKind.PROVIDES;
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)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   134
        public TypeElement getService() {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   135
            return service;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   136
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   137
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   138
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   139
        public TypeElement getImplementation() {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   140
            return impl;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   141
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   142
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   143
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   144
        public String toString() {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   145
            return "Provides[" + service + "," + impl + "]";
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   146
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   147
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   148
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   149
        public boolean equals(Object obj) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   150
            if (!(obj instanceof ProvidesDirective)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   151
                return false;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   152
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   153
            ProvidesDirective other = (ProvidesDirective)obj;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   154
            return service == other.service && impl == other.impl;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   155
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   156
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   157
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   158
        public int hashCode() {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   159
            return service.hashCode() * 31 + impl.hashCode() * 37;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   160
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   161
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   162
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   163
    /**
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   164
     * 'requires' ['public'] ModuleName ';'
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   165
     */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   166
    public static class RequiresDirective extends Directive
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   167
            implements ModuleElement.RequiresDirective {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   168
        public final ModuleSymbol module;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   169
        public final Set<RequiresFlag> flags;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   170
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   171
        public RequiresDirective(ModuleSymbol module) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   172
            this(module, EnumSet.noneOf(RequiresFlag.class));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   173
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   174
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   175
        public RequiresDirective(ModuleSymbol module, Set<RequiresFlag> flags) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   176
            this.module = module;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   177
            this.flags = flags;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   178
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   179
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   180
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   181
        public ModuleElement.DirectiveKind getKind() {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   182
            return ModuleElement.DirectiveKind.REQUIRES;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   183
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   184
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   185
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   186
        public boolean isPublic() {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   187
            return flags.contains(RequiresFlag.PUBLIC);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   188
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   189
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   190
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   191
        public ModuleElement getDependency() {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   192
            return module;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   193
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   194
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   195
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   196
        public String toString() {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   197
            return "Requires[" + flags + "," + module + "]";
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   198
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   199
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   200
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   201
    /**
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   202
     * 'uses' ServiceName ';'
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   203
     */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   204
    public static class UsesDirective extends Directive
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   205
            implements ModuleElement.UsesDirective {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   206
        public final ClassSymbol service;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   207
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   208
        public UsesDirective(ClassSymbol service) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   209
            this.service = service;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   210
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   211
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   212
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   213
        public ModuleElement.DirectiveKind getKind() {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   214
            return ModuleElement.DirectiveKind.USES;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   215
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   216
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   217
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   218
        public TypeElement getService() {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   219
            return service;
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
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   223
        public String toString() {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   224
            return "Uses[" + service + "]";
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
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   228
        public boolean equals(Object obj) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   229
            if (!(obj instanceof UsesDirective)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   230
                return false;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   231
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   232
            UsesDirective other = (UsesDirective)obj;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   233
            return service == other.service;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   234
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   235
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   236
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   237
        public int hashCode() {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   238
            return service.hashCode() * 31;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   239
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   240
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   241
}