public void Resolve(ITypeOwner typeOwner) { TypeOwner = typeOwner; Type = typeOwner.Type; TypeName = typeOwner.Type.GetPresentableName(typeOwner.PresentationLanguage); TypeOwnerName = TypeOwner.ShortName; }
private static ILocalVariableName GetName(this ITypeOwner variable, ISubstitution substitution, IDictionary <DeclaredElementInstance, IName> seenElements) { var identifier = new StringBuilder(); identifier.AppendType(variable.Type, seenElements).Append(' ').Append(variable.ShortName); return(Names.LocalVariable(identifier.ToString())); }
internal TypeBuilder(ITypeOwner owner, string ns, string name) { this.owner = owner; this.token = this.ModuleBuilder.TypeDef.AllocToken(); this.ns = ns; this.name = name; this.typeNameSpace = ns == null ? 0 : this.ModuleBuilder.Strings.Add(ns); this.typeName = this.ModuleBuilder.Strings.Add(name); }
public override void Populate(CSharpGeneratorContext context) { // use context.ProvidedElements.AddRange to add new // generator elements (e.g., GeneratorDeclaredElement<T>) IClassLikeDeclaration typeDeclaration = context.ClassDeclaration; ITypeElement typeElement = typeDeclaration.DeclaredElement; ListHandler.Initialize(context); MethodGeneratorBase.Initialize(context); GetBytesMethodGenerator.Initialize(context); SetBytesMethodGenerator.Initialize(context); if (typeElement is IClass || typeElement is IStruct) { var ctx = new TypeHandlingContext(context); foreach (ITypeMember member in typeElement.GetMembers()) { ITypeOwner owner = null; var field = member as IField; if (field != null) { if (field.GetAccessRights() != AccessRights.PRIVATE && !field.IsConstant && !field.IsReadonly && !field.IsStatic) { owner = field; } } var property = member as IProperty; if (property != null) { if (property.IsReadable && property.IsWritable && !property.IsStatic) { owner = property; } } if (owner != null) { ctx.Resolve(owner); if (TypeHandlers.All.Any(h => h.CanHandle(ctx))) { context.ProvidedElements.Add(new GeneratorDeclaredElement <ITypeOwner>(owner)); } } } } }
public void HandleEnumWrite(ITypeOwner element, StringBuilder builder, IList <object> args) { int fieldIndex = args.Count; args.Add(element); int typeIndex = args.Count; args.Add(element.Type); builder.AppendFormat("bytes[index] = (${1})${0};", fieldIndex, typeIndex); builder.AppendFormat("index += sizeof(${0});", typeIndex); }
public TypeHandlingContext(TypeHandlingContext other) { ElementFactory = other.ElementFactory; GeneratorContext = other.GeneratorContext; Builder = other.Builder; Args = other.Args; Variables = other.Variables; TypeOwner = other.TypeOwner; TypeOwnerName = other.TypeOwnerName; Type = other.Type; TypeName = other.TypeName; SizeVariableKey = other.SizeVariableKey; }
static string QualifiedNetNotationWithoutAssembly(ITypeOwner field) { if (field == null) { throw new ArgumentException("Tried to create normalized type from a null reference."); } var typeName = field.Type.ToString(); typeName = typeName.Substring(typeName.IndexOf("-> ") + 3); typeName = typeName.Remove(typeName.Length - 1); typeName = OpenBracketFollowedByDart.Replace(typeName, "["); return typeName; }
static string QualifiedNetNotationWithoutAssembly(ITypeOwner field) { if (field == null) { throw new ArgumentException("Tried to create normalized type from a null reference."); } var typeName = field.Type.ToString(); typeName = typeName.Substring(typeName.IndexOf("-> ") + 3); typeName = typeName.Remove(typeName.Length - 1); typeName = OpenBracketFollowedByDart.Replace(typeName, "["); return(typeName); }
public IList <ITypeOwner> GetFields() { var fieldDeclarations = Fields; var result = new ITypeOwner[fieldDeclarations.Count]; for (var i = 0; i < fieldDeclarations.Count; i++) { if (fieldDeclarations[i].DeclaredElement is ITypeOwner field) { result[i] = field; } } return(result); }
internal TypeBuilder(ITypeOwner owner, string name, Type baseType, TypeAttributes attribs) { this.owner = owner; this.token = this.ModuleBuilder.TypeDef.AllocToken(); this.nameOrFullName = TypeNameParser.Escape(name); SetParent(baseType); this.attribs = attribs; if (!this.IsNested) { int lastdot = name.LastIndexOf('.'); if (lastdot > 0) { this.typeNameSpace = this.ModuleBuilder.Strings.Add(name.Substring(0, lastdot)); name = name.Substring(lastdot + 1); } } this.typeName = this.ModuleBuilder.Strings.Add(name); }
private HashSet <string> getLocalNames(IDeclaration declaration) { HashSet <string> localNames = new HashSet <string>(); ITypeOwner var = declaration as ITypeOwner; if (var != null) { string name = var.Type.GetPresentableName(declaration.Language); string acronym = ""; foreach (char c in name) { if (char.IsUpper(c)) { acronym += c; } } localNames.Add(acronym.ToLower()); CamelHumpLexer lexer = new CamelHumpLexer(name, 0, name.Length); foreach (LexerToken token in lexer) { localNames.Add(token.Value.ToLower()); } } IClassLikeDeclaration decl = declaration as IClassLikeDeclaration; if (decl != null) { foreach (IDeclaredType type in decl.SuperTypes) { string name = type.GetPresentableName(declaration.Language); CamelHumpLexer lexer = new CamelHumpLexer(name, 0, name.Length); foreach (LexerToken token in lexer) { localNames.Add(token.Value.ToLower()); } } } return(localNames); }
/// <summary> /// Swap variable declaration to built in type. /// </summary> /// <param name="variableDeclaration"> /// The variable declaration. /// </param> private static void SwapVariableDeclarationToBuiltInType(IVariableDeclaration variableDeclaration) { if (variableDeclaration is ILocalVariableDeclaration) { ProcessLocalVariableDeclaration((ILocalVariableDeclaration)variableDeclaration); } else if (variableDeclaration is IForeachVariableDeclaration) { ProcessForeachVariableDeclaration((IForeachVariableDeclaration)variableDeclaration); } else { IDeclaredElement declaredElement = variableDeclaration.DeclaredElement; ITypeOwner typeOwner = (ITypeOwner)declaredElement; if (typeOwner != null) { using (WriteLockCookie.Create(true)) { variableDeclaration.SetType(typeOwner.Type); } } } }
public FSharpGeneratedParameter([NotNull] IParametersOwner owner, [CanBeNull] ITypeOwner origin) { Owner = owner; Origin = origin; }
private void HighlightPropertyType(IAccessor accessor, IElement nameAttribute, ITypeOwner field, IElement typeAttribute, IXmlTag xmlTag, string attributeName) { ITypeElement propertyClass = HighlightUndefinedType(xmlTag, attributeName); if (accessor != null) { // TODO: use accessor.ReturnType on getter IDeclaredType declaredType = accessor.Parameters[0].Type as IDeclaredType; if (declaredType != null) { ITypeElement propertyTypeElement = declaredType.GetTypeElement(); if ((propertyTypeElement != null) && (propertyClass != null) && (!propertyClass.IsDescendantOf(propertyTypeElement))) { AddHighlighting(typeAttribute, new TypeHighlighting(string.Format("Class name '{0}' should be '{1}' or a descendant", propertyClass.ShortName, propertyTypeElement.ShortName))); } } } if (field != null) { IDeclaredType declaredType = field.Type as IDeclaredType; if (declaredType != null) { ITypeElement fieldTypeElement = declaredType.GetTypeElement(); if ((fieldTypeElement != null) && (propertyClass != null) && (!propertyClass.IsDescendantOf(fieldTypeElement))) { AddHighlighting(typeAttribute, new TypeHighlighting(string.Format("Class name '{0}' should be '{1}' or a descendant", propertyClass.ShortName, fieldTypeElement.ShortName))); } } } if ((accessor != null) && (field != null)) { IDeclaredType declaredAccessorType = accessor.Parameters[0].Type as IDeclaredType; IDeclaredType declaredFieldType = field.Type as IDeclaredType; if ((declaredAccessorType != null) && (declaredFieldType != null)) { ITypeElement propertyTypeElement = declaredAccessorType.GetTypeElement(); ITypeElement fieldTypeElement = declaredFieldType.GetTypeElement(); if ((propertyTypeElement != null) && (fieldTypeElement != null) && (!propertyTypeElement.Equals(fieldTypeElement))) { AddHighlighting(nameAttribute, new TypeHighlighting(string.Format("Property and field type differ: '{0}' vs. '{1}'", propertyTypeElement.ShortName, fieldTypeElement.ShortName))); } } } }
public CommonMember GetCommonMember(ITypeOwner member) { return(new CommonMember(member.ShortName, member.Type.ToCommon())); }
public NormalizedTypeName(ITypeOwner field) { this._normalized = QualifiedNetNotationWithoutAssembly(field); }
public NormalizedTypeName(ITypeOwner field) { _normalized = QualifiedNetNotationWithoutAssembly(field); }
public FSharpGeneratedConstructorParameter([NotNull] IConstructor constructor, [CanBeNull] ITypeOwner origin) { Constructor = constructor; Origin = origin; }
public static CommonMember ToCommon(this ITypeOwner member) { return(IntrospectionUtility.Instance.GetCommonMember(member)); }