Example #1
0
        public void SetUpFixture()
        {
            RubyParser         parser             = new RubyParser();
            MockProjectContent mockProjectContent = new MockProjectContent();
            ICompilationUnit   compilationUnit    = parser.Parse(mockProjectContent, @"C:\Projects\test\MainForm.py", GetRubyCode());

            parseInfo = new ParseInformation(compilationUnit);

            if (compilationUnit.Classes.Count > 0)
            {
                mainFormClass = compilationUnit.Classes[0];
                initializeComponentsMethod = FormsDesignerSecondaryDisplayBinding.GetInitializeComponents(mainFormClass);
            }
        }
Example #2
0
 /// <summary>
 /// Gets the non-generated InitializeComponents from the compilation unit.
 /// </summary>
 public static IMethod GetInitializeComponents(ICompilationUnit unit)
 {
     foreach (IClass c in unit.Classes)
     {
         if (FormsDesignerSecondaryDisplayBinding.BaseClassIsFormOrControl(c))
         {
             IMethod method = FormsDesignerSecondaryDisplayBinding.GetInitializeComponents(c);
             if (method != null)
             {
                 return(method);
             }
         }
     }
     return(null);
 }
 public bool CanAttachTo(IViewContent viewContent)
 {
     if (viewContent is ITextEditorControlProvider)
     {
         ITextEditorControlProvider textAreaControlProvider = (ITextEditorControlProvider)viewContent;
         string fileExtension = String.Empty;
         string fileName      = viewContent.PrimaryFileName;
         if (fileName == null)
         {
             return(false);
         }
         if (Path.GetExtension(fileName).Equals(".boo", StringComparison.OrdinalIgnoreCase))
         {
             ParseInformation info = ParserService.ParseFile(fileName, textAreaControlProvider.TextEditorControl.Document.TextContent, false);
             if (FormsDesignerSecondaryDisplayBinding.IsDesignable(info))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
        Module ParseFormAsModule()
        {
            // The module is cached while loading so that
            // determining the localization model and generating the CodeDOM
            // does not require the code to be parsed twice.
            if (this.parsedModule != null && lastTextContent == this.Generator.ViewContent.DesignerCodeFileContent)
            {
                return(this.parsedModule);
            }

            lastTextContent = this.Generator.ViewContent.DesignerCodeFileContent;

            ParseInformation parseInfo = ParserService.ParseFile(this.Generator.ViewContent.DesignerCodeFile.FileName, this.Generator.ViewContent.DesignerCodeFileContent, false);
            // ensure that there are no syntax errors in the file:
            Module mainModule = Parse(this.Generator.ViewContent.DesignerCodeFile.FileName, lastTextContent);

            IClass         formClass;
            bool           isFirstClassInFile;
            IList <IClass> parts = NRefactoryDesignerLoader.FindFormClassParts(parseInfo, out formClass, out isFirstClassInFile);

            IMethod initMethod = FormsDesignerSecondaryDisplayBinding.GetInitializeComponents(formClass);

            if (initMethod == null)
            {
                throw new FormsDesignerLoadException("The InitializeComponent method was not found. Designer cannot be loaded.");
            }

            Module module = new Module();

            module.Namespace = new NamespaceDeclaration(formClass.Namespace);
            ClassDefinition cld = new ClassDefinition();

            cld.Name = formClass.Name;
            module.Members.Add(cld);
            if (formClass.BaseClass == null)
            {
                throw new FormsDesignerLoadException("formClass.BaseClass returned null.");
            }
            cld.BaseTypes.Add(new SimpleTypeReference(formClass.BaseClass.FullyQualifiedName));

            System.Diagnostics.Debug.Assert(FileUtility.IsEqualFileName(initMethod.DeclaringType.CompilationUnit.FileName, this.Generator.ViewContent.DesignerCodeFile.FileName));

            foreach (IField f in formClass.Fields)
            {
                Field field = new Field();
                field.Name = f.Name;
                if (f.ReturnType.IsDefaultReturnType)
                {
                    field.Type = new SimpleTypeReference(f.ReturnType.FullyQualifiedName);
                }
                field.Modifiers = CodeCompletion.ConvertVisitor.ConvertVisibilityBack(f.Modifiers);
                cld.Members.Add(field);
            }

            // Now find InitializeComponent in parsed module and put it into our new module
            foreach (TypeMember m in mainModule.Members)
            {
                TypeDefinition td = m as TypeDefinition;
                if (td == null)
                {
                    continue;
                }
                foreach (TypeMember m2 in td.Members)
                {
                    Method method = m2 as Method;
                    if (method != null &&
                        FormsDesignerSecondaryDisplayBinding.IsInitializeComponentsMethodName(method.Name) &&
                        method.Parameters.Count == 0)
                    {
                        cld.Members.Add(method);
                        this.parsedModule = module;
                        return(module);
                    }
                }
            }
            throw new FormsDesignerLoadException("Could not find InitializeComponent in parsed module.");
        }
 /// <summary>
 /// Determines whether the specified parse information contains
 /// a class which is designable.
 /// </summary>
 protected virtual bool IsDesignable(ParseInformation parseInfo)
 {
     return(FormsDesignerSecondaryDisplayBinding.IsDesignable(parseInfo));
 }
Example #6
0
 public void IsDesignable()
 {
     Assert.IsTrue(FormsDesignerSecondaryDisplayBinding.IsDesignable(parseInfo));
 }
Example #7
0
 public void BaseClassIsForm()
 {
     Assert.IsTrue(FormsDesignerSecondaryDisplayBinding.BaseClassIsFormOrControl(mainFormClass));
 }