Esempio n. 1
0
        public ArrayList IsAsResolve(string expression, int caretLine, int caretColumn, string fileName, string fileContent)
        {
            ArrayList result = new ArrayList ();
            this.caretLine = caretLine;
            this.caretColumn = caretColumn;

            IParseInformation parseInfo = parserContext.GetParseInformation (fileName);
            ICSharpCode.SharpRefactory.Parser.AST.CompilationUnit fcu = parseInfo.MostRecentCompilationUnit.Tag as ICSharpCode.SharpRefactory.Parser.AST.CompilationUnit;
            if (fcu == null)
                return null;
            ICSharpCode.SharpRefactory.Parser.Parser p = new ICSharpCode.SharpRefactory.Parser.Parser ();
            Lexer l = new Lexer (new StringReader (expression));
            Expression expr = p.ParseExpression(l);
            if (expr == null)
                return null;

            lookupTableVisitor = new LookupTableVisitor ();
            lookupTableVisitor.Visit (fcu, null);

            TypeVisitor typeVisitor = new TypeVisitor (this);

            CSharpVisitor csharpVisitor = new CSharpVisitor ();
            cu = (ICompilationUnit)csharpVisitor.Visit (fcu, null);
            if (cu != null) {
                callingClass = GetInnermostClass ();
            }

            IReturnType type = expr.AcceptVisitor (typeVisitor, null) as IReturnType;
            if (type == null || type.PointerNestingLevel != 0) {
                fcu = parserContext.ParseFile (fileName, fileContent).MostRecentCompilationUnit.Tag as ICSharpCode.SharpRefactory.Parser.AST.CompilationUnit;
                lookupTableVisitor.Visit (fcu, null);
                cu = (ICompilationUnit)csharpVisitor.Visit (fcu, 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");

            IClass returnClass = SearchType (type.FullyQualifiedName, cu);
            //			IClass returnClass = parserContext.SearchType (type.FullyQualifiedName, null, cu);
            if (returnClass == null)
                return null;

            foreach (IClass iclass in parserContext.GetClassInheritanceTree (returnClass)) {
                if (!result.Contains (iclass))
                    result.Add (iclass);
            }
            return result;
        }
Esempio n. 2
0
        public IReturnType internalResolve(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;
            }
            this.caretLine     = caretLineNumber;
            this.caretColumn   = caretColumn;

            IParseInformation parseInfo = parserContext.GetParseInformation(fileName);
            ICSharpCode.SharpRefactory.Parser.AST.CompilationUnit fileCompilationUnit = parseInfo.MostRecentCompilationUnit.Tag as ICSharpCode.SharpRefactory.Parser.AST.CompilationUnit;
            if (fileCompilationUnit == null) {
            //				ICSharpCode.SharpRefactory.Parser.Parser fileParser = new ICSharpCode.SharpRefactory.Parser.Parser();
            //				fileParser.Parse(new Lexer(new StringReader(fileContent)));
                Console.WriteLine("Warning: no parse information!");
                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;
            ICSharpCode.SharpRefactory.Parser.Parser p = new ICSharpCode.SharpRefactory.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
            */
            ICSharpCode.SharpRefactory.Parser.Parser p = new ICSharpCode.SharpRefactory.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);

            CSharpVisitor cSharpVisitor = new CSharpVisitor();
            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 = parserContext.ParseFile (fileName, fileContent).MostRecentCompilationUnit.Tag
                    as ICSharpCode.SharpRefactory.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);
            return type;
        }