langtools/src/share/classes/com/sun/tools/javac/code/Symbol.java

Print this page




1195         /** The implementation of this (abstract) symbol in class origin;
1196          *  null if none exists. Synthetic methods are not considered
1197          *  as possible implementations.
1198          */
1199         public MethodSymbol implementation(TypeSymbol origin, Types types, boolean checkResult) {
1200             MethodSymbol res = types.implementation(this, origin, types, checkResult);
1201             if (res != null)
1202                 return res;
1203             // if origin is derived from a raw type, we might have missed
1204             // an implementation because we do not know enough about instantiations.
1205             // in this case continue with the supertype as origin.
1206             if (types.isDerivedRaw(origin.type))
1207                 return implementation(types.supertype(origin.type).tsym, types, checkResult);
1208             else
1209                 return null;
1210         }
1211 
1212         public List<VarSymbol> params() {
1213             owner.complete();
1214             if (params == null) {
1215                 List<Name> names = savedParameterNames;
1216                 savedParameterNames = null;
1217                 if (names == null) {
1218                     names = List.nil();
1219                     int i = 0;
1220                     for (Type t : type.getParameterTypes())
1221                         names = names.prepend(name.table.fromString("arg" + i++));
1222                     names = names.reverse();
1223                 }
1224                 ListBuffer<VarSymbol> buf = new ListBuffer<VarSymbol>();




1225                 for (Type t : type.getParameterTypes()) {
1226                     buf.append(new VarSymbol(PARAMETER, names.head, t, this));
1227                     names = names.tail;












1228                 }
1229                 params = buf.toList();
1230             }
1231             return params;
1232         }
1233 










1234         public Symbol asMemberOf(Type site, Types types) {
1235             return new MethodSymbol(flags_field, name, types.memberType(site, this), owner);
1236         }
1237 
1238         public ElementKind getKind() {
1239             if (name == name.table.names.init)
1240                 return ElementKind.CONSTRUCTOR;
1241             else if (name == name.table.names.clinit)
1242                 return ElementKind.STATIC_INIT;
1243             else
1244                 return ElementKind.METHOD;
1245         }
1246 
1247         public Attribute getDefaultValue() {
1248             return defaultValue;
1249         }
1250 
1251         public List<VarSymbol> getParameters() {
1252             return params();
1253         }




1195         /** The implementation of this (abstract) symbol in class origin;
1196          *  null if none exists. Synthetic methods are not considered
1197          *  as possible implementations.
1198          */
1199         public MethodSymbol implementation(TypeSymbol origin, Types types, boolean checkResult) {
1200             MethodSymbol res = types.implementation(this, origin, types, checkResult);
1201             if (res != null)
1202                 return res;
1203             // if origin is derived from a raw type, we might have missed
1204             // an implementation because we do not know enough about instantiations.
1205             // in this case continue with the supertype as origin.
1206             if (types.isDerivedRaw(origin.type))
1207                 return implementation(types.supertype(origin.type).tsym, types, checkResult);
1208             else
1209                 return null;
1210         }
1211 
1212         public List<VarSymbol> params() {
1213             owner.complete();
1214             if (params == null) {
1215                 List<Name> paramNames = savedParameterNames;
1216                 savedParameterNames = null;
1217                 if (paramNames == null || paramNames.size() != type.getParameterTypes().size())
1218                     paramNames = List.nil();





1219                 ListBuffer<VarSymbol> buf = new ListBuffer<VarSymbol>();
1220                 List<Name> remaining = paramNames;
1221                 // assert: remaining and paramNames are both empty or both
1222                 // have same cardinality as type.getParameterTypes()
1223                 int i = 0;
1224                 for (Type t : type.getParameterTypes()) {
1225                     Name paramName;
1226                     if (remaining.isEmpty()) {
1227                         // no names for any parameters available
1228                         paramName = createArgName(i, paramNames);
1229                     } else {
1230                         paramName = remaining.head;
1231                         remaining = remaining.tail;
1232                         if (paramName.isEmpty()) {
1233                             // no name for this specific parameter
1234                             paramName = createArgName(i, paramNames);
1235                         }
1236                     }
1237                     buf.append(new VarSymbol(PARAMETER, paramName, t, this));
1238                     i++;
1239                 }
1240                 params = buf.toList();
1241             }
1242             return params;
1243         }
1244 
1245         private Name createArgName(int index, List<Name> exclude) {
1246             String prefix = "arg";
1247             while (true) {
1248                 Name argName = name.table.fromString(prefix + index);
1249                 if (!exclude.contains(argName))
1250                     return argName;
1251                 prefix += "$";
1252             }
1253         }
1254 
1255         public Symbol asMemberOf(Type site, Types types) {
1256             return new MethodSymbol(flags_field, name, types.memberType(site, this), owner);
1257         }
1258 
1259         public ElementKind getKind() {
1260             if (name == name.table.names.init)
1261                 return ElementKind.CONSTRUCTOR;
1262             else if (name == name.table.names.clinit)
1263                 return ElementKind.STATIC_INIT;
1264             else
1265                 return ElementKind.METHOD;
1266         }
1267 
1268         public Attribute getDefaultValue() {
1269             return defaultValue;
1270         }
1271 
1272         public List<VarSymbol> getParameters() {
1273             return params();
1274         }