|
|
|
@ -6,10 +6,12 @@
@@ -6,10 +6,12 @@
|
|
|
|
|
// </file>
|
|
|
|
|
using System; |
|
|
|
|
using System.Collections.Generic; |
|
|
|
|
using ICSharpCode.SharpDevelop; |
|
|
|
|
using ICSharpCode.SharpDevelop.Dom; |
|
|
|
|
using ICSharpCode.SharpDevelop.Editor; |
|
|
|
|
using ICSharpCode.SharpDevelop.Editor.AvalonEdit; |
|
|
|
|
using ICSharpCode.SharpDevelop.Refactoring; |
|
|
|
|
using System.Linq; |
|
|
|
|
|
|
|
|
|
namespace SharpRefactoring.ContextActions |
|
|
|
|
{ |
|
|
|
@ -24,28 +26,92 @@ namespace SharpRefactoring.ContextActions
@@ -24,28 +26,92 @@ namespace SharpRefactoring.ContextActions
|
|
|
|
|
if (currentLineAST == null) |
|
|
|
|
yield break; |
|
|
|
|
var symbol = context.CurrentSymbol; |
|
|
|
|
foreach (var contextAction in GetAddUsingContextActions(symbol, context.Editor)) { |
|
|
|
|
foreach (var contextAction in GetAddUsingContextActions(symbol, context.Editor, context.CurrentExpression.Context)) { |
|
|
|
|
yield return contextAction; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
IEnumerable<IContextAction> GetAddUsingContextActions(ResolveResult symbol, ITextEditor editor) |
|
|
|
|
IEnumerable<IContextAction> GetAddUsingContextActions(ResolveResult symbol, ITextEditor editor, ExpressionContext exprContext) |
|
|
|
|
{ |
|
|
|
|
IEnumerable<RefactoringService.AddUsingAction> addUsingActions = null; |
|
|
|
|
if (symbol is UnknownIdentifierResolveResult) { |
|
|
|
|
addUsingActions = RefactoringService.GetAddUsingActions((UnknownIdentifierResolveResult)symbol, editor); |
|
|
|
|
} else if (symbol is UnknownConstructorCallResolveResult) { |
|
|
|
|
addUsingActions = RefactoringService.GetAddUsingActions((UnknownConstructorCallResolveResult)symbol, editor); |
|
|
|
|
foreach (var addUsingAction in RefactoringService.GetAddUsingActions(symbol,editor)) { |
|
|
|
|
yield return addUsingAction; |
|
|
|
|
} |
|
|
|
|
if (exprContext == ExpressionContext.Attribute) { |
|
|
|
|
foreach (var addUsingAction in GetAddUsingAttributeActions(symbol, editor)) { |
|
|
|
|
yield return addUsingAction; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (addUsingActions == null) |
|
|
|
|
foreach (var addUsingAction in GetAddUsingExtensionMethodActions(symbol, editor)) { |
|
|
|
|
yield return addUsingAction; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
IEnumerable<IContextAction> GetAddUsingExtensionMethodActions(ResolveResult symbol, ITextEditor editor) |
|
|
|
|
{ |
|
|
|
|
yield break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#region GetAddUsingAttributeActions
|
|
|
|
|
IEnumerable<IContextAction> GetAddUsingAttributeActions(ResolveResult symbol, ITextEditor editor) |
|
|
|
|
{ |
|
|
|
|
if (!(symbol is UnknownIdentifierResolveResult || symbol is UnknownMethodResolveResult)) |
|
|
|
|
yield break; |
|
|
|
|
|
|
|
|
|
List<IClass> results = new List<IClass>(); |
|
|
|
|
|
|
|
|
|
ParseInformation info = ParserService.GetParseInformation(editor.FileName); |
|
|
|
|
if (info == null || info.CompilationUnit == null || info.CompilationUnit.ProjectContent == null) |
|
|
|
|
yield break; |
|
|
|
|
foreach (var addUsingAction in addUsingActions) { |
|
|
|
|
var addUsingActionCopy = addUsingAction; |
|
|
|
|
yield return new DelegateAction { |
|
|
|
|
Title = "using " + addUsingActionCopy.NewNamespace, |
|
|
|
|
ExecuteAction = addUsingActionCopy.Execute |
|
|
|
|
ICompilationUnit unit = info.CompilationUnit; |
|
|
|
|
IProjectContent pc = info.CompilationUnit.ProjectContent; |
|
|
|
|
|
|
|
|
|
string name = null; |
|
|
|
|
if (symbol is UnknownMethodResolveResult) { |
|
|
|
|
name = Search((UnknownMethodResolveResult)symbol, pc, results); |
|
|
|
|
} |
|
|
|
|
if (symbol is UnknownIdentifierResolveResult) { |
|
|
|
|
name = Search((UnknownIdentifierResolveResult)symbol, pc, results); |
|
|
|
|
} else { |
|
|
|
|
yield break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
foreach (IClass c in results) { |
|
|
|
|
string newNamespace = c.Namespace; |
|
|
|
|
yield return new DelegateAction {Title = "using " + newNamespace, |
|
|
|
|
ExecuteAction = delegate { |
|
|
|
|
NamespaceRefactoringService.AddUsingDeclaration(unit, editor.Document, newNamespace, true); |
|
|
|
|
ParserService.BeginParse(editor.FileName, editor.Document); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public string Search(UnknownMethodResolveResult rr, IProjectContent pc, List<IClass> results) |
|
|
|
|
{ |
|
|
|
|
SearchAttributesWithName(results, pc, rr.CallName); |
|
|
|
|
foreach (IProjectContent content in pc.ReferencedContents) |
|
|
|
|
SearchAttributesWithName(results, content, rr.CallName); |
|
|
|
|
return rr.CallName; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public string Search(UnknownIdentifierResolveResult rr, IProjectContent pc, List<IClass> results) |
|
|
|
|
{ |
|
|
|
|
SearchAttributesWithName(results, pc, rr.Identifier); |
|
|
|
|
foreach (IProjectContent content in pc.ReferencedContents) |
|
|
|
|
SearchAttributesWithName(results, content, rr.Identifier); |
|
|
|
|
return rr.Identifier; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
IClass baseClass = null; |
|
|
|
|
void SearchAttributesWithName(List<IClass> results, IProjectContent pc, string name) |
|
|
|
|
{ |
|
|
|
|
if (baseClass == null) |
|
|
|
|
baseClass = pc.GetClass("System.Attribute", 0); |
|
|
|
|
foreach (IClass c in pc.Classes) { |
|
|
|
|
if (c.IsTypeInInheritanceTree(baseClass) && (c.Name == name || c.Name == name + "Attribute")) |
|
|
|
|
results.Add(c); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
#endregion
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|