private void create_assemblies() { first_namespace = Namespace("First"); first_type = Type <First>(first_namespace); second_namespace = Namespace("Second"); second_type = Type <Second>(second_namespace); third_namespace = Namespace("Third"); third_type = Type <Third>(third_namespace); namespaces = new[] { first_namespace, second_namespace, third_namespace }; }
public override object visitDeclaredType(DeclaredType declaredType, WritableScope scope) { Symbol sym = scope.findFirst(declaredType.name, s => (s.kind & Kind.STRUCT) != 0); if (sym != null) { return(sym.type); } log.error(declaredType.Pos, messages.undefinedType, declaredType.name); return(symtab.errorType); }
public override void Write() { var prop = DeclaredType.GetProperty("Results"); var resultsType = prop.PropertyType; var results = prop.GetValue(Result); Write(results, resultsType); var total = (long)DeclaredType.GetProperty("Total").GetValue(Result); Console.WriteLine($" TOTAL: {total}"); }
public override Type visitDeclaredType(DeclaredType declaredType, Environment env) { Symbol classSym = env.scope.findFirst(declaredType.name, s => s.kind == Kind.STRUCT); if (classSym == null) { log.error(declaredType.Pos, messages.undefinedStruct, declaredType.name); return(symtab.errorType); } return(classSym.type); }
public override bool?visitDeclared(DeclaredType map, Void ignored) { //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: java.util.List<? extends javax.lang.model.type.TypeMirror> typeArguments = map.getTypeArguments(); IList <TypeMirror> typeArguments = map.TypeArguments; if (typeArguments.Count != 2) { return(false); } TypeMirror key = typeArguments[0]; return(_outerInstance.typeUtils.isSameType(key, _outerInstance.typeMirrors.typeMirror(typeof(string))) && _outerInstance.test(typeArguments[1])); }
/// <summary> /// Initializes a new instance of the <see cref="ExpressionTarget" /> class. /// </summary> /// <param name="expression">Required. The static expression which should be used by compilers.</param> /// <param name="declaredType">Declared type of the target to be created (used when registering without /// an explicit type or when this target is used as a value inside another target).</param> /// <param name="scopeBehaviour">Scope behaviour for this expression. The default is <see cref="ScopeBehaviour.Implicit"/>, which means /// that that any returned instance will be tracked implicitly by the active scope. If the expression produces a new instance, then /// this or <see cref="ScopeBehaviour.Explicit"/> can be used safely - the choice being whether /// the expression should produce one instance per scope, or should act as a disposable transient object.</param> /// <param name="scopePreference">If <paramref name="scopeBehaviour"/> is not <see cref="ScopeBehaviour.None"/>, then this controls /// the preferred scope for the instance to be tracked. Defaults to <see cref="ScopePreference.Current"/></param> /// <remarks><paramref name="declaredType"/> will automatically be determined if not provided /// by examining the type of the <paramref name="expression"/>. For lambdas, the type will /// be derived from the Type of the lambda's body. For all other expressions, the type is /// taken directly from the Type property of the expression itself.</remarks> public ExpressionTarget( Expression expression, Type declaredType = null, ScopeBehaviour scopeBehaviour = ScopeBehaviour.None, ScopePreference scopePreference = ScopePreference.Current) { Expression = expression ?? throw new ArgumentNullException(nameof(expression)); var expressionType = (expression.NodeType == ExpressionType.Lambda ? ((LambdaExpression)expression).Body.Type : expression.Type); DeclaredType = declaredType ?? expressionType; if (!DeclaredType.IsAssignableFrom(expressionType)) { throw new ArgumentException($"{nameof(declaredType)} must be compatible with the type of the expression", nameof(declaredType)); } }
/// <summary> /// Initializes the display information for this <see cref="CliOutput"/> instance, to /// determine whether to writ a table, list, or singular value. /// </summary> private void Initialize() { if (typeof(IEnumerable).IsAssignableFrom(DeclaredType)) { isTable = true; var enumerableType = DeclaredType.GetInterfaces().Union(new[] { DeclaredType }).FirstOrDefault(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IEnumerable <>)); if (enumerableType != null) { var itemType = enumerableType.GetGenericArguments()[0]; if (itemType.IsClass) { props = GetProps(itemType); } } } else if (DeclaredType.IsClass) { props = GetProps(DeclaredType); } if (props != null) { // Table of cells, structured cells[row][col] cells = new List <List <string> > { props.Select(x => x.Info.Name.ToUpper()).ToList() }; if (isTable) { // Add rows for all the values foreach (var item in (IEnumerable)Result) { cells.Add(props .Select(x => x.Info.GetValue(item)?.ToString()) .ToList()); } } else { cells.Add(props .Select(x => x.Info.GetValue(Result)?.ToString()) .ToList()); } } }
public void Add(List <Namespace> namespaces, DocumentedType association) { Namespace ns = FindNamespace(association, namespaces); DeclaredType doc = DeclaredType.Unresolved((TypeIdentifier)association.Name, association.TargetType, ns); ParseSummary(association, doc); ParseRemarks(association, doc); ParseValue(association, doc); ParseExample(association, doc); if (matchedAssociations.ContainsKey(association.Name)) { return; } matchedAssociations.Add(association.Name, doc); ns.AddType(doc); }
public void Add(List <Namespace> namespaces, DocumentedEvent association) { if (association.Event == null) { return; } DeclaredType type = FindType(association, namespaces); Event doc = Event.Unresolved(IdentifierFor.Event(association.Event, association.TargetType), type); ParseSummary(association, doc); ParseRemarks(association, doc); ParseExample(association, doc); _matchedAssociations.Add(association.Name, doc); type.AddEvent(doc); }
public override void Write() { var response = (Response)Result; if (DeclaredType.IsGenericType) { var contentType = DeclaredType.GetGenericArguments()[0]; var content = DeclaredType.GetProperty("Content").GetValue(response); Write(content, contentType); Console.WriteLine(); } Console.WriteLine($" STATUS: {(int)response.StatusCode} ({response.StatusCode})"); if (!string.IsNullOrWhiteSpace(response.Message)) { Console.WriteLine($" MESSAGE: {response.Message}"); } }
public void Add(List <Namespace> namespaces, DocumentedProperty association) { if (association.Property == null) { return; } DeclaredType type = FindType(association, namespaces); var isStatic = association.Property.GetGetMethod().IsStatic; DeclaredType propertyReturnType = DeclaredType.Unresolved( IdentifierFor.Type(association.Property.PropertyType), association.Property.PropertyType, Namespace.Unresolved(IdentifierFor.Namespace(association.Property.PropertyType.Namespace))); Property doc = Property.Unresolved( IdentifierFor.Property(association.Property, association.TargetType, isStatic), type, association.Property, propertyReturnType); ParseSummary(association, doc); ParseValue(association, doc); ParseRemarks(association, doc); ParseExample(association, doc); if (_matchedAssociations.ContainsKey(association.Name)) { return; } _matchedAssociations.Add(association.Name, doc); if (type == null) { return; } type.AddProperty(doc); }
public void Add(List <Namespace> namespaces, DocumentedField association) { if (association.Field == null) { return; } var ns = FindNamespace(association, namespaces); var type = FindType(ns, association); var returnType = DeclaredType.Unresolved(Identifier.FromType(association.Field.FieldType), association.Field.FieldType, Namespace.Unresolved( Identifier.FromNamespace(association.Field.FieldType.Namespace))); var doc = Field.Unresolved(Identifier.FromField(association.Field, association.TargetType), type, returnType); ParseSummary(association, doc); ParseRemarks(association, doc); ParseExample(association, doc); matchedAssociations[association.Name] = doc; type.AddField(doc); }
public void Add(List <Namespace> namespaces, DocumentedField association) { if (association.Field == null) { return; } DeclaredType type = FindType(association, namespaces); DeclaredType returnType = DeclaredType.Unresolved( IdentifierFor.Type(association.Field.FieldType), association.Field.FieldType, Namespace.Unresolved(IdentifierFor.Namespace(association.Field.FieldType.Namespace))); Field doc = Field.Unresolved( IdentifierFor.Field(association.Field, association.TargetType), type, returnType); ParseSummary(association, doc); ParseRemarks(association, doc); ParseExample(association, doc); _matchedAssociations.Add(association.Name, doc); type.AddField(doc); }
public IComment Parse(ICommentParser parser, XmlNode node, bool first, bool last, ParseOptions options) { IReferencable reference = new NullReference(); if (node.Attributes["cref"] == null) { return(new See(reference)); } var referenceTarget = Identifier.FromString(node.Attributes["cref"].Value); if (referenceTarget is NamespaceIdentifier) { reference = Namespace.Unresolved((NamespaceIdentifier)referenceTarget); } else if (referenceTarget is TypeIdentifier) { reference = DeclaredType.Unresolved((TypeIdentifier)referenceTarget, Namespace.Unresolved(referenceTarget.CloneAsNamespace())); } else if (referenceTarget is MethodIdentifier) { reference = Method.Unresolved( (MethodIdentifier)referenceTarget, DeclaredType.Unresolved( referenceTarget.CloneAsType(), Namespace.Unresolved(referenceTarget.CloneAsNamespace()) ) ); } else if (referenceTarget is PropertyIdentifier) { reference = Property.Unresolved( (PropertyIdentifier)referenceTarget, DeclaredType.Unresolved( referenceTarget.CloneAsType(), Namespace.Unresolved(referenceTarget.CloneAsNamespace()) ) ); } else if (referenceTarget is EventIdentifier) { reference = Event.Unresolved( (EventIdentifier)referenceTarget, DeclaredType.Unresolved( referenceTarget.CloneAsType(), Namespace.Unresolved(referenceTarget.CloneAsNamespace()) ) ); } else if (referenceTarget is FieldIdentifier) { reference = Field.Unresolved( (FieldIdentifier)referenceTarget, DeclaredType.Unresolved( referenceTarget.CloneAsType(), Namespace.Unresolved(referenceTarget.CloneAsNamespace()) ) ); } return(new See(reference)); }
public override bool?VisitDeclared(DeclaredType parameterType, Void ignored) { return(Validate(parameterType)); }
public string Declaration() { return(DeclaredType == null ? $"{Variable.AssignmentUsage} = {Invocation()}" : $"{DeclaredType.FullNameInCode()} {Variable.Usage} = {Invocation()}"); }
public virtual T visitDeclaredType(DeclaredType declaredType, A arg) => visit(declaredType, arg);
public override int GetHashCode() { return((17 * 23 + DeclaredType.GetHashCode()) * 23 + Name.GetHashCode()); }
/// <summary> /// Validates the instance, declared and stated profiles for consistenty. /// </summary> /// <returns></returns> public OperationOutcome Validate() { if (_lastValidationOutcome != null) { return(_lastValidationOutcome); } var outcome = new OperationOutcome(); // Resolve input profiles first (note: this is cached) var resolutionOutcome = Resolve(); if (!resolutionOutcome.Success) { return(resolutionOutcome); } else { outcome.Add(resolutionOutcome); } // If we have an instance type, it should be compatible with the declared type on the definition and the stated profiles if (InstanceType != null) { if (DeclaredType != null) { if (!ModelInfo.IsInstanceTypeFor(DeclaredType.BaseType(), InstanceType.BaseType())) { outcome.AddIssue($"The declared type of the element ({DeclaredType.ReadableName()}) is incompatible with that of the instance ('{InstanceType.ReadableName()}')", Issue.CONTENT_ELEMENT_HAS_INCORRECT_TYPE, _path); } } foreach (var type in StatedProfiles) { if (!ModelInfo.IsInstanceTypeFor(type.BaseType(), InstanceType.BaseType())) { outcome.AddIssue($"Instance of type '{InstanceType.ReadableName()}' is incompatible with the stated profile '{type.Url}' which is constraining constrained type '{type.ReadableName()}'", Issue.CONTENT_ELEMENT_HAS_INCORRECT_TYPE, _path); } } } // All stated profiles should be profiling the same core type if (StatedProfiles.Any()) { var baseTypes = StatedProfiles.Select(p => p.BaseType()).Distinct().ToList(); if (baseTypes.Count > 1) { var combinedNames = String.Join(" and ", baseTypes.Select(bt => bt.GetLiteral())); outcome.AddIssue($"The stated profiles are constraints on multiple different core types ({combinedNames}), which can never be satisfied.", Issue.CONTENT_MISMATCHING_PROFILES, _path); } else { // The stated profiles should be compatible with the declared type of the element if (DeclaredType != null) { if (!ModelInfo.IsInstanceTypeFor(DeclaredType.BaseType(), baseTypes.Single())) { outcome.AddIssue($"The stated profiles are all constraints on '{baseTypes.Single()}', which is incompatible with the declared type '{DeclaredType.ReadableName()}' of the element", Issue.CONTENT_MISMATCHING_PROFILES, _path); } } } } _lastValidationOutcome = outcome; return(outcome); }
public static MethodParameter to_method_parameter_called(this DeclaredType type, string name) { return(new MethodParameter(name, type)); }
private void AddMatch(string outputPath, string templatePath, ViewData data, Namespace ns, DeclaredType type) { var clone = data.Clone(); clone.Type = type; AddMatch(outputPath, templatePath, clone, ns); }
public override Stream <CompilationMessage> VisitDeclared(DeclaredType returnType, Void ignored) { return(returnType.TypeArguments.stream().flatMap(this.validateRecord)); }