public Field(ReturnType type, string fullyQualifiedName, Modifier m, IRegion region) { this.returnType = type; this.FullyQualifiedName = fullyQualifiedName; this.region = region; modifiers = (ModifierEnum)m; // Console.WriteLine("modifiers for field {0} are {1} were {2}", fullyQualifiedName, modifiers, m); }
public Property(string fullyQualifiedName, ReturnType type, Modifier m, IRegion region, IRegion bodyRegion) { this.FullyQualifiedName = fullyQualifiedName; returnType = type; this.region = region; this.bodyRegion = bodyRegion; modifiers = (ModifierEnum)m; }
public Indexer(ReturnType type, ParameterCollection parameters, Modifier m, IRegion region, IRegion bodyRegion) { returnType = type; this.parameters = parameters; this.region = region; this.bodyRegion = bodyRegion; modifiers = (ModifierEnum)m; }
public Method(string name, ReturnType type, Modifier m, IRegion region, IRegion bodyRegion) { FullyQualifiedName = name; returnType = type; this.region = region; this.bodyRegion = bodyRegion; modifiers = (ModifierEnum)m; }
public override object Visit(InvocationExpression invocationExpression, object data) { if (invocationExpression.TargetObject is FieldReferenceOrInvocationExpression) { FieldReferenceOrInvocationExpression field = (FieldReferenceOrInvocationExpression)invocationExpression.TargetObject; IReturnType type = field.TargetObject.AcceptVisitor(this, data) as IReturnType; ArrayList methods = resolver.SearchMethod(type, field.FieldName); resolver.ShowStatic = false; if (methods.Count <= 0) { return null; } // TODO: Find the right method return ((IMethod)methods[0]).ReturnType; } else if (invocationExpression.TargetObject is IdentifierExpression) { string id = ((IdentifierExpression)invocationExpression.TargetObject).Identifier; if (resolver.CallingClass == null) { return null; } IReturnType type = new ReturnType(resolver.CallingClass.FullyQualifiedName); ArrayList methods = resolver.SearchMethod(type, id); resolver.ShowStatic = false; if (methods.Count <= 0) { return null; } // TODO: Find the right method return ((IMethod)methods[0]).ReturnType; } // invocationExpression is delegate call IReturnType t = invocationExpression.AcceptChildren(this, data) as IReturnType; if (t == null) { return null; } IClass c = resolver.SearchType(t.FullyQualifiedName, resolver.CallingClass, resolver.CompilationUnit); if (c.ClassType == ClassType.Delegate) { ArrayList methods = resolver.SearchMethod(t, "invoke"); if (methods.Count <= 0) { return null; } return ((IMethod)methods[0]).ReturnType; } return null; }
public Parameter(string name, ReturnType type) { Name = name; returnType = type; }
public override object Visit(ArrayCreateExpression arrayCreateExpression, object data) { ReturnType type = new ReturnType(arrayCreateExpression.CreateType); if (arrayCreateExpression.Parameters != null && arrayCreateExpression.Parameters.Count > 0) { int[] newRank = new int[arrayCreateExpression.CreateType.RankSpecifier.Count + 1]; newRank[0] = arrayCreateExpression.Parameters.Count - 1; for (int i = 0; i < type.ArrayDimensions.Length; ++i) { newRank[i + 1] = type.ArrayDimensions[i]; } Array.Copy(type.ArrayDimensions, 0, newRank, 1, type.ArrayDimensions.Length); type.ArrayDimensions = newRank; } return type; }
public ArrayList IsAsResolve(string expression, int caretLine, int caretColumn, string fileName, string fileContent) { //Console.WriteLine("Entering IsAsResolve for " + expression); ArrayList result = new ArrayList (); this.caretLine = caretLine; this.caretColumn = caretColumn; IParseInformation parseInfo = parserContext.GetParseInformation (fileName); ICSharpCode.SharpRefactory.Parser.AST.VB.CompilationUnit fcu = parseInfo.MostRecentCompilationUnit.Tag as ICSharpCode.SharpRefactory.Parser.AST.VB.CompilationUnit; if (fcu == null) return null; ICSharpCode.SharpRefactory.Parser.VB.Parser p = new ICSharpCode.SharpRefactory.Parser.VB.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); VBNetVisitor vbVisitor = new VBNetVisitor (); cu = (ICompilationUnit)vbVisitor.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.VB.CompilationUnit; lookupTableVisitor.Visit (fcu, null); cu = (ICompilationUnit)vbVisitor.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, null, 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; }
public IReturnType internalResolve(string expression, int caretLineNumber, int caretColumn, string fileName, string fileContent) { try{ //Console.WriteLine("Start Resolving " + expression); 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.VB.CompilationUnit fileCompilationUnit = parseInfo.MostRecentCompilationUnit.Tag as ICSharpCode.SharpRefactory.Parser.AST.VB.CompilationUnit; if (fileCompilationUnit == null) { ICSharpCode.SharpRefactory.Parser.VB.Parser fileParser = new ICSharpCode.SharpRefactory.Parser.VB.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; 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.VB.Parser p = new ICSharpCode.SharpRefactory.Parser.VB.Parser(); Lexer l = new Lexer(new StringReader(expression)); Expression expr = p.ParseExpression(l); if (expr == null) { return null; //}else{ //Console.WriteLine(expr.ToString()); } lookupTableVisitor = new LookupTableVisitor(); lookupTableVisitor.Visit(fileCompilationUnit, null); //Console.WriteLine("Visited lookup table"); TypeVisitor typeVisitor = new TypeVisitor(this); VBNetVisitor vbVisitor = new VBNetVisitor(); cu = (ICompilationUnit)vbVisitor.Visit(fileCompilationUnit, null); //Console.WriteLine("Visited VBNetVisitor"); 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("Accepted visitor: " + type.FullyQualifiedName); //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.VB.CompilationUnit; lookupTableVisitor.Visit(fileCompilationUnit,null); //Console.WriteLine("Lookup table visited again"); cu = (ICompilationUnit)vbVisitor.Visit(fileCompilationUnit, null); if (cu != null) { callingClass = GetInnermostClass(); //Console.WriteLine("Got new cu, calling class = " + callingClass.FullyQualifiedName); } type=expr.AcceptVisitor(typeVisitor,null) as IReturnType; //Console.WriteLine("Type visited again"); 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; }catch(Exception ex){ //Console.WriteLine("Exception in internalResolve: " + ex.Message); //Console.WriteLine(ex.StackTrace); return null; } }
ReturnType SearchVariable(string name) { // Console.WriteLine("Searching Variable"); // // Console.WriteLine("LookUpTable has {0} entries", lookupTableVisitor.variables.Count); // Console.WriteLine("Listing Variables:"); // IDictionaryEnumerator enumerator = lookupTableVisitor.variables.GetEnumerator(); // while (enumerator.MoveNext()) { // Console.WriteLine(enumerator.Key); // } // Console.WriteLine("end listing"); ArrayList variables = (ArrayList)lookupTableVisitor.Variables[name.ToLower()]; // if (variables == null || variables.Count <= 0) { // Console.WriteLine(name + " not in LookUpTable"); // return null; // } ReturnType found = null; if (variables != null) { foreach (LocalLookupVariable v in variables) { // Console.WriteLine("Position: ({0}/{1})", v.StartPos, v.EndPos); if (IsInside(new Point(caretColumn, caretLine), v.StartPos, v.EndPos)) { found = new ReturnType(v.TypeRef); // Console.WriteLine("Variable found"); break; } } } // if (found == null) { // Console.WriteLine("No Variable found"); // return null; // } return found; }
public override object Visit(AST.FieldDeclaration fieldDeclaration, object data) { DefaultRegion region = GetRegion(fieldDeclaration.StartLocation, fieldDeclaration.EndLocation); Class c = (Class)currentClass.Peek(); if (currentClass.Count > 0) { foreach (AST.VariableDeclaration field in fieldDeclaration.Fields) { ReturnType type = null; if (field.Type != null) { type = new ReturnType(field.Type); } Field f = new Field(type, field.Name, fieldDeclaration.Modifier, region); if (type == null) { f.SetModifiers(ModifierEnum.Const | ModifierEnum.SpecialName); } c.Fields.Add(f); } } return null; }
public override object Visit(AST.ConstructorDeclaration constructorDeclaration, object data) { DefaultRegion region = GetRegion(constructorDeclaration.StartLocation, constructorDeclaration.EndLocation); DefaultRegion bodyRegion = GetRegion(constructorDeclaration.EndLocation, constructorDeclaration.Body != null ? constructorDeclaration.Body.EndLocation : new Point(-1, -1)); Class c = (Class)currentClass.Peek(); Constructor constructor = new Constructor(constructorDeclaration.Modifier, region, bodyRegion); ParameterCollection parameters = new ParameterCollection(); if (constructorDeclaration.Parameters != null) { foreach (AST.ParameterDeclarationExpression par in constructorDeclaration.Parameters) { ReturnType parType = new ReturnType(par.TypeReference); Parameter p = new Parameter(par.ParameterName, parType); parameters.Add(p); } } constructor.Parameters = parameters; c.Methods.Add(constructor); return null; }
public override object Visit(AST.MethodDeclaration methodDeclaration, object data) { DefaultRegion region = GetRegion(methodDeclaration.StartLocation, methodDeclaration.EndLocation); DefaultRegion bodyRegion = GetRegion(methodDeclaration.EndLocation, methodDeclaration.Body != null ? methodDeclaration.Body.EndLocation : new Point(-1, -1)); ReturnType type = methodDeclaration.TypeReference == null ? new ReturnType("System.Void") : new ReturnType(methodDeclaration.TypeReference); Class c = (Class)currentClass.Peek(); Method method = new Method(String.Concat(methodDeclaration.Name), type, methodDeclaration.Modifier, region, bodyRegion); ParameterCollection parameters = new ParameterCollection(); if (methodDeclaration.Parameters != null) { foreach (AST.ParameterDeclarationExpression par in methodDeclaration.Parameters) { ReturnType parType = new ReturnType(par.TypeReference); Parameter p = new Parameter(par.ParameterName, parType); parameters.Add(p); } } method.Parameters = parameters; c.Methods.Add(method); return null; }