void AddMethod(MethodDefinition method) { if (IsVisible(method.Attributes)) { DefaultMethod m = new DefaultMethod(this, method.IsConstructor ? "#ctor" : method.Name); if (method.GenericParameters.Count > 0) { foreach (GenericParameter g in method.GenericParameters) { m.TypeParameters.Add(new DefaultTypeParameter(m, g.Name, g.Position)); } int i = 0; foreach (GenericParameter g in method.GenericParameters) { AddConstraintsFromType(m.TypeParameters[i++], g); } } m.ReturnType = CreateType(this.ProjectContent, m, method.ReturnType.ReturnType); if (this.ClassType == ClassType.Interface) { m.Modifiers = ModifierEnum.Public | ModifierEnum.Abstract; } else { m.Modifiers = TranslateModifiers(method); } AddParameters(m, method.Parameters); AddExplicitInterfaceImplementations(method.Overrides, m); Methods.Add(m); } }
/// <summary> /// Adds extension methods to <paramref name="res"/>. /// </summary> public static void AddExtensions(LanguageProperties language, ArrayList res, IClass callingClass, IReturnType resolvedType) { if (language == null) { throw new ArgumentNullException("language"); } if (res == null) { throw new ArgumentNullException("res"); } if (callingClass == null) { throw new ArgumentNullException("callingClass"); } if (resolvedType == null) { throw new ArgumentNullException("resolvedType"); } bool supportsExtensionMethods = language.SupportsExtensionMethods; bool supportsExtensionProperties = language.SupportsExtensionProperties; if (supportsExtensionMethods || supportsExtensionProperties) { ArrayList list = new ArrayList(); IMethod dummyMethod = new DefaultMethod("dummy", VoidReturnType.Instance, ModifierEnum.Static, DomRegion.Empty, DomRegion.Empty, callingClass); CtrlSpaceResolveHelper.AddContentsFromCalling(list, callingClass, dummyMethod); CtrlSpaceResolveHelper.AddImportedNamespaceContents(list, callingClass.CompilationUnit, callingClass); bool searchExtensionsInClasses = language.SearchExtensionsInClasses; foreach (object o in list) { if (supportsExtensionMethods && o is IMethod || supportsExtensionProperties && o is IProperty) { TryAddExtension(language, res, o as IMethodOrProperty, resolvedType); } else if (searchExtensionsInClasses && o is IClass) { IClass c = o as IClass; if (c.HasExtensionMethods) { if (supportsExtensionProperties) { foreach (IProperty p in c.Properties) { TryAddExtension(language, res, p, resolvedType); } } if (supportsExtensionMethods) { foreach (IMethod m in c.Methods) { TryAddExtension(language, res, m, resolvedType); } } } } } } }
IMethod ReadMethod() { DefaultMethod m = new DefaultMethod(currentClass, ReadString()); currentMethod = m; ReadMember(m); int count = reader.ReadByte(); for (int i = 0; i < count; i++) { m.TypeParameters.Add(new DefaultTypeParameter(m, ReadString(), i)); } if (count > 0) { foreach (ITypeParameter typeParameter in m.TypeParameters) { count = reader.ReadInt32(); for (int i = 0; i < count; i++) { typeParameter.Constraints.Add(ReadType()); } } } else { m.TypeParameters = DefaultTypeParameter.EmptyTypeParameterList; } m.ReturnType = ReadType(); m.IsExtensionMethod = reader.ReadBoolean(); ReadParameters(m); currentMethod = null; return(m); }
public void ExpressionResultContextShowItemReturnsTrueForIMethod() { MockProjectContent projectContent = new MockProjectContent(); DefaultCompilationUnit unit = new DefaultCompilationUnit(projectContent); DefaultClass c = new DefaultClass(unit, "MyClass"); DefaultMethod method = new DefaultMethod(c, "Test"); Assert.IsTrue(expressionResult.Context.ShowEntry(method)); }
void CreateResolver() { resolverHelper = new PythonResolverTestsHelper(); myClass = resolverHelper.CreateClass("MyClass"); myMethod = myClass.AddMethod("MyMethod"); myMethod.ReturnType = new DefaultReturnType(myClass); resolverHelper.ProjectContent.SetClassToReturnFromGetClass("MyClass", myClass); }
public void FindMethodFromArrayReturnsNullForUnknownMethod() { DefaultClass c = new DefaultClass(new DefaultCompilationUnit(new DefaultProjectContent()), "Test"); DefaultMethod method = new DefaultMethod(c, "abc"); ArrayList items = new ArrayList(); items.Add(method); Assert.IsNull(PythonCompletionItemsHelper.FindMethodFromCollection("unknown", items)); }
public void FindMethodFromArrayReturnsExpectedMethod() { DefaultClass c = CreateClass(); DefaultMethod method = new DefaultMethod(c, "abc"); ArrayList items = new ArrayList(); items.Add(method); Assert.AreEqual(method, PythonCompletionItemsHelper.FindMethodFromCollection("abc", items)); }
public override IMember Clone() { DefaultMethod p = new DefaultMethod(Name, ReturnType, Modifiers, Region, BodyRegion, DeclaringType); p.parameters = DefaultParameter.Clone(this.Parameters); p.typeParameters = new List<ITypeParameter>(this.typeParameters); p.CopyDocumentationFrom(this); p.isExtensionMethod = this.isExtensionMethod; foreach (ExplicitInterfaceImplementation eii in InterfaceImplementations) { p.InterfaceImplementations.Add(eii.Clone()); } return p; }
void ReadParameters(DefaultMethod m) { int count = reader.ReadUInt16(); if (count > 0) { ReadParameters(m.Parameters, count); } else { m.Parameters = DefaultParameter.EmptyParameterList; } }
public override IMember Clone() { DefaultMethod p = new DefaultMethod(Name, ReturnType, Modifiers, Region, BodyRegion, DeclaringType); p.parameters = DefaultParameter.Clone(this.Parameters); p.typeParameters = new List <ITypeParameter>(this.typeParameters); p.CopyDocumentationFrom(this); p.isExtensionMethod = this.isExtensionMethod; foreach (ExplicitInterfaceImplementation eii in InterfaceImplementations) { p.InterfaceImplementations.Add(eii.Clone()); } return(p); }
public void Init() { DefaultProjectContent projectContent = new DefaultProjectContent(); unit = new DefaultCompilationUnit(projectContent); DefaultClass c = new DefaultClass(unit, "Foo"); DefaultMethod buttonClickMethod = new DefaultMethod(c, "ButtonClick"); AddSenderAndEventArgsParameters(buttonClickMethod); c.Methods.Add(buttonClickMethod); projectContent.AddClassToNamespaceList(c); parseInfo = new ParseInformation(unit); }
internal static void AddDefaultDelegateMethod(DefaultClass c, IReturnType returnType, IList<IParameter> parameters) { ModifierEnum modifiers = ModifierEnum.Public | ModifierEnum.Synthetic; DefaultMethod invokeMethod = new DefaultMethod("Invoke", returnType, modifiers, c.Region, DomRegion.Empty, c); foreach (IParameter par in parameters) { invokeMethod.Parameters.Add(par); } c.Methods.Add(invokeMethod); invokeMethod = new DefaultMethod("BeginInvoke", c.ProjectContent.SystemTypes.IAsyncResult, modifiers, c.Region, DomRegion.Empty, c); foreach (IParameter par in parameters) { invokeMethod.Parameters.Add(par); } invokeMethod.Parameters.Add(new DefaultParameter("callback", c.ProjectContent.SystemTypes.AsyncCallback, DomRegion.Empty)); invokeMethod.Parameters.Add(new DefaultParameter("object", c.ProjectContent.SystemTypes.Object, DomRegion.Empty)); c.Methods.Add(invokeMethod); invokeMethod = new DefaultMethod("EndInvoke", returnType, modifiers, c.Region, DomRegion.Empty, c); invokeMethod.Parameters.Add(new DefaultParameter("result", c.ProjectContent.SystemTypes.IAsyncResult, DomRegion.Empty)); c.Methods.Add(invokeMethod); }
internal static void AddDefaultDelegateMethod(DefaultClass c, IReturnType returnType, IList <IParameter> parameters) { ModifierEnum modifiers = ModifierEnum.Public | ModifierEnum.Synthetic; DefaultMethod invokeMethod = new DefaultMethod("Invoke", returnType, modifiers, c.Region, DomRegion.Empty, c); foreach (IParameter par in parameters) { invokeMethod.Parameters.Add(par); } c.Methods.Add(invokeMethod); invokeMethod = new DefaultMethod("BeginInvoke", c.ProjectContent.SystemTypes.IAsyncResult, modifiers, c.Region, DomRegion.Empty, c); foreach (IParameter par in parameters) { invokeMethod.Parameters.Add(par); } invokeMethod.Parameters.Add(new DefaultParameter("callback", c.ProjectContent.SystemTypes.AsyncCallback, DomRegion.Empty)); invokeMethod.Parameters.Add(new DefaultParameter("object", c.ProjectContent.SystemTypes.Object, DomRegion.Empty)); c.Methods.Add(invokeMethod); invokeMethod = new DefaultMethod("EndInvoke", returnType, modifiers, c.Region, DomRegion.Empty, c); invokeMethod.Parameters.Add(new DefaultParameter("result", c.ProjectContent.SystemTypes.IAsyncResult, DomRegion.Empty)); c.Methods.Add(invokeMethod); }
public ICompilationUnit Parse(IProjectContent projectContent, string fileName, ITextBuffer fileContent) { Init(fileContent.Text); SimpleCocoParser parser = new SimpleCocoParser(new Scanner(new StringStream(fileContent.Text))); parser.Parse(); DefaultCompilationUnit cu = new DefaultCompilationUnit(projectContent); Location start, end; if (parser.CopySection != null) { start = OffsetToLocation(parser.CopySection.StartOffset); end = OffsetToLocation(parser.CopySection.EndOffset); cu.FoldingRegions.Add(new FoldingRegion("[copy]", new DomRegion(start.Line, start.Column, end.Line, end.Column))); } if (parser.UsingSection != null) { start = OffsetToLocation(parser.UsingSection.StartOffset); end = OffsetToLocation(parser.UsingSection.EndOffset); cu.FoldingRegions.Add(new FoldingRegion("[...]", new DomRegion(start.Line, start.Column, end.Line, end.Column))); } DefaultClass parserClass = null; if (parser.ParserSection != null) { start = OffsetToLocation(parser.ParserSection.StartOffset); end = OffsetToLocation(parser.ParserSection.EndOffset); parserClass = new DefaultClass(cu, parser.ParserName); parserClass.ClassType = ClassType.Class; parserClass.Modifiers = ModifierEnum.None; parserClass.Region = new DomRegion(start.Line, start.Column, end.Line, end.Column); cu.Classes.Add(parserClass); foreach (var info in parser.Lists) { start = OffsetToLocation(info.segment.StartOffset); end = OffsetToLocation(info.segment.EndOffset); var region = new DomRegion(start.Line, start.Column, start.Line, start.Column + info.name.Length); var body = new DomRegion(start.Line, start.Column, end.Line, end.Column); var prop = new DefaultProperty(parserClass, info.name) { Region = region, BodyRegion = body, Modifiers = ModifierEnum.Public }; parserClass.Properties.Add(prop); } foreach (var info in parser.Productions) { start = OffsetToLocation(info.segment.StartOffset); end = OffsetToLocation(info.segment.EndOffset); var region = new DomRegion(start.Line, start.Column, start.Line, start.Column + info.name.Length); var body = new DomRegion(start.Line, start.Column, end.Line, end.Column); var method = new DefaultMethod(parserClass, info.name) { Region = region, BodyRegion = body, Modifiers = ModifierEnum.Public }; parserClass.Methods.Add(method); } } return cu; }
IMethod ReadMethod() { DefaultMethod m = new DefaultMethod(currentClass, ReadString()); currentMethod = m; ReadMember(m); int count = reader.ReadByte(); for (int i = 0; i < count; i++) { m.TypeParameters.Add(new DefaultTypeParameter(m, ReadString(), i)); } if (count > 0) { foreach (ITypeParameter typeParameter in m.TypeParameters) { count = reader.ReadInt32(); for (int i = 0; i < count; i++) { typeParameter.Constraints.Add(ReadType()); } } } else { m.TypeParameters = DefaultTypeParameter.EmptyTypeParameterList; } m.ReturnType = ReadType(); m.IsExtensionMethod = reader.ReadBoolean(); ReadParameters(m); currentMethod = null; return m; }
public void FindAllMethodsFromArrayWithParameterCountReturnsExpectedMethods() { DefaultClass c = CreateClass(); DefaultMethod method1 = new DefaultMethod(c, "abc"); method1.Parameters.Add(CreateParameter("a")); DefaultMethod method2 = new DefaultMethod(c, "abc"); method2.Parameters.Add(CreateParameter("a")); method2.Parameters.Add(CreateParameter("b")); DefaultMethod method3 = new DefaultMethod(c, "abc"); method3.Parameters.Add(CreateParameter("c")); ArrayList items = new ArrayList(); items.Add(method1); items.Add(method2); items.Add(method3); List<IMethod> expectedMethods = new List<IMethod>(); expectedMethods.Add(method1); expectedMethods.Add(method3); int parameterCount = 1; List<IMethod> methods = PythonCompletionItemsHelper.FindAllMethodsFromCollection("abc", parameterCount, items); Assert.AreEqual(expectedMethods, methods); }
public override object VisitEventDeclaration(NRefactoryAST.EventDeclaration eventDeclaration, object data) { DomRegion region = GetRegion(eventDeclaration.StartLocation, eventDeclaration.EndLocation); DomRegion bodyRegion = GetRegion(eventDeclaration.BodyStart, eventDeclaration.BodyEnd); DefaultClass c = GetCurrentClass(); IReturnType type; if (eventDeclaration.TypeReference.IsNull) { DefaultClass del = new DefaultClass(cu, ClassType.Delegate, ConvertModifier(eventDeclaration.Modifier), region, c); del.Modifiers |= ModifierEnum.Synthetic; CreateDelegate(del, eventDeclaration.Name + "EventHandler", new NRefactoryAST.TypeReference("System.Void", true), new NRefactoryAST.TemplateDefinition[0], eventDeclaration.Parameters); type = del.DefaultReturnType; } else { type = CreateReturnType(eventDeclaration.TypeReference); } DefaultEvent e = new DefaultEvent(eventDeclaration.Name, type, ConvertModifier(eventDeclaration.Modifier), region, bodyRegion, c); ConvertAttributes(eventDeclaration, e); c.Events.Add(e); e.Documentation = GetDocumentation(region.BeginLine, eventDeclaration.Attributes); if (eventDeclaration.HasAddRegion) { var defaultMethod = new DefaultMethod(e.DeclaringType, "add_" + e.Name); var defaultParameters = new List<IParameter>(); defaultParameters.Add(new DefaultParameter("value", e.ReturnType, DomRegion.Empty)); defaultMethod.Parameters = defaultParameters; defaultMethod.Region = GetRegion(eventDeclaration.AddRegion.StartLocation, eventDeclaration.AddRegion.EndLocation); defaultMethod.BodyRegion = GetRegion(eventDeclaration.AddRegion.Block.StartLocation, eventDeclaration.AddRegion.Block.EndLocation); e.AddMethod = defaultMethod; } if (eventDeclaration.HasRemoveRegion) { var defaultMethod = new DefaultMethod(e.DeclaringType, "remove_" + e.Name); var defaultParameters = new List<IParameter>(); defaultParameters.Add(new DefaultParameter("value", e.ReturnType, DomRegion.Empty)); defaultMethod.Parameters = defaultParameters; defaultMethod.Region = GetRegion(eventDeclaration.RemoveRegion.StartLocation, eventDeclaration.RemoveRegion.EndLocation); defaultMethod.BodyRegion = GetRegion(eventDeclaration.RemoveRegion.Block.StartLocation, eventDeclaration.RemoveRegion.Block.EndLocation); e.RemoveMethod = defaultMethod; } return null; }
public static IList <IMethodOrProperty> FindAllExtensions(LanguageProperties language, IClass callingClass) { if (language == null) { throw new ArgumentNullException("language"); } if (callingClass == null) { throw new ArgumentNullException("callingClass"); } HashSet <IMethodOrProperty> res = new HashSet <IMethodOrProperty>(); bool supportsExtensionMethods = language.SupportsExtensionMethods; bool supportsExtensionProperties = language.SupportsExtensionProperties; if (supportsExtensionMethods || supportsExtensionProperties) { ArrayList list = new ArrayList(); IMethod dummyMethod = new DefaultMethod("dummy", callingClass.ProjectContent.SystemTypes.Void, ModifierEnum.Static, DomRegion.Empty, DomRegion.Empty, callingClass); CtrlSpaceResolveHelper.AddContentsFromCalling(list, callingClass, dummyMethod); CtrlSpaceResolveHelper.AddImportedNamespaceContents(list, callingClass.CompilationUnit, callingClass); bool searchExtensionsInClasses = language.SearchExtensionsInClasses; foreach (object o in list) { IMethodOrProperty mp = o as IMethodOrProperty; if (mp != null && mp.IsExtensionMethod && (supportsExtensionMethods && o is IMethod || supportsExtensionProperties && o is IProperty)) { res.Add(mp); } else if (searchExtensionsInClasses && o is IClass) { IClass c = o as IClass; if (c.HasExtensionMethods) { if (supportsExtensionProperties) { foreach (IProperty p in c.Properties) { if (p.IsExtensionMethod) { res.Add(p); } } } if (supportsExtensionMethods) { foreach (IMethod m in c.Methods) { if (m.IsExtensionMethod) { res.Add(m); } } } } } } } return(res.ToList()); }
/// <summary> /// Gets a method implementing the signature specified by the event descriptor /// </summary> protected static IMethod ConvertEventInvokeMethodToDom(IClass declaringType, Type eventType, string methodName) { MethodInfo mInfo = eventType.GetMethod("Invoke"); DefaultMethod m = new DefaultMethod(declaringType, methodName); m.ReturnType = ReflectionLayer.ReflectionReturnType.Create(m, mInfo.ReturnType); foreach (ParameterInfo pInfo in mInfo.GetParameters()) { m.Parameters.Add(new ReflectionLayer.ReflectionParameter(pInfo, m)); } return m; }
void AddMethod(MethodDefinition method) { if (IsVisible(method.Attributes)) { DefaultMethod m = new DefaultMethod(this, method.IsConstructor ? "#ctor" : method.Name); if (method.GenericParameters.Count > 0) { foreach (GenericParameter g in method.GenericParameters) { m.TypeParameters.Add(new DefaultTypeParameter(m, g.Name, g.Position)); } int i = 0; foreach (GenericParameter g in method.GenericParameters) { AddConstraintsFromType(m.TypeParameters[i++], g); } } if (method.IsConstructor) m.ReturnType = this.DefaultReturnType; else m.ReturnType = CreateType(this.ProjectContent, m, method.ReturnType); AddAttributes(CompilationUnit.ProjectContent, m.Attributes, method.CustomAttributes); if (this.ClassType == ClassType.Interface) { m.Modifiers = ModifierEnum.Public | ModifierEnum.Abstract; } else { m.Modifiers = TranslateModifiers(method); } AddParameters(m, method.Parameters); AddExplicitInterfaceImplementations(method.Overrides, m); ReflectionLayer.ReflectionMethod.ApplySpecialsFromAttributes(m); Methods.Add(m); } }
/// <summary> /// Copies methods from one class to another. /// </summary> /// <param name="oldClass">Source class</param> /// <param name="newClass">Target class</param> private void copyMethods(IClass oldClass, IClass newClass) { foreach(IMethod element in oldClass.Methods){ DefaultMethod newMethod = new DefaultMethod(element.Name,element.ReturnType, element.Modifiers,element.Region,element.BodyRegion,newClass); foreach(IParameter param in element.Parameters){ DefaultParameter newParam = new DefaultParameter(param); newMethod.Parameters.Add(newParam); } newMethod.BodyRegion = new DomRegion(element.BodyRegion.BeginLine,element.BodyRegion.BeginColumn, element.BodyRegion.EndLine,element.BodyRegion.EndColumn); newClass.Methods.Add(newMethod); } }
void AddMethod(NavigateToItem item, IDocument document) { IClass c = FindParentClass(item); var method = new DefaultMethod(c, item.name); UpdateMethodRegions(method, item, document); c.Methods.Add(method); }
public DefaultMethod AddMethod(string name) { DefaultMethod method = new DefaultMethod(this, name); Methods.Add(method); return method; }
public override object VisitDeclareDeclaration(NRefactoryAST.DeclareDeclaration declareDeclaration, object data) { DefaultClass currentClass = GetCurrentClass(); DomRegion region = GetRegion(declareDeclaration.StartLocation, declareDeclaration.EndLocation); DefaultMethod method = new DefaultMethod(declareDeclaration.Name, null, ConvertModifier(declareDeclaration.Modifier), region, DomRegion.Empty, currentClass); method.Documentation = GetDocumentation(region.BeginLine, declareDeclaration.Attributes); method.Modifiers |= ModifierEnum.Extern | ModifierEnum.Static; method.ReturnType = CreateReturnType(declareDeclaration.TypeReference, method, TypeVisitor.ReturnTypeOptions.None); ConvertAttributes(declareDeclaration, method); foreach (NRefactoryAST.ParameterDeclarationExpression par in declareDeclaration.Parameters) { method.Parameters.Add(CreateParameter(par, method)); } currentClass.Methods.Add(method); return null; }
void ConvertTemplates(List<NRefactoryAST.TemplateDefinition> templateList, DefaultMethod m) { int index = 0; if (templateList.Count == 0) { m.TypeParameters = DefaultTypeParameter.EmptyTypeParameterList; } else { Debug.Assert(m.TypeParameters.Count == 0); foreach (NRefactoryAST.TemplateDefinition template in templateList) { m.TypeParameters.Add(new DefaultTypeParameter(m, template.Name, index++)); } // converting the constraints requires that the type parameters are already present for (int i = 0; i < templateList.Count; i++) { ConvertConstraints(templateList[i], (DefaultTypeParameter)m.TypeParameters[i]); } } }
IClass AddClass(string className, AXmlElement element) { if (projectContent.Language == LanguageProperties.VBNet && projectContent.Project is IProject) className = ((IProject)projectContent.Project).RootNamespace + "." + className; DefaultClass c = new DefaultClass(CompilationUnit, className); string modifierValue = (element.GetAttributeValue(CompletionDataHelper.XamlNamespace, "ClassModifier") ?? string.Empty).Trim(); c.Modifiers = ModifierEnum.Partial; string internalString = currentAmbience.ConvertAccessibility(ModifierEnum.Internal).Trim(); if (projectContent.Language.NameComparer.Compare(modifierValue, internalString) == 0) c.Modifiers |= ModifierEnum.Internal; else c.Modifiers |= ModifierEnum.Public; c.Region = CreateRegion(element.StartOffset, element.EndOffset); var baseType = TypeFromXmlNode(CompilationUnit, element); if (baseType != null) c.BaseTypes.Add(baseType); CompilationUnit.Classes.Add(c); DefaultMethod initializeComponent = new DefaultMethod( "InitializeComponent", projectContent.SystemTypes.Void, ModifierEnum.Public | ModifierEnum.Synthetic, c.Region, DomRegion.Empty, c); c.Methods.Add(initializeComponent); return c; }
public override object VisitMethodDeclaration(NRefactoryAST.MethodDeclaration methodDeclaration, object data) { DomRegion region = GetRegion(methodDeclaration.StartLocation, methodDeclaration.EndLocation); DomRegion bodyRegion = GetRegion(methodDeclaration.EndLocation, methodDeclaration.Body != null ? methodDeclaration.Body.EndLocation : RefParser.Location.Empty); DefaultClass currentClass = GetCurrentClass(); DefaultMethod method = new DefaultMethod(methodDeclaration.Name, null, ConvertModifier(methodDeclaration.Modifier), region, bodyRegion, currentClass); method.IsExtensionMethod = methodDeclaration.IsExtensionMethod; method.Documentation = GetDocumentation(region.BeginLine, methodDeclaration.Attributes); ConvertTemplates(methodDeclaration.Templates, method); method.ReturnType = CreateReturnType(methodDeclaration.TypeReference, method, TypeVisitor.ReturnTypeOptions.None); ConvertAttributes(methodDeclaration, method); if (methodDeclaration.Parameters.Count > 0) { foreach (NRefactoryAST.ParameterDeclarationExpression par in methodDeclaration.Parameters) { method.Parameters.Add(CreateParameter(par, method)); } } else { method.Parameters = DefaultParameter.EmptyParameterList; } if (methodDeclaration.HandlesClause.Count > 0) { foreach (string handlesClause in methodDeclaration.HandlesClause) { if (handlesClause.ToLowerInvariant().StartsWith("me.")) method.HandlesClauses.Add(handlesClause.Substring(3)); else if (handlesClause.ToLowerInvariant().StartsWith("mybase.")) method.HandlesClauses.Add(handlesClause.Substring(7)); else method.HandlesClauses.Add(handlesClause); } } else { method.HandlesClauses = EmptyList<string>.Instance; } currentClass.Methods.Add(method); mapMethod(methodDeclaration, method); return null; }
public static IList<IMethodOrProperty> FindAllExtensions(LanguageProperties language, IClass callingClass, bool searchInAllNamespaces = false) { if (language == null) throw new ArgumentNullException("language"); if (callingClass == null) throw new ArgumentNullException("callingClass"); HashSet<IMethodOrProperty> res = new HashSet<IMethodOrProperty>(); bool supportsExtensionMethods = language.SupportsExtensionMethods; bool supportsExtensionProperties = language.SupportsExtensionProperties; if (supportsExtensionMethods || supportsExtensionProperties) { List<ICompletionEntry> list = new List<ICompletionEntry>(); IMethod dummyMethod = new DefaultMethod("dummy", callingClass.ProjectContent.SystemTypes.Void, ModifierEnum.Static, DomRegion.Empty, DomRegion.Empty, callingClass); CtrlSpaceResolveHelper.AddContentsFromCalling(list, callingClass, dummyMethod); if (searchInAllNamespaces) { // search extension methods in all referenced projects, no matter the using section CtrlSpaceResolveHelper.AddReferencedProjectsContents(list, callingClass.CompilationUnit, callingClass); } else { CtrlSpaceResolveHelper.AddImportedNamespaceContents(list, callingClass.CompilationUnit, callingClass); } bool searchExtensionsInClasses = language.SearchExtensionsInClasses; foreach (object o in list) { IMethodOrProperty mp = o as IMethodOrProperty; if (mp != null && mp.IsExtensionMethod && (supportsExtensionMethods && o is IMethod || supportsExtensionProperties && o is IProperty)) { res.Add(mp); } else if (searchExtensionsInClasses && o is IClass) { IClass c = o as IClass; if (c.HasExtensionMethods) { if (supportsExtensionProperties) { foreach (IProperty p in c.Properties) { if (p.IsExtensionMethod) res.Add(p); } } if (supportsExtensionMethods) { foreach (IMethod m in c.Methods) { if (m.IsExtensionMethod) res.Add(m); } } } } } } return res.ToList(); } // FindAllExtensions
public override object VisitOperatorDeclaration(NRefactoryAST.OperatorDeclaration operatorDeclaration, object data) { DefaultClass c = GetCurrentClass(); DomRegion region = GetRegion(operatorDeclaration.StartLocation, operatorDeclaration.EndLocation); DomRegion bodyRegion = GetRegion(operatorDeclaration.EndLocation, operatorDeclaration.Body != null ? operatorDeclaration.Body.EndLocation : RefParser.Location.Empty); DefaultMethod method = new DefaultMethod(operatorDeclaration.Name, CreateReturnType(operatorDeclaration.TypeReference), ConvertModifier(operatorDeclaration.Modifier), region, bodyRegion, c); ConvertAttributes(operatorDeclaration, method); if(operatorDeclaration.Parameters != null) { foreach (NRefactoryAST.ParameterDeclarationExpression par in operatorDeclaration.Parameters) { method.Parameters.Add(CreateParameter(par, method)); } } c.Methods.Add(method); return null; }
void ConvertTemplates(AST.Node node, DefaultMethod m) { m.TypeParameters = DefaultTypeParameter.EmptyTypeParameterList; }
void UpdateRegions(DefaultMethod method) { var methodRegion = new JavaScriptMethodRegion(ast, tree); method.Region = methodRegion.GetHeaderRegion(); method.BodyRegion = methodRegion.GetBodyRegion(); }
void ConvertParameters(AST.ParameterDeclarationCollection parameters, DefaultMethod m) { if (parameters == null || parameters.Count == 0) { m.Parameters = DefaultParameter.EmptyParameterList; } else { AddParameters(parameters, m.Parameters, m, m.DeclaringType); } }
void UpdateMethodRegions(DefaultMethod method, NavigateToItem item, IDocument document) { DomRegion region = item.ToRegion(document); method.Region = new DomRegion( region.BeginLine, region.BeginColumn, region.BeginLine, region.BeginColumn); method.BodyRegion = region; }
public override void OnCallableDefinition(AST.CallableDefinition node) { LoggingService.Debug("OnCallableDefinition: " + node.FullName); DomRegion region = GetRegion(node); DefaultClass c = new DefaultClass(_cu, ClassType.Delegate, GetModifier(node), region, OuterClass); ConvertAttributes(node, c); c.BaseTypes.Add(c.ProjectContent.SystemTypes.Delegate); c.FullyQualifiedName = node.FullName; if (_currentClass.Count > 0) { OuterClass.InnerClasses.Add(c); } else { _cu.Classes.Add(c); } _currentClass.Push(c); // necessary for CreateReturnType ConvertTemplates(node, c); IReturnType returnType = CreateReturnType(node.ReturnType); DefaultMethod invokeMethod = new DefaultMethod("Invoke", returnType, ModifierEnum.Public, DomRegion.Empty, DomRegion.Empty, c); ConvertParameters(node.Parameters, invokeMethod); c.Methods.Add(invokeMethod); invokeMethod = new DefaultMethod("BeginInvoke", c.ProjectContent.SystemTypes.IAsyncResult, ModifierEnum.Public, DomRegion.Empty, DomRegion.Empty, c); ConvertParameters(node.Parameters, invokeMethod); if (invokeMethod.Parameters == DefaultParameter.EmptyParameterList) { invokeMethod.Parameters = new List<IParameter>(); } invokeMethod.Parameters.Add(new DefaultParameter("callback", c.ProjectContent.SystemTypes.AsyncCallback, DomRegion.Empty)); invokeMethod.Parameters.Add(new DefaultParameter("object", c.ProjectContent.SystemTypes.Object, DomRegion.Empty)); c.Methods.Add(invokeMethod); invokeMethod = new DefaultMethod("EndInvoke", returnType, ModifierEnum.Public, DomRegion.Empty, DomRegion.Empty, c); invokeMethod.Parameters.Add(new DefaultParameter("result", c.ProjectContent.SystemTypes.IAsyncResult, DomRegion.Empty)); c.Methods.Add(invokeMethod); _currentClass.Pop(); }
public void SetupDataProvider(string fileName, TextArea textArea) { if (setupOnlyOnce && this.textArea != null) return; IDocument document = textArea.Document; this.fileName = fileName; this.document = document; this.textArea = textArea; int useOffset = (lookupOffset < 0) ? textArea.Caret.Offset : lookupOffset; initialOffset = useOffset; ExpressionResult expressionResult = new ExpressionResult(TextUtilities.GetExpressionBeforeOffset(textArea, useOffset)); if (expressionResult.Expression == null) // expression is null when cursor is in string/comment return; expressionResult.Expression = expressionResult.Expression.Trim(); string expression = (expressionResult.Expression ?? "").Trim(); if (!string.IsNullOrEmpty(expression)) { if (mainForm.Specification != null) { DefaultMethod m = new DefaultMethod(dummyClass, expression); string[] parameters = mainForm.Specification.GetParameterNames(expression); if(parameters != null) { foreach (string parameter in parameters) { m.Parameters.Add(new DefaultParameter(parameter, varClass.DefaultReturnType, DomRegion.Empty)); } //// for the insight window, remove first parameter and mark the //// method as normal - this is required to show the list of //// parameters the method expects. m.IsExtensionMethod = false; methods.Add(m); } } } // foreach (KeyValuePair<string, List<FuncStruct>> pair in PredefinedFuncTable.symbolTableList) // { // if (pair.Key == expression) // { // string funName = pair.Key; // foreach (FuncStruct func in pair.Value) // { // if (func.getFuncName() != null) // { // DefaultMethod m = new DefaultMethod(dummyClass, funName); // m.ReturnType = GetType(func.getReturnType()); // //m.Documentation = func.Description; // List<int> types = func.getParamTypes(); // List<string> names = func.getParamNames(); // for (int i = 0; i < types.Count; i++) // { // int type = types[i]; // string name = names[i]; // m.Parameters.Add(new DefaultParameter(name, GetType(type), DomRegion.Empty)); // } // //// for the insight window, remove first parameter and mark the // //// method as normal - this is required to show the list of // //// parameters the method expects. // m.IsExtensionMethod = false; // //m.Parameters.RemoveAt(0); // methods.Add(m); // } // } // } // } //} //if (setupOnlyOnce && this.textArea != null) return; //IDocument document = textArea.Document; //this.fileName = fileName; //this.document = document; //this.textArea = textArea; //int useOffset = (lookupOffset < 0) ? textArea.Caret.Offset : lookupOffset; //initialOffset = useOffset; //IExpressionFinder expressionFinder = ParserService.GetExpressionFinder(fileName); //ExpressionResult expressionResult; //if (expressionFinder == null) // expressionResult = new ExpressionResult(TextUtilities.GetExpressionBeforeOffset(textArea, useOffset)); //else // expressionResult = expressionFinder.FindExpression(textArea.Document.TextContent, useOffset); //if (expressionResult.Expression == null) // expression is null when cursor is in string/comment // return; //expressionResult.Expression = expressionResult.Expression.Trim(); //if (LoggingService.IsDebugEnabled) { // if (expressionResult.Context == ExpressionContext.Default) // LoggingService.DebugFormatted("ShowInsight for >>{0}<<", expressionResult.Expression); // else // LoggingService.DebugFormatted("ShowInsight for >>{0}<<, context={1}", expressionResult.Expression, expressionResult.Context); //} //int caretLineNumber = document.GetLineNumberForOffset(useOffset); //int caretColumn = useOffset - document.GetLineSegment(caretLineNumber).Offset; //// the parser works with 1 based coordinates //SetupDataProvider(fileName, document, expressionResult, caretLineNumber + 1, caretColumn + 1); }
public override void OnMethod(AST.Method node) { //LoggingService.Debug("Method: " + node.FullName + " (" + node.Modifiers + ")"); DefaultMethod method = new DefaultMethod(node.Name, null, GetModifier(node), GetRegion(node), GetClientRegion(node), OuterClass); foreach (AST.Attribute a in node.Attributes) { if (a.Name == "Extension" || a.Name == "Boo.Lang.Extension" || a.Name == "ExtensionAttribute" || a.Name == "Boo.Lang.ExtensionAttribute") { method.IsExtensionMethod = true; } } ConvertAttributes(node, method); ConvertTemplates(node, method); // return type must be assigned AFTER ConvertTemplates method.ReturnType = CreateReturnType(node, method); ConvertParameters(node.Parameters, method); _currentClass.Peek().Methods.Add(method); method.UserData = node; }