/// <summary> /// Constructs the exception. /// </summary> /// <param name="name">The name related to the exception.</param> /// <param name="types">The metatype(s) related to the exception.</param> /// <param name="message">Description of the exception.</param> /// <param name="inner">The inner exception causing this one (optional).</param> public NameException(SoaObject scope, string name, System.Type[] types, string message, Exception inner) : base(message, inner) { Scope = scope; Name = name; Types = types; }
/// <summary> /// Constructs a new context. /// </summary> /// <remarks> /// The method is accessible only by the scope class. /// </remarks> /// <param name="scope">The object whose scope is represented by the context.</param> internal NameContext(SoaObject scope) { this.Scope = scope; this.Imports = new HashSet<SoaObject>(); this.Imports.Add(this.Scope); }
public static void CheckName(IEnumerable<SoaObject> objects, SoaObject scope, string name, params System.Type[] types) { List<SoaObject> objs = new List<SoaObject>(objects); if (objs.Count > 0) { throw new NameCollisionException(scope, name, types, objects); } }
protected void Error_NameNotFound(SoaObject site, NameNotFoundException exception) { // Build type string StringBuilder sb = new StringBuilder(); sb.Append(AttributeHelpers.GetTypeName(exception.Types[0])); for (int i = 1; i < exception.Types.Length - 1; i++) sb.Append(", " + AttributeHelpers.GetTypeName(exception.Types[i]).ToLower()); if (exception.Types.Length > 1) sb.Append(" or " + AttributeHelpers.GetTypeName(exception.Types[exception.Types.Length - 1]).ToLower()); errorReporter.Error(site.GetMetaInfo<SourceLocationInfo>(), "{0} \"{1}\" is not declared.", sb.ToString(), exception.Name); }
public void AddObject(DynamicObjectNode node, SoaObject @object) { try { objects.Add(node.GetNode(), @object); @object.AddMetaInfo(new NodeInfo(node)); } catch (ArgumentException exception) { throw new SoaLanguageException("The node had been already processed", exception); } }
/// <summary> /// Processes one identifier of a dotted namespace name. /// </summary> /// <remarks> /// The method is called recursively until only the last identifier remains. /// </remarks> /// <param name="identifiers">The list of identifiers.</param> /// <param name="scope">The parent namespace to search next identifier in.</param> /// <returns>The namespace that the list identifies.</returns> private Namespace Process_NamespaceReference(List<string> identifiers, SoaObject scope) { Namespace @namespace = null; try { // Try to find the namespace identified by the first of the remaining name parts @namespace = (Namespace)NameContext.ResolveName(scope, identifiers[0], typeof(Namespace)); } catch (NameNotFoundException) { // If not found, create @namespace = new Namespace(); @namespace.Name = identifiers[0]; @namespace.Namespace = (Namespace)scope; } if (identifiers.Count == 1) { // If this is the last part, simply return it return @namespace; } else { // Otherwise continue searching/creating with the next part of the name identifiers.RemoveAt(0); return this.Process_NamespaceReference(identifiers, @namespace); } }
/// <summary> /// Constructs the exception. /// </summary> /// <param name="name">The name not found with a given metatype.</param> /// <param name="types">The metatype(s) not found with a given name.</param> /// <param name="inner">The inner exception causing this one (optional).</param> public NameNotFoundException(SoaObject scope, string name, System.Type[] types, Exception inner = null) : base(scope, name, types, "Name not found", inner) { }
public static IEnumerable<SoaObject> LookupNameMany(SoaObject scope, string name, params System.Type[] types) { if (scope is Namespace) { return from d in ((Namespace)scope).Declarations where d.Name == name && types.Contains(d.GetType()) select d; } if (scope is Authorization) { return from opa in ((Authorization)scope).OperationAuthorizations where (opa.Operation != null) && (opa.Operation.Name == name) && types.Contains(opa.GetType()) select opa; } if (scope is Contract) { return from opc in ((Contract)scope).OperationContracts where (opc.Operation != null) && (opc.Operation.Name == name) && types.Contains(opc.GetType()) select opc; } if (scope is Operation) { return from p in ((Operation)scope).Parameters where p.Name == name && types.Contains(p.GetType()) select p; } if (scope is OperationAuthorization) { return from r in ((OperationAuthorization)scope).References where r.Name == name && types.Contains(r.GetType()) select r; } if (scope is OperationContract) { return from r in ((OperationContract)scope).References where r.Name == name && types.Contains(r.GetType()) select r; } if (scope is Binding) { return from p in ((Binding)scope).Protocols where p.Name == name && types.Contains(typeof(ProtocolBindingElement)) select p; } if (scope is BindingElement) { return from p in ((BindingElement)scope).Properties where p.Name == name && types.Contains(p.GetType()) select p; } if (scope is ClaimsetType) { return from field in ((ClaimsetType)scope).Fields where field.Name == name && types.Contains(field.GetType()) select field; } if (scope is EnumType) { return from v in ((EnumType)scope).Values where v.Name == name && types.Contains(v.GetType()) select v; } if (scope is StructType) { StructType structType = scope as StructType; List<StructType> structs = new List<StructType>(); structs.Add(structType); structs.AddRange(structType.GetSuperTypes()); List<SoaObject> result = new List<SoaObject>(); foreach (StructType strct in structs) { foreach (StructField field in strct.Fields) { if (types.Contains(field.GetType()) && field.Name == name) { result.Add(field); } } } return result; } if (scope is ExceptionType) { ExceptionType exceptionType = scope as ExceptionType; List<ExceptionType> exceptions = new List<ExceptionType>(); exceptions.Add(exceptionType); exceptions.AddRange(exceptionType.GetSuperTypes()); List<SoaObject> result = new List<SoaObject>(); foreach (ExceptionType exception in exceptions) { foreach (ExceptionField field in exception.Fields) { if (types.Contains(field.GetType()) && field.Name == name) { result.Add(field); } } } return result; } if (scope is Interface) { Interface intf = scope as Interface; List<Interface> interfaces = new List<Interface>(); interfaces.Add(intf); interfaces.AddRange(intf.GetSuperTypes()); List<SoaObject> result = new List<SoaObject>(); foreach (Interface iface in interfaces) { foreach (Operation operation in iface.Operations) { if (types.Contains(operation.GetType()) && operation.Name == name) { result.Add(operation); } } } return result; } return new List<SoaObject>(); }
public static SoaObject SelectName(IEnumerable<SoaObject> objects, SoaObject scope, string name, params System.Type[] types) { List<SoaObject> objs = new List<SoaObject>(objects); if (objs.Count == 1) { return objs[0]; } else if (objs.Count > 1) { throw new NameCollisionException(scope, name, types, objects); } else { throw new NameNotFoundException(scope, name, types); } }
public static SoaObject GetCommonType(SoaObject type1, SoaObject type2) { if (type1 == null) throw new ArgumentNullException("type1"); if (type2 == null) throw new ArgumentNullException("type2"); if (type1 is Declaration && type2 is Declaration) { if (type1 == PseudoType.Object || type2 == PseudoType.Object) { return PseudoType.Object; } if (type2 is Contract && type1 is Interface) { return TypeHelpers.GetCommonType(type1, ((Contract)type2).Interface); } if (type1 is Contract && type2 is Interface) { return TypeHelpers.GetCommonType(type2, ((Contract)type1).Interface); } if (type2 is Authorization && type1 is Interface) { return TypeHelpers.GetCommonType(type1, ((Authorization)type2).Interface); } if (type1 is Authorization && type2 is Interface) { return TypeHelpers.GetCommonType(type2, ((Authorization)type1).Interface); } if (type1 is StructType && type2 is StructType) { if (type1 == type2) { return type1; } if (((StructType)type2).GetSuperTypes().Contains(type1)) { return type1; } if (((StructType)type1).GetSuperTypes().Contains(type2)) { return type2; } } if (type1 is ExceptionType && type2 is ExceptionType) { if (type1 == type2) { return type1; } if (((ExceptionType)type2).GetSuperTypes().Contains(type1)) { return type1; } if (((ExceptionType)type1).GetSuperTypes().Contains(type2)) { return type2; } } if (type1 is Interface && type2 is Interface) { if (type1 == type2) { return type1; } if (((Interface)type2).GetSuperTypes().Contains(type1)) { return type1; } if (((Interface)type1).GetSuperTypes().Contains(type2)) { return type2; } } if (type1 is NullableType && type2 is NullableType) { if (((NullableType)type1) == ((NullableType)type2)) { return type1; } } if (type1 is ArrayType && type2 is ArrayType) { if (((ArrayType)type1) == ((ArrayType)type2)) { return type1; } } if (type1 is DelegateType && type2 is DelegateType) { if (((DelegateType)type1) == ((DelegateType)type2)) { return type1; } } if (type1 is BuiltInType && type2 is BuiltInType) { BuiltInTypeKind kind1 = ((BuiltInType)type1).Kind; BuiltInTypeKind kind2 = ((BuiltInType)type2).Kind; switch (kind1) { case BuiltInTypeKind.Bool: case BuiltInTypeKind.String: case BuiltInTypeKind.Guid: case BuiltInTypeKind.DateTime: case BuiltInTypeKind.Date: case BuiltInTypeKind.Time: case BuiltInTypeKind.TimeSpan: if (kind2 == kind1) return type1; break; case BuiltInTypeKind.Byte: if (kind2 == BuiltInTypeKind.Byte) return type1; else if (kind2 == BuiltInTypeKind.Int || kind2 == BuiltInTypeKind.Long || kind2 == BuiltInTypeKind.Float || kind2 == BuiltInTypeKind.Double) return type2; break; case BuiltInTypeKind.Int: if (kind2 == BuiltInTypeKind.Byte || kind2 == BuiltInTypeKind.Int) return type1; else if (kind2 == BuiltInTypeKind.Long || kind2 == BuiltInTypeKind.Float || kind2 == BuiltInTypeKind.Double) return type2; break; case BuiltInTypeKind.Long: if (kind2 == BuiltInTypeKind.Byte || kind2 == BuiltInTypeKind.Int || kind2 == BuiltInTypeKind.Long) return type1; else if (kind2 == BuiltInTypeKind.Float || kind2 == BuiltInTypeKind.Double) return type2; break; case BuiltInTypeKind.Float: if (kind2 == BuiltInTypeKind.Byte || kind2 == BuiltInTypeKind.Int || kind2 == BuiltInTypeKind.Long || kind2 == BuiltInTypeKind.Float) return type1; else if (kind2 == BuiltInTypeKind.Double) return type2; break; case BuiltInTypeKind.Double: if (kind2 == BuiltInTypeKind.Byte || kind2 == BuiltInTypeKind.Int || kind2 == BuiltInTypeKind.Long || kind2 == BuiltInTypeKind.Float || kind2 == BuiltInTypeKind.Double) return type2; break; default: break; } } } throw new ValidationException(string.Format("Incompatible types: '{0}' and '{1}'", type1, type2)); }
/// <summary> /// Resolves name in the given scope. /// </summary> /// <remarks> /// Does not search in parent scopes. /// </remarks> /// <param name="scope">The scope to search in.</param> /// <param name="name">The name to find</param> /// <param name="types">The types to find.</param> /// <returns>The objects found.</returns> /// <exception cref="NameNotFoundException">If the object is not found.</exception> /// <exception cref="NameCollisionException">If multiple objects are found.</exception> public static SoaObject ResolveName(SoaObject scope, string name, params System.Type[] types) { return NameHelpers.SelectName(NameContext.ResolveNameMany(scope, name, types), scope, name, types); }
/// <summary> /// Processes one identifier of a dotted namespace name. /// </summary> /// <remarks> /// The method is called recursively until only the last identifier remains. /// </remarks> /// <param name="identifiers">The list of identifiers.</param> /// <param name="scope">The parent namespace to search next identifier in.</param> /// <returns>The namespace that the list identifies.</returns> /// <exception cref="NameNotFoundException">If a namespace is not found along the path.</exception> private Namespace Process_NamespaceReference(List<string> identifiers, SoaObject scope) { Namespace @namespace = (Namespace)NameContext.ResolveName(scope, identifiers[0], typeof(Namespace));; if (identifiers.Count == 1) { // If this is the last part, simply return it return @namespace; } else { // Otherwise continue searching/creating with the next part of the name identifiers.RemoveAt(0); return this.Process_NamespaceReference(identifiers, @namespace); } }
protected void Error_MissingProtocol(SoaObject site, string protocol) { errorReporter.Error(site.GetMetaInfo<SourceLocationInfo>(), "A {0} protocol is missing.", protocol); }
public static bool IsSame(SoaObject typeTo, SoaObject typeFrom) { if (typeTo == null || typeFrom == null) { return false; } else { return typeTo == typeFrom; } }
public NameContextScope(SoaObject scope) { NameContext.Contexts.Push(new NameContext(scope)); }
public static IEnumerable<SoaObject> ResolveOperationMany(SoaObject scope, string name, List<Type> paramTypes, bool exact) { return NameHelpers.LookupOperationMany(scope, name, paramTypes, exact); }
public static SoaObject ResolveOperation(SoaObject scope, string name, List<Type> paramTypes, bool exact = false) { return NameHelpers.SelectName(NameContext.ResolveOperationMany(scope, name, paramTypes, exact), scope, name, typeof(Operation)); }
/// <summary> /// Returns the objects that matches the name and type in the given scope. /// </summary> /// <remarks> /// Does not search in parent scopes. /// </remarks> /// <param name="scope">The scope to search in.</param> /// <param name="name">The name to find</param> /// <param name="types">The types to find.</param> /// <returns>The objects found.</returns> public static IEnumerable<SoaObject> ResolveNameMany(SoaObject scope, string name, params System.Type[] types) { return NameHelpers.LookupNameMany(scope, name, types); }
/// <summary> /// Constructs the exception. /// </summary> /// <param name="name">The name causing the collision among the given metatypes.</param> /// <param name="types">The metatype(s) having a same name.</param> /// <param name="inner">The inner exception causing this one (optional).</param> public NameCollisionException(SoaObject scope, string name, System.Type[] types, IEnumerable<SoaObject> collidingObjects, Exception inner = null) : base(scope, name, types, "Name collides with another", inner) { this.CollidingObjects = collidingObjects; }
protected void Error_NameRedundant(SoaObject site, string name) { Error_NameRedundant(site, site.GetType(), name); }
public static bool IsAssignableFrom(SoaObject typeTo, SoaObject typeFrom) { if (typeTo == null || typeFrom == null) return false; if (typeTo is Declaration && typeFrom is Declaration) { if (typeTo == PseudoType.Object) { return true; } if (typeFrom is Contract && typeTo is Interface) { return TypeHelpers.IsAssignableFrom(typeTo, ((Contract)typeFrom).Interface); } if (typeFrom is Authorization && typeTo is Interface) { return TypeHelpers.IsAssignableFrom(typeTo, ((Authorization)typeFrom).Interface); } if (typeFrom is EnumType && typeTo is EnumType) { return (typeFrom == typeTo); } if (typeFrom is StructType && typeTo is StructType) { return (typeFrom == typeTo) || ((StructType)typeFrom).GetSuperTypes().Contains(typeTo); } if (typeFrom is ExceptionType && typeTo is ExceptionType) { return (typeFrom == typeTo) || ((ExceptionType)typeFrom).GetSuperTypes().Contains(typeTo); } if (typeFrom is Interface && typeTo is Interface) { return (typeFrom == typeTo) || ((Interface)typeFrom).GetSuperTypes().Contains(typeTo); } if (typeTo is NullableType && typeFrom is NullableType) { if (((NullableType)typeTo) == ((NullableType)typeFrom)) { return true; } } if (typeTo is ArrayType && typeFrom is ArrayType) { if (((ArrayType)typeTo) == ((ArrayType)typeFrom)) { return true; } } if (typeTo is DelegateType && typeFrom is DelegateType) { if (((DelegateType)typeTo) == ((DelegateType)typeFrom)) { return true; } } if (typeTo is BuiltInType && typeFrom is BuiltInType) { BuiltInTypeKind kindTo = ((BuiltInType)typeTo).Kind; BuiltInTypeKind kindFrom = ((BuiltInType)typeFrom).Kind; switch (kindTo) { case BuiltInTypeKind.Bool: case BuiltInTypeKind.String: case BuiltInTypeKind.Guid: case BuiltInTypeKind.DateTime: case BuiltInTypeKind.Date: case BuiltInTypeKind.Time: case BuiltInTypeKind.TimeSpan: return kindFrom == kindTo; case BuiltInTypeKind.Byte: if (kindFrom == BuiltInTypeKind.Byte) return true; else if (kindFrom == BuiltInTypeKind.Int || kindFrom == BuiltInTypeKind.Long || kindFrom == BuiltInTypeKind.Float || kindFrom == BuiltInTypeKind.Double) return false; break; case BuiltInTypeKind.Int: if (kindFrom == BuiltInTypeKind.Byte || kindFrom == BuiltInTypeKind.Int) return true; else if (kindFrom == BuiltInTypeKind.Long || kindFrom == BuiltInTypeKind.Float || kindFrom == BuiltInTypeKind.Double) return false; break; case BuiltInTypeKind.Long: if (kindFrom == BuiltInTypeKind.Byte || kindFrom == BuiltInTypeKind.Int || kindFrom == BuiltInTypeKind.Long) return true; else if (kindFrom == BuiltInTypeKind.Float || kindFrom == BuiltInTypeKind.Double) return false; break; case BuiltInTypeKind.Float: if (kindFrom == BuiltInTypeKind.Byte || kindFrom == BuiltInTypeKind.Int || kindFrom == BuiltInTypeKind.Long || kindFrom == BuiltInTypeKind.Float) return true; else if (kindFrom == BuiltInTypeKind.Double) return false; break; case BuiltInTypeKind.Double: if (kindFrom == BuiltInTypeKind.Byte || kindFrom == BuiltInTypeKind.Int || kindFrom == BuiltInTypeKind.Long || kindFrom == BuiltInTypeKind.Float || kindFrom == BuiltInTypeKind.Double) return true; break; default: break; } } } return false; }
protected void Error_NameExists(SoaObject site, NameCollisionException exception) { Error_NameExists(site.GetMetaInfo<SourceLocationInfo>(), exception); }
protected void Error_MultipleProtocol(SoaObject site, string protocol) { errorReporter.Error(site.GetMetaInfo<SourceLocationInfo>(), "A {0} protocol is already included.", protocol); }
public OldExpression(SoaObject @object) : base(ExpressionType.Old, @object) { }
protected void Warning_NameLowerCase(SoaObject site, string name) { errorReporter.Warning(site.GetMetaInfo<SourceLocationInfo>(), "Name of {0} \"{1}\" starts with a lowercase letter.", AttributeHelpers.GetTypeName(site.GetType()).ToLower(), name); }
/// <summary> /// Checks whether the name exists in the given scope. /// </summary> /// <remarks> /// Does not search in parent scopes. /// </remarks> /// <param name="scope">The scope to search in.</param> /// <param name="name">The name to find</param> /// <param name="types">The types to find.</param> /// <exception cref="NameCollisionException">If the name exists.</exception> public static void CheckName(SoaObject scope, string name, params System.Type[] types) { NameHelpers.CheckName(NameContext.ResolveNameMany(scope, name, types), scope, name, types); }
protected void Error_NameRedundant(SoaObject site, System.Type type, string name) { Error_NameRedundant(site.GetMetaInfo<SourceLocationInfo>(), type, name); }
public static IEnumerable<SoaObject> LookupOperationMany(SoaObject scope, string name, List<Type> paramTypes, bool exact) { if (scope is Interface) { Interface intf = scope as Interface; List<Interface> interfaces = new List<Interface>(); interfaces.Add(intf); interfaces.AddRange(intf.GetSuperTypes()); List<SoaObject> result = new List<SoaObject>(); foreach (Interface iface in interfaces) { foreach (Operation operation in iface.Operations) { if (operation.Name == name && operation.Parameters.Count == paramTypes.Count) { int i = 0; while (i < operation.Parameters.Count) { if (exact ? TypeHelpers.IsSame(operation.Parameters[i].Type, paramTypes[i]) : TypeHelpers.IsAssignableFrom(operation.Parameters[i].Type, paramTypes[i])) { ++i; } else { break; } } if (i == operation.Parameters.Count) { result.Add(operation); } } } } return result; } if (scope is Authorization) { return NameHelpers.LookupOperationMany(((Authorization)scope).Interface, name, paramTypes, exact); } if (scope is Contract) { return NameHelpers.LookupOperationMany(((Contract)scope).Interface, name, paramTypes, exact); } return new List<SoaObject>(); }
protected void Error_NameNotFound(SoaObject site, NameNotFoundException exception) { Error_NameNotFound(site.GetMetaInfo<SourceLocationInfo>(), exception); }
public NameExpression(ExpressionType nodeType, SoaObject @object) : base(nodeType) { this.Object = @object; ModelClass.LazyInit(this, TypeProperty, () => this.CalculateType()); ModelClass.LazyInit(this, ValueProperty, () => { throw new EvaluationException(this); }); }