Example #1
0
        public void MakeCallShared(IReference reference)
        {
            var referenceExpression1 = reference.GetTreeNode() as IReferenceExpression;

            if (referenceExpression1 == null || !reference.Resolve().Result.IsExtensionMethod())
            {
                return;
            }

            var byExpression = IndexExpressionNavigator.GetByExpression(referenceExpression1);

            if (byExpression == null)
            {
                return;
            }

            var substitution         = reference.Resolve().Result.Substitution;
            var referenceExpression2 = byExpression.Expression as IReferenceExpression;

            if (referenceExpression2 == null)
            {
                return;
            }

            var instance     = VBElementFactory.GetInstance(referenceExpression1.GetPsiModule());
            var vbExpression = referenceExpression2.QualifierExpression ?? instance.CreateExpression("me", new object[0]);

            byExpression.AddArgumentAfter(instance.CreateArgument(vbExpression), null);
            //byExpression.SetExpression(instance.CreateReferenceExpression(this.Executer.Method.ShortName, new object[0]));
            //((IReferenceExpression)byExpression.Expression).Reference.BindTo((IDeclaredElement)this.Executer.Method);
            //if (((IReferenceExpression)byExpression.Expression).Reference.BindTo((IDeclaredElement)this.Workflow.Method, substitution).CheckResolveResult() == ResolveErrorType.OK) return;

            //this.Driver.AddConflict((IConflict)ReferenceConflict.CreateError(reference, "{0} can not be transformed correctly"));
        }
Example #2
0
        private UpdateAspDesignerFileService.Generator GetGenerator()
        {
            var treeNode = _reference.GetTreeNode();

            var updateAspDesignerFileService = treeNode.GetSolution().GetComponent <UpdateAspDesignerFileService>();

            return(updateAspDesignerFileService.GetGenerator(treeNode.GetSourceFile()));
        }
        private CreateFromUsageFix(IReference reference)
        {
            myUnfilteredItems = new List <ICreateFromUsageActionProvider>();

            var treeNode = reference.GetTreeNode();

            if (treeNode.IsFromUnityProject())
            {
                myUnfilteredItems.Add(new CreateSerializedFieldFromUsageAction(reference));
            }
        }
        public override MethodInvocation ProcessUsage(IReference reference)
        {
            var referenceExpression = reference.GetTreeNode() as IReferenceExpression;

            if (referenceExpression == null)
            {
                Driver.AddConflict(ReferenceConflict.CreateError(reference, "{0} can not be updated correctly.", "Usage"));
                return(null);
            }

            bool isExtensionMethod           = referenceExpression.IsExtensionMethod();
            IInvocationExpression invocation = InvocationExpressionNavigator.GetByInvokedExpression(referenceExpression);

            if (invocation == null)
            {
                Driver.AddConflict(ReferenceConflict.CreateError(reference, "{0} can not be updated correctly.", "Usage"));
                return(null);
            }

            ITreeNode element = GetArgument(invocation, isExtensionMethod);

            var   argument = element as ICSharpArgument;
            IType type     = argument != null?GetTypeOfValue(argument.Value) : GetTypeOfValue(element);

            if (type == null || !type.CanUseExplicitly(invocation))
            {
                Driver.AddConflict(ReferenceConflict.CreateError(
                                       reference, "Argument of {0} is not valid 'typeof' expression.", "usage"));
                return(null);
            }

            // we can rely on resolve result since method declaration is not yet changed.
            ResolveResultWithInfo resolveResult = reference.Resolve();
            ISubstitution         substitution  = resolveResult.Result.Substitution;
            var method = resolveResult.DeclaredElement as IMethod;

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

            if (argument != null)
            {
                invocation.RemoveArgument(argument);
                return(new MethodInvocation(reference, type, method, substitution));
            }

            CSharpElementFactory factory = CSharpElementFactory.GetInstance(invocation.GetPsiModule());
            IReferenceExpression newInvokedExpression =
                invocation.InvokedExpression.ReplaceBy(factory.CreateReferenceExpression("$0", Executer.Method));

            return(new MethodInvocation(newInvokedExpression.Reference, type, method, substitution));
        }
        private static ICSharpInvocationReference?FindInvocationReference(IReference reference)
        {
            if (reference is ICSharpInvocationReference invocationReference)
            {
                return(invocationReference);
            }

            ITreeNode treeNode       = reference.GetTreeNode();
            var       argumentsOwner = treeNode.GetContainingNode <ICSharpArgumentsOwner>();

            if (argumentsOwner?.LBound is { } lBound&& treeNode.GetTreeEndOffset() <= lBound.GetTreeStartOffset())
            {
                return(argumentsOwner.Reference);
            }

            return(null);
        }
    public override MethodInvocation ProcessUsage(IReference reference)
    {
      var referenceExpression = reference.GetTreeNode() as IReferenceExpression;
      if (referenceExpression == null)
      {
        Driver.AddConflict(ReferenceConflict.CreateError(reference, "{0} can not be updated correctly.", "Usage"));
        return null;
      }

      bool isExtensionMethod = referenceExpression.IsExtensionMethod();
      IInvocationExpression invocation = InvocationExpressionNavigator.GetByInvokedExpression(referenceExpression);
      if (invocation == null)
      {
        Driver.AddConflict(ReferenceConflict.CreateError(reference, "{0} can not be updated correctly.", "Usage"));
        return null;
      }

      ITreeNode element = GetArgument(invocation, isExtensionMethod);

      var argument = element as ICSharpArgument;
      IType type = argument != null ? GetTypeOfValue(argument.Value) : GetTypeOfValue(element);
      if (type == null || !type.CanUseExplicitly(invocation))
      {
        Driver.AddConflict(ReferenceConflict.CreateError(
          reference, "Arguemnt of {0} is not valid 'typeof' expression.", "usage"));
        return null;
      }

      // we can rely on resolve result since method declaration is not yet changed. 
      ResolveResultWithInfo resolveResult = reference.Resolve();
      ISubstitution substitution = resolveResult.Result.Substitution;
      var method = resolveResult.DeclaredElement as IMethod;
      if (method == null)
        return null;

      if (argument != null)
      {
        invocation.RemoveArgument(argument);
        return new MethodInvocation(reference, type, method, substitution);
      }

      CSharpElementFactory factory = CSharpElementFactory.GetInstance(invocation.GetPsiModule());
      IReferenceExpression newInvokedExpression =
        invocation.InvokedExpression.ReplaceBy(factory.CreateReferenceExpression("$0", Executer.Method));
      return new MethodInvocation(newInvokedExpression.Reference, type, method, substitution);
    }
        private static ICSharpInvocationReference FindInvocationReference([NotNull] IReference reference)
        {
            if (reference is ICSharpInvocationReference invocationReference)
            {
                return(invocationReference);
            }

            ITreeNode  treeNode       = reference.GetTreeNode();
            var        argumentsOwner = treeNode.GetContainingNode <ICSharpArgumentsOwner>();
            ITokenNode lBound         = argumentsOwner?.LBound;

            if (lBound != null && treeNode.GetTreeEndOffset() <= lBound.GetTreeStartOffset())
            {
                return(argumentsOwner.Reference);
            }

            return(null);
        }
        public static string SuggestShortReferenceName([NotNull] IReference reference,
                                                       [NotNull] IDeclaredElement declaredElement)
        {
            var sourceName = declaredElement.GetSourceName();

            var treeNode = reference.GetTreeNode();

            if (declaredElement is ITypeElement)
            {
                var referenceName = treeNode as ITypeReferenceName;
                if (AttributeNavigator.GetByReferenceName(referenceName) != null &&
                    sourceName.EndsWith(FSharpImplUtil.AttributeSuffix, StringComparison.Ordinal) &&
                    sourceName != FSharpImplUtil.AttributeSuffix)
                {
                    sourceName = sourceName.TrimFromEnd(FSharpImplUtil.AttributeSuffix);
                }
            }

            return(SuggestShortReferenceName(sourceName, treeNode.Language));
        }
        public void MakeCallExtension(IReference reference)
        {
            var treeNode = reference.GetTreeNode();
            if (!treeNode.IsVB9Supported()) return;

            var referenceExpression = treeNode as IReferenceExpression;
            if (referenceExpression == null) return;

            IIndexExpression byExpression = IndexExpressionNavigator.GetByExpression(referenceExpression);
            if (byExpression == null) return;

            IVBArgument vbArgument = null;
            int index = 0;
            using (var enumerator = byExpression.ArgumentList.Arguments.GetEnumerator()) {
                while (enumerator.MoveNext()) {
                    var current = enumerator.Current;
                    var matchingParameter = current.GetMatchingParameter();
                    if (matchingParameter != null && matchingParameter.Element.IndexOf() == 0) {
                        vbArgument = current;
                        break;
                    }

                    ++index;
                }
            }

            if (vbArgument == null) return;

            IVBExpression vbExpression = null;
            var expressionArgument = vbArgument as IExpressionArgument;
            if (expressionArgument != null)
                vbExpression = expressionArgument.Expression;
            if (vbExpression == null) return;

            var indexExpression1 =
                (IIndexExpression) VBElementFactory.GetInstance(treeNode.GetPsiModule())
                    .CreateExpression("$0." + reference.GetName() + "()", new object[] { vbExpression });
            indexExpression1.SetArgumentList(byExpression.ArgumentList);
            indexExpression1.RemoveArgument(indexExpression1.Arguments[index]);
            byExpression.ReplaceBy(indexExpression1);
        }
        public void MakeCallShared(IReference reference)
        {
            var referenceExpression1 = reference.GetTreeNode() as IReferenceExpression;
            if (referenceExpression1 == null || !reference.Resolve().Result.IsExtensionMethod()) return;

            var byExpression = IndexExpressionNavigator.GetByExpression(referenceExpression1);
            if (byExpression == null) return;

            var substitution = reference.Resolve().Result.Substitution;
            var referenceExpression2 = byExpression.Expression as IReferenceExpression;
            if (referenceExpression2 == null) return;

            var instance = VBElementFactory.GetInstance(referenceExpression1.GetPsiModule());
            var vbExpression = referenceExpression2.QualifierExpression ?? instance.CreateExpression("me", new object[0]);
            byExpression.AddArgumentAfter(instance.CreateArgument(vbExpression), null);
            //byExpression.SetExpression(instance.CreateReferenceExpression(this.Executer.Method.ShortName, new object[0]));
            //((IReferenceExpression)byExpression.Expression).Reference.BindTo((IDeclaredElement)this.Executer.Method);
            //if (((IReferenceExpression)byExpression.Expression).Reference.BindTo((IDeclaredElement)this.Workflow.Method, substitution).CheckResolveResult() == ResolveErrorType.OK) return;

            //this.Driver.AddConflict((IConflict)ReferenceConflict.CreateError(reference, "{0} can not be transformed correctly"));
        }
 public override void ProcessParameterReference(IReference reference)
 {
     Driver.AddConflict(new UnsupportedLanguageConflict(reference.GetTreeNode(), "parameter usage",
                                                        ConflictSeverity.Error));
 }
 public override MethodInvocation ProcessUsage(IReference reference)
 {
     // when something goes wrong just add conflict
     Driver.AddConflict(new UnsupportedLanguageConflict(reference.GetTreeNode(), "usage", ConflictSeverity.Error));
     return(null);
 }
Example #13
0
        public static void AppendCandidates([NotNull] this CSharpColorizer colorizer, [CanBeNull] IReference reference)
        {
            if (reference == null)
            {
                return;
            }

            IResolveResult           resolveResult = reference.Resolve().Result;
            IList <IDeclaredElement> candidates    = resolveResult.Candidates;
            IList <ISubstitution>    substitutions = resolveResult.CandidateSubstitutions;

            for (int i = 0; i < candidates.Count; ++i)
            {
                colorizer.AppendPlainText(Environment.NewLine);
                colorizer.AppendPlainText("  ");
                colorizer.AppendDeclaredElement(candidates[i].EliminateDelegateInvokeMethod(), substitutions[i], PresenterOptions.FullWithoutParameterNames, reference.GetTreeNode());
            }
        }
Example #14
0
 private IReferenceExpression GetReferenceExpression()
 {
     return(_myReference != null
         ? _myReference.GetTreeNode() as IReferenceExpression
         : null);
 }
 public override MethodInvocation ProcessUsage(IReference reference)
 {
   // when something goes wrong just add conflict
   Driver.AddConflict(new UnsupportedLanguageConflict(reference.GetTreeNode(), "usage", ConflictSeverity.Error));
   return null;
 }
Example #16
0
        public void MakeCallExtension(IReference reference)
        {
            var treeNode = reference.GetTreeNode();

            if (!treeNode.IsVB9Supported())
            {
                return;
            }

            var referenceExpression = treeNode as IReferenceExpression;

            if (referenceExpression == null)
            {
                return;
            }

            IIndexExpression byExpression = IndexExpressionNavigator.GetByExpression(referenceExpression);

            if (byExpression == null)
            {
                return;
            }

            IVBArgument vbArgument = null;
            int         index      = 0;

            using (var enumerator = byExpression.ArgumentList.Arguments.GetEnumerator()) {
                while (enumerator.MoveNext())
                {
                    var current           = enumerator.Current;
                    var matchingParameter = current.GetMatchingParameter();
                    if (matchingParameter != null && matchingParameter.Element.IndexOf() == 0)
                    {
                        vbArgument = current;
                        break;
                    }

                    ++index;
                }
            }

            if (vbArgument == null)
            {
                return;
            }

            IVBExpression vbExpression       = null;
            var           expressionArgument = vbArgument as IExpressionArgument;

            if (expressionArgument != null)
            {
                vbExpression = expressionArgument.Expression;
            }
            if (vbExpression == null)
            {
                return;
            }

            var indexExpression1 =
                (IIndexExpression)VBElementFactory.GetInstance(treeNode.GetPsiModule())
                .CreateExpression("$0." + reference.GetName() + "()", new object[] { vbExpression });

            indexExpression1.SetArgumentList(byExpression.ArgumentList);
            indexExpression1.RemoveArgument(indexExpression1.Arguments[index]);
            byExpression.ReplaceBy(indexExpression1);
        }
 public override void ProcessParameterReference(IReference reference)
 {
   Driver.AddConflict(new UnsupportedLanguageConflict(reference.GetTreeNode(), "parameter usage",
                                                      ConflictSeverity.Error));
 }