Exemplo n.º 1
0
 public override void ApplyInterningProvider(IInterningProvider provider)
 {
     base.ApplyInterningProvider(provider);
     getter     = provider.Intern(getter);
     setter     = provider.Intern(setter);
     parameters = provider.InternList(parameters);
 }
            public void AddMember(IUnresolvedEntity entity, Mono.Cecil.MemberReference cecilObject)
            {
                rwLock.EnterWriteLock();
                try {
                    uint token = cecilObject.MetadataToken.ToUInt32();
                    metadataTokens[entity] = token;

                    var cecilMethod = cecilObject as Mono.Cecil.MethodDefinition;
                    if (cecilMethod != null)
                    {
                        IUnresolvedMethod method = (IUnresolvedMethod)entity;
                        tokenToMethod[token] = method;
                        if (cecilMethod.HasBody)
                        {
                            var locals = cecilMethod.Body.Variables;
                            if (locals.Count > 0)
                            {
                                localVariableTypes[method] = locals.Select(v => typeRefLoader.ReadTypeReference(v.VariableType)).ToArray();
                            }
                            if (cecilMethod.RVA != 0)
                            {
                                // The method was loaded from image - we can free the memory for the body
                                // because Cecil will re-initialize it on demand
                                cecilMethod.Body = null;
                            }
                        }
                    }
                } finally {
                    rwLock.ExitWriteLock();
                }
            }
Exemplo n.º 3
0
		public NUnitTestMethod(ITestProject parentProject, IUnresolvedMethod method, FullTypeName derivedFixture = default(FullTypeName))
		{
			if (parentProject == null)
				throw new ArgumentNullException("parentProject");
			this.parentProject = parentProject;
			UpdateTestMethod(method, derivedFixture);
		}
Exemplo n.º 4
0
		public override void ApplyInterningProvider(IInterningProvider provider)
		{
			base.ApplyInterningProvider(provider);
			addAccessor    = provider.Intern(addAccessor);
			removeAccessor = provider.Intern(removeAccessor);
			invokeAccessor = provider.Intern(invokeAccessor);
		}
Exemplo n.º 5
0
        private static IMember ConvertToMember(IUnresolvedMember input)
        {
            IUnresolvedField field = input as IUnresolvedField;

            if (field != null)
            {
                return(new VB6Field(field));
            }

            IUnresolvedMethod method = input as IUnresolvedMethod;

            if (method != null)
            {
                return(new VB6Method(method));
            }

            IUnresolvedProperty property = input as IUnresolvedProperty;

            if (property != null)
            {
                return(new VB6Property(property));
            }

            return(null);
        }
Exemplo n.º 6
0
        IEnumerable <IMethod> GetFilteredMethods(Predicate <IUnresolvedMethod> filter)
        {
            var members = GetMemberList();

            for (int i = 0; i < members.unresolvedMembers.Length; i++)
            {
                IUnresolvedMethod unresolved = members.unresolvedMembers[i] as IUnresolvedMethod;
                if (unresolved != null && (filter == null || filter(unresolved)))
                {
                    yield return((IMethod)members[i]);
                }
            }
            for (int i = members.unresolvedMembers.Length; i < members.Count; i++)
            {
                var  method = (IMethod)members[i];
                bool ok     = false;
                foreach (var part in method.Parts)
                {
                    if (filter == null || filter(part))
                    {
                        ok = true;
                        break;
                    }
                }
                if (ok)
                {
                    yield return(method);
                }
            }
        }
Exemplo n.º 7
0
        public DelegateDeclaration(TypeContainer parent, FullNamedExpression type, Modifiers mod_flags, MemberName name, ParametersCompiled param_list,
                                   VSharpAttributes attrs, CompilationSourceFile file)
            : base(parent, mod_flags | Modifiers.SEALED, AllowedModifiers, name, attrs, name.Location, TypeKind.Delegate, file)

        {
            BaseTypes.Add(KnownTypeReference.MulticastDelegate);
            this.ReturnType = type;
            parameters      = param_list;
            List <IUnresolvedParameter> uparameters = new List <IUnresolvedParameter>();

            foreach (Parameter p in param_list.parameters)
            {
                uparameters.Add(p);
            }


            AddDefaultMethodsToDelegate(type as ITypeReference, uparameters);


            if (attrs != null)
            {
                IUnresolvedMethod invokeMethod = (IUnresolvedMethod)Members.Single(m => m.Name == "Invoke");
                foreach (IUnresolvedAttribute attr in attrs.Attrs.Where(x => x.ExplicitTarget == "ret").ToList())
                {
                    invokeMethod.ReturnTypeAttributes.Add(attr);
                }
            }
        }
Exemplo n.º 8
0
		public override void ApplyInterningProvider(IInterningProvider provider)
		{
			base.ApplyInterningProvider(provider);
			getter = provider.Intern(getter);
			setter = provider.Intern(setter);
			parameters = provider.InternList(parameters);
		}
Exemplo n.º 9
0
 public override void ApplyInterningProvider(IInterningProvider provider)
 {
     base.ApplyInterningProvider(provider);
     addAccessor    = provider.Intern(addAccessor);
     removeAccessor = provider.Intern(removeAccessor);
     invokeAccessor = provider.Intern(invokeAccessor);
 }
Exemplo n.º 10
0
 public PartialMethodInfo(IUnresolvedMethod method, ITypeResolveContext context)
 {
     this.Name = method.Name;
     this.TypeParameterCount = method.TypeParameters.Count;
     this.Parameters         = method.Parameters.CreateResolvedParameters(context);
     this.Parts.Add(method);
     this.Contexts.Add(context);
 }
Exemplo n.º 11
0
 public DefaultResolvedMethod(IUnresolvedMethod unresolved, ITypeResolveContext parentContext, bool isExtensionMethod)
     : base(unresolved, parentContext)
 {
     this.Parameters           = unresolved.Parameters.CreateResolvedParameters(context);
     this.ReturnTypeAttributes = unresolved.ReturnTypeAttributes.CreateResolvedAttributes(parentContext);
     this.TypeParameters       = unresolved.TypeParameters.CreateResolvedTypeParameters(context);
     this.IsExtensionMethod    = isExtensionMethod;
 }
Exemplo n.º 12
0
		public DefaultResolvedMethod(IUnresolvedMethod unresolved, ITypeResolveContext parentContext, bool isExtensionMethod)
			: base(unresolved, parentContext)
		{
			this.Parameters = unresolved.Parameters.CreateResolvedParameters(context);
			this.ReturnTypeAttributes = unresolved.ReturnTypeAttributes.CreateResolvedAttributes(parentContext);
			this.TypeParameters = unresolved.TypeParameters.CreateResolvedTypeParameters(context);
			this.IsExtensionMethod = isExtensionMethod;
		}
        /// <summary>
        /// Gets the CompletionImage instance for the specified entity.
        /// Returns null when no image is available for the entity type.
        /// </summary>
        public static CompletionImage GetCompletionImage(IUnresolvedEntity entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }
            switch (entity.SymbolKind)
            {
            case SymbolKind.TypeDefinition:
                return(GetCompletionImageForType(((IUnresolvedTypeDefinition)entity).Kind, entity.IsStatic));

            case SymbolKind.Field:
                IUnresolvedField field = (IUnresolvedField)entity;
                if (field.IsConst)
                {
                    if (field.DeclaringTypeDefinition != null && field.DeclaringTypeDefinition.Kind == TypeKind.Enum)
                    {
                        return(imageEnumValue);
                    }
                    else
                    {
                        return(imageLiteral);
                    }
                }
                return(field.IsReadOnly ? imageFieldReadOnly : imageField);

            case SymbolKind.Method:
                IUnresolvedMethod method = (IUnresolvedMethod)entity;
                // We cannot reliably detect extension methods in the unresolved type system (e.g. in VB we need to resolve an attribute),
                // but at least we can do it for C#:
                var defMethod = method as DefaultUnresolvedMethod;
                if (defMethod != null && defMethod.IsExtensionMethod)
                {
                    return(imageExtensionMethod);
                }
                return(method.IsOverridable ? imageVirtualMethod : imageMethod);

            case SymbolKind.Property:
                return(imageProperty);

            case SymbolKind.Indexer:
                return(imageIndexer);

            case SymbolKind.Event:
                return(imageEvent);

            case SymbolKind.Operator:
            case SymbolKind.Destructor:
                return(imageOperator);

            case SymbolKind.Constructor:
                return(imageConstructor);

            default:
                return(null);
            }
        }
 public NUnitTestMethod(ITestProject parentProject, IUnresolvedMethod method, FullTypeName derivedFixture = default(FullTypeName))
 {
     if (parentProject == null)
     {
         throw new ArgumentNullException("parentProject");
     }
     this.parentProject = parentProject;
     UpdateTestMethod(method, derivedFixture);
 }
 public void AddPart(IUnresolvedMethod method, ITypeResolveContext context)
 {
     if (method.IsPartialMethodImplementation)
     {
         // make the implementation the primary part
         this.Parts.Insert(0, method);
         this.PrimaryContext = context;
     }
     else
     {
         this.Parts.Add(method);
     }
 }
        MethodDefinition GetCecilObject(IUnresolvedMethod method)
        {
            object cecilObj;

            if (unresolvedTypeSystemToCecilDict.TryGetValue(method, out cecilObj))
            {
                return(cecilObj as MethodDefinition);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 17
0
        /// <summary>
        /// Gets the CompletionImage instance for the specified entity.
        /// Returns null when no image is available for the entity type.
        /// </summary>
        public static CompletionImage GetCompletionImage(IUnresolvedEntity entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }
            switch (entity.SymbolKind)
            {
            case SymbolKind.TypeDefinition:
                return(GetCompletionImageForType(((IUnresolvedTypeDefinition)entity).Kind, entity.IsStatic));

            case SymbolKind.Field:
                IUnresolvedField field = (IUnresolvedField)entity;
                if (field.IsConst)
                {
                    if (field.DeclaringTypeDefinition != null && field.DeclaringTypeDefinition.Kind == TypeKind.Enum)
                    {
                        return(imageEnumValue);
                    }
                    else
                    {
                        return(imageLiteral);
                    }
                }
                return(field.IsReadOnly ? imageFieldReadOnly : imageField);

            case SymbolKind.Method:
                IUnresolvedMethod method = (IUnresolvedMethod)entity;
                return(method.IsOverridable ? imageVirtualMethod : imageMethod);

            case SymbolKind.Property:
                return(imageProperty);

            case SymbolKind.Indexer:
                return(imageIndexer);

            case SymbolKind.Event:
                return(imageEvent);

            case SymbolKind.Operator:
            case SymbolKind.Destructor:
                return(imageOperator);

            case SymbolKind.Constructor:
                return(imageConstructor);

            default:
                return(null);
            }
        }
Exemplo n.º 18
0
 public void AddPart(IUnresolvedMethod method, ITypeResolveContext context)
 {
     if (method.HasBody)
     {
         // make the implementation the primary part
         this.Parts.Insert(0, method);
         this.Contexts.Insert(0, context);
     }
     else
     {
         this.Parts.Add(method);
         this.Contexts.Add(context);
     }
 }
Exemplo n.º 19
0
		public void UpdateTestMethod(IUnresolvedMethod method, FullTypeName derivedFixture = default(FullTypeName))
		{
			if (method == null)
				throw new ArgumentNullException("method");
			string oldDisplayName = this.displayName;
			this.derivedFixture = derivedFixture;
			this.method = method;
			if (this.IsInherited)
				displayName = method.DeclaringTypeDefinition.Name + "." + method.Name;
			else
				displayName = method.Name;
			
			if (displayName != oldDisplayName && DisplayNameChanged != null)
				DisplayNameChanged(this, EventArgs.Empty);
		}
Exemplo n.º 20
0
		internal static IConstantValue ConvertConstantValue(
			ITypeReference targetType, AstNode expression,
			IUnresolvedTypeDefinition parentTypeDefinition, IUnresolvedMethod parentMethodDefinition, UsingScope parentUsingScope)
		{
			ConstantValueBuilder b = new ConstantValueBuilder(false);
			ConstantExpression c = expression.AcceptVisitor(b, null);
			if (c == null)
				return new ErrorConstantValue(targetType);
			PrimitiveConstantExpression pc = c as PrimitiveConstantExpression;
			if (pc != null && pc.Type == targetType) {
				// Save memory by directly using a SimpleConstantValue.
				return new SimpleConstantValue(targetType, pc.Value);
			}
			// cast to the desired type
			return new ConstantCast(targetType, c);
		}
Exemplo n.º 21
0
        internal IMethod GetAccessor(ref IMethod accessorField, IUnresolvedMethod unresolvedAccessor)
        {
            if (unresolvedAccessor == null)
            {
                return(null);
            }
            IMethod result = LazyInit.VolatileRead(ref accessorField);

            if (result != null)
            {
                return(result);
            }
            else
            {
                return(LazyInit.GetOrSet(ref accessorField, (IMethod)unresolvedAccessor.CreateResolved(context)));
            }
        }
        static void AddPlaceholders(Step action, IUnresolvedMethod method)
        {
            var parameters = new List <IUnresolvedParameter> ();

            int index = 0;

            foreach (var placeholder in action.Placeholders)
            {
                var typeRef = new DefaultUnresolvedTypeDefinition(placeholder.Name);

                var p = new DefaultUnresolvedParameter(typeRef, "p" + index);

                method.Parameters.Add(p);

                index++;
            }
        }
Exemplo n.º 23
0
        public void Parse_ModuleWithOneClassThatHasOneMethod_NestedClassHasOneMethod()
        {
            string code =
                "module MyModule {\r\n" +
                "    class Student {\r\n" +
                "         speak() {\r\n" +
                "         }\r\n" +
                "    }\r\n" +
                "}\r\n";

            Parse(code);

            IUnresolvedTypeDefinition module = GetFirstClass();
            IUnresolvedTypeDefinition c      = module.NestedTypes.FirstOrDefault();
            IUnresolvedMethod         method = c.Methods.First();

            Assert.AreEqual("speak", method.Name);
        }
Exemplo n.º 24
0
        public void Parse_ClassWithOneMethod_ClassHasOneMethodWithCorrectBodyRegionAndName()
        {
            string code =
                "class Student {\r\n" +
                "    sayHello() {\r\n" +
                "        return \"Hello\";\r\n" +
                "    }\r\n" +
                "}\r\n";

            Parse(code);

            IUnresolvedTypeDefinition c      = GetFirstClass();
            IUnresolvedMethod         method = c.Methods.First();

            Assert.AreEqual("sayHello", method.Name);
            Assert.AreEqual(2, method.Region.EndLine);
            Assert.AreEqual(15, method.Region.EndColumn);
            Assert.AreEqual(4, method.BodyRegion.EndLine);
            Assert.AreEqual(6, method.BodyRegion.EndColumn);
        }
Exemplo n.º 25
0
        public void Parse_ClassWithConstructor_ClassHasOneConstructorMethodWithCorrectBodyRegionAndName()
        {
            string code =
                "class Student {\r\n" +
                "    constructor() {\r\n" +
                "    \r\n" +
                "    }\r\n" +
                "}\r\n";

            Parse(code);

            IUnresolvedTypeDefinition c      = GetFirstClass();
            IUnresolvedMethod         method = c.Methods.First();

            Assert.AreEqual("constructor", method.Name);
            Assert.AreEqual(2, method.Region.EndLine);
            Assert.AreEqual(18, method.Region.EndColumn);
            Assert.AreEqual(4, method.BodyRegion.EndLine);
            Assert.AreEqual(6, method.BodyRegion.EndColumn);
        }
Exemplo n.º 26
0
        MemberList GetMemberList()
        {
            var result = LazyInit.VolatileRead(ref this.memberList);

            if (result != null)
            {
                return(result);
            }
            List <IUnresolvedMember>   unresolvedMembers = new List <IUnresolvedMember>();
            List <ITypeResolveContext> contextPerMember  = new List <ITypeResolveContext>();
            bool addDefaultConstructorIfRequired         = false;

            foreach (IUnresolvedTypeDefinition part in parts)
            {
                ITypeResolveContext parentContextForPart = part.CreateResolveContext(parentContext);
                ITypeResolveContext contextForPart       = parentContextForPart.WithCurrentTypeDefinition(this);
                foreach (var member in part.Members)
                {
                    IUnresolvedMethod method = member as IUnresolvedMethod;

                    unresolvedMembers.Add(member);
                    contextPerMember.Add(contextForPart);
                }

                addDefaultConstructorIfRequired |= part.AddDefaultConstructorIfRequired;
            }
            if (addDefaultConstructorIfRequired)
            {
                TypeKind kind = this.Kind;
                if (kind == TypeKind.Class && !this.IsStatic && !unresolvedMembers.Any(m => m.SymbolKind == SymbolKind.Constructor && !m.IsStatic) ||
                    kind == TypeKind.Enum || kind == TypeKind.Struct)
                {
                    contextPerMember.Add(parts[0].CreateResolveContext(parentContext).WithCurrentTypeDefinition(this));
                    unresolvedMembers.Add(MethodCore.CreateDefaultConstructor(parts[0]));
                }
            }
            result = new MemberList(contextPerMember, unresolvedMembers);
            return(LazyInit.GetOrSet(ref this.memberList, result));
        }
Exemplo n.º 27
0
		public override IUnresolvedEntity VisitDelegateDeclaration(DelegateDeclaration delegateDeclaration, object data)
		{
			var td = currentTypeDefinition = CreateTypeDefinition(delegateDeclaration.Name);
			td.Kind = TypeKind.Delegate;
			td.Region = MakeRegion(delegateDeclaration);
			td.BaseTypes.Add(KnownTypeReference.MulticastDelegate);
			
			ApplyModifiers(td, delegateDeclaration.Modifiers);
			td.IsSealed = true; // delegates are implicitly sealed
			
			ConvertTypeParameters(td.TypeParameters, delegateDeclaration.TypeParameters, delegateDeclaration.Constraints, EntityType.TypeDefinition);
			
			ITypeReference returnType = delegateDeclaration.ReturnType.ToTypeReference();
			List<IUnresolvedParameter> parameters = new List<IUnresolvedParameter>();
			ConvertParameters(parameters, delegateDeclaration.Parameters);
			AddDefaultMethodsToDelegate(td, returnType, parameters);
			
			foreach (AttributeSection section in delegateDeclaration.Attributes) {
				if (section.AttributeTarget == "return") {
					List<IUnresolvedAttribute> returnTypeAttributes = new List<IUnresolvedAttribute>();
					ConvertAttributes(returnTypeAttributes, section);
					IUnresolvedMethod invokeMethod = (IUnresolvedMethod)td.Members.Single(m => m.Name == "Invoke");
					IUnresolvedMethod endInvokeMethod = (IUnresolvedMethod)td.Members.Single(m => m.Name == "EndInvoke");
					foreach (IUnresolvedAttribute attr in returnTypeAttributes) {
						invokeMethod.ReturnTypeAttributes.Add(attr);
						endInvokeMethod.ReturnTypeAttributes.Add(attr);
					}
				} else {
					ConvertAttributes(td.Attributes, section);
				}
			}
			
			currentTypeDefinition = (CSharpUnresolvedTypeDefinition)currentTypeDefinition.DeclaringTypeDefinition;
			if (interningProvider != null) {
				td.ApplyInterningProvider(interningProvider);
			}
			return td;
		}
        public void UpdateTestMethod(IUnresolvedMethod method, FullTypeName derivedFixture = default(FullTypeName))
        {
            if (method == null)
            {
                throw new ArgumentNullException("method");
            }
            string oldDisplayName = this.displayName;

            this.derivedFixture = derivedFixture;
            this.method         = method;
            if (this.IsInherited)
            {
                displayName = method.DeclaringTypeDefinition.Name + "." + method.Name;
            }
            else
            {
                displayName = method.Name;
            }

            if (displayName != oldDisplayName && DisplayNameChanged != null)
            {
                DisplayNameChanged(this, EventArgs.Empty);
            }
        }
Exemplo n.º 29
0
        public void Parse_TwoClassesAndSecondOneHasOneMethod_SecondClassHasOneMethodWithCorrectBodyRegionAndName()
        {
            string code =
                "class Class1 {\r\n" +
                "}\r\n" +
                "\r\n" +
                "class Class2 {\r\n" +
                "    sayHello() {\r\n" +
                "        return \"Hello\";\r\n" +
                "    }\r\n" +
                "}\r\n";

            Parse(code);

            IUnresolvedTypeDefinition c      = GetSecondClass();
            IUnresolvedMethod         method = c.Methods.FirstOrDefault();

            Assert.AreEqual(2, ParseInfo.UnresolvedFile.TopLevelTypeDefinitions.Count);
            Assert.AreEqual("sayHello", method.Name);
            Assert.AreEqual(5, method.Region.EndLine);
            Assert.AreEqual(15, method.Region.EndColumn);
            Assert.AreEqual(7, method.BodyRegion.EndLine);
            Assert.AreEqual(6, method.BodyRegion.EndColumn);
        }
Exemplo n.º 30
0
        MemberList GetMemberList()
        {
            var result = LazyInit.VolatileRead(ref this.memberList);

            if (result != null)
            {
                return(result);
            }
            List <IUnresolvedMember>   unresolvedMembers  = new List <IUnresolvedMember>();
            List <ITypeResolveContext> contextPerMember   = new List <ITypeResolveContext>();
            List <PartialMethodInfo>   partialMethodInfos = null;
            bool addDefaultConstructorIfRequired          = false;

            foreach (IUnresolvedTypeDefinition part in parts)
            {
                ITypeResolveContext parentContextForPart = part.CreateResolveContext(parentContext);
                ITypeResolveContext contextForPart       = parentContextForPart.WithCurrentTypeDefinition(this);
                foreach (var member in part.Members)
                {
                    IUnresolvedMethod method = member as IUnresolvedMethod;
                    if (method != null && method.IsPartial)
                    {
                        // Merge partial method declaration and implementation
                        if (partialMethodInfos == null)
                        {
                            partialMethodInfos = new List <PartialMethodInfo>();
                        }
                        PartialMethodInfo newInfo      = new PartialMethodInfo(method, contextForPart);
                        PartialMethodInfo existingInfo = null;
                        foreach (var info in partialMethodInfos)
                        {
                            if (newInfo.IsSameSignature(info, Compilation.NameComparer))
                            {
                                existingInfo = info;
                                break;
                            }
                        }
                        if (existingInfo != null)
                        {
                            // Add the unresolved method to the PartialMethodInfo:
                            existingInfo.AddPart(method, contextForPart);
                        }
                        else
                        {
                            partialMethodInfos.Add(newInfo);
                        }
                    }
                    else
                    {
                        unresolvedMembers.Add(member);
                        contextPerMember.Add(contextForPart);
                    }
                }

                addDefaultConstructorIfRequired |= part.AddDefaultConstructorIfRequired;
            }
            if (addDefaultConstructorIfRequired)
            {
                TypeKind kind = this.Kind;
                if (kind == TypeKind.Class && !this.IsStatic && !unresolvedMembers.Any(m => m.SymbolKind == SymbolKind.Constructor && !m.IsStatic) ||
                    kind == TypeKind.Enum || kind == TypeKind.Struct)
                {
                    contextPerMember.Add(parts[0].CreateResolveContext(parentContext).WithCurrentTypeDefinition(this));
                    unresolvedMembers.Add(DefaultUnresolvedMethod.CreateDefaultConstructor(parts[0]));
                }
            }
            result = new MemberList(contextPerMember, unresolvedMembers, partialMethodInfos);
            return(LazyInit.GetOrSet(ref this.memberList, result));
        }
Exemplo n.º 31
0
		public static DefaultResolvedMethod CreateFromMultipleParts(IUnresolvedMethod[] parts, ITypeResolveContext firstPartParentContext, bool isExtensionMethod)
		{
			DefaultResolvedMethod method = new DefaultResolvedMethod(parts[0], firstPartParentContext, isExtensionMethod);
			method.parts = parts;
			return method;
		}
Exemplo n.º 32
0
		internal IMethod GetAccessor(ref IMethod accessorField, IUnresolvedMethod unresolvedAccessor)
		{
			if (unresolvedAccessor == null)
				return null;
			IMethod result = accessorField;
			if (result != null) {
				LazyInit.ReadBarrier();
				return result;
			} else {
				return LazyInit.GetOrSet(ref accessorField, (IMethod)unresolvedAccessor.CreateResolved(context));
			}
		}
        static void AddPlaceholders(Step action, IUnresolvedMethod method)
        {
            var parameters = new List<IUnresolvedParameter> ();

            int index = 0;

            foreach (var placeholder in action.Placeholders) {
                var typeRef = new DefaultUnresolvedTypeDefinition (placeholder.Name);

                var p =  new DefaultUnresolvedParameter (typeRef, "p" + index);

                method.Parameters.Add (p);

                index++;
            }
        }
Exemplo n.º 34
0
 internal IMethod GetAccessor(ref IMethod accessorField, IUnresolvedMethod unresolvedAccessor)
 {
     if (unresolvedAccessor == null)
         return null;
     IMethod result = LazyInit.VolatileRead(ref accessorField);
     if (result != null) {
         return result;
     } else {
         return LazyInit.GetOrSet(ref accessorField, CreateResolvedAccessor(unresolvedAccessor));
     }
 }
        void FormatLineInternal(ITextEditor textArea, int lineNr, int cursorOffset, char ch)
        {
            IDocumentLine curLine    = textArea.Document.GetLineByNumber(lineNr);
            IDocumentLine lineAbove  = lineNr > 1 ? textArea.Document.GetLineByNumber(lineNr - 1) : null;
            string        terminator = DocumentUtilities.GetLineTerminator(textArea.Document, lineNr);

            string curLineText;

            // local string for curLine segment
            if (ch == '/')
            {
                curLineText = textArea.Document.GetText(curLine);
                string lineAboveText = lineAbove == null ? "" : textArea.Document.GetText(lineAbove);
                if (curLineText != null && curLineText.EndsWith("///", StringComparison.Ordinal) && (lineAboveText == null || !lineAboveText.Trim().StartsWith("///", StringComparison.Ordinal)))
                {
                    string            indentation = DocumentUtilities.GetWhitespaceAfter(textArea.Document, curLine.Offset);
                    IUnresolvedEntity member      = GetMemberAfter(textArea, lineNr);
                    if (member != null)
                    {
                        StringBuilder sb = new StringBuilder();
                        sb.Append(" <summary>");
                        sb.Append(terminator);
                        sb.Append(indentation);
                        sb.Append("/// ");
                        sb.Append(terminator);
                        sb.Append(indentation);
                        sb.Append("/// </summary>");

                        IUnresolvedMethod method = null;
                        if (member is IUnresolvedMethod)
                        {
                            method = (IUnresolvedMethod)member;
                        }
                        else if (member is IUnresolvedTypeDefinition)
                        {
                            IUnresolvedTypeDefinition type = (IUnresolvedTypeDefinition)member;
                            if (type.Kind == TypeKind.Delegate)
                            {
                                method = type.Methods.FirstOrDefault(m => m.Name == "Invoke");
                            }
                        }

                        if (method != null)
                        {
                            for (int i = 0; i < method.Parameters.Count; ++i)
                            {
                                sb.Append(terminator);
                                sb.Append(indentation);
                                sb.Append("/// <param name=\"");
                                sb.Append(method.Parameters[i].Name);
                                sb.Append("\"></param>");
                            }
                            if (!method.IsConstructor)
                            {
                                KnownTypeReference returnType = method.ReturnType as KnownTypeReference;
                                if (returnType == null || returnType.KnownTypeCode != KnownTypeCode.Void)
                                {
                                    sb.Append(terminator);
                                    sb.Append(indentation);
                                    sb.Append("/// <returns></returns>");
                                }
                            }
                        }

                        textArea.Document.Insert(cursorOffset, sb.ToString());
                        textArea.Caret.Offset = cursorOffset + indentation.Length + "/// ".Length + " <summary>".Length + terminator.Length;
                    }
                }
                return;
            }

            if (ch != '\n' && ch != '>')
            {
                if (IsInsideStringOrComment(textArea, curLine, cursorOffset))
                {
                    return;
                }
            }
            switch (ch)
            {
            case '>':
                if (IsInsideDocumentationComment(textArea, curLine, cursorOffset))
                {
                    curLineText = textArea.Document.GetText(curLine);
                    int column = cursorOffset - curLine.Offset;
                    int index  = Math.Min(column - 1, curLineText.Length - 1);

                    while (index >= 0 && curLineText[index] != '<')
                    {
                        --index;
                        if (curLineText[index] == '/')
                        {
                            return;                                     // the tag was an end tag or already
                        }
                    }

                    if (index > 0)
                    {
                        StringBuilder commentBuilder = new StringBuilder("");
                        for (int i = index; i < curLineText.Length && i < column && !Char.IsWhiteSpace(curLineText[i]); ++i)
                        {
                            commentBuilder.Append(curLineText[i]);
                        }
                        string tag = commentBuilder.ToString().Trim();
                        if (!tag.EndsWith(">", StringComparison.Ordinal))
                        {
                            tag += ">";
                        }
                        if (!tag.StartsWith("/", StringComparison.Ordinal))
                        {
                            textArea.Document.Insert(cursorOffset, "</" + tag.Substring(1), AnchorMovementType.BeforeInsertion);
                        }
                    }
                }
                break;

            case ':':
            case ')':
            case ']':
            case '{':
                //if (textArea.Document.TextEditorProperties.IndentStyle == IndentStyle.Smart) {
                IndentLine(textArea, curLine);
                //}
                break;

            case '}':
                // Try to get corresponding block beginning brace
                var bracketSearchResult = textArea.Language.BracketSearcher.SearchBracket(textArea.Document, cursorOffset);
                if (bracketSearchResult != null)
                {
                    // Format the block
                    if (!FormatStatement(textArea, cursorOffset, bracketSearchResult.OpeningBracketOffset))
                    {
                        // No auto-formatting seems to be active, at least indent the line
                        IndentLine(textArea, curLine);
                    }
                }
                break;

            case ';':
                // Format this line
                if (!FormatStatement(textArea, cursorOffset, cursorOffset))
                {
                    // No auto-formatting seems to be active, at least indent the line
                    IndentLine(textArea, curLine);
                }
                break;

            case '\n':
                string lineAboveText = lineAbove == null ? "" : textArea.Document.GetText(lineAbove);
                // curLine might have some text which should be added to indentation
                curLineText = textArea.Document.GetText(curLine);

                if (lineAboveText != null && lineAboveText.Trim().StartsWith("#region", StringComparison.Ordinal) &&
                    NeedEndregion(textArea.Document))
                {
                    textArea.Document.Insert(cursorOffset, "#endregion");
                    return;
                }

                IHighlighter highlighter          = textArea.GetService(typeof(IHighlighter)) as IHighlighter;
                bool         isInMultilineComment = false;
                bool         isInMultilineString  = false;
                if (highlighter != null && lineAbove != null)
                {
                    var spanStack = highlighter.GetColorStack(lineNr).Select(c => c.Name).ToArray();
                    isInMultilineComment = spanStack.Contains(HighlighterKnownSpanNames.Comment);
                    isInMultilineString  = spanStack.Contains(HighlighterKnownSpanNames.String);
                }
                bool isInNormalCode = !(isInMultilineComment || isInMultilineString);

                if (lineAbove != null && isInMultilineComment)
                {
                    string lineAboveTextTrimmed = lineAboveText.TrimStart();
                    if (lineAboveTextTrimmed.StartsWith("/*", StringComparison.Ordinal))
                    {
                        textArea.Document.Insert(cursorOffset, " * ");
                        return;
                    }

                    if (lineAboveTextTrimmed.StartsWith("*", StringComparison.Ordinal))
                    {
                        textArea.Document.Insert(cursorOffset, "* ");
                        return;
                    }
                }

                if (lineAbove != null && isInNormalCode)
                {
                    IDocumentLine nextLine     = lineNr + 1 <= textArea.Document.LineCount ? textArea.Document.GetLineByNumber(lineNr + 1) : null;
                    string        nextLineText = (nextLine != null) ? textArea.Document.GetText(nextLine) : "";

                    int indexAbove = lineAboveText.IndexOf("///", StringComparison.Ordinal);
                    int indexNext  = nextLineText.IndexOf("///", StringComparison.Ordinal);
                    if (indexAbove > 0 && (indexNext != -1 || indexAbove + 4 < lineAbove.Length))
                    {
                        textArea.Document.Insert(cursorOffset, "/// ");
                        return;
                    }

                    if (IsInNonVerbatimString(lineAboveText, curLineText))
                    {
                        textArea.Document.Insert(cursorOffset, "\"");
                        textArea.Document.Insert(lineAbove.Offset + lineAbove.Length,
                                                 "\" +");
                    }
                }
                if (textArea.Options.AutoInsertBlockEnd && lineAbove != null && isInNormalCode)
                {
                    string oldLineText = textArea.Document.GetText(lineAbove);
                    if (oldLineText.EndsWith("{", StringComparison.Ordinal))
                    {
                        if (NeedCurlyBracket(textArea.Document.Text))
                        {
                            int insertionPoint = curLine.Offset + curLine.Length;
                            textArea.Document.Insert(insertionPoint, terminator + "}");
                            IndentLine(textArea, textArea.Document.GetLineByNumber(lineNr + 1));
                            textArea.Caret.Offset = insertionPoint;
                        }
                    }
                }
                return;
            }
        }
Exemplo n.º 36
0
 public AnonymousTypeAccessor(IUnresolvedMethod unresolved, ITypeResolveContext parentContext, AnonymousTypeProperty owner)
     : base(unresolved, parentContext, isExtensionMethod: false)
 {
     this.owner = owner;
 }
Exemplo n.º 37
0
 protected override IMethod CreateResolvedAccessor(IUnresolvedMethod unresolvedAccessor)
 {
     return(new AnonymousTypeAccessor(unresolvedAccessor, context, this));
 }
Exemplo n.º 38
0
 protected virtual IMethod CreateResolvedAccessor(IUnresolvedMethod unresolvedAccessor)
 {
     return (IMethod)unresolvedAccessor.CreateResolved(context);
 }
Exemplo n.º 39
0
 public AnonymousTypeAccessor(IUnresolvedMethod unresolved, ITypeResolveContext parentContext, AnonymousTypeProperty owner)
     : base(unresolved, parentContext, isExtensionMethod: false)
 {
     this.owner = owner;
 }
Exemplo n.º 40
0
 protected override IMethod CreateResolvedAccessor(IUnresolvedMethod unresolvedAccessor)
 {
     return new AnonymousTypeAccessor(unresolvedAccessor, context, this);
 }
Exemplo n.º 41
0
		MethodDefinition GetCecilObject(IUnresolvedMethod method)
		{
			object cecilObj;
			if (unresolvedTypeSystemToCecilDict.TryGetValue(method, out cecilObj)) {
				return cecilObj as MethodDefinition;
			} else {
				return null;
			}
		}
Exemplo n.º 42
0
		bool MatchDelegate(IType delegateType, IUnresolvedMethod method)
		{
			var delegateMethod = delegateType.GetDelegateInvokeMethod();
			if (delegateMethod == null || delegateMethod.Parameters.Count != method.Parameters.Count) {
				return false;
			}
			
			for (int i = 0; i < delegateMethod.Parameters.Count; i++) {
				if (!delegateMethod.Parameters [i].Type.Equals(method.Parameters [i].Type.Resolve(ctx))) {
					return false;
				}
			}
			return true;
		}
Exemplo n.º 43
0
 protected virtual IMethod CreateResolvedAccessor(IUnresolvedMethod unresolvedAccessor)
 {
     return((IMethod)unresolvedAccessor.CreateResolved(context));
 }
Exemplo n.º 44
0
		IMethod GetImplementation(ITypeDefinition type, IUnresolvedMethod method)
		{
			foreach (var cur in type.Methods) {
				if (cur.Name == method.Name && cur.Parameters.Count == method.Parameters.Count && !cur.BodyRegion.IsEmpty) {
					bool equal = true;
					/*					for (int i = 0; i < cur.Parameters.Count; i++) {
						if (!cur.Parameters [i].Type.Equals (method.Parameters [i].Type)) {
							equal = false;
							break;
						}
					}*/
					if (equal) {
						return cur;
					}
				}
			}
			return null;
		}
Exemplo n.º 45
0
        public void UpdateTestClass(ITypeDefinition typeDefinition)
        {
            fullTypeName = typeDefinition.FullTypeName;
            if (this.NestedTestsInitialized)
            {
                int baseClassIndex = 0;
                foreach (IType baseType in typeDefinition.GetNonInterfaceBaseTypes())
                {
                    ITypeDefinition baseTypeDef = baseType.GetDefinition();
                    // Check that the base type isn't equal to System.Object or the current class itself
                    if (baseTypeDef == null || baseTypeDef == typeDefinition || baseTypeDef.KnownTypeCode == KnownTypeCode.Object)
                    {
                        continue;
                    }
                    if (baseTypeDef.DeclaringTypeDefinition != null)
                    {
                        continue;                         // we only support inheriting from top-level classes
                    }
                    var baseClassName = baseTypeDef.FullTypeName;
                    if (baseClassIndex < baseClassNames.Count && baseClassName == baseClassNames[baseClassIndex])
                    {
                        // base class is already in the list, just keep it
                        baseClassIndex++;
                    }
                    else
                    {
                        // base class is not in the list, or the remaining portion of the list differs
                        // remove remaining portion of the list:
                        RemoveBaseClasses(baseClassIndex);
                        // Add new base class:
                        parentProject.RegisterInheritedClass(baseClassName, this);
                        baseClassNames.Add(baseClassName);
                        baseClassIndex++;
                    }
                }

                HashSet <ITest> newOrUpdatedNestedTests = new HashSet <ITest>();
                // Update nested test classes:
                foreach (ITypeDefinition nestedClass in typeDefinition.NestedTypes)
                {
                    if (!NUnitTestFramework.IsTestClass(nestedClass))
                    {
                        continue;
                    }

                    NUnitTestClass nestedTestClass = FindNestedTestClass(nestedClass.Name, nestedClass.TypeParameterCount);
                    if (nestedTestClass != null)
                    {
                        nestedTestClass.UpdateTestClass(nestedClass);
                    }
                    else
                    {
                        nestedTestClass = new NUnitTestClass(parentProject, nestedClass.FullTypeName);
                        this.NestedTestCollection.Add(nestedTestClass);
                    }
                    newOrUpdatedNestedTests.Add(nestedTestClass);
                }
                // Get methods (not operators etc.)
                foreach (IMethod method in typeDefinition.GetMethods(m => m.SymbolKind == SymbolKind.Method))
                {
                    if (!NUnitTestFramework.IsTestMethod(method))
                    {
                        continue;
                    }

                    IUnresolvedMethod unresolvedMethod = (IUnresolvedMethod)method.UnresolvedMember;
                    string            methodNameWithDeclaringType;
                    FullTypeName      derivedFixture;
                    if (method.DeclaringTypeDefinition == typeDefinition)
                    {
                        derivedFixture = default(FullTypeName);                         // method is not inherited
                        methodNameWithDeclaringType = method.Name;
                    }
                    else
                    {
                        if (method.DeclaringTypeDefinition == null)
                        {
                            continue;
                        }
                        derivedFixture = fullTypeName;                         // method is inherited
                        methodNameWithDeclaringType = method.DeclaringTypeDefinition.Name + "." + method.Name;
                    }

                    NUnitTestMethod testMethod;
                    if (method.IsOverride)
                    {
                        testMethod = FindTestMethodWithShortName(method.Name);
                    }
                    else
                    {
                        testMethod = FindTestMethod(methodNameWithDeclaringType);
                    }
                    if (testMethod != null)
                    {
                        testMethod.UpdateTestMethod(unresolvedMethod, derivedFixture);
                    }
                    else
                    {
                        testMethod = new NUnitTestMethod(parentProject, unresolvedMethod, derivedFixture);
                        this.NestedTestCollection.Add(testMethod);
                    }
                    newOrUpdatedNestedTests.Add(testMethod);
                }
                // Remove all tests that weren't contained in the new type definition anymore:
                this.NestedTestCollection.RemoveAll(t => !newOrUpdatedNestedTests.Contains(t));
            }
        }