private static string Evaluate(IHotspotContext context)
 {
     string fileName = GetFileNameWithoutExtension(context);
     return fileName.EndsWith("Specs", false, CultureInfo.InvariantCulture)
                ? fileName.Substring(0, fileName.Length - 5)
                : "ConcernType";
 }
Example #2
0
        public override string EvaluateQuickResult(IHotspotContext context)
        {
            var sourceFile = context.ExpressionRange.Document.GetPsiSourceFile(context.SessionContext.Solution);

            var controllerName = sourceFile == null ? "Replace This" : sourceFile.Name.Substring(0, sourceFile.Name.Length - 13);

            return(controllerName);
        }
 private static string GetFileNameWithoutExtension(IHotspotContext context)
 {
     IProjectFile projectItem =
         DocumentManager.GetInstance(context.SessionContext.Solution)
             .GetProjectFile(context.HotspotSession.Context.TextControl.Document);
     return projectItem != null
                ? projectItem.Location.NameWithoutExtension
                : string.Empty;
 }
        public string EvaluateQuickResult(IHotspotContext context, IList<string> arguments)
        {
            if (arguments.Count != 1)
            {
                return "<wrong number of arguments>";
            }

            return arguments[0].ToLowerInvariant();
        }
        public override string EvaluateQuickResult(IHotspotContext context)
        {
            var q =
                from hotspot in context.HotspotSession.Hotspots
                where ShouldHandle(hotspot)
                select QuickEvaluate(HotspotValue(hotspot));

            return q.FirstOrDefault();
        }
        public string EvaluateQuickResult(IHotspotContext context, IList<string> arguments)
        {
            if (arguments.Count != 1)
            {
                return null;
            }

            return PerformReplacement(arguments[0]);
        }
        public override string EvaluateQuickResult(IHotspotContext context)
        {
            var q =
                from hotspot in context.HotspotSession.Hotspots
                where ShouldHandle(hotspot)
                select QuickEvaluate(HotspotValue(hotspot));

            return(q.FirstOrDefault());
        }
        public override string EvaluateQuickResult(IHotspotContext context)
        {
            var sourceFile = context.ExpressionRange.Document.GetPsiSourceFile(context.SessionContext.Solution);

            var baseName      = sourceFile == null ? "Replace This" : sourceFile.Name.Substring(2, sourceFile.Name.Length - 5);
            var interfaceName = "I" + baseName;

            return(interfaceName);
        }
        public string EvaluateQuickResult(IHotspotContext context, IList <string> arguments)
        {
            if (arguments.Count != 1)
            {
                return(null);
            }

            return(PerformReplacement(arguments[0]));
        }
        private static string Evaluate(IHotspotContext context)
        {
            var solution      = context.SessionContext.Solution;
            var psiSourceFile = context.ExpressionRange.Document.GetPsiSourceFile(solution);

            if (psiSourceFile == null)
            {
                return(null);
            }

            using (ReadLockCookie.Create())
            {
                solution.GetPsiServices().Files.AssertAllDocumentAreCommitted();

                var primaryPsiFile = psiSourceFile.GetPrimaryPsiFile();
                if (primaryPsiFile == null)
                {
                    return(null);
                }

                var treeTextRange = primaryPsiFile.Translate(context.ExpressionRange);
                if (!(primaryPsiFile.FindTokenAt(treeTextRange.StartOffset) is ITokenNode tokenAt))
                {
                    return("");
                }

                var previousShouldInvocation = tokenAt.FindPreviousNode(x =>
                {
                    if (x is ITypeMemberDeclaration)
                    {
                        return(TreeNodeActionType.IGNORE_SUBTREE);
                    }

                    if (x is IInvocationExpression invocationExpression)
                    {
                        var referenceExpression = invocationExpression.InvokedExpression as IReferenceExpression;
                        return(referenceExpression?.NameIdentifier.Name == "Should" &&
                               referenceExpression.QualifierExpression?.GetText() != "a" &&
                               !invocationExpression.ContainsLineBreak()
                            ? TreeNodeActionType.ACCEPT
                            : TreeNodeActionType.CONTINUE);
                    }

                    return(TreeNodeActionType.CONTINUE);
                }) as IInvocationExpression;

                if (previousShouldInvocation == null)
                {
                    return("result");
                }

                var referenceExpression2 = (IReferenceExpression)previousShouldInvocation.InvokedExpression;
                var qualifier            = referenceExpression2.QualifierExpression;
                return(qualifier?.GetText() ?? "result");
            }
        }
        public override HotspotItems GetLookupItems(IHotspotContext context)
        {
            var solution        = context.SessionContext.Solution;
            var currentDocument = context.ExpressionRange.Document;

            IProjectFile projectItem = solution.GetComponent <DocumentManager>().GetProjectFile(currentDocument);
            var          path        = projectItem.Location.FullPath;

            return(MacroUtil.SimpleEvaluateResult(path));
        }
        public override string EvaluateQuickResult(IHotspotContext context)
        {
            var hotspotToEvaluate =
                from hotspot in context.HotspotSession.Hotspots
                from rangeMarker in hotspot.RangeMarkers
                where rangeMarker.DocumentRange == context.ExpressionRange
                select QuickEvaluate(HotspotValue(hotspot));

            return(hotspotToEvaluate.FirstOrDefault());
        }
Example #13
0
        public override string EvaluateQuickResult(IHotspotContext context)
        {
            if (_variableParameter == null)
            {
                return(null);
            }

            var value = _variableParameter.GetValue();

            return(_functionToRun(value));
        }
Example #14
0
        public override string EvaluateQuickResult(IHotspotContext context)
        {
            if (_variableParameter == null)
            {
                return(null);
            }

            var existing = _variableParameter.GetValue();

            existing = ProcessHelper.FirstToLower(existing);
            return("_" + existing);
        }
        public string EvaluateQuickResult(IHotspotContext context, IList <string> arguments)
        {
            foreach (var hotspot in context.HotspotSession.Hotspots)
            {
                if (ShouldHandle(hotspot))
                {
                    return(QuickEvaluate(HotspotValue(hotspot)));
                }
            }

            return(null);
        }
        public string EvaluateQuickResult(IHotspotContext context, IList<string> arguments)
        {
            foreach (var hotspot in context.HotspotSession.Hotspots)
            {
                if (ShouldHandle(hotspot))
                {
                    return QuickEvaluate(HotspotValue(hotspot));
                }
            }

            return null;
        }
    private static string Evaluate(IHotspotContext context)
    {
      var ctx = context.SessionContext;

      var textControl = ctx.TextControl;
      if (textControl == null)
        return null;

      IDocument currentDocument = textControl.Document;

      IProjectFile projectItem = ctx.Solution.GetComponent<DocumentManager>().GetProjectFile(currentDocument);
      return projectItem.Location.FullPath;
    }
        public override string EvaluateQuickResult(IHotspotContext context, IList<string> arguments)
        {
            if (arguments.Count != 1){
                return null;
            }

            try
            {
                return MethodNameFromString(arguments[0]);
            }
            catch (Exception e)
            {
                return "<" + e.Message + ">";
            }
        }
        private static string Evaluate(IHotspotContext context)
        {
            var ctx = context.SessionContext;

            var textControl = ctx.TextControl;

            if (textControl == null)
            {
                return(null);
            }

            IDocument currentDocument = textControl.Document;

            IProjectFile projectItem = ctx.Solution.GetComponent <DocumentManager>().GetProjectFile(currentDocument);

            return(projectItem.Location.FullPath);
        }
Example #20
0
        public HotspotItems GetLookupItems(IHotspotContext context, IList <string> arguments)
        {
            var method = TextControlToPsi.GetContainingTypeOrTypeMember(context.SessionContext.Solution, context.SessionContext.TextControl);

            if (method is IMethod)
            {
                var lookupItems = new List <ILookupItem>();

                var item = new TextLookupItem(((IMethod)method).ReturnType.GetPresentableName(method.PresentationLanguage));

                lookupItems.Add(item);

                var hotSpotItems = new HotspotItems(lookupItems);

                return(hotSpotItems);
            }
            return(null);
        }
Example #21
0
        public HotspotItems GetLookupItems(IHotspotContext context, IList<string> arguments)
        {
            var method = TextControlToPsi.GetContainingTypeOrTypeMember(context.SessionContext.Solution, context.SessionContext.TextControl);

            if (method is IMethod)
            {
                var lookupItems = new List<ILookupItem>();

                var item = new TextLookupItem(((IMethod)method).ReturnType.GetPresentableName(method.PresentationLanguage));
                
                lookupItems.Add(item);
                
                var hotSpotItems = new HotspotItems(lookupItems);
                
                return hotSpotItems;
            }
            return null;
        }
        /// <summary>
        /// The get lookup items.
        /// </summary>
        /// <param name="context">
        /// The context.
        /// </param>
        /// <param name="arguments">
        /// The arguments.
        /// </param>
        /// <returns>
        /// </returns>
        public HotspotItems GetLookupItems(IHotspotContext context, IList<string> arguments)
        {
            var solution = context.SessionContext.Solution;
              var textControl = context.SessionContext.TextControl;

              var element = TextControlToPsi.GetElementFromCaretPosition<IElement>(solution, textControl);

              var text = GetText(element);
              if (text == null)
              {
            return null;
              }

              var item = new TextLookupItem(text);

              var result = new HotspotItems(item);

              return result;
        }
        public override string EvaluateQuickResult(IHotspotContext context)
        {
            if (_variableParameter == null)
            {
                return(null);
            }

            var value = _variableParameter.GetValue();

            if (string.IsNullOrEmpty(value))
            {
                return(value);
            }

            value = ProcessHelper.RemovePrefix(value, _prefix);
            value = ProcessHelper.RemoveSuffix(value, _suffix);

            return(ProcessHelper.ProcessValue(_transform, value));
        }
Example #24
0
        public string EvaluateQuickResult(IHotspotContext context, IList<string> arguments)
        {
            if (arguments.Count != 3)
            {
                return null;
            }
            else
            {
                try
                {
                    var result = Regex.Replace(arguments[2], arguments[0], arguments[1], RegexOptions.IgnoreCase);

                    return result;
                }
                catch (Exception e)
                {
                    return "<" + e.Message + ">";
                }
            }
        }
        public override string EvaluateQuickResult(IHotspotContext context)
        {
            if (_variableParameter == null)
            {
                return(null);
            }

            var value   = ProcessHelper.ProcessVariable(_variableParameter, _transform);
            var builder = new StringBuilder();

            if (_prefix != null)
            {
                builder.Append(_prefix);
            }
            builder.Append(value);
            if (_suffix != null)
            {
                builder.Append(_suffix);
            }
            return(builder.ToString());
        }
        private string Evaluate(IHotspotContext context)
        {
            var psiSourceFile      = context.SessionContext.Documents.First().GetPsiSourceFile(context.SessionContext.Solution);
            var sourceFileLocation = psiSourceFile.GetLocation();

            var gitRepositoryInfo = _gitRepositoryProvider.FetchGitRepositoryInfo(sourceFileLocation.Directory);

            if (gitRepositoryInfo == null)
            {
                return("<cannot find Git repository directory>");
            }

            var headFileReference = gitRepositoryInfo.ReadHeadFileReference();

            if (headFileReference == null)
            {
                return("<cannot read reference in Git's HEAD file>");
            }

            return(ApplyStripingRegexArgument(headFileReference));
        }
        public HotspotItems GetLookupItems(IHotspotContext context, IList <string> arguments)
        {
            if (context.SessionContext.TextControl == null)
            {
                return(null);
            }

            var container = TextControlToPsi.GetContainingTypeOrTypeMember(
                context.SessionContext.Solution,
                context.SessionContext.TextControl);

            if (!(container is IMethod))
            {
                return(null);
            }
            var method = (IMethod)container;

            var lookupItems = new List <ILookupItem>();

            lookupItems.AddRange(method.Parameters.Select(param => new TextLookupItem(param.ShortName)));

            return(new HotspotItems(lookupItems));
        }
Example #28
0
        public override string EvaluateQuickResult(IHotspotContext context)
        {
            if (_variableArgument == null)
            {
                return(null);
            }
            string value   = _variableArgument.GetValue();
            string regex   = _regexArgument?.GetValue() ?? string.Empty;
            string replace = _replacementArgument?.GetValue() ?? string.Empty;

            if (string.IsNullOrEmpty(value) || string.IsNullOrEmpty(regex))
            {
                return(value);
            }
            try
            {
                return(Regex.Replace(value, regex, replace));
            }
            catch (Exception exception) when(_ignoredException.Any(x => x.IsInstanceOfType(exception)))
            {
                return(value);
            }
        }
Example #29
0
        public override HotspotItems GetLookupItems(IHotspotContext context)
        {
            var document = context.ExpressionRange.Document;

            if (document == null)
            {
                return(null);
            }

            var method = TextControlToPsi.GetContainingTypeOrTypeMember(context.SessionContext.Solution, document, context.ExpressionRange.StartOffsetRange().TextRange.StartOffset) as IMethod;

            if (method != null)
            {
                var lookupItems          = new List <ILookupItem>();
                var methodReturnTypeName = method.ReturnType.GetPresentableName(method.PresentationLanguage);
                var item = new TextLookupItem(methodReturnTypeName);
                lookupItems.Add(item);
                var hotSpotItems = new HotspotItems(lookupItems);
                return(hotSpotItems);
            }

            return(null);
        }
 public HotspotItems GetLookupItems(IHotspotContext context, IList <string> arguments)
 {
     return(null);
 }
 public override HotspotItems GetLookupItems(IHotspotContext context)
 {
     return(MacroUtil.SimpleEvaluateResult(Evaluate(context)));
 }
        public string EvaluateQuickResult(IHotspotContext context, IList<string> arguments)
        {
            if (arguments.Count != 1 || arguments[0] == null) return null;

            return arguments[0].ToLower().Replace(' ', '-');
        }
 public bool HandleExpansion(IHotspotContext context, IList <string> arguments)
 {
     return(false);
 }
 public HotspotItems GetLookupItems(IHotspotContext context, IList <string> arguments)
 {
     return(new HotspotItems(new TextLookupItem(Evaluate(context))));
 }
        public override bool HandleExpansion(IHotspotContext context)
        {
            context.HotspotSession.HotspotUpdated += HotspotSessionHotspotUpdated;

            return(false);
        }
        public bool HandleExpansion(IHotspotContext context, IList<string> arguments)
        {
            context.HotspotSession.HotspotUpdated += HotspotSessionHotspotUpdated;

            return false;
        }
Example #37
0
 public override HotspotItems GetLookupItems(IHotspotContext context)
 {
     return MacroUtil.SimpleEvaluateResult("my timestamp");
 }
 public QuickParameterlessMacroTests()
 {
     _quickParamterlessMacro = new DomainAndUsernameMacro();
     _hotspotSession = CreateFakeHotspotSession();
     _context = CreateFakeHotspotContext(_hotspotSession);
 }
 public HotspotItems GetLookupItems(IHotspotContext context, IList<string> arguments)
 {
     return MacroUtil.SimpleEvaluateResult(Evaluate(context));
 }
        public override bool HandleExpansion(IHotspotContext context)
        {
            context.HotspotSession.HotspotUpdated += HotspotSessionHotspotUpdated;

            return false;
        }
 public QuickParameterlessMacroTests()
 {
     _quickParamterlessMacro = new DomainAndUsernameMacro();
     _hotspotSession         = CreateFakeHotspotSession();
     _context = CreateFakeHotspotContext(_hotspotSession);
 }
 public override HotspotItems GetLookupItems(IHotspotContext context)
 {
     return(MacroUtil.SimpleEvaluateResult(GetServiceName(_interfaceName)));
 }
        /// <summary>
        /// Execute custom action on expanding this macro
        /// </summary>
        /// <param name="context">
        /// </param>
        /// <param name="arguments">
        /// </param>
        /// <returns>
        /// <c>true</c> if all neccessary actions have been taken or <c>false</c> to proceed with normal <see cref="M:JetBrains.ReSharper.Feature.Services.LiveTemplates.Macros.IMacro.GetLookupItems(JetBrains.ReSharper.Feature.Services.LiveTemplates.Hotspots.IHotspotContext,System.Collections.Generic.IList{System.String})"/> procedure
        /// </returns>
        public bool HandleExpansion(IHotspotContext context, IList<string> arguments)
        {
            var solution = context.SessionContext.Solution;
              var textControl = context.SessionContext.TextControl;

              var projectFile = DocumentManager.GetInstance(solution).GetProjectFile(textControl.Document);
              if (projectFile == null)
              {
            return false;
              }

              var psiManager = PsiManager.GetInstance(solution);
              if (psiManager == null)
              {
            return false;
              }

              var file = psiManager.GetPsiFile(projectFile, PsiLanguageType.GetByProjectFile(projectFile)) as ICSharpFile;
              if (file == null)
              {
            return false;
              }

              var element = file.FindTokenAt(new TreeOffset(textControl.Caret.Offset()));
              if (element == null)
              {
            return false;
              }

              var referenceExpression = element.GetContainingElement(typeof(IExpression), true) as IExpression;
              if (referenceExpression == null)
              {
            return false;
              }

              var expressionType = referenceExpression.GetExpressionType();

              var declaredType = expressionType as IDeclaredType;
              if (declaredType == null)
              {
            return false;
              }

              var typeElement = declaredType.GetTypeElement();
              if (typeElement == null)
              {
            return false;
              }

              var properties = typeElement.Properties;

              foreach (var property in properties)
              {
            arguments.Add(property.ShortName);
              }

              return true;
        }
 public void SetUp()
 {
     _quickParamterlessMacro = new DomainAndUsernameMacroImpl();
     _hotspotSession         = CreateFakeHotspotSession();
     _context = CreateFakeHotspotContext(_hotspotSession);
 }
 public HotspotItems GetLookupItems(IHotspotContext context, IList<string> arguments)
 {
   return new HotspotItems(new TextLookupItem(Evaluate(context)));
 }
 public string EvaluateQuickResult(IHotspotContext context, IList <string> arguments)
 {
     return(Evaluate(context));
 }
 public void SetUp()
 {
     _quickParamterlessMacro = new DomainAndUsernameMacroImpl();
     _hotspotSession = CreateFakeHotspotSession();
     _context = CreateFakeHotspotContext(_hotspotSession);
 }
 /// <summary>
 /// Evaluates "quick result" for this macro.
 /// Unlike the result returned by <see cref="M:JetBrains.ReSharper.Feature.Services.LiveTemplates.Macros.IMacro.GetLookupItems(JetBrains.ReSharper.Feature.Services.LiveTemplates.Hotspots.IHotspotContext,System.Collections.Generic.IList{System.String})"/> method,
 /// quick result is re-evaluated on each typing and so its implementation should be very quick.
 /// If the macro cannot provide any result that can be evaluated very quickly, it should return null.
 /// </summary>
 /// <param name="context">
 /// </param>
 /// <param name="arguments">
 /// Values
 /// </param>
 /// <returns>
 /// The evaluate quick result.
 /// </returns>
 public string EvaluateQuickResult(IHotspotContext context, IList<string> arguments)
 {
     return null;
 }
 /// <summary>
 /// Evaluates list of lookup items to show
 /// </summary>
 /// <param name="context">
 /// </param>
 /// <param name="arguments">
 /// </param>
 /// <returns>
 /// List of lookup items to show in order of preference. That is,
 /// </returns>
 public HotspotItems GetLookupItems(IHotspotContext context, IList<string> arguments)
 {
     return null;
 }
 public string EvaluateQuickResult(IHotspotContext context)
 {
     return(_text);
 }
 /// <summary>
 /// The handle expansion.
 /// </summary>
 /// <param name="context">
 /// The context.
 /// </param>
 /// <param name="arguments">
 /// The arguments.
 /// </param>
 /// <returns>
 /// The handle expansion.
 /// </returns>
 public bool HandleExpansion(IHotspotContext context, IList<string> arguments)
 {
     return true;
 }
 public bool HandleExpansion(IHotspotContext context)
 {
     return(true);
 }
 public HotspotItems GetLookupItems(IHotspotContext context)
 {
     return(HotspotItems.Empty);
 }
Example #54
0
 public abstract string EvaluateQuickResult(IHotspotContext context, IList<string> arguments);