• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2016 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.common.collect.ImmutableMap;
21 import com.google.turbine.binder.sym.FieldSymbol;
22 import com.google.turbine.binder.sym.MethodSymbol;
23 import com.google.turbine.binder.sym.TyVarSymbol;
24 import com.google.turbine.model.Const;
25 import com.google.turbine.model.TurbineFlag;
26 import com.google.turbine.tree.Tree;
27 import com.google.turbine.tree.Tree.MethDecl;
28 import com.google.turbine.type.AnnoInfo;
29 import com.google.turbine.type.Type;
30 import com.google.turbine.type.Type.IntersectionTy;
31 
32 /** A bound node that augments {@link HeaderBoundClass} with type information. */
33 public interface TypeBoundClass extends HeaderBoundClass {
34 
35   /** The super-class type. */
superClassType()36   Type superClassType();
37 
38   /** Implemented interface types. */
interfaceTypes()39   ImmutableList<Type> interfaceTypes();
40 
typeParameterTypes()41   ImmutableMap<TyVarSymbol, TyVarInfo> typeParameterTypes();
42 
43   /** Declared fields. */
fields()44   ImmutableList<FieldInfo> fields();
45 
46   /** Declared methods. */
methods()47   ImmutableList<MethodInfo> methods();
48 
49   /**
50    * Annotation metadata, e.g. from {@link @java.lang.annotation.Target}, {@link
51    * java.lang.annotation.Retention}, and {@link java.lang.annotation.Repeatable}.
52    */
annotationMetadata()53   AnnotationMetadata annotationMetadata();
54 
55   /** Declaration annotations. */
annotations()56   ImmutableList<AnnoInfo> annotations();
57 
58   /** A type parameter declaration. */
59   class TyVarInfo {
60     private final IntersectionTy bound;
61     private final ImmutableList<AnnoInfo> annotations;
62 
TyVarInfo(IntersectionTy bound, ImmutableList<AnnoInfo> annotations)63     public TyVarInfo(IntersectionTy bound, ImmutableList<AnnoInfo> annotations) {
64       this.bound = bound;
65       this.annotations = annotations;
66     }
67 
68     /** The bound. */
bound()69     public IntersectionTy bound() {
70       return bound;
71     }
72 
73     /** Type parameter declaration annotations. */
annotations()74     public ImmutableList<AnnoInfo> annotations() {
75       return annotations;
76     }
77   }
78 
79   /** A field declaration. */
80   class FieldInfo {
81     private final FieldSymbol sym;
82     private final Type type;
83     private final int access;
84     private final ImmutableList<AnnoInfo> annotations;
85 
86     private final Tree.VarDecl decl;
87     private final Const.Value value;
88 
FieldInfo( FieldSymbol sym, Type type, int access, ImmutableList<AnnoInfo> annotations, Tree.VarDecl decl, Const.Value value)89     public FieldInfo(
90         FieldSymbol sym,
91         Type type,
92         int access,
93         ImmutableList<AnnoInfo> annotations,
94         Tree.VarDecl decl,
95         Const.Value value) {
96       this.sym = sym;
97       this.type = type;
98       this.access = access;
99       this.annotations = annotations;
100       this.decl = decl;
101       this.value = value;
102     }
103 
104     /** The field symbol. */
sym()105     public FieldSymbol sym() {
106       return sym;
107     }
108 
109     /** The field name. */
name()110     public String name() {
111       return sym.name();
112     }
113 
114     /** The field type. */
type()115     public Type type() {
116       return type;
117     }
118 
119     /** Access bits. */
access()120     public int access() {
121       return access;
122     }
123 
124     /** The field's declaration. */
decl()125     public Tree.VarDecl decl() {
126       return decl;
127     }
128 
129     /** The constant field value. */
value()130     public Const.Value value() {
131       return value;
132     }
133 
134     /** Declaration annotations. */
annotations()135     public ImmutableList<AnnoInfo> annotations() {
136       return annotations;
137     }
138   }
139 
140   /** A declared method. */
141   class MethodInfo {
142     private final MethodSymbol sym;
143     private final ImmutableMap<TyVarSymbol, TyVarInfo> tyParams;
144     private final Type returnType;
145     private final ImmutableList<ParamInfo> parameters;
146     private final ImmutableList<Type> exceptions;
147     private final int access;
148     private final Const defaultValue;
149     private final MethDecl decl;
150     private final ImmutableList<AnnoInfo> annotations;
151     private final ParamInfo receiver;
152 
MethodInfo( MethodSymbol sym, ImmutableMap<TyVarSymbol, TyVarInfo> tyParams, Type returnType, ImmutableList<ParamInfo> parameters, ImmutableList<Type> exceptions, int access, Const defaultValue, MethDecl decl, ImmutableList<AnnoInfo> annotations, ParamInfo receiver)153     public MethodInfo(
154         MethodSymbol sym,
155         ImmutableMap<TyVarSymbol, TyVarInfo> tyParams,
156         Type returnType,
157         ImmutableList<ParamInfo> parameters,
158         ImmutableList<Type> exceptions,
159         int access,
160         Const defaultValue,
161         MethDecl decl,
162         ImmutableList<AnnoInfo> annotations,
163         ParamInfo receiver) {
164       this.sym = sym;
165       this.tyParams = tyParams;
166       this.returnType = returnType;
167       this.parameters = parameters;
168       this.exceptions = exceptions;
169       this.access = access;
170       this.defaultValue = defaultValue;
171       this.decl = decl;
172       this.annotations = annotations;
173       this.receiver = receiver;
174     }
175 
176     /** The method symbol. */
sym()177     public MethodSymbol sym() {
178       return sym;
179     }
180 
181     /** The method name. */
name()182     public String name() {
183       return sym.name();
184     }
185 
186     /** The type parameters */
tyParams()187     public ImmutableMap<TyVarSymbol, TyVarInfo> tyParams() {
188       return tyParams;
189     }
190 
191     /** Type return type, possibly {#link Type#VOID}. */
returnType()192     public Type returnType() {
193       return returnType;
194     }
195 
196     /** The formal parameters. */
parameters()197     public ImmutableList<ParamInfo> parameters() {
198       return parameters;
199     }
200 
201     /** Thrown exceptions. */
exceptions()202     public ImmutableList<Type> exceptions() {
203       return exceptions;
204     }
205 
206     /** Access bits. */
access()207     public int access() {
208       return access;
209     }
210 
211     /** The default value of an annotation interface method. */
defaultValue()212     public Const defaultValue() {
213       return defaultValue;
214     }
215 
216     /** The declaration. */
decl()217     public MethDecl decl() {
218       return decl;
219     }
220 
221     /** Declaration annotations. */
annotations()222     public ImmutableList<AnnoInfo> annotations() {
223       return annotations;
224     }
225 
226     /** Receiver parameter. */
receiver()227     public ParamInfo receiver() {
228       return receiver;
229     }
230   }
231 
232   /** A formal parameter declaration. */
233   class ParamInfo {
234     private final Type type;
235     private final String name;
236     private final int access;
237     private final ImmutableList<AnnoInfo> annotations;
238 
ParamInfo(Type type, String name, ImmutableList<AnnoInfo> annotations, int access)239     public ParamInfo(Type type, String name, ImmutableList<AnnoInfo> annotations, int access) {
240       this.type = type;
241       this.name = name;
242       this.access = access;
243       this.annotations = annotations;
244     }
245 
246     /** The parameter type. */
type()247     public Type type() {
248       return type;
249     }
250 
251     /**
252      * Returns true if the parameter is synthetic, e.g. the enclosing instance parameter in an inner
253      * class constructor.
254      */
synthetic()255     public boolean synthetic() {
256       return (access & (TurbineFlag.ACC_SYNTHETIC | TurbineFlag.ACC_MANDATED)) != 0;
257     }
258 
259     /** Parameter annotations. */
annotations()260     public ImmutableList<AnnoInfo> annotations() {
261       return annotations;
262     }
263 
264     /** The parameter's name. */
name()265     public String name() {
266       return name;
267     }
268 
269     /** The parameter's modifiers. */
access()270     public int access() {
271       return access;
272     }
273   }
274 }
275