Exemplo n.º 1
0
        public static NSObjectProjectInfo GetProjectInfo(ProjectDom dom)
        {
            NSObjectProjectInfo info;

            lock (infos) {
                if (infos.TryGetValue(dom, out info))
                {
                    return(info);
                }

                //only include DOMs that can resolve NSObject
                var nso = dom.GetType(nsobjectType);
                if (nso == null)
                {
                    infos[dom] = null;
                    return(null);
                }

                info                   = new NSObjectProjectInfo(dom);
                infos[dom]             = info;
                dom.Unloaded          += HandleDomUnloaded;
                dom.ReferencesUpdated += HandleDomReferencesUpdated;
            }
            return(info);
        }
Exemplo n.º 2
0
        /// <summary>Filters out members whose names conflict with existing accessible members</summary>
        /// <param name="members">Full list of CodeBehind members</param>
        /// <param name="cls">The class to which these members' partial class will be added.</param>
        /// <param name="designerFile">Members in this file will be ignored.</param>
        /// <param name="resolveDom">The ProjectDom to use for resolving base types.</param>
        /// <param name="internalDom">The ProjectDom to use for checking whether members are accessible as internal.</param>
        /// <returns>The filtered list of non-conflicting members.</returns>
        // TODO: check compatibilty with existing members
        public static IEnumerable <CodeBehindMember> GetDesignerMembers(
            IEnumerable <CodeBehindMember> members, IType cls, string designerFile, ProjectDom resolveDom,
            ProjectDom internalDom)
        {
            var existingMembers = new HashSet <string> ();

            while (cls != null)
            {
                foreach (var member in cls.Members)
                {
                    if (member.IsPrivate || (member.IsInternal && member.DeclaringType.SourceProjectDom != internalDom))
                    {
                        continue;
                    }
                    if (member.DeclaringType.CompilationUnit.FileName == designerFile)
                    {
                        continue;
                    }
                    existingMembers.Add(member.Name);
                }
                if (cls.BaseType == null)
                {
                    break;
                }
                cls = resolveDom.GetType(cls.BaseType);
            }
            return(members.Where(m => !existingMembers.Contains(m.Name)));
        }
Exemplo n.º 3
0
        IMethod FindConstructor(ProjectDom dom, IAttribute att)
        {
            // The constructor provided by CustomAttribute.Constructor is lacking some information, such as the parameter
            // name and custom attributes. Since we need the full info, we have to look it up in the declaring type.

            IType atd = dom.GetType(att.AttributeType);

            foreach (IMethod met in atd.Methods)
            {
                if (met.IsConstructor)
                {
                    continue;
                }

                if (met.Parameters.Count == att.PositionalArguments.Count)
                {
                    for (int n = met.Parameters.Count - 1; n >= 0; n--)
                    {
                        var res = Evaluate(att.PositionalArguments [n]);
                        if (met.Parameters[n].ReturnType.FullName != res.Type)
                        {
                            break;
                        }
                        if (n == 0)
                        {
                            return(met);
                        }
                    }
                }
            }
            return(null);
        }
Exemplo n.º 4
0
        protected override void GetElementCompletions(CompletionDataList list)
        {
            base.GetElementCompletions(list);
            ProjectDom database = GetDb();

            if (database == null)
            {
                return;
            }

            IType type = database.GetType("System.Windows.DependencyObject");

            if (type == null)
            {
                return;
            }

            foreach (string namespc in namespaces)
            {
                foreach (IType t in ListControlClasses(database, namespc))
                {
                    list.Add(t.Name, Gtk.Stock.GoForward, t.Documentation);
                }
            }
        }
Exemplo n.º 5
0
        public static IEnumerable <IType> ListControlClasses(IType baseType, ProjectDom database, string namespac)
        {
            if (database == null)
            {
                yield break;
            }

            //return classes if they derive from system.web.ui.control
            foreach (IType type in database.GetSubclasses(baseType, false, new string [] { namespac }))
            {
                if (!type.IsAbstract && type.IsPublic)
                {
                    yield return(type);
                }
            }

            if (!baseType.IsAbstract && baseType.IsPublic && baseType.Namespace == namespac)
            {
                IType t = database.GetType(baseType.FullName);
                if (t != null)
                {
                    yield return(baseType);
                }
            }
        }
Exemplo n.º 6
0
        public override IEnumerable <object> CreateResolveResult(ProjectDom dom, IMember callingMember)
        {
            List <object> result = new List <object> ();

            if (IsLoopVariable)
            {
                if (ResolvedType.Name == "IEnumerable" && ResolvedType.GenericArguments != null && ResolvedType.GenericArguments.Count > 0)
                {
                    MemberResolveResult.AddType(dom, result, ResolvedType.GenericArguments [0], callingMember, StaticResolve);
                }
                else if (ResolvedType.Name == "IEnumerable")
                {
                    MemberResolveResult.AddType(dom, result, DomReturnType.Object, callingMember, StaticResolve);
                }
                else
                {
                    MemberResolveResult.AddType(dom, result, dom.GetType(ResolvedType), callingMember, StaticResolve);
                }
            }
            else
            {
                MemberResolveResult.AddType(dom, result, ResolvedType, callingMember, StaticResolve);
            }
            return(result);
        }
Exemplo n.º 7
0
        public Dictionary <string, IType> GetToolboxItems()
        {
            Dictionary <string, IType> tb_items = new Dictionary <string, IType> ();

            IType wt = ctx.GetType("Gtk.Widget", true);

            if (wt != null)
            {
                foreach (IType t in ctx.GetSubclasses(wt, true))
                {
                    if (t.SourceProjectDom == ctx && IsToolboxWidget(t))
                    {
                        tb_items [t.FullName] = t;
                    }
                }
            }

            return(tb_items);
        }
Exemplo n.º 8
0
 IType GetFullClass(out ProjectDom ctx)
 {
     if (project == null || className == null)
     {
         ctx = null;
         return(null);
     }
     ctx = MonoDevelop.Projects.Dom.Parser.ProjectDomService.GetProjectDom(project);
     return(ctx.GetType(className, false, false));
 }
Exemplo n.º 9
0
        static IType EnsureClassExists(ProjectDom ctx, string className, DomRegion location)
        {
            IType cls = ctx.GetType(className);

            if (cls == null)
            {
                throw new TypeNotFoundException(className, location, null);
            }
            return(cls);
        }
Exemplo n.º 10
0
        public override IEnumerable <object> CreateResolveResult(ProjectDom dom, IMember callingMember)
        {
            List <object> result = new List <object> ();

            if (ResolvedExpression != null && ResolvedExpression.ExpressionContext != null && ResolvedExpression.ExpressionContext.IsObjectCreation)
            {
                AddType(dom, result, dom.GetType(ResolvedType), callingMember, true);
            }
            else
            {
                AddType(dom, result, ResolvedType, callingMember, StaticResolve);
            }
            return(result);
        }
Exemplo n.º 11
0
        void GetCodeBehind(out IType codeBehindClass, out ProjectDom projectDatabase)
        {
            codeBehindClass = null;
            projectDatabase = null;

            if (HasDoc && !string.IsNullOrEmpty(aspDoc.Info.InheritedClass))
            {
                projectDatabase = ProjectDomService.GetProjectDom(project);
                if (projectDatabase != null)
                {
                    codeBehindClass = projectDatabase.GetType(aspDoc.Info.InheritedClass, false, false);
                }
            }
        }
Exemplo n.º 12
0
            public void Add(ProjectDom dom, IReturnType parameterType, IReturnType type)
            {
//				Console.WriteLine ("Add:" + parameterType +"\n\t->" + type);
                if (type == null || string.IsNullOrEmpty(type.FullName))
                {
                    return;
                }
                string name     = parameterType.Name;
                bool   contains = typeTable.ContainsKey(name);

                // when the type is already in the table use the type that is more general in the inheritance tree.
                if (contains && dom != null)
                {
                    var t1 = dom.GetType(typeTable[name]);
                    var t2 = dom.GetType(type);
                    if (t1 != null && !dom.GetInheritanceTree(t1).Any(t => t.DecoratedFullName == t2.DecoratedFullName))
                    {
                        return;
                    }
                }

                DomReturnType newType = new DomReturnType(type.FullName);

                newType.ArrayDimensions     = Math.Max(0, type.ArrayDimensions - parameterType.ArrayDimensions);
                newType.PointerNestingLevel = Math.Max(0, type.PointerNestingLevel - parameterType.PointerNestingLevel);
                newType.Type = type.Type;                  // May be anonymous type
                for (int i = 0; i < newType.ArrayDimensions; i++)
                {
                    newType.SetDimension(i, parameterType.GetDimension(i));
                }
                foreach (var generic in type.GenericArguments)
                {
                    newType.AddTypeParameter(generic);
                }
                typeTable[name] = newType;
            }
Exemplo n.º 13
0
        public void SimpleGetType()
        {
            // Simple get
            IType type = mainProject.GetType("CompletionDbTest.MainClass");

            Assert.IsNotNull(type);
            Assert.AreEqual("CompletionDbTest.MainClass", type.FullName);

            // Deep search in local project
            type = mainProject.GetType("CompletionDbTest.MainClass", true);
            Assert.IsNotNull(type);
            Assert.AreEqual("CompletionDbTest.MainClass", type.FullName);

            // Non deep search
            // FIXME: deep search is currently the same as non-deep-search
//			type = mainProject.GetType ("Library2.CWidget", false);
//			Assert.IsNull (type);

            // Deep search by default
            type = mainProject.GetType("Library2.CWidget");
            Assert.IsNotNull(type);
            Assert.AreEqual("Library2.CWidget", type.FullName);

            //check that references are accessible, but not references of references
            type = mainProject.GetType("Library3.Lib3Class");
            Assert.IsNull(type);
            type = lib2.GetType("Library3.Lib3Class");
            Assert.IsNotNull(type);

            // Deep insensitive
            type = mainProject.GetType("library2.cwidget", true, false);
            Assert.IsNotNull(type);
            Assert.AreEqual("Library2.CWidget", type.FullName);

            // Case sensitive
            type = mainProject.GetType("library2.cwidget", true, true);
            Assert.IsNull(type);

            // Not generic
            type = mainProject.GetType("CompletionDbTest.MainClass", 1, true);
            Assert.IsNull(type);

            // System.Object
            type = mainProject.GetType("System.Object", true, true);
            Assert.IsNotNull(type);
            Assert.AreEqual("System.Object", type.FullName);
        }
Exemplo n.º 14
0
        public static IReturnType GetComponentType(ProjectDom dom, IReturnType returnType)
        {
            if (dom == null || returnType == null)
            {
                return(null);
            }
            if (returnType.FullName == DomReturnType.String.FullName && returnType.ArrayDimensions == 0)
            {
                return(DomReturnType.Char);
            }
            if (returnType.ArrayDimensions > 0)
            {
                return(new DomReturnType(returnType.FullName));
            }

            IType resolvedType = dom.GetType(returnType);

            if (resolvedType != null)
            {
                foreach (IType curType in dom.GetInheritanceTree(resolvedType))
                {
                    foreach (IReturnType baseType in curType.BaseTypes)
                    {
                        if (baseType.FullName == "System.Collections.Generic.IEnumerable" && baseType.GenericArguments.Count == 1)
                        {
                            return(baseType.GenericArguments [0]);
                        }
                    }

                    foreach (IProperty property in curType.Properties)
                    {
                        if (property.IsIndexer && !property.IsExplicitDeclaration)
                        {
                            return(property.ReturnType);
                        }
                    }
                }
            }

            if (returnType.GenericArguments.Count > 0)
            {
                return(returnType.GenericArguments [0]);
            }

            return(null);
        }
Exemplo n.º 15
0
        void GetType(IAttributedXObject attributedOb, Action <IType, ProjectDom> action)
        {
            ProjectDom database = GetDb();

            if (database == null)
            {
                return;
            }
            foreach (string namespc in namespaces)
            {
                IType controlType = database.GetType(namespc + "." + attributedOb.Name.Name);
                if (controlType != null)
                {
                    action(controlType, database);
                    break;
                }
            }
        }
Exemplo n.º 16
0
        protected override SourceCodeLocation GetSourceCodeLocation(string fullClassName, string methodName)
        {
            ProjectDom ctx = ProjectDomService.GetProjectDom(project);
            IType      cls = ctx.GetType(fullClassName);

            if (cls == null)
            {
                return(null);
            }

            foreach (IMethod met in cls.Methods)
            {
                if (met.Name == methodName)
                {
                    return(new SourceCodeLocation(cls.CompilationUnit.FileName, met.Location.Line, met.Location.Column));
                }
            }
            return(new SourceCodeLocation(cls.CompilationUnit.FileName, cls.Location.Line, cls.Location.Column));
        }
Exemplo n.º 17
0
        internal bool IsValidClass(ProjectDom ctx, IType cls)
        {
            if (cls.BaseTypes != null)
            {
                foreach (IReturnType bt in cls.BaseTypes)
                {
                    if (bt.FullName == rootWidget.Component.Type.ClassName)
                    {
                        return(true);
                    }

                    IType baseCls = ctx.GetType(bt);
                    if (baseCls != null && IsValidClass(ctx, baseCls))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Exemplo n.º 18
0
        bool IsSubclass(ProjectDom ctx, IType baseClass, IType subclass)
        {
            foreach (IReturnType clsName in subclass.BaseTypes)
            {
                if (clsName.FullName == baseClass.FullName)
                {
                    return(true);
                }
            }

            foreach (IReturnType clsName in subclass.BaseTypes)
            {
                IType cls = ctx.GetType(clsName);
                if (cls != null && IsSubclass(ctx, baseClass, cls))
                {
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 19
0
        IEnumerable <NSObjectTypeInfo> GetRegisteredObjects(ProjectDom dom)
        {
            var nso = dom.GetType(nsobjectType);

            if (nso == null)
            {
                throw new Exception("Could not get NSObject from type database");
            }

            yield return(new NSObjectTypeInfo("NSObject", nsobjectType.FullName, null, null, false));

            foreach (var type in dom.GetSubclasses(nso, true))
            {
                var info = ConvertType(dom, type);
                if (info != null)
                {
                    yield return(info);
                }
            }
        }
Exemplo n.º 20
0
        internal static bool IsValidClass(ProjectDom ctx, IType cls)
        {
            if (cls.BaseTypes != null)
            {
                foreach (IReturnType bt in cls.BaseTypes)
                {
                    if (bt.FullName == "Gtk.ActionGroup")
                    {
                        return(true);
                    }

                    IType baseCls = ctx.GetType(bt);
                    if (baseCls != null && IsValidClass(ctx, baseCls))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Exemplo n.º 21
0
        public static IMethod GetMethodSignature(ProjectDom context, IEvent ev)
        {
            if (ev.ReturnType == null)
            {
                return(null);
            }
            IType cls = context.GetType(ev.ReturnType);

            if (cls == null)
            {
                return(null);
            }
            foreach (IMethod m in cls.Methods)
            {
                if (m.Name == "Invoke")
                {
                    return(m);
                }
            }
            return(null);
        }
 void FillClasses(MoonlightProject project)
 {
     if (classesFilled)
     {
         return;
     }
     classesFilled = true;
     try {
         ProjectDom dom     = ProjectDomService.GetProjectDom(project);
         IType      appType = dom.GetType("System.Windows.Application", true);
         if (appType == null)
         {
             return;
         }
         foreach (IType type in dom.GetSubclasses(appType, false))
         {
             classListStore.AppendValues(type.FullName);
         }
     } catch (InvalidOperationException) {
         // Project not found in parser database
     }
 }
Exemplo n.º 23
0
        internal static void AddType(ProjectDom dom, List <object> result, IReturnType returnType, IMember callingMember, bool showStatic)
        {
            if (returnType == null || returnType.FullName == "System.Void")
            {
                return;
            }
            if (returnType.ArrayDimensions > 0)
            {
                DomReturnType elementType = new DomReturnType(returnType.FullName);
                elementType.ArrayDimensions = returnType.ArrayDimensions - 1;
                for (int i = 0; i < elementType.ArrayDimensions; i++)
                {
                    elementType.SetDimension(i, returnType.ArrayDimensions - 1);
                }
                elementType.PointerNestingLevel = returnType.PointerNestingLevel;

                AddType(dom, result, dom.GetArrayType(elementType), callingMember, showStatic);
                return;
            }
            IType type = dom.GetType(returnType);

            AddType(dom, result, type, callingMember, showStatic);
        }
Exemplo n.º 24
0
        static bool IsValidClass(ProjectDom ctx, IType cls, Stetic.Component obj)
        {
            if (cls.BaseTypes != null)
            {
                string typeName = obj.Type.ClassName;

                foreach (IReturnType bt in cls.BaseTypes)
                {
                    System.Console.WriteLine("tn:" + typeName + " bt:" + bt.FullName);
                    if (bt.FullName == typeName)
                    {
                        return(true);
                    }

                    IType baseCls = ctx.GetType(bt);
                    if (baseCls != null && IsValidClass(ctx, baseCls, obj))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Exemplo n.º 25
0
        void FindOverridables(ProjectDom pctx, IType motherClass, IType cls, List <IMember> classMembers, List <IMember> interfaceMembers, List <IType> visited, bool includeOverridenClassMembers, bool includeOverridenInterfaceMembers)
        {
            if (visited.Contains(cls))
            {
                return;
            }

            visited.Add(cls);

            foreach (IReturnType rt in cls.BaseTypes)
            {
                IType baseCls = pctx.GetType(rt);

                if (baseCls == null)
                {
                    continue;
                }

                if (visited.Contains(baseCls))
                {
                    continue;
                }

                bool isInterface = baseCls.ClassType == ClassType.Interface;
                if (isInterface && interfaceMembers == null)
                {
                    continue;
                }
                List <IMember> list             = isInterface ? interfaceMembers : classMembers;
                bool           includeOverriden = isInterface ? includeOverridenInterfaceMembers : includeOverridenClassMembers;

                foreach (IMethod m in baseCls.Methods)
                {
                    if (m.IsInternal && motherClass.SourceProject != null && motherClass.SourceProject != m.DeclaringType.SourceProject)
                    {
                        continue;
                    }
                    if ((isInterface || m.IsVirtual || m.IsAbstract) && !m.IsSpecialName && !m.IsSealed && (includeOverriden || !IsOverridenMethod(motherClass, m)))
                    {
                        list.Add(m);
                    }
                }
                foreach (IProperty m in baseCls.Properties)
                {
                    if (m.IsIndexer)
                    {
                        continue;
                    }
                    if (m.IsInternal && motherClass.SourceProject != null && motherClass.SourceProject != m.DeclaringType.SourceProject)
                    {
                        continue;
                    }
                    if ((isInterface || m.IsVirtual || m.IsAbstract) && !m.IsSpecialName && !m.IsSealed && (includeOverriden || !IsOverridenProperty(motherClass, m)))
                    {
                        list.Add(m);
                    }
                }
                foreach (IProperty m in baseCls.Properties)
                {
                    if (!m.IsIndexer)
                    {
                        continue;
                    }
                    if (m.IsInternal && motherClass.SourceProject != null && motherClass.SourceProject != m.DeclaringType.SourceProject)
                    {
                        continue;
                    }
                    if ((isInterface || m.IsVirtual || m.IsAbstract) && !m.IsSpecialName && !m.IsSealed && (includeOverriden || !IsOverridenIndexer(motherClass, m)))
                    {
                        list.Add(m);
                    }
                }
                foreach (IEvent m in baseCls.Events)
                {
                    if (m.IsInternal && motherClass.SourceProject != null && motherClass.SourceProject != m.DeclaringType.SourceProject)
                    {
                        continue;
                    }
                    if ((isInterface || m.IsVirtual || m.IsAbstract) && !m.IsSpecialName && !m.IsSealed)
                    {
                        list.Add(m);
                    }
                }

                FindOverridables(pctx, motherClass, baseCls, classMembers, isInterface ? interfaceMembers : null, visited,
                                 includeOverridenClassMembers, includeOverridenInterfaceMembers);
            }
        }
Exemplo n.º 26
0
        //TODO: check accessibility
        public static IEnumerable <IMethod> GetCompatibleMethodsInClass(ProjectDom ctx, IType cls, IMethod matchMeth)
        {
            IList <IType>[] pars = new IList <IType> [matchMeth.Parameters.Count];
            for (int i = 0; i < matchMeth.Parameters.Count; i++)
            {
                IType t = ctx.GetType(matchMeth.Parameters[i].ReturnType);
                if (t != null)
                {
                    pars[i] = new List <IType> (ctx.GetInheritanceTree(t));
                }
                else
                {
                    pars[i] = new IType[0];
                }
            }

            foreach (IType type in ctx.GetInheritanceTree(cls))
            {
                if (type.ClassType != ClassType.Class)
                {
                    continue;
                }

                foreach (IMethod method in type.Methods)
                {
                    if (method.IsPrivate || method.Parameters.Count != pars.Length || method.ReturnType.FullName != matchMeth.ReturnType.FullName

                        || method.IsInternal)
                    {
                        continue;
                    }

                    bool allCompatible = true;

                    //compare each parameter
                    for (int i = 0; i < pars.Length; i++)
                    {
                        bool parCompatible = false;
                        foreach (IType t in pars[i])
                        {
                            if (t.FullName == method.Parameters[i].ReturnType.FullName)
                            {
                                parCompatible = true;
                                break;
                            }
                        }

                        if (!parCompatible)
                        {
                            allCompatible = false;
                            break;
                        }
                    }

                    if (allCompatible)
                    {
                        yield return(method);
                    }
                }
            }
        }
Exemplo n.º 27
0
        public static IMember GetCompatibleMemberInClass(ProjectDom ctx, IType cls, CodeTypeMember member)
        {
            //check for identical property names
            foreach (IProperty prop in cls.Properties)
            {
                if (string.Compare(prop.Name, member.Name, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    EnsureClassExists(ctx, prop.ReturnType.FullName, GetValidRegion(prop));
                    CodeMemberProperty memProp = member as CodeMemberProperty;
                    if (memProp == null || !IsTypeCompatible(ctx, prop.ReturnType.FullName, memProp.Type.BaseType))
                    {
                        throw new MemberExistsException(cls.FullName, MemberType.Property, member, GetValidRegion(prop), cls.CompilationUnit.FileName);
                    }
                    return(prop);
                }
            }

            //check for identical method names
            foreach (IMethod meth in cls.Methods)
            {
                if (string.Compare(meth.Name, member.Name, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    EnsureClassExists(ctx, meth.ReturnType.FullName, GetValidRegion(meth));
                    CodeMemberMethod memMeth = member as CodeMemberMethod;
                    if (memMeth == null || !IsTypeCompatible(ctx, meth.ReturnType.FullName, memMeth.ReturnType.BaseType))
                    {
                        throw new MemberExistsException(cls.FullName, MemberType.Method, member, GetValidRegion(meth), cls.CompilationUnit.FileName);
                    }
                    return(meth);
                }
            }

            //check for identical event names
            foreach (IEvent ev in cls.Events)
            {
                if (string.Compare(ev.Name, member.Name, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    EnsureClassExists(ctx, ev.ReturnType.FullName, GetValidRegion(ev));
                    CodeMemberEvent memEv = member as CodeMemberEvent;
                    if (memEv == null || !IsTypeCompatible(ctx, ev.ReturnType.FullName, memEv.Type.BaseType))
                    {
                        throw new MemberExistsException(cls.FullName, MemberType.Event, member, GetValidRegion(ev), cls.CompilationUnit.FileName);
                    }
                    return(ev);
                }
            }

            //check for identical field names
            foreach (IField field in cls.Fields)
            {
                if (string.Compare(field.Name, member.Name, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    EnsureClassExists(ctx, field.ReturnType.FullName, GetValidRegion(field));
                    CodeMemberField memField = member as CodeMemberField;
                    if (memField == null || !IsTypeCompatible(ctx, field.ReturnType.FullName, memField.Type.BaseType))
                    {
                        throw new MemberExistsException(cls.FullName, MemberType.Field, member, GetValidRegion(field), cls.CompilationUnit.FileName);
                    }
                    return(field);
                }
            }

            //walk down into base classes, if any
            foreach (IReturnType baseType in cls.BaseTypes)
            {
                IType c = ctx.GetType(baseType);
                if (c == null)
                {
                    throw new TypeNotFoundException(baseType.FullName, cls.BodyRegion, cls.CompilationUnit.FileName);
                }
                IMember mem = GetCompatibleMemberInClass(ctx, c, member);
                if (mem != null)
                {
                    return(mem);
                }
            }

            //return null if no match
            return(null);
        }
Exemplo n.º 28
0
        void Refactor(IProgressMonitor monitor, IType cls, RefactoryScope scope, RefactorDelegate refactorDelegate)
        {
            switch (scope)
            {
            case RefactoryScope.DeclaringType:
                ProjectDom ctx = GetParserContext(cls);
                if (cls is InstantiatedType)
                {
                    cls = ((InstantiatedType)cls).UninstantiatedType;
                }
                IType resolvedType = ctx.GetType(cls.FullName, cls.TypeParameters.Count, true, true);
                if (resolvedType == null)
                {
                    goto case RefactoryScope.Solution;
                }
                foreach (IType part in resolvedType.Parts)
                {
                    string            file = part.CompilationUnit.FileName;
                    RefactorerContext gctx = GetGeneratorContext(part);
                    IRefactorer       gen  = LanguageBindingService.GetRefactorerForFile(file);
                    if (gen == null)
                    {
                        return;
                    }
                    refactorDelegate(monitor, gctx, gen, file);
                    gctx.Save();
                }
                break;

            case RefactoryScope.File: {
                string            file = cls.CompilationUnit.FileName;
                RefactorerContext gctx = GetGeneratorContext(cls);
                IRefactorer       gen  = LanguageBindingService.GetRefactorerForFile(file);
                if (gen == null)
                {
                    return;
                }
                refactorDelegate(monitor, gctx, gen, file);
                gctx.Save();
                break;
            }

            case RefactoryScope.Project:
                Project prj = GetProjectForFile(cls.CompilationUnit.FileName);
                if (prj == null)
                {
                    return;
                }
                RefactorProject(monitor, prj, refactorDelegate);
                break;

            case RefactoryScope.Solution:
                if (solution == null)
                {
                    goto case RefactoryScope.File;
                }
                foreach (Project project in solution.GetAllProjects())
                {
                    RefactorProject(monitor, project, refactorDelegate);
                }
                break;
            }
        }
Exemplo n.º 29
0
 public static IType AssemblyTypeLookup(ProjectDom assemblyDatabase, string namespac, string tagName)
 {
     return((assemblyDatabase == null)
                         ? null
                         : assemblyDatabase.GetType(namespac + "." + tagName, false, false));
 }
Exemplo n.º 30
0
        /// <summary>
        /// Resolves the Objective-C types by mapping the known .NET type information.
        /// </summary>
        /// <param name='type'>
        /// An NSObjectTypeInfo with the .NET type information filled in.
        /// </param>
        public void ResolveCliToObjc(NSObjectTypeInfo type)
        {
            NSObjectTypeInfo resolved;

            if (type.BaseObjCType == null && type.BaseCliType != null)
            {
                if (TryResolveCliToObjc(type.BaseCliType, out resolved))
                {
                    if (resolved.IsModel)
                    {
                        type.BaseIsModel = true;
                    }
                    type.BaseObjCType = resolved.ObjCName;
                    //FIXME: handle type references better
                    if (resolved.IsUserType)
                    {
                        type.UserTypeReferences.Add(resolved.ObjCName);
                    }
                }
                else
                {
                    // managed classes may have implicitly registered base classes with a name not
                    // expressible in obj-c. In this case, the best we can do is walk down the
                    // hierarchy until we find a valid base class
                    foreach (var bt in dom.GetInheritanceTree(dom.GetType(type.BaseCliType)))
                    {
                        if (bt.ClassType != ClassType.Class)
                        {
                            continue;
                        }

                        if (TryResolveCliToObjc(bt.FullName, out resolved))
                        {
                            if (resolved.IsModel)
                            {
                                type.BaseIsModel = true;
                            }
                            type.BaseObjCType = resolved.ObjCName;
                            if (resolved.IsUserType)
                            {
                                type.UserTypeReferences.Add(resolved.ObjCName);
                            }
                            break;
                        }
                    }
                }
            }

            foreach (var outlet in type.Outlets)
            {
                if (outlet.ObjCType != null)
                {
                    continue;
                }

                if (TryResolveCliToObjc(outlet.CliType, out resolved))
                {
                    outlet.ObjCType = resolved.ObjCName;
                    if (resolved.IsUserType)
                    {
                        type.UserTypeReferences.Add(resolved.ObjCName);
                    }
                }
            }

            foreach (var action in type.Actions)
            {
                foreach (var param in action.Parameters)
                {
                    if (param.ObjCType != null)
                    {
                        continue;
                    }

                    if (TryResolveCliToObjc(param.CliType, out resolved))
                    {
                        param.ObjCType = resolved.ObjCName;
                        if (resolved.IsUserType)
                        {
                            type.UserTypeReferences.Add(resolved.ObjCName);
                        }
                    }
                }
            }
        }