📄 resolver.cs
字号:
}
bool IsInside(Point between, Point start, Point end)
{
if (between.Y < start.Y || between.Y > end.Y) {
// Console.WriteLine("Y = {0} not between {1} and {2}", between.Y, start.Y, end.Y);
return false;
}
if (between.Y > start.Y) {
if (between.Y < end.Y) {
return true;
}
// between.Y == end.Y
// Console.WriteLine("between.Y = {0} == end.Y = {1}", between.Y, end.Y);
// Console.WriteLine("returning {0}:, between.X = {1} <= end.X = {2}", between.X <= end.X, between.X, end.X);
return between.X <= end.X;
}
// between.Y == start.Y
// Console.WriteLine("between.Y = {0} == start.Y = {1}", between.Y, start.Y);
if (between.X < start.X) {
return false;
}
// start is OK and between.Y <= end.Y
return between.Y < end.Y || between.X <= end.X;
}
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];
if (variables == null || variables.Count <= 0) {
// Console.WriteLine(name + " not in LookUpTable");
return null;
}
ReturnType found = 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)) {
IClass c = SearchType(v.TypeRef.SystemType, callingClass, cu);
if (c != null) {
found = new ReturnType(c.FullyQualifiedName);
} else {
found = new ReturnType(v.TypeRef);
}
// Console.WriteLine("Variable found");
break;
}
}
if (found == null) {
// Console.WriteLine("No Variable found");
return null;
}
return found;
}
/// <remarks>
/// does the dynamic lookup for the typeName
/// </remarks>
public IReturnType DynamicLookup(string typeName)
{
// Console.WriteLine("starting dynamic lookup");
// Console.WriteLine("name == " + typeName);
// try if it exists a variable named typeName
ReturnType variable = SearchVariable(typeName);
if (variable != null) {
showStatic = false;
return variable;
}
// Console.WriteLine("No Variable found");
if (callingClass == null) {
return null;
}
//// somehow search in callingClass fields is not returning anything, so I am searching here once again
foreach (IField f in callingClass.Fields) {
if (f.Name == typeName) {
// Console.WriteLine("Field found " + f.Name);
return f.ReturnType;
}
}
//// end of mod for search in Fields
// try if typeName is a method parameter
IReturnType p = SearchMethodParameter(typeName);
if (p != null) {
// Console.WriteLine("MethodParameter Found");
showStatic = false;
return p;
}
// Console.WriteLine("No Parameter found");
// check if typeName == value in set method of a property
if (typeName == "value") {
p = SearchProperty();
if (p != null) {
showStatic = false;
return p;
}
}
// Console.WriteLine("No Property found");
// try if there exists a nonstatic member named typeName
showStatic = false;
IReturnType t = SearchMember(callingClass == null ? null : new ReturnType(callingClass.FullyQualifiedName), typeName);
if (t != null) {
return t;
}
// Console.WriteLine("No nonstatic member found");
// try if there exists a static member named typeName
showStatic = true;
t = SearchMember(callingClass == null ? null : new ReturnType(callingClass.FullyQualifiedName), typeName);
if (t != null) {
showStatic = false;
return t;
}
// Console.WriteLine("No static member found");
// try if there exists a static member in outer classes named typeName
ClassCollection classes = parserService.GetOuterClasses(cu, caretLine, caretColumn);
foreach (IClass c in classes) {
t = SearchMember(callingClass == null ? null : new ReturnType(c.FullyQualifiedName), typeName);
if (t != null) {
showStatic = false;
return t;
}
}
// Console.WriteLine("No static member in outer classes found");
// Console.WriteLine("DynamicLookUp resultless");
//// Alex: look in namespaces
//// Alex: look inside namespaces
string[] innamespaces=parserService.GetNamespaceList("");
foreach (string ns in innamespaces) {
ArrayList objs=parserService.GetNamespaceContents(ns);
if (objs==null) continue;
foreach (object o in objs) {
if (o is IClass) {
IClass oc=(IClass)o;
if (oc.Name==typeName || oc.FullyQualifiedName==typeName) {
//Debug.WriteLine(((IClass)o).Name);
/// now we can set completion data
objs.Clear();
objs=null;
return new ReturnType(oc.FullyQualifiedName);
}
}
}
if (objs==null) break;
}
innamespaces=null;
//// Alex: end of mod
return null;
}
IProperty GetProperty()
{
foreach (IProperty property in callingClass.Properties) {
if (property.BodyRegion != null && property.BodyRegion.IsInside(caretLine, caretColumn)) {
return property;
}
}
return null;
}
IMethod GetMethod(int caretLine, int caretColumn)
{
foreach (IMethod method in callingClass.Methods) {
if (method.BodyRegion != null && method.BodyRegion.IsInside(caretLine, caretColumn)) {
return method;
}
}
return null;
}
IReturnType SearchProperty()
{
IProperty property = GetProperty();
if (property == null) {
return null;
}
if (property.SetterRegion != null && property.SetterRegion.IsInside(caretLine, caretColumn)) {
return property.ReturnType;
}
return null;
}
IReturnType SearchMethodParameter(string parameter)
{
IMethod method = GetMethod(caretLine, caretColumn);
if (method == null) {
// Console.WriteLine("Method not found");
return null;
}
foreach (IParameter p in method.Parameters) {
if (p.Name == parameter) {
// Console.WriteLine("Parameter found");
return p.ReturnType;
}
}
return null;
}
/// <remarks>
/// use the usings to find the correct name of a namespace
/// </remarks>
public string SearchNamespace(string name, ICompilationUnit unit)
{
return parserService.SearchNamespace(name, unit, caretLine, caretColumn);
}
/// <remarks>
/// use the usings and the name of the namespace to find a class
/// </remarks>
public IClass SearchType(string name, IClass curType)
{
return parserService.SearchType(name, curType, caretLine, caretColumn);
}
/// <remarks>
/// use the usings and the name of the namespace to find a class
/// </remarks>
public IClass SearchType(string name, IClass curType, ICompilationUnit unit)
{
return parserService.SearchType(name, curType, unit, caretLine, caretColumn);
}
public ArrayList NewCompletion(IParserService parserService, int caretLine, int caretColumn, string fileName)
{
ArrayList result = new ArrayList();
this.parserService = parserService;
IParseInformation parseInfo = parserService.GetParseInformation(fileName);
ICSharpCode.SharpRefactory.Parser.AST.CompilationUnit fileCompilationUnit = parseInfo.MostRecentCompilationUnit.Tag as ICSharpCode.SharpRefactory.Parser.AST.CompilationUnit;
if (fileCompilationUnit == null) {
// Console.WriteLine("!Warning: no parseinformation!");
return null;
}
CSharpVisitor cSharpVisitor = new CSharpVisitor();
cu = (ICompilationUnit)cSharpVisitor.Visit(fileCompilationUnit, null);
if (cu != null) {
callingClass = parserService.GetInnermostClass(cu, caretLine, caretColumn);
// Console.WriteLine("CallingClass is " + callingClass == null ? "null" : callingClass.Name);
if (callingClass != null) {
result.AddRange(parserService.GetNamespaceContents(callingClass.Namespace));
// foreach (IClass c in callingClass.
}
}
result.AddRange(parserService.GetNamespaceContents(""));
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;
}
public ArrayList CtrlSpace(IParserService parserService, int caretLine, int caretColumn, string fileName)
{
ArrayList result = new ArrayList(TypeReference.PrimitiveTypes);
this.parserService = parserService;
IParseInformation parseInfo = parserService.GetParseInformation(fileName);
ICSharpCode.SharpRefactory.Parser.AST.CompilationUnit fileCompilationUnit = parseInfo.MostRecentCompilationUnit.Tag as ICSharpCode.SharpRefactory.Parser.AST.CompilationUnit;
if (fileCompilationUnit == null) {
// Console.WriteLine("!Warning: no parseinformation!");
return null;
}
lookupTableVisitor = new LookupTableVisitor();
lookupTableVisitor.Visit(fileCompilationUnit, null);
CSharpVisitor cSharpVisitor = new CSharpVisitor();
cu = (ICompilationUnit)cSharpVisitor.Visit(fileCompilationUnit, null);
if (cu != null) {
callingClass = parserService.GetInnermostClass(cu, caretLine, caretColumn);
// Console.WriteLine("CallingClass is " + callingClass == null ? "null" : callingClass.Name);
if (callingClass != null) {
IMethod method = GetMethod(caretLine, caretColumn);
if (method != null) {
foreach (IParameter p in method.Parameters) {
result.Add(new Field(new ReturnType(p.ReturnType.Name, p.ReturnType.ArrayDimensions, p.ReturnType.PointerNestingLevel), p.Name, Modifier.None, method.Region));
}
}
result.AddRange(parserService.GetNamespaceContents(callingClass.Namespace));
bool inStatic = InStatic();
result = parserService.ListMembers(result, callingClass, callingClass, inStatic);
if (inStatic == false) {
result = parserService.ListMembers(result, callingClass, callingClass, !inStatic);
}
}
}
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)) {
// LocalLookupVariable in no known Type in DisplayBindings.TextEditor
// so add Field for the Variables
result.Add(new Field(new ReturnType(v.TypeRef), name, Modifier.None, new DefaultRegion(v.StartPos, v.EndPos)));
break;
}
}
}
}
result.AddRange(parserService.GetNamespaceContents(""));
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;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -