protected override IExpressionStatement CreateStatement(CSharpElementFactory factory, ICSharpExpression expression) { var statement = (IExpressionStatement)factory.CreateStatement("__ = expression;"); var newDeclaration = CreateMemberDeclaration(factory); var assignment = (IAssignmentExpression)statement.Expression; assignment.SetSource(expression); var psiServices = expression.GetPsiServices(); var suggestionManager = psiServices.Naming.Suggestion; var classDeclaration = expression.GetContainingNode <IClassDeclaration>().NotNull(); var suggestion = suggestionManager.CreateEmptyCollection( PluralityKinds.Unknown, expression.Language, true, expression); suggestion.Add(expression, new EntryOptions { SubrootPolicy = SubrootPolicy.Decompose, PredefinedPrefixPolicy = PredefinedPrefixPolicy.Remove }); suggestion.Prepare(newDeclaration.DeclaredElement, new SuggestionOptions { UniqueNameContext = (ITreeNode)classDeclaration.Body ?? classDeclaration }); newDeclaration.SetName(suggestion.FirstName()); myMemberNames = suggestion.AllNames(); var memberAnchor = GetAnchorMember(classDeclaration.MemberDeclarations.ToList()); var newMember = classDeclaration.AddClassMemberDeclarationAfter( newDeclaration, (IClassMemberDeclaration)memberAnchor); myMemberPointer = newMember.CreatePointer(); return(statement); }
public override bool IsAvailable(IDataContext context) { // check text control if (!base.IsAvailable(context)) return false; var sourceTokenAtCaret = TextControlToPsi.GetSourceTokenAtCaret(Solution, TextControl); var usingDirective = sourceTokenAtCaret.FindParent<IUsingNamespaceDirective>(); if (usingDirective == null || usingDirective.ImportedNamespace == null) return false; // Does not support Linq if (_ignoredNamespaces.Contains(usingDirective.ImportedNamespace.QualifiedName)) return false; ImportedNamespacePointer = usingDirective.CreateTreeElementPointer(); return true; }
protected T4CodeStructureElement([NotNull] CodeStructureElement parent, [NotNull] T treeNode) : base(parent) { _textRange = treeNode.GetDocumentRange().TextRange; _pointer = treeNode.CreateTreeElementPointer(); }