internal static bool IsEqualResolveResult(ResolveResult rr1, ResolveResult rr2) { if (rr1 == rr2) { return(true); } if (rr1 == null || rr2 == null) { return(false); } if (rr1.GetType() != rr2.GetType()) { return(false); } bool eq = true; foreach (var property in rr1.GetType().GetProperties()) { object val1 = property.GetValue(rr1, null); object val2 = property.GetValue(rr2, null); eq &= Compare(val1, val2, property.PropertyType); } foreach (var field in rr1.GetType().GetFields()) { object val1 = field.GetValue(rr1); object val2 = field.GetValue(rr2); eq &= Compare(val1, val2, field.FieldType); } return(eq); }
private void ProcessPositionalArgs(IList <ResolveResult> args) { if (args.Count == 0) { return; } Console.WriteLine("attribute.PositionalArguments :"); for (Int32 index = 0; index < args.Count; ++index) { ResolveResult argResult = args[index]; Console.Write("index = {0}, type = {1}", index, argResult.GetType()); if (argResult is ConstantResolveResult) { ConstantResolveResult constResult = (ConstantResolveResult)argResult; Console.Write(", value = {0}", constResult.ConstantValue); } if (argResult is MemberResolveResult) { MemberResolveResult memberResult = (MemberResolveResult)argResult; IMember member = memberResult.Member; Console.Write(", value = {0}, memberKind = {1}, typeKind = {2}", member.Name, member.SymbolKind, memberResult.Type.Kind); } Console.WriteLine(); } }
public IEnumerable <string> FindReferences(string editorText, string pattern, ResolveResult target, string fileName) { var references = new List <string>(); IDocument document = null; Type patternType = target.GetType(); string targetReflectionName = target.ToString(); if (target is MemberResolveResult) //the caret is on the member implementation { targetReflectionName = targetReflectionName.Replace("MemberResolveResult", "CSharpInvocationResolveResult"); patternType = typeof(CSharpInvocationResolveResult); } //we are looking for the member invocation code. //For example: "[CSharpInvocationResolveResult [Method Test.Who():System.Void]]" foreach (Match m in Regex.Matches(editorText, pattern)) { var match = ResolveFromPosition(editorText, m.Index, fileName); if (match != null && match.GetType() == patternType && match.ToString() == targetReflectionName) { if (document == null) { document = new ReadOnlyDocument(editorText); } int position = m.Index; var location = document.GetLocation(position); var line = document.GetLineByOffset(position); string lineText = editorText.GetTextOf(line); Tuple <int, int> decoration = CSScriptHelper.GetDecorationInfo(editorText); if (decoration.Item1 != -1) //the file content is no the actual one but an auto-generated (decorated) { if (position > decoration.Item1) { position -= decoration.Item2; string actualText = File.ReadAllText(fileName); if (actualText != editorText) { document = new ReadOnlyDocument(actualText); location = document.GetLocation(position); line = document.GetLineByOffset(position); lineText = actualText.GetTextOf(line); } } } references.Add(string.Format("{0}({1},{2}): {3}", fileName, location.Line, location.Column, lineText.Trim())); } } return(references); }
Value Visit(ResolveResult result) { if (result is ErrorResolveResult) { var err = (ErrorResolveResult)result; if (!string.IsNullOrWhiteSpace(err.Message)) { throw new GetValueException(err.Message); } } if (result.IsError) { throw new GetValueException("Unknown error"); } if (result.ConstantValue == null && result.Type.Equals(SpecialType.NullType)) { return(Eval.CreateValue(evalThread, null)); } throw new GetValueException("Unsupported language construct: " + result.GetType().Name); }
public TooltipItem GetItem(Mono.TextEditor.TextEditor editor, int offset) { if (offset >= editor.Document.TextLength) { return(null); } if (!DebuggingService.IsDebugging || DebuggingService.IsRunning) { return(null); } StackFrame frame = DebuggingService.CurrentFrame; if (frame == null) { return(null); } var ed = (ExtensibleTextEditor)editor; string expression = null; int startOffset = 0, length = 0; if (ed.IsSomethingSelected && offset >= ed.SelectionRange.Offset && offset <= ed.SelectionRange.EndOffset) { expression = ed.SelectedText; startOffset = ed.SelectionRange.Offset; length = ed.SelectionRange.Length; } else { ICSharpCode.NRefactory.TypeSystem.DomRegion expressionRegion; ResolveResult res = ed.GetLanguageItem(offset, out expressionRegion); if (res == null || res.IsError || res.GetType() == typeof(ResolveResult)) { return(null); } //Console.WriteLine ("res is a {0}", res.GetType ().Name); if (expressionRegion.IsEmpty) { return(null); } if (res is NamespaceResolveResult || res is ConversionResolveResult || res is ForEachResolveResult || res is TypeIsResolveResult || res is TypeOfResolveResult || res is ErrorResolveResult) { return(null); } var start = new DocumentLocation(expressionRegion.BeginLine, expressionRegion.BeginColumn); var end = new DocumentLocation(expressionRegion.EndLine, expressionRegion.EndColumn); startOffset = editor.Document.LocationToOffset(start); int endOffset = editor.Document.LocationToOffset(end); length = endOffset - startOffset; if (res is LocalResolveResult) { var lr = (LocalResolveResult)res; // Capture only the local variable portion of the expression... expression = lr.Variable.Name; length = expression.Length; // Calculate start offset based on the end offset because we don't want to include the type information. startOffset = endOffset - length; } else if (res is InvocationResolveResult) { var ir = (InvocationResolveResult)res; if (ir.Member.Name != ".ctor") { return(null); } expression = ir.Member.DeclaringType.FullName; } else if (res is MemberResolveResult) { var mr = (MemberResolveResult)res; if (mr.TargetResult == null) { // User is hovering over a member definition... if (mr.Member is IProperty) { // Visual Studio will evaluate Properties if you hover over their definitions... var prop = (IProperty)mr.Member; if (prop.CanGet) { if (prop.IsStatic) { expression = prop.FullName; } else { expression = prop.Name; } } else { return(null); } } else if (mr.Member is IField) { var field = (IField)mr.Member; if (field.IsStatic) { expression = field.FullName; } else { expression = field.Name; } } else { return(null); } } // If the TargetResult is not null, then treat it like any other ResolveResult. } else if (res is ConstantResolveResult) { // Fall through... } else if (res is ThisResolveResult) { // Fall through... } else if (res is TypeResolveResult) { // Fall through... } else { return(null); } if (expression == null) { expression = ed.GetTextBetween(start, end); } } if (string.IsNullOrEmpty(expression)) { return(null); } ObjectValue val; if (!cachedValues.TryGetValue(expression, out val)) { val = frame.GetExpressionValue(expression, true); cachedValues [expression] = val; } if (val == null || val.IsUnknown || val.IsNotSupported) { return(null); } val.Name = expression; return(new TooltipItem(val, startOffset, length)); }
string Visit(ResolveResult result) { return("Not supported: " + result.GetType().Name); }
bool IsEqualResolveResult(ResolveResult rr1, ResolveResult rr2) { if (rr1 == rr2) return true; if (rr1 == null || rr2 == null) return false; if (rr1.GetType() != rr2.GetType()) return false; bool eq = true; foreach (var property in rr1.GetType().GetProperties()) { object val1 = property.GetValue(rr1, null); object val2 = property.GetValue(rr2, null); eq &= Compare(val1, val2, property.PropertyType); } foreach (var field in rr1.GetType().GetFields()) { object val1 = field.GetValue(rr1); object val2 = field.GetValue(rr2); eq &= Compare(val1, val2, field.FieldType); } return eq; }
string Visit(ResolveResult result) { return "Not supported: " + result.GetType().Name; }
Value Visit(ResolveResult result) { if (result is ErrorResolveResult) { var err = (ErrorResolveResult)result; if (!string.IsNullOrWhiteSpace(err.Message)) throw new GetValueException(err.Message); } if (result.IsError) throw new GetValueException("Unknown error"); if (result.ConstantValue == null && result.Type.Equals(SpecialType.NullType)) return Eval.CreateValue(evalThread, null); throw new GetValueException("Unsupported language construct: " + result.GetType().Name); }
Value Visit(ResolveResult result) { if (result is ErrorResolveResult) { var err = (ErrorResolveResult)result; if (!string.IsNullOrWhiteSpace(err.Message)) throw new GetValueException(err.Message); } if (result.IsError) throw new GetValueException("Unknown error"); throw new GetValueException("Unsupported language construct: " + result.GetType().Name); }
public override TooltipItem GetItem(TextEditor editor, int offset) { if (offset >= editor.Document.TextLength) { return(null); } if (!DebuggingService.IsDebugging || DebuggingService.IsRunning) { return(null); } StackFrame frame = DebuggingService.CurrentFrame; if (frame == null) { return(null); } var ed = (ExtensibleTextEditor)editor; string expression = null; int startOffset = 0, length = 0; if (ed.IsSomethingSelected && offset >= ed.SelectionRange.Offset && offset <= ed.SelectionRange.EndOffset) { expression = ed.SelectedText; startOffset = ed.SelectionRange.Offset; length = ed.SelectionRange.Length; } else { DomRegion expressionRegion; ResolveResult res = ed.GetLanguageItem(offset, out expressionRegion); if (res == null || res.IsError || res.GetType() == typeof(ResolveResult)) { return(null); } //Console.WriteLine ("res is a {0}", res.GetType ().Name); if (expressionRegion.IsEmpty) { return(null); } if (res is NamespaceResolveResult || res is ConversionResolveResult || res is ForEachResolveResult || res is TypeIsResolveResult || res is TypeOfResolveResult || res is ErrorResolveResult) { return(null); } var start = new DocumentLocation(expressionRegion.BeginLine, expressionRegion.BeginColumn); var end = new DocumentLocation(expressionRegion.EndLine, expressionRegion.EndColumn); startOffset = editor.Document.LocationToOffset(start); int endOffset = editor.Document.LocationToOffset(end); length = endOffset - startOffset; if (res is LocalResolveResult) { var lr = (LocalResolveResult)res; // Use the start and end offsets of the variable region so that we get the "@" in variable names like "@class" start = new DocumentLocation(lr.Variable.Region.BeginLine, lr.Variable.Region.BeginColumn); end = new DocumentLocation(lr.Variable.Region.EndLine, lr.Variable.Region.EndColumn); startOffset = editor.Document.LocationToOffset(start); endOffset = editor.Document.LocationToOffset(end); expression = ed.GetTextBetween(startOffset, endOffset).Trim(); // Note: When the LocalResolveResult is a parameter, the Variable.Region includes the type if (lr.IsParameter) { int index = IndexOfLastWhiteSpace(expression); if (index != -1) { expression = expression.Substring(index + 1); } } length = expression.Length; } else if (res is InvocationResolveResult) { var ir = (InvocationResolveResult)res; if (ir.Member.Name != ".ctor") { return(null); } expression = ir.Member.DeclaringType.FullName; } else if (res is MemberResolveResult) { var mr = (MemberResolveResult)res; if (mr.TargetResult == null) { // User is hovering over a member definition... if (mr.Member is IProperty) { // Visual Studio will evaluate Properties if you hover over their definitions... var prop = (IProperty)mr.Member; if (prop.CanGet) { if (prop.IsStatic) { expression = prop.FullName; } else { expression = prop.Name; } } else { return(null); } } else if (mr.Member is IField) { var field = (IField)mr.Member; if (field.IsStatic) { expression = field.FullName; } else { expression = field.Name; } } else { return(null); } } // If the TargetResult is not null, then treat it like any other ResolveResult. } else if (res is ConstantResolveResult) { // Fall through... } else if (res is ThisResolveResult) { // Fall through... } else if (res is TypeResolveResult) { // Fall through... } else { return(null); } if (expression == null) { expression = ed.GetTextBetween(start, end); } } if (string.IsNullOrEmpty(expression)) { return(null); } ObjectValue val; if (!cachedValues.TryGetValue(expression, out val)) { val = frame.GetExpressionValue(expression, true); cachedValues [expression] = val; } if (val == null || val.IsUnknown || val.IsNotSupported) { return(null); } val.Name = expression; return(new TooltipItem(val, startOffset, length)); }
public static object GetValue(this ResolveResult result, bool ignoreError = false) { if (null == result || (result.IsError && !ignoreError)) { return(null); } object value = null; if (result.TryCast <UnknownIdentifierResolveResult>(r => value = r.Identifier)) { return(value); } if (result.TryCast <ConstantResolveResult>(r => value = r.ConstantValue)) { return(value); } if (result.TryCast <MemberResolveResult>(r => value = r.ConstantValue)) { return(value); } if (result.TryCast <TypeOfResolveResult>(r => value = r.ReferencedType)) { return(value); } if (result.TryCast <ConversionResolveResult>(r => value = r.Input.GetValue())) { return(value); } if (result.TryCast <ArrayCreateResolveResult>(r => value = r.InitializerElements .Select(x => x.GetValue(ignoreError: true)) .ToArray())) { return(value); } throw new Exception("THIS IS A BUG: Do not know how to get Value from a ResolveResult: " + result.GetType().Name); }