public virtual bool IsIgnoreType(ICSharpCode.NRefactory.TypeSystem.ITypeDefinition typeDefinition, bool ignoreLiteral = false) { string ignoreAttr = Translator.Bridge_ASSEMBLY + ".IgnoreAttribute"; string objectLiteralAttr = Translator.Bridge_ASSEMBLY + ".ObjectLiteralAttribute"; return(typeDefinition.Attributes.Any(attr => attr.Constructor != null && ((attr.Constructor.DeclaringType.FullName == ignoreAttr) || (!ignoreLiteral && attr.Constructor.DeclaringType.FullName == objectLiteralAttr)))); }
void GetFilesToUpdate() { _filesToBeEdited = new List <string> (); if (!(_document.ParsedDocument.TopLevelTypeDefinitions?.Count > 0)) { return; } var entities = _document.ParsedDocument.TopLevelTypeDefinitions; var topLevelClass = entities [0]; _typeDefinition = topLevelClass.Resolve(_project) as ICSharpCode.NRefactory.TypeSystem.ITypeDefinition; _typeName = _typeDefinition.Name; _originalFullTypeName = _originalNamespace + "." + _typeName; _newFullTypeName = _newNamespace + "." + _typeName; var memberRefs = ReferenceFinder.FindReferences(_project.ParentSolution, _typeDefinition, true, ReferenceFinder.RefactoryScope.Unknown, null); foreach (var memberRef in memberRefs) { if (!(_filesToBeEdited).Contains(memberRef.FileName)) { _filesToBeEdited.Add(memberRef.FileName); } } }
public virtual bool IsExternalType(ICSharpCode.NRefactory.TypeSystem.ITypeDefinition typeDefinition, bool ignoreLiteral = false) { string externalAttr = Translator.Bridge_ASSEMBLY + ".ExternalAttribute"; var has = typeDefinition.Attributes.Any(attr => attr.Constructor != null && attr.Constructor.DeclaringType.FullName == externalAttr); if (!has) { has = typeDefinition.ParentAssembly.AssemblyAttributes.Any(attr => attr.Constructor != null && attr.Constructor.DeclaringType.FullName == externalAttr); } return(has); }
public virtual bool IsExternalInterface(ICSharpCode.NRefactory.TypeSystem.ITypeDefinition typeDefinition, out bool isNative) { string externalAttr = Translator.Bridge_ASSEMBLY + ".ExternalInterfaceAttribute"; var attr = typeDefinition.Attributes.FirstOrDefault(a => a.Constructor != null && (a.Constructor.DeclaringType.FullName == externalAttr)); isNative = attr != null && attr.PositionalArguments.Count == 1 && (bool)attr.PositionalArguments[0].ConstantValue; if (attr == null) { isNative = typeDefinition.ParentAssembly.AssemblyName == "Bridge" || !this.IsIgnoreType(typeDefinition); } return(attr != null); }
protected virtual List <IField> GetFieldOverloads(List <IField> list = null, ITypeDefinition typeDef = null) { typeDef = typeDef ?? this.TypeDefinition; bool isTop = list == null; list = list ?? new List <IField>(); if (typeDef != null) { var fields = typeDef.Fields.Where(f => { if (f.IsExplicitInterfaceImplementation) { return(false); } var inline = this.Emitter.GetInline(f); if (!string.IsNullOrWhiteSpace(inline)) { return(false); } var name = this.Emitter.GetEntityName(f); if ((name == this.JsName || name == this.AltJsName || name == this.FieldJsName) && f.IsStatic == this.Static) { return(true); } return(false); }); list.AddRange(fields); if (this.Inherit) { var baseTypeDefinitions = typeDef.DirectBaseTypes.Where(t => t.Kind == typeDef.Kind || (typeDef.Kind == TypeKind.Struct && t.Kind == TypeKind.Class)); foreach (var baseTypeDef in baseTypeDefinitions) { var result = this.GetFieldOverloads(list, baseTypeDef.GetDefinition()); list.AddRange(result); } } } var returnFields = isTop ? list.Distinct().ToList() : list; return(returnFields); }
public virtual IExternalInterface IsExternalInterface(ICSharpCode.NRefactory.TypeSystem.ITypeDefinition typeDefinition) { string externalAttr = Translator.Bridge_ASSEMBLY + ".ExternalInterfaceAttribute"; var attr = typeDefinition.Attributes.FirstOrDefault(a => a.Constructor != null && (a.Constructor.DeclaringType.FullName == externalAttr)); if (attr == null) { attr = typeDefinition.ParentAssembly.AssemblyAttributes.FirstOrDefault(a => a.Constructor != null && (a.Constructor.DeclaringType.FullName == externalAttr)); } if (attr != null) { var ei = new ExternalInterface(); if (attr.PositionalArguments.Count == 1) { bool isNative = (bool)attr.PositionalArguments[0].ConstantValue; if (isNative) { ei.IsNativeImplementation = true; } else { ei.IsSimpleImplementation = true; } } if (attr.NamedArguments.Count == 1) { if (attr.NamedArguments[0].Key.Name == "IsVirtual") { ei.IsVirtual = (bool)attr.NamedArguments[0].Value.ConstantValue; } } return(ei); } return(null); }
public virtual bool IsObjectLiteral(ICSharpCode.NRefactory.TypeSystem.ITypeDefinition type) { return(this.HasAttribute(type.Attributes, Translator.Bridge_ASSEMBLY + ".ObjectLiteralAttribute")); }
protected virtual List <IEvent> GetEventOverloads(List <IEvent> list = null, ITypeDefinition typeDef = null) { bool isTop = list == null; list = list ?? new List <IEvent>(); typeDef = typeDef ?? this.TypeDefinition; if (typeDef != null) { var events = typeDef.Events.Where(e => { if (e.IsExplicitInterfaceImplementation) { return(false); } var inline = e.AddAccessor != null ? this.Emitter.GetInline(e.AddAccessor) : null; if (!string.IsNullOrWhiteSpace(inline)) { return(false); } inline = e.RemoveAccessor != null ? this.Emitter.GetInline(e.RemoveAccessor) : null; if (!string.IsNullOrWhiteSpace(inline)) { return(false); } bool eq = false; bool?equalsByAdd = null; if (e.IsStatic == this.Static) { var addName = e.AddAccessor != null && e.CanAdd ? Helpers.GetEventRef(e, this.Emitter, false, true, true) : null; var removeName = e.RemoveAccessor != null && e.CanRemove ? Helpers.GetEventRef(e, this.Emitter, true, true, true) : null; var fieldName = Helpers.GetEventRef(e, this.Emitter, true, true, true, false, true); if (addName != null && (addName == this.JsName || addName == this.AltJsName || addName == this.FieldJsName)) { eq = true; equalsByAdd = true; } else if (removeName != null && (removeName == this.JsName || removeName == this.AltJsName || removeName == this.FieldJsName)) { eq = true; equalsByAdd = false; } else if (fieldName != null && (fieldName == this.JsName || fieldName == this.AltJsName || fieldName == this.FieldJsName)) { eq = true; } } if (eq) { if (e.IsOverride && !this.IsTemplateOverride(e)) { return(false); } if (equalsByAdd.HasValue && this.Member is IMethod && this.AltJsName == null) { this.AltJsName = Helpers.GetEventRef(e, this.Emitter, equalsByAdd.Value, true, true); } return(true); } return(false); }); list.AddRange(events); if (this.Inherit) { var baseTypeDefinitions = typeDef.DirectBaseTypes.Where(t => t.Kind == typeDef.Kind || (typeDef.Kind == TypeKind.Struct && t.Kind == TypeKind.Class)); foreach (var baseTypeDef in baseTypeDefinitions) { var result = this.GetEventOverloads(list, baseTypeDef.GetDefinition()); list.AddRange(result); } } } return(isTop ? list.Distinct().ToList() : list); }
protected virtual List <IProperty> GetPropertyOverloads(List <IProperty> list = null, ITypeDefinition typeDef = null) { bool isTop = list == null; list = list ?? new List <IProperty>(); typeDef = typeDef ?? this.TypeDefinition; if (typeDef != null) { var bridgeType = this.Emitter.BridgeTypes.Get(typeDef); var monoTypeDef = bridgeType != null ? bridgeType.TypeDefinition : null; var properties = typeDef.Properties.Where(p => { if (p.IsExplicitInterfaceImplementation) { return(false); } var canGet = p.CanGet && p.Getter != null; var canSet = p.CanSet && p.Setter != null; if (monoTypeDef != null) { var monoProp = monoTypeDef.Properties.FirstOrDefault(mp => mp.Name == p.Name); if (monoProp != null) { canGet = monoProp.GetMethod != null; canSet = monoProp.SetMethod != null; } } if (!this.IncludeInline) { var inline = canGet ? this.Emitter.GetInline(p.Getter) : null; if (!string.IsNullOrWhiteSpace(inline)) { return(false); } inline = canSet ? this.Emitter.GetInline(p.Setter) : null; if (!string.IsNullOrWhiteSpace(inline)) { return(false); } if (p.IsIndexer && canGet && p.Getter.Attributes.Any(a => a.AttributeType.FullName == "Bridge.ExternalAttribute")) { return(false); } } bool eq = false; bool?equalsByGetter = null; if (p.IsStatic == this.Static) { var getterIgnore = canGet && this.Emitter.Validator.IsExternalType(p.Getter); var setterIgnore = canSet && this.Emitter.Validator.IsExternalType(p.Setter); var getterName = canGet ? Helpers.GetPropertyRef(p, this.Emitter, false, true, true) : null; var setterName = canSet ? Helpers.GetPropertyRef(p, this.Emitter, true, true, true) : null; var fieldName = Helpers.IsAutoProperty(p) ? (Helpers.IsFieldProperty(p, this.Emitter) ? this.Emitter.GetEntityName(p) : Helpers.GetPropertyRef(p, this.Emitter, true, true, true, false, true)) : null; if (!getterIgnore && getterName != null && (getterName == this.JsName || getterName == this.AltJsName || getterName == this.FieldJsName)) { eq = true; equalsByGetter = true; } else if (!setterIgnore && setterName != null && (setterName == this.JsName || setterName == this.AltJsName || setterName == this.FieldJsName)) { eq = true; equalsByGetter = false; } else if (fieldName != null && (fieldName == this.JsName || fieldName == this.AltJsName || fieldName == this.FieldJsName)) { eq = true; } } if (eq) { if (p.IsOverride && !this.IsTemplateOverride(p)) { return(false); } if (equalsByGetter.HasValue && this.Member is IMethod && this.AltJsName == null) { this.AltJsName = Helpers.GetPropertyRef(p, this.Emitter, equalsByGetter.Value, true, true); } return(true); } return(false); }); list.AddRange(properties); if (this.Inherit) { var baseTypeDefinitions = typeDef.DirectBaseTypes.Where(t => t.Kind == typeDef.Kind || (typeDef.Kind == TypeKind.Struct && t.Kind == TypeKind.Class)); foreach (var baseTypeDef in baseTypeDefinitions) { var result = this.GetPropertyOverloads(list, baseTypeDef.GetDefinition()); list.AddRange(result); } } } return(isTop ? list.Distinct().ToList() : list); }
protected virtual List <IMethod> GetMethodOverloads(List <IMethod> list = null, ITypeDefinition typeDef = null) { bool isTop = list == null; list = list ?? new List <IMethod>(); typeDef = typeDef ?? this.TypeDefinition; if (typeDef != null) { var methods = typeDef.Methods.Where(m => { if (m.IsExplicitInterfaceImplementation) { return(false); } if (!this.IncludeInline) { var inline = this.Emitter.GetInline(m); if (!string.IsNullOrWhiteSpace(inline)) { return(false); } } var name = this.Emitter.GetEntityName(m, false, true); if ((name == this.JsName || name == this.AltJsName || name == this.FieldJsName) && m.IsStatic == this.Static && ((m.IsConstructor && this.JsName == JS.Funcs.CONSTRUCTOR) || m.IsConstructor == this.Constructor)) { if (m.IsConstructor != this.Constructor && (m.Parameters.Count > 0 || m.DeclaringTypeDefinition != this.TypeDefinition)) { return(false); } if (m.IsOverride && !this.IsTemplateOverride(m)) { return(false); } return(true); } return(false); }); list.AddRange(methods); if (this.Inherit) { var baseTypeDefinitions = typeDef.DirectBaseTypes.Where(t => t.Kind == typeDef.Kind || (typeDef.Kind == TypeKind.Struct && t.Kind == TypeKind.Class)); foreach (var baseTypeDef in baseTypeDefinitions) { var result = this.GetMethodOverloads(list, baseTypeDef.GetDefinition()); list.AddRange(result); } } } return(isTop ? list.Distinct().ToList() : list); }
protected virtual List <IMethod> GetMethodOverloads(List <IMethod> list = null, ITypeDefinition typeDef = null) { typeDef = typeDef ?? this.TypeDefinition; bool isTop = list == null; list = list ?? new List <IMethod>(); var toStringOverride = (this.JsName == "toString" && this.Member is IMethod && ((IMethod)this.Member).Parameters.Count == 0); if (this.Member != null && this.Member.IsOverride && (!this.IsTemplateOverride(this.Member) || toStringOverride)) { if (this.OriginalMember == null) { this.OriginalMember = this.Member; } this.Member = InheritanceHelper.GetBaseMember(this.Member); typeDef = this.Member.DeclaringTypeDefinition; } if (typeDef != null) { var isExternalType = this.Emitter.Validator.IsExternalType(typeDef); bool externalFound = false; var oldIncludeInline = this.IncludeInline; if (toStringOverride) { this.IncludeInline = true; } var methods = typeDef.Methods.Where(m => { if (m.IsExplicitInterfaceImplementation) { return(false); } if (!this.IncludeInline) { var inline = this.Emitter.GetInline(m); if (!string.IsNullOrWhiteSpace(inline) && !(m.Name == "ToString" && m.Parameters.Count == 0 && !m.IsOverride)) { return(false); } } var name = this.Emitter.GetEntityName(m); if ((name == this.JsName || name == this.AltJsName || name == this.FieldJsName) && m.IsStatic == this.Static && (m.IsConstructor && this.JsName == JS.Funcs.CONSTRUCTOR || m.IsConstructor == this.Constructor)) { if (m.IsConstructor != this.Constructor && (m.Parameters.Count > 0 || m.DeclaringTypeDefinition != this.TypeDefinition)) { return(false); } if (m.IsOverride && (!this.IsTemplateOverride(m) || m.Name == "ToString" && m.Parameters.Count == 0)) { return(false); } if (!isExternalType) { var isExtern = !m.HasBody && !m.IsAbstract || this.Emitter.Validator.IsExternalType(m); if (isExtern) { return(false); } } else { if (externalFound) { return(false); } externalFound = true; } return(true); } return(false); }); this.IncludeInline = oldIncludeInline; list.AddRange(methods); if (this.Inherit) { var baseTypeDefinitions = typeDef.DirectBaseTypes.Where(t => t.Kind == typeDef.Kind || (typeDef.Kind == TypeKind.Struct && t.Kind == TypeKind.Class)); foreach (var baseTypeDef in baseTypeDefinitions) { list = this.GetMethodOverloads(list, baseTypeDef.GetDefinition()); } } } var returnMethods = isTop ? list.Distinct().ToList() : list; return(returnMethods); }
protected virtual List<IProperty> GetPropertyOverloads(List<IProperty> list = null, ITypeDefinition typeDef = null) { typeDef = typeDef ?? this.TypeDefinition; bool isTop = list == null; list = list ?? new List<IProperty>(); if (this.Member != null && this.Member.IsOverride && !this.IsTemplateOverride(this.Member)) { if (this.OriginalMember == null) { this.OriginalMember = this.Member; } this.Member = InheritanceHelper.GetBaseMember(this.Member); typeDef = this.Member.DeclaringTypeDefinition; } if (typeDef != null) { bool isMember = this.Member is IMethod; var properties = typeDef.Properties.Where(p => { if (p.IsExplicitInterfaceImplementation) { return false; } var canGet = p.CanGet && p.Getter != null; var canSet = p.CanSet && p.Setter != null; if (!this.IncludeInline) { var inline = canGet ? this.Emitter.GetInline(p.Getter) : null; if (!string.IsNullOrWhiteSpace(inline)) { return false; } inline = canSet ? this.Emitter.GetInline(p.Setter) : null; if (!string.IsNullOrWhiteSpace(inline)) { return false; } if (p.IsIndexer && canGet && p.Getter.Attributes.Any(a => a.AttributeType.FullName == "Bridge.ExternalAttribute")) { return false; } } bool eq = false; bool? equalsByGetter = null; if (p.IsStatic == this.Static) { var fieldName = this.Emitter.GetEntityName(p); if (fieldName != null && (fieldName == this.JsName || fieldName == this.AltJsName || fieldName == this.FieldJsName)) { eq = true; } if (!eq && p.IsIndexer) { var getterIgnore = canGet && this.Emitter.Validator.IsExternalType(p.Getter); var setterIgnore = canSet && this.Emitter.Validator.IsExternalType(p.Setter); var getterName = canGet ? Helpers.GetPropertyRef(p, this.Emitter, false, true, true) : null; var setterName = canSet ? Helpers.GetPropertyRef(p, this.Emitter, true, true, true) : null; if (!getterIgnore && getterName != null && (getterName == this.JsName || getterName == this.AltJsName || getterName == this.FieldJsName)) { eq = true; equalsByGetter = true; } else if (!setterIgnore && setterName != null && (setterName == this.JsName || setterName == this.AltJsName || setterName == this.FieldJsName)) { eq = true; equalsByGetter = false; } } } if (eq) { if (p.IsOverride && !this.IsTemplateOverride(p)) { return false; } if (equalsByGetter.HasValue && isMember && this.AltJsName == null) { this.AltJsName = Helpers.GetPropertyRef(p, this.Emitter, equalsByGetter.Value, true, true); } return true; } return false; }); list.AddRange(properties); if (this.Inherit) { var baseTypeDefinitions = typeDef.DirectBaseTypes.Where(t => t.Kind == typeDef.Kind || (typeDef.Kind == TypeKind.Struct && t.Kind == TypeKind.Class)); foreach (var baseTypeDef in baseTypeDefinitions) { list = this.GetPropertyOverloads(list, baseTypeDef.GetDefinition()); } } } var returnProperties = isTop ? list.Distinct().ToList() : list; return returnProperties; }
public virtual Task <Script> InsertWithCursor(string operation, ITypeDefinition parentType, Func <Script, RefactoringContext, IList <AstNode> > nodeCallback) { throw new NotImplementedException(); }
public virtual bool IsExternalInterface(ICSharpCode.NRefactory.TypeSystem.ITypeDefinition typeDefinition) { string externalAttr = Translator.Bridge_ASSEMBLY + ".ExternalInterfaceAttribute"; return(typeDefinition.Attributes.Any(attr => attr.Constructor != null && (attr.Constructor.DeclaringType.FullName == externalAttr))); }
public virtual bool IsIgnoreType(ICSharpCode.NRefactory.TypeSystem.ITypeDefinition typeDefinition, bool ignoreLiteral = false) { string name = typeDefinition.FullName; return(BaseTypeFullNames.Contains(name)); }
public virtual Task<Script> InsertWithCursor(string operation, ITypeDefinition parentType, Func<Script, RefactoringContext, IList<AstNode>> nodeCallback) { throw new NotImplementedException(); }
public Task<Script> InsertWithCursor(string operation, ITypeDefinition parentType, Func<Script, RefactoringContext, AstNode> nodeCallback) { return InsertWithCursor(operation, parentType, (Func<Script, RefactoringContext, IList<AstNode>>)delegate (Script s, RefactoringContext ctx) { return new AstNode[] { nodeCallback(s, ctx) }; }); }
public Task <Script> InsertWithCursor(string operation, ITypeDefinition parentType, Func <Script, RefactoringContext, AstNode> nodeCallback) { return(InsertWithCursor(operation, parentType, (Func <Script, RefactoringContext, IList <AstNode> >) delegate(Script s, RefactoringContext ctx) { return new AstNode[] { nodeCallback(s, ctx) }; })); }