Beispiel #1
0
        public INamedTypeSymbol GetClass(bool getUserClass)
        {
            if (targetObject == null)
            {
                return(null);
            }

            var cls = gproject.FindClass(className, getUserClass);

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

            // The class name may have changed. Try to guess the new name.
//			TODO (roslyn port) - is that really required ?
//			var matches = new List<INamedTypeSymbol> ();
//			ParsedDocument unit = null;
//			var ctx = gproject.GetParserContext ();
//			var doc = IdeApp.TypeSystemService.ParseFile (project, classFile);
//			if (doc != null) {
//				unit = doc;
//				foreach (var fcls in unit.TopLevelTypeDefinitions) {
//					if (IsValidClass (fcls, targetObject))
//						matches.Add (fcls);
//				}
//			}
//
//			// If found the class, just return it
//			if (matches.Count == 1) {
//				cls = matches [0];
//				className = cls.GetFullName ();
//				targetObject.Name = className;
//				gproject.SaveWindow (true, targetObject.Name);
//				return cls;
//			}
//
//			// If not found, warn the user.
//
//			if (unit != null && unit.TopLevelTypeDefinitions.Count > 0) {
//				using (var dialog = new SelectRenamedClassDialog (unit.TopLevelTypeDefinitions.Select (c => c.Resolve (project)))) {
//					if (dialog.Run ()) {
//						className = dialog.SelectedClass;
//						if (className == null)
//							return null;
//						else {
//							targetObject.Name = className;
//							gproject.SaveWindow (true, targetObject.Name);
//							return gproject.FindClass (className);
//						}
//					}
//				}
//			} else {
//				MessageService.ShowError (GettextCatalog.GetString ("The class bound to the component '{0}' could not be found. This may be due to syntax errors in the source code file.", GetObjectName(targetObject)));
//			}

            return(null);
        }
Beispiel #2
0
        public IType GetClass(bool getUserClass)
        {
            if (targetObject == null)
            {
                return(null);
            }

            IType cls = gproject.FindClass(className, getUserClass);

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

            // The class name may have changed. Try to guess the new name.

            ArrayList        matches = new ArrayList();
            ICompilationUnit unit    = null;
            ProjectDom       ctx     = gproject.GetParserContext();
            ParsedDocument   doc     = ProjectDomService.Parse(project, classFile, null);

            if (doc != null && doc.CompilationUnit != null)
            {
                unit = doc.CompilationUnit;
                foreach (IType fcls in unit.Types)
                {
                    if (IsValidClass(ctx, fcls, targetObject))
                    {
                        matches.Add(fcls);
                    }
                }
            }

            // If found the class, just return it
            if (matches.Count == 1)
            {
                cls               = (IType)matches [0];
                className         = cls.FullName;
                targetObject.Name = className;
                gproject.Save(true);
                return(cls);
            }

            // If not found, warn the user.

            if (unit != null && unit.Types.Count > 0)
            {
                using (SelectRenamedClassDialog dialog = new SelectRenamedClassDialog(unit.Types)) {
                    if (dialog.Run())
                    {
                        className = dialog.SelectedClass;
                        if (className == null)
                        {
                            return(null);
                        }
                        else
                        {
                            targetObject.Name = className;
                            gproject.Save(true);
                            return(gproject.FindClass(className));
                        }
                    }
                }
            }
            else
            {
                MessageService.ShowError(GettextCatalog.GetString("The class bound to the component '{0}' could not be found. This may be due to syntax errors in the source code file.", GetObjectName(targetObject)));
            }

            return(null);
        }
Beispiel #3
0
        public IUnresolvedTypeDefinition GetClass(bool getUserClass)
        {
            if (targetObject == null)
            {
                return(null);
            }

            var cls = gproject.FindClass(className, getUserClass);

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

            // The class name may have changed. Try to guess the new name.

            var            matches = new List <IUnresolvedTypeDefinition> ();
            ParsedDocument unit    = null;
            var            ctx     = gproject.GetParserContext();
            var            doc     = TypeSystemService.ParseFile(project, classFile);

            if (doc != null)
            {
                unit = doc;
                foreach (var fcls in unit.TopLevelTypeDefinitions)
                {
                    if (IsValidClass(fcls.Resolve(project), targetObject))
                    {
                        matches.Add(fcls);
                    }
                }
            }

            // If found the class, just return it
            if (matches.Count == 1)
            {
                cls               = matches [0];
                className         = cls.FullName;
                targetObject.Name = className;
                gproject.Save(true);
                return(cls);
            }

            // If not found, warn the user.

            if (unit != null && unit.TopLevelTypeDefinitions.Count > 0)
            {
                using (SelectRenamedClassDialog dialog = new SelectRenamedClassDialog(unit.TopLevelTypeDefinitions.Select(c => c.Resolve(project)))) {
                    if (dialog.Run())
                    {
                        className = dialog.SelectedClass;
                        if (className == null)
                        {
                            return(null);
                        }
                        else
                        {
                            targetObject.Name = className;
                            gproject.Save(true);
                            return(gproject.FindClass(className));
                        }
                    }
                }
            }
            else
            {
                MessageService.ShowError(GettextCatalog.GetString("The class bound to the component '{0}' could not be found. This may be due to syntax errors in the source code file.", GetObjectName(targetObject)));
            }

            return(null);
        }