Home | History | Annotate | Download | only in bound
      1 /*
      2  * Copyright 2018 Google Inc. All Rights Reserved.
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *     http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.google.turbine.binder.bound;
     18 
     19 import com.google.common.collect.ImmutableList;
     20 import com.google.turbine.binder.sym.ClassSymbol;
     21 import com.google.turbine.type.AnnoInfo;
     22 import javax.annotation.Nullable;
     23 
     24 /** A bound module declaration (see JLS 7.7). */
     25 public class ModuleInfo {
     26 
     27   private final String name;
     28   @Nullable private final String version;
     29   private final int flags;
     30   private final ImmutableList<AnnoInfo> annos;
     31   private final ImmutableList<RequireInfo> requires;
     32   private final ImmutableList<ExportInfo> exports;
     33   private final ImmutableList<OpenInfo> opens;
     34   private final ImmutableList<UseInfo> uses;
     35   private final ImmutableList<ProvideInfo> provides;
     36 
     37   public ModuleInfo(
     38       String name,
     39       @Nullable String version,
     40       int flags,
     41       ImmutableList<AnnoInfo> annos,
     42       ImmutableList<RequireInfo> requires,
     43       ImmutableList<ExportInfo> exports,
     44       ImmutableList<OpenInfo> opens,
     45       ImmutableList<UseInfo> uses,
     46       ImmutableList<ProvideInfo> provides) {
     47     this.name = name;
     48     this.version = version;
     49     this.flags = flags;
     50     this.annos = annos;
     51     this.requires = requires;
     52     this.exports = exports;
     53     this.opens = opens;
     54     this.uses = uses;
     55     this.provides = provides;
     56   }
     57 
     58   public String name() {
     59     return name;
     60   }
     61 
     62   @Nullable
     63   public String version() {
     64     return version;
     65   }
     66 
     67   public int flags() {
     68     return flags;
     69   }
     70 
     71   public ImmutableList<AnnoInfo> annos() {
     72     return annos;
     73   }
     74 
     75   public ImmutableList<RequireInfo> requires() {
     76     return requires;
     77   }
     78 
     79   public ImmutableList<ExportInfo> exports() {
     80     return exports;
     81   }
     82 
     83   public ImmutableList<OpenInfo> opens() {
     84     return opens;
     85   }
     86 
     87   public ImmutableList<UseInfo> uses() {
     88     return uses;
     89   }
     90 
     91   public ImmutableList<ProvideInfo> provides() {
     92     return provides;
     93   }
     94 
     95   /** A JLS 7.7.1 requires directive. */
     96   public static class RequireInfo {
     97 
     98     private final String moduleName;
     99     private final int flags;
    100     private final String version;
    101 
    102     public RequireInfo(String moduleName, int flags, String version) {
    103       this.moduleName = moduleName;
    104       this.flags = flags;
    105       this.version = version;
    106     }
    107 
    108     public String moduleName() {
    109       return moduleName;
    110     }
    111 
    112     public int flags() {
    113       return flags;
    114     }
    115 
    116     public String version() {
    117       return version;
    118     }
    119   }
    120 
    121   /** A JLS 7.7.2 exports directive. */
    122   public static class ExportInfo {
    123 
    124     private final String packageName;
    125     private final ImmutableList<String> modules;
    126 
    127     public ExportInfo(String packageName, ImmutableList<String> modules) {
    128       this.packageName = packageName;
    129       this.modules = modules;
    130     }
    131 
    132     public String packageName() {
    133       return packageName;
    134     }
    135 
    136     public ImmutableList<String> modules() {
    137       return modules;
    138     }
    139   }
    140 
    141   /** A JLS 7.7.2 opens directive. */
    142   public static class OpenInfo {
    143 
    144     private final String packageName;
    145     private final ImmutableList<String> modules;
    146 
    147     public OpenInfo(String packageName, ImmutableList<String> modules) {
    148       this.packageName = packageName;
    149       this.modules = modules;
    150     }
    151 
    152     public String packageName() {
    153       return packageName;
    154     }
    155 
    156     public ImmutableList<String> modules() {
    157       return modules;
    158     }
    159   }
    160 
    161   /** A JLS 7.7.3 uses directive. */
    162   public static class UseInfo {
    163 
    164     private final ClassSymbol sym;
    165 
    166     public UseInfo(ClassSymbol sym) {
    167       this.sym = sym;
    168     }
    169 
    170     public ClassSymbol sym() {
    171       return sym;
    172     }
    173   }
    174 
    175   /** A JLS 7.7.4 provides directive. */
    176   public static class ProvideInfo {
    177 
    178     private final ClassSymbol sym;
    179     private final ImmutableList<ClassSymbol> impls;
    180 
    181     public ProvideInfo(ClassSymbol sym, ImmutableList<ClassSymbol> impls) {
    182       this.sym = sym;
    183       this.impls = impls;
    184     }
    185 
    186     public ClassSymbol sym() {
    187       return sym;
    188     }
    189 
    190     public ImmutableList<ClassSymbol> impls() {
    191       return impls;
    192     }
    193   }
    194 }
    195