Beispiel #1
0
        public LanguageItemCollection CtrlSpace(IParserContext parserService, int caretLine, int caretColumn, string fileName)
        {
            LanguageItemCollection result = new LanguageItemCollection();

            this.parserService = parserService;
            IParseInformation parseInfo = parserService.GetParseInformation(fileName);

            JRefactory.Parser.AST.CompilationUnit fileCompilationUnit = parseInfo.MostRecentCompilationUnit.Tag as JRefactory.Parser.AST.CompilationUnit;
            if (fileCompilationUnit == null)
            {
                return(null);
            }
            lookupTableVisitor = new LookupTableVisitor();
            lookupTableVisitor.Visit(fileCompilationUnit, null);
            JavaVisitor cSharpVisitor = new JavaVisitor();

            cu = (ICompilationUnit)cSharpVisitor.Visit(fileCompilationUnit, null);
            if (cu != null)
            {
                callingClass = GetInnermostClass();
//				Console.WriteLine("CallingClass is " + callingClass == null ? "null" : callingClass.Name);
            }
            foreach (string name in lookupTableVisitor.variables.Keys)
            {
                ArrayList variables = (ArrayList)lookupTableVisitor.variables[name];
                if (variables != null && variables.Count > 0)
                {
                    foreach (LocalLookupVariable v in variables)
                    {
                        if (IsInside(new Point(caretColumn, caretLine), v.StartPos, v.EndPos))
                        {
                            result.Add(v);
                            break;
                        }
                    }
                }
            }
            if (callingClass != null)
            {
                result = ListMembers(result, callingClass);
            }
            string n = "";

            result.AddRange(parserService.GetNamespaceContents(n));
            foreach (IUsing u in cu.Usings)
            {
                if (u != null && (u.Region == null || u.Region.IsInside(caretLine, caretColumn)))
                {
                    foreach (string name in u.Usings)
                    {
                        result.AddRange(parserService.GetNamespaceContents(name));
                    }
                    foreach (string alias in u.Aliases.Keys)
                    {
                        result.Add(alias);
                    }
                }
            }
            return(result);
        }
Beispiel #2
0
        public ResolveResult real_resolve(IParserContext parserContext, int caretLineNumber, int caretColumn, string fileName, string fileContent, bool completeLocals)
        {
            try
            {
                DefaultCompilationUnit comp = (DefaultCompilationUnit)parserContext.GetParseInformation(fileName).MostRecentCompilationUnit;
                Class the_class             = null;
                foreach (DefaultClass cl in comp.Classes)
                {
                    if (cl.BodyRegion.BeginLine <= caretLineNumber &&
                        cl.BodyRegion.EndLine >= caretLineNumber)
                    {
                        the_class = (Class)cl;
                    }
                    foreach (DefaultClass nc in cl.InnerClasses)
                    {
                        if (nc.BodyRegion.BeginLine <= caretLineNumber &&
                            nc.BodyRegion.EndLine >= caretLineNumber)
                        {
                            the_class = (Class)nc;
                        }
                    }
                    if (the_class != null)
                    {
                        break;
                    }
                }

                if (the_class == null)
                {
                    return(null);
                }
                else
                {
                    INemerleMethod the_method = null;
                    int            line = 0, column = 0, end_line = 0, end_column = 0;
                    foreach (DefaultMethod m in the_class.Methods)
                    {
                        if (m.BodyRegion.BeginLine <= caretLineNumber &&
                            m.BodyRegion.EndLine >= caretLineNumber &&
                            m.BodyRegion.BeginLine != the_class.BodyRegion.BeginLine)
                        {
                            the_method = (INemerleMethod)m;
                            line       = m.BodyRegion.BeginLine;
                            column     = m.BodyRegion.BeginColumn;
                            end_line   = m.BodyRegion.EndLine;
                            end_column = m.BodyRegion.EndColumn;
                            break;
                        }
                    }

                    if (the_method == null)
                    {
                        // Try with properties
                        foreach (Property p in the_class.Properties)
                        {
                            if (p.GetterRegion != null)
                            {
                                if (p.GetterRegion.BeginLine <= caretLineNumber &&
                                    p.GetterRegion.EndLine >= caretLineNumber)
                                {
                                    the_method = (INemerleMethod)p.Getter;
                                    line       = p.GetterRegion.BeginLine;
                                    column     = p.GetterRegion.BeginColumn;
                                    end_line   = p.BodyRegion.EndLine;
                                    end_column = p.BodyRegion.EndColumn;
                                    break;
                                }
                            }

                            if (p.SetterRegion != null)
                            {
                                if (p.SetterRegion.BeginLine <= caretLineNumber &&
                                    p.SetterRegion.EndLine >= caretLineNumber)
                                {
                                    the_method = (INemerleMethod)p.Setter;
                                    line       = p.SetterRegion.BeginLine;
                                    column     = p.SetterRegion.BeginColumn;
                                    end_line   = p.BodyRegion.EndLine;
                                    end_column = p.BodyRegion.EndColumn;
                                    break;
                                }
                            }
                        }

                        foreach (Indexer p in the_class.Indexer)
                        {
                            if (p.GetterRegion != null)
                            {
                                if (p.GetterRegion.BeginLine <= caretLineNumber &&
                                    p.GetterRegion.EndLine >= caretLineNumber)
                                {
                                    the_method = (INemerleMethod)p.Getter;
                                    line       = p.GetterRegion.BeginLine;
                                    column     = p.GetterRegion.BeginColumn;
                                    end_line   = p.BodyRegion.EndLine;
                                    end_column = p.BodyRegion.EndColumn;
                                    break;
                                }
                            }

                            if (p.SetterRegion != null)
                            {
                                if (p.SetterRegion.BeginLine <= caretLineNumber &&
                                    p.SetterRegion.EndLine >= caretLineNumber)
                                {
                                    the_method = (INemerleMethod)p.Setter;
                                    line       = p.SetterRegion.BeginLine;
                                    column     = p.SetterRegion.BeginColumn;
                                    end_line   = p.BodyRegion.EndLine;
                                    end_column = p.BodyRegion.EndColumn;
                                    break;
                                }
                            }
                        }
                    }

                    if (the_method == null)
                    {
                        return(null);
                    }
                    else
                    {
                        // Recover the text from the start of the method to cursor
                        string method_start = Crop(fileContent, line, column, caretLineNumber, caretColumn);
                        string method_end   = Crop(fileContent, caretLineNumber, caretColumn, end_line, end_column) + "}";
                        // System.Console.WriteLine (method_start + method_end);
                        NCC.CompletionResult infox = engine.RunCompletionEngine((NCC.MethodBuilder)the_method.Member,
                                                                                method_start + method_end, method_start.Length);

                        return(GetResults(infox, comp, completeLocals));
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
                return(null);
            }
        }
Beispiel #3
0
        public ResolveResult Resolve(IParserContext parserService, string expression, int caretLineNumber, int caretColumn, string fileName, string fileContent)
        {
            Console.WriteLine("Start Resolving");
            if (expression == null)
            {
                return(null);
            }
            expression = expression.TrimStart(null);
            if (expression == "")
            {
                return(null);
            }
            if (expression.StartsWith("using "))
            {
                // expression[expression.Length - 1] != '.'
                // the period that causes this Resove() is not part of the expression
                if (expression[expression.Length - 1] == '.')
                {
                    return(null);
                }
                int i;
                for (i = expression.Length - 1; i >= 0; --i)
                {
                    if (!(Char.IsLetterOrDigit(expression[i]) || expression[i] == '_' || expression[i] == '.'))
                    {
                        break;
                    }
                }
                // no Identifier before the period
                if (i == expression.Length - 1)
                {
                    return(null);
                }
                string t = expression.Substring(i + 1);
//				Console.WriteLine("in Using Statement");
                string[] namespaces = parserService.GetNamespaceList(t);
                if (namespaces == null || namespaces.Length <= 0)
                {
                    return(null);
                }
                return(new ResolveResult(namespaces));
            }

            Console.WriteLine("Not in Using");
            this.caretLine   = caretLineNumber;
            this.caretColumn = caretColumn;

            this.parserService = parserService;
            IParseInformation parseInfo = parserService.GetParseInformation(fileName);

            JRefactory.Parser.AST.CompilationUnit fileCompilationUnit = parseInfo.MostRecentCompilationUnit.Tag as JRefactory.Parser.AST.CompilationUnit;
            if (fileCompilationUnit == null)
            {
//				JRefactory.Parser.Parser fileParser = new JRefactory.Parser.Parser();
//				fileParser.Parse(new Lexer(new StringReader(fileContent)));
                Console.WriteLine("!Warning: no parseinformation!");
                return(null);
            }

            /*
             * //// try to find last expression in original string, it could be like " if (act!=null) act"
             * //// in this case only "act" should be parsed as expression
             * !!is so!! don't change things that work
             * Expression expr=null;	// tentative expression
             * Lexer l=null;
             * JRefactory.Parser.Parser p = new JRefactory.Parser.Parser();
             * while (expression.Length > 0) {
             *      l = new Lexer(new StringReader(expression));
             *      expr = p.ParseExpression(l);
             *      if (l.LookAhead.val != "" && expression.LastIndexOf(l.LookAhead.val) >= 0) {
             *              if (expression.Substring(expression.LastIndexOf(l.LookAhead.val) + l.LookAhead.val.Length).Length > 0)
             *                      expression=expression.Substring(expression.LastIndexOf(l.LookAhead.val) + l.LookAhead.val.Length).Trim();
             *              else {
             *                      expression=l.LookAhead.val.Trim();
             *                      l=new Lexer(new StringReader(expression));
             *                      expr=p.ParseExpression(l);
             *                      break;
             *              }
             *      } else {
             *              if (l.Token.val!="" || expr!=null) break;
             *      }
             * }
             * //// here last subexpression should be fixed in expr
             * if it should be changed in expressionfinder don't fix it here
             */
            JRefactory.Parser.Parser p = new JRefactory.Parser.Parser();
            Lexer      l    = new Lexer(new StringReader(expression));
            Expression expr = p.ParseExpression(l);

            if (expr == null)
            {
                return(null);
            }
            lookupTableVisitor = new LookupTableVisitor();
            lookupTableVisitor.Visit(fileCompilationUnit, null);

            TypeVisitor typeVisitor = new TypeVisitor(this);

            JavaVisitor cSharpVisitor = new JavaVisitor();

            cu = (ICompilationUnit)cSharpVisitor.Visit(fileCompilationUnit, null);
            if (cu != null)
            {
                callingClass = GetInnermostClass();
                //Console.WriteLine("CallingClass is " + callingClass == null ? "null" : callingClass.Name);
            }
            //Console.WriteLine("expression = " + expr.ToString());
            IReturnType type = expr.AcceptVisitor(typeVisitor, null) as IReturnType;

            //Console.WriteLine("type visited");
            if (type == null || type.PointerNestingLevel != 0)
            {
//				Console.WriteLine("Type == null || type.PointerNestingLevel != 0");
                if (type != null)
                {
                    //Console.WriteLine("PointerNestingLevel is " + type.PointerNestingLevel);
                }
                else
                {
                    //Console.WriteLine("Type == null");
                }
                //// when type is null might be file needs to be reparsed - some vars were lost
                fileCompilationUnit = parserService.ParseFile(fileName, fileContent).MostRecentCompilationUnit.Tag
                                      as JRefactory.Parser.AST.CompilationUnit;
                lookupTableVisitor.Visit(fileCompilationUnit, null);
                cu = (ICompilationUnit)cSharpVisitor.Visit(fileCompilationUnit, null);
                if (cu != null)
                {
                    callingClass = GetInnermostClass();
                }
                type = expr.AcceptVisitor(typeVisitor, null) as IReturnType;
                if (type == null)
                {
                    return(null);
                }
            }
            if (type.ArrayDimensions != null && type.ArrayDimensions.Length > 0)
            {
                type = new ReturnType("System.Array");
            }
            Console.WriteLine("Here: Type is " + type.FullyQualifiedName);
            IClass returnClass = SearchType(type.FullyQualifiedName, cu);

            if (returnClass == null)
            {
                // Try if type is Namespace:
                string n = SearchNamespace(type.FullyQualifiedName, cu);
                if (n == null)
                {
                    return(null);
                }
                ArrayList content = parserService.GetNamespaceContents(n);
                ArrayList classes = new ArrayList();
                for (int i = 0; i < content.Count; ++i)
                {
                    if (content[i] is IClass)
                    {
                        classes.Add((IClass)content[i]);
                    }
                }
                string[] namespaces = parserService.GetNamespaceList(n);
                return(new ResolveResult(namespaces, classes));
            }
            Console.WriteLine("Returning Result!");
            return(new ResolveResult(returnClass, ListMembers(new ArrayList(), returnClass)));
        }
Beispiel #4
0
		public LanguageItemCollection CtrlSpace(IParserContext parserService, int caretLine, int caretColumn, string fileName)
		{
			LanguageItemCollection result = new LanguageItemCollection();
			this.parserService = parserService;
			IParseInformation parseInfo = parserService.GetParseInformation(fileName);
			JRefactory.Parser.AST.CompilationUnit fileCompilationUnit = parseInfo.MostRecentCompilationUnit.Tag as JRefactory.Parser.AST.CompilationUnit;
			if (fileCompilationUnit == null) {
				return null;
			}
			lookupTableVisitor = new LookupTableVisitor();
			lookupTableVisitor.Visit(fileCompilationUnit, null);
			JavaVisitor cSharpVisitor = new JavaVisitor ();
			cu = (ICompilationUnit)cSharpVisitor.Visit(fileCompilationUnit, null);
			if (cu != null) {
				callingClass = GetInnermostClass();
//				Console.WriteLine("CallingClass is " + callingClass == null ? "null" : callingClass.Name);
			}
			foreach (string name in lookupTableVisitor.variables.Keys) {
				ArrayList variables = (ArrayList)lookupTableVisitor.variables[name];
				if (variables != null && variables.Count > 0) {
					foreach (LocalLookupVariable v in variables) {
						if (IsInside(new Point(caretColumn, caretLine), v.StartPos, v.EndPos)) {
							result.Add(v);
							break;
						}
					}
				}
			}
			if (callingClass != null) {
				result = ListMembers(result, callingClass);
			}
			string n = "";
			result.AddRange(parserService.GetNamespaceContents(n));
			foreach (IUsing u in cu.Usings) {
				if (u != null && (u.Region == null || u.Region.IsInside(caretLine, caretColumn))) {
					foreach (string name in u.Usings) {
						result.AddRange(parserService.GetNamespaceContents(name));
					}
					foreach (string alias in u.Aliases.Keys) {
						result.Add(alias);
					}
				}
			}
			return result;
		}
Beispiel #5
0
		public ResolveResult Resolve(IParserContext parserService, string expression, int caretLineNumber, int caretColumn, string fileName, string fileContent)
		{
			Console.WriteLine("Start Resolving");
			if (expression == null) {
				return null;
			}
			expression = expression.TrimStart(null);
			if (expression == "") {
				return null;
			}
			if (expression.StartsWith("using ")) {
				// expression[expression.Length - 1] != '.'
				// the period that causes this Resove() is not part of the expression
				if (expression[expression.Length - 1] == '.') {
					return null;
				}
				int i;
				for (i = expression.Length - 1; i >= 0; --i) {
					if (!(Char.IsLetterOrDigit(expression[i]) || expression[i] == '_' || expression[i] == '.')) {
						break;
					}
				}
				// no Identifier before the period
				if (i == expression.Length - 1) {
					return null;
				}
				string t = expression.Substring(i + 1);
//				Console.WriteLine("in Using Statement");
				string[] namespaces = parserService.GetNamespaceList(t);
				if (namespaces == null || namespaces.Length <= 0) {
					return null;
				}
				return new ResolveResult(namespaces);
			}
			
			Console.WriteLine("Not in Using");
			this.caretLine     = caretLineNumber;
			this.caretColumn   = caretColumn;
			
			this.parserService = parserService;
			IParseInformation parseInfo = parserService.GetParseInformation(fileName);
			JRefactory.Parser.AST.CompilationUnit fileCompilationUnit = parseInfo.MostRecentCompilationUnit.Tag as JRefactory.Parser.AST.CompilationUnit;
			if (fileCompilationUnit == null) {
//				JRefactory.Parser.Parser fileParser = new JRefactory.Parser.Parser();
//				fileParser.Parse(new Lexer(new StringReader(fileContent)));
				Console.WriteLine("!Warning: no parseinformation!");
				return null;
			}
			/*
			//// try to find last expression in original string, it could be like " if (act!=null) act"
			//// in this case only "act" should be parsed as expression  
			!!is so!! don't change things that work
			Expression expr=null;	// tentative expression
			Lexer l=null;
			JRefactory.Parser.Parser p = new JRefactory.Parser.Parser();
			while (expression.Length > 0) {
				l = new Lexer(new StringReader(expression));
				expr = p.ParseExpression(l);
				if (l.LookAhead.val != "" && expression.LastIndexOf(l.LookAhead.val) >= 0) {
					if (expression.Substring(expression.LastIndexOf(l.LookAhead.val) + l.LookAhead.val.Length).Length > 0) 
						expression=expression.Substring(expression.LastIndexOf(l.LookAhead.val) + l.LookAhead.val.Length).Trim();
					else {
						expression=l.LookAhead.val.Trim();
						l=new Lexer(new StringReader(expression));
						expr=p.ParseExpression(l);
						break;
					}
				} else {
					if (l.Token.val!="" || expr!=null) break;
				}
			}
			//// here last subexpression should be fixed in expr
			if it should be changed in expressionfinder don't fix it here
			*/
			JRefactory.Parser.Parser p = new JRefactory.Parser.Parser();
			Lexer l = new Lexer(new StringReader(expression));
			Expression expr = p.ParseExpression(l);
			if (expr == null) {
				return null;
			}
			lookupTableVisitor = new LookupTableVisitor();
			lookupTableVisitor.Visit(fileCompilationUnit, null);
			
			TypeVisitor typeVisitor = new TypeVisitor(this);
			
			JavaVisitor cSharpVisitor = new JavaVisitor();
			cu = (ICompilationUnit)cSharpVisitor.Visit(fileCompilationUnit, null);
			if (cu != null) {
				callingClass = GetInnermostClass();
				//Console.WriteLine("CallingClass is " + callingClass == null ? "null" : callingClass.Name);
			}
			//Console.WriteLine("expression = " + expr.ToString());
			IReturnType type = expr.AcceptVisitor(typeVisitor, null) as IReturnType;
			//Console.WriteLine("type visited");
			if (type == null || type.PointerNestingLevel != 0) {
//				Console.WriteLine("Type == null || type.PointerNestingLevel != 0");
				if (type != null) {
					//Console.WriteLine("PointerNestingLevel is " + type.PointerNestingLevel);
				} else {
					//Console.WriteLine("Type == null");
				}
				//// when type is null might be file needs to be reparsed - some vars were lost
				fileCompilationUnit=parserService.ParseFile(fileName, fileContent).MostRecentCompilationUnit.Tag 
					as JRefactory.Parser.AST.CompilationUnit;
				lookupTableVisitor.Visit(fileCompilationUnit,null);
				cu = (ICompilationUnit)cSharpVisitor.Visit(fileCompilationUnit, null);
				if (cu != null) {
					callingClass = GetInnermostClass();
				}
				type=expr.AcceptVisitor(typeVisitor,null) as IReturnType;
				if (type==null)	return null;
			}
			if (type.ArrayDimensions != null && type.ArrayDimensions.Length > 0) {
				type = new ReturnType("System.Array");
			}
			Console.WriteLine("Here: Type is " + type.FullyQualifiedName);
			IClass returnClass = SearchType(type.FullyQualifiedName, cu);
			if (returnClass == null) {
				// Try if type is Namespace:
				string n = SearchNamespace(type.FullyQualifiedName, cu);
				if (n == null) {
					return null;
				}
				ArrayList content = parserService.GetNamespaceContents(n);
				ArrayList classes = new ArrayList();
				for (int i = 0; i < content.Count; ++i) {
					if (content[i] is IClass) {
						classes.Add((IClass)content[i]);
					}
				}
				string[] namespaces = parserService.GetNamespaceList(n);
				return new ResolveResult(namespaces, classes);
			}
			Console.WriteLine("Returning Result!");
			return new ResolveResult(returnClass, ListMembers(new ArrayList(), returnClass));
		}
Beispiel #6
0
 public ResolveResult real_resolve (IParserContext parserContext, int caretLineNumber, int caretColumn, string fileName, string fileContent, bool completeLocals)
 {
     try
     {
         DefaultCompilationUnit comp = (DefaultCompilationUnit)parserContext.GetParseInformation (fileName).MostRecentCompilationUnit;
         Class the_class = null;
         foreach (DefaultClass cl in comp.Classes)
         {
             if (cl.BodyRegion.BeginLine <= caretLineNumber &&
                 cl.BodyRegion.EndLine >= caretLineNumber)
             {
                 the_class = (Class)cl;
             }
             foreach (DefaultClass nc in cl.InnerClasses)
             {
                 if (nc.BodyRegion.BeginLine <= caretLineNumber &&
                     nc.BodyRegion.EndLine >= caretLineNumber)
                 {
                     the_class = (Class)nc;
                 } 
             }
             if (the_class != null) break;
         }
         
         if (the_class == null)
             return null;
         else
         {
             INemerleMethod the_method = null;
             int line = 0, column = 0, end_line = 0, end_column = 0;
             foreach (DefaultMethod m in the_class.Methods)
             {
                 if (m.BodyRegion.BeginLine <= caretLineNumber &&
                     m.BodyRegion.EndLine >= caretLineNumber &&
                     m.BodyRegion.BeginLine != the_class.BodyRegion.BeginLine)
                 {
                     the_method = (INemerleMethod)m;
                     line = m.BodyRegion.BeginLine;
                     column = m.BodyRegion.BeginColumn;
                     end_line = m.BodyRegion.EndLine;
                     end_column = m.BodyRegion.EndColumn;
                     break;
                 }
             }
             
             if (the_method == null)
             {
                 // Try with properties
                 foreach (Property p in the_class.Properties)
                 {
                     if (p.GetterRegion != null)
                     {
                         if (p.GetterRegion.BeginLine <= caretLineNumber &&
                             p.GetterRegion.EndLine >= caretLineNumber)
                         {
                             the_method = (INemerleMethod)p.Getter;
                             line = p.GetterRegion.BeginLine;
                             column = p.GetterRegion.BeginColumn;
                             end_line = p.BodyRegion.EndLine;
                             end_column = p.BodyRegion.EndColumn;
                             break;
                         }
                     }
                     
                     if (p.SetterRegion != null)
                     {
                         if (p.SetterRegion.BeginLine <= caretLineNumber &&
                             p.SetterRegion.EndLine >= caretLineNumber)
                         {
                             the_method = (INemerleMethod)p.Setter;
                             line = p.SetterRegion.BeginLine;
                             column = p.SetterRegion.BeginColumn;
                             end_line = p.BodyRegion.EndLine;
                             end_column = p.BodyRegion.EndColumn;
                             break;
                         }
                     }
                 }
                 
                 foreach (Indexer p in the_class.Indexer)
                 {
                     if (p.GetterRegion != null)
                     {
                         if (p.GetterRegion.BeginLine <= caretLineNumber &&
                             p.GetterRegion.EndLine >= caretLineNumber)
                         {
                             the_method = (INemerleMethod)p.Getter;
                             line = p.GetterRegion.BeginLine;
                             column = p.GetterRegion.BeginColumn;
                             end_line = p.BodyRegion.EndLine;
                             end_column = p.BodyRegion.EndColumn;
                             break;
                         }
                     }
                     
                     if (p.SetterRegion != null)
                     {
                         if (p.SetterRegion.BeginLine <= caretLineNumber &&
                             p.SetterRegion.EndLine >= caretLineNumber)
                         {
                             the_method = (INemerleMethod)p.Setter;
                             line = p.SetterRegion.BeginLine;
                             column = p.SetterRegion.BeginColumn;
                             end_line = p.BodyRegion.EndLine;
                             end_column = p.BodyRegion.EndColumn;
                             break;
                         }
                     }
                 }
             }
             
             if (the_method == null)
                 return null;
             else
             {   
                 // Recover the text from the start of the method to cursor
                 string method_start = Crop (fileContent, line, column, caretLineNumber, caretColumn);
                 string method_end = Crop (fileContent, caretLineNumber, caretColumn, end_line, end_column) + "}";
                 // System.Console.WriteLine (method_start + method_end);
                 NCC.CompletionResult infox = engine.RunCompletionEngine ((NCC.MethodBuilder)the_method.Member,
                     method_start + method_end, method_start.Length);
                 
                 return GetResults (infox, comp, completeLocals);                        
             }
         }
     }
     catch(Exception ex)
     {
         Console.WriteLine (ex.Message);
         Console.WriteLine (ex.StackTrace);
         return null;
     }
 }