// Return true if our list of args is a superset of those in def. public bool IsMoreSpecificThan(IConstructorDef def) { // Is everything in def also in this? for (int i = 0; i < def.GetArgs().Count; i++) { bool found = false; for (int j = 0; j < this.GetArgs().Count; j++) { if (GetArgs()[j].Equals(def.GetArgs()[i])) { found = true; break; } } // If not, then argument j from def is not in our list. Return false. if (found == false) { return(false); } } // Everything in def's arg list is in ours. Do we have at least one extra // argument? return(GetArgs().Count > def.GetArgs().Count); }
private ConstructorInfo GetConstructor(IConstructorDef constructor) { Type clazz = (Type)this.classHierarchy.ClassForName(constructor.GetClassName()); IConstructorArg[] args = constructor.GetArgs().ToArray(); Type[] parameterTypes = new Type[args.Length]; for (int i = 0; i < args.Length; i++) { if (args[i].IsInjectionFuture()) { parameterTypes[i] = typeof(IInjectionFuture <>).MakeGenericType(new Type[] { this.classHierarchy.ClassForName(args[i].Gettype()) }); } else { parameterTypes[i] = this.classHierarchy.ClassForName(args[i].Gettype()); } } ConstructorInfo cons = clazz.GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, parameterTypes, null); //// TODO //// cons.setAccessible(true); if (cons == null) { Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Throw(new ApplicationException("Failed to look up constructor: " + constructor.ToString()), LOGGER); } return(cons); }
private static Org.Apache.REEF.Tang.Protobuf.ConstructorDef SerializeConstructorDef(IConstructorDef def) { IList <Org.Apache.REEF.Tang.Protobuf.ConstructorArg> args = new List <Org.Apache.REEF.Tang.Protobuf.ConstructorArg>(); foreach (IConstructorArg arg in def.GetArgs()) { args.Add(NewConstructorArg(arg.Gettype(), arg.GetNamedParameterName(), arg.IsInjectionFuture())); } return(newConstructorDef(def.GetClassName(), args)); }
private static ClassHierarchyProto.ConstructorDef SerializeConstructorDef(IConstructorDef def) { IList <ClassHierarchyProto.ConstructorArg> args = new List <ClassHierarchyProto.ConstructorArg>(); foreach (IConstructorArg arg in def.GetArgs()) { args.Add(NewConstructorArg(arg.Gettype(), arg.GetNamedParameterName(), arg.IsInjectionFuture())); } return(newConstructorDef(def.GetClassName(), args)); }
//A(int i, string j) vs. A(string i, int j) is Ambiguous in injection private bool EqualsIgnoreOrder(IConstructorDef def) { if (GetArgs().Count != def.GetArgs().Count) { return(false); } for (int i = 0; i < GetArgs().Count; i++) { bool found = false; for (int j = 0; j < def.GetArgs().Count; j++) { if (GetArgs()[i].GetName().Equals(def.GetArgs()[j].GetName())) { found = true; } } if (!found) { return(false); } } return(true); }
private AvroConstructorDef NewConstructorDef(IConstructorDef def) { IList <AvroConstructorArg> args = new List <AvroConstructorArg>(); foreach (IConstructorArg arg in def.GetArgs()) { args.Add(NewConstructorArg(arg.Gettype(), arg.GetNamedParameterName(), arg.IsInjectionFuture())); } AvroConstructorDef constDef = new AvroConstructorDef(); constDef.fullClassName = def.GetClassName(); constDef.constructorArgs = new List <AvroConstructorArg>(); foreach (AvroConstructorArg arg in args) { constDef.constructorArgs.Add(arg); } return(constDef); }
private ConstructorInfo GetConstructor(IConstructorDef constructor) { Type clazz = (Type)this.classHierarchy.ClassForName(constructor.GetClassName()); IConstructorArg[] args = constructor.GetArgs().ToArray(); Type[] parameterTypes = new Type[args.Length]; for (int i = 0; i < args.Length; i++) { if (args[i].IsInjectionFuture()) { parameterTypes[i] = typeof(InjectionFuture); } else { parameterTypes[i] = this.classHierarchy.ClassForName(args[i].Gettype()); } } ConstructorInfo cons = clazz.GetConstructor(parameterTypes); //cons.setAccessible(true); return(cons); }
private AvroConstructorDef NewConstructorDef(IConstructorDef def) { IList<AvroConstructorArg> args = new List<AvroConstructorArg>(); foreach (IConstructorArg arg in def.GetArgs()) { args.Add(NewConstructorArg(arg.Gettype(), arg.GetNamedParameterName(), arg.IsInjectionFuture())); } AvroConstructorDef constDef = new AvroConstructorDef(); constDef.fullClassName = def.GetClassName(); constDef.constructorArgs = new List<AvroConstructorArg>(); foreach (AvroConstructorArg arg in args) { constDef.constructorArgs.Add(arg); } return constDef; }
private void AddConfiguration(IClassHierarchy ns, ConfigurationBuilderImpl builder) { this.ClassHierarchy = this.ClassHierarchy.Merge(ns); if ((ClassHierarchy is ClassHierarchyImpl || builder.ClassHierarchy is ClassHierarchyImpl)) { if ((ClassHierarchy is ClassHierarchyImpl && builder.ClassHierarchy is ClassHierarchyImpl)) { ((ClassHierarchyImpl)ClassHierarchy).Parameterparser.MergeIn(((ClassHierarchyImpl)builder.ClassHierarchy).Parameterparser); } else { Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Throw(new ArgumentException("Attempt to merge Java and non-Java class hierarchy! Not supported."), LOGGER); } } foreach (IClassNode cn in builder.BoundImpls.Keys) { IClassNode n = null; builder.BoundImpls.TryGetValue(cn, out n); if (n != null) { Bind(cn.GetFullName(), n.GetFullName()); } } foreach (IClassNode cn in builder.BoundConstructors.Keys) { IClassNode n = null; builder.BoundConstructors.TryGetValue(cn, out n); if (n != null) { Bind(cn.GetFullName(), n.GetFullName()); } } // The namedParameters set contains the strings that can be used to // instantiate new // named parameter instances. Create new ones where we can. foreach (INamedParameterNode np in builder.NamedParameters.Keys) { string v = null; builder.NamedParameters.TryGetValue(np, out v); Bind(np.GetFullName(), v); } foreach (IClassNode cn in builder.LegacyConstructors.Keys) { IConstructorDef cd = null; builder.LegacyConstructors.TryGetValue(cn, out cd); RegisterLegacyConstructor(cn, cd.GetArgs()); } foreach (KeyValuePair <INamedParameterNode, object> e in builder.BoundSetEntries) { String name = ((INamedParameterNode)e.Key).GetFullName(); if (e.Value is INode) { BindSetEntry(name, (INode)e.Value); } else if (e.Value is string) { BindSetEntry(name, (string)e.Value); } else { var ex = new IllegalStateException(string.Format(CultureInfo.CurrentCulture, "The value {0} set to the named parameter {1} is illegel.", e.Value, name)); Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Throw(ex, LOGGER); } } foreach (var p in builder.BoundLists) { BoundLists.Add(p.Key, p.Value); } }
private static ConstructorDef SerializeConstructorDef(IConstructorDef def) { IList<ConstructorArg> args = new List<ConstructorArg>(); foreach (IConstructorArg arg in def.GetArgs()) { args.Add(NewConstructorArg(arg.Gettype(), arg.GetNamedParameterName(), arg.IsInjectionFuture())); } return newConstructorDef(def.GetClassName(), args); }
// Return true if our list of args is a superset of those in def. public bool IsMoreSpecificThan(IConstructorDef def) { // Is everything in def also in this? for (int i = 0; i < def.GetArgs().Count; i++) { bool found = false; for (int j = 0; j < this.GetArgs().Count; j++) { if (GetArgs()[j].Equals(def.GetArgs()[i])) { found = true; break; } } // If not, then argument j from def is not in our list. Return false. if (found == false) { return false; } } // Everything in def's arg list is in ours. Do we have at least one extra // argument? return GetArgs().Count > def.GetArgs().Count; }
// A(int i, string j) vs. A(string i, int j) is Ambiguous in injection private bool EqualsIgnoreOrder(IConstructorDef def) { if (GetArgs().Count != def.GetArgs().Count) { return false; } for (int i = 0; i < GetArgs().Count; i++) { bool found = false; for (int j = 0; j < def.GetArgs().Count; j++) { if (GetArgs()[i].GetName().Equals(def.GetArgs()[j].GetName())) { found = true; } } if (!found) { return false; } } return true; }
private ConstructorInfo GetConstructor(IConstructorDef constructor) { Type clazz = (Type) this.classHierarchy.ClassForName(constructor.GetClassName()); IConstructorArg[] args = constructor.GetArgs().ToArray(); Type[] parameterTypes= new Type[args.Length]; for (int i = 0; i < args.Length; i++) { if (args[i].IsInjectionFuture()) { parameterTypes[i] = typeof(InjectionFuture); } else { parameterTypes[i] = this.classHierarchy.ClassForName(args[i].Gettype()); } } ConstructorInfo cons = clazz.GetConstructor(parameterTypes); //cons.setAccessible(true); return cons; }