public static Action <ITextControl> CreateHotspotSession(this IAttribute attribute) { var hotspotsRegistry = new HotspotsRegistry(attribute.GetSolution().GetPsiServices()); var arguments = attribute.Arguments; for (var i = 0; i < arguments.Count; i++) { if (arguments[i].Value is ICSharpLiteralExpression literalExpression) { var range = literalExpression.Literal.GetUnquotedDocumentRange().CreateRangeMarker(); hotspotsRegistry.Register(range, new NameSuggestionsExpression(new[] { literalExpression.ConstantValue.GetPresentation(attribute.Language) })); } } var propertyAssignments = attribute.PropertyAssignments; for (var i = 0; i < propertyAssignments.Count; i++) { if (propertyAssignments[i].Source is ICSharpLiteralExpression literalExpression) { var range = literalExpression.Literal.GetUnquotedDocumentRange().CreateRangeMarker(); hotspotsRegistry.Register(range, new NameSuggestionsExpression(new[] { literalExpression.ConstantValue.GetPresentation(attribute.Language) })); } } return(BulbActionUtils.ExecuteHotspotSession(hotspotsRegistry, DocumentOffset.InvalidOffset)); }
private Action <ITextControl> CreateHotspotSession(IAttribute attribute) { var hotspotsRegistry = new HotspotsRegistry(myMultipleFieldDeclaration.GetSolution().GetPsiServices()); for (var i = 0; i < myAttributeValues.Length; i++) { var attributeValue = myAttributeValues[i]; if (attributeValue.ConstantValue.IsString()) { var value = $"\"{attributeValue.ConstantValue.Value}\""; hotspotsRegistry.Register(new ITreeNode[] { attribute.Arguments[i] }, new NameSuggestionsExpression(new[] { value })); } else { hotspotsRegistry.Register(new ITreeNode[] { attribute.Arguments[i] }, new NameSuggestionsExpression(new[] { attributeValue.ConstantValue.GetPresentation(attribute.Language) })); } } return(BulbActionUtils.ExecuteHotspotSession(hotspotsRegistry, DocumentOffset.InvalidOffset)); }
public void Execute(ISolution solution, ITextControl textControl) { solution.Locks.AssertReadAccessAllowed(); var text = Text; if (!UnityCallGraphUtil.IsCallGraphReady(solution)) { BulbActionUtils.ShowTooltip(text + TooltipSuffix, textControl); return; } if (!solution.GetPsiServices().Caches.WaitForCaches(text)) { return; } var manager = CallHierarchyExplorerViewManager.GetInstance(solution); var filter = GetFilter(solution); var start = GetStartElement(); var callType = CallsType; ShowCalls(manager, filter, start, callType); }
protected override Action <ITextControl> ExecutePsiTransaction(ISolution solution, IProgressIndicator progress) { var oldMethod = myExpression.Reference.Resolve().DeclaredElement as IMethod; if (oldMethod == null) { return(null); } var factory = CSharpElementFactory.GetInstance(myInvocationExpression); var builder = FactoryArgumentsBuilder.Create(); if (myExpression.QualifierExpression != null) { builder.Argument(myExpression.QualifierExpression); builder.Append("."); } builder.Append(myNewMethod.ShortName); builder.Append("("); var returnType = oldMethod.ReturnType; var oldArguments = myInvocationExpression.Arguments; var firstPositionalArgIdx = GetPositionalArgumentIndex(oldArguments); var curArgIdx = 0; var newParameters = myNewMethod.Parameters; var argumentIndex = 0; // insert new argument to correct position. If we should use positional argument, we will check it and use. for (int i = 0; i < newParameters.Count; i++) { var parameter = newParameters[i]; if (parameter.Type.Equals(returnType)) { var referenceExpression = factory.CreateReferenceExpression(GetUniqueName(myInvocationExpression, ResultParamName)); IArgument argument = curArgIdx > firstPositionalArgIdx ? factory.CreateArgument(ParameterKind.VALUE, ResultParamName, referenceExpression) : factory.CreateArgument(ParameterKind.VALUE, referenceExpression); builder.Argument(argument); argumentIndex = i; } else { builder.Argument(oldArguments[curArgIdx]); curArgIdx++; } if (i + 1 != newParameters.Count) { builder.Append(","); } } builder.Append(")"); var newInvocation = factory.CreateExpression(builder.ToString(), builder.ToArguments()); var newDeclaration = (IDeclarationStatement)factory.CreateStatement("var $0 = $1;", GetUniqueName(myInvocationExpression, "size"), newInvocation); var oldStatement = myInvocationExpression.GetContainingStatement().NotNull("oldStatement != null"); IDeclarationStatement result; if (oldStatement is IExpressionStatement) { result = oldStatement.ReplaceBy(newDeclaration); } else { var declaration = (oldStatement as IDeclarationStatement).NotNull(nameof(oldStatement) + " is not IDeclarationStatement"); // if only one declaration just replace it if (declaration.Declaration.Declarators.Count == 1) { result = oldStatement.ReplaceBy(newDeclaration); } else { // There are several declaration, exclude our and transform it. var expression = myInvocationExpression.GetContainingParenthesizedExpression(); var currentInitializer = ExpressionInitializerNavigator.GetByValue(expression); var selectedDeclarator = LocalVariableDeclarationNavigator.GetByInitial(currentInitializer).NotNull("selectedDeclarator != null"); MultipleDeclarationUtil.SplitDeclarationBefore(selectedDeclarator); MultipleDeclarationUtil.SplitDeclarationAfter(selectedDeclarator); result = declaration.ReplaceBy(newDeclaration); } } var actualArgument = result.Descendants <IArgumentList>().First().Arguments[argumentIndex]; if (!actualArgument.IsValid()) { return(null); } // allow user to decide which array he will use var hotspotsRegistry = new HotspotsRegistry(newInvocation.GetPsiServices()); hotspotsRegistry.Register(new ITreeNode[] { actualArgument }); return(BulbActionUtils.ExecuteHotspotSession(hotspotsRegistry, actualArgument.GetDocumentRange())); }
protected override Action <ITextControl> ExecutePsiTransaction(ISolution _, IProgressIndicator __) { Highlighting.ParameterDeclaration.SetType(Highlighting.ArgumentExpression.Type()); return(BulbActionUtils.SetSelection(Highlighting.ParameterDeclaration)); }