public ConvertWebFormsToRazorRefactoringBase(
     ConvertWebFormsToRazorRefactoringWorkflow workflow,
     ISolution solution,
     IRefactoringDriver driver)
     : base(workflow, solution, driver)
 {
 }
        public override void Rename(IRenameRefactoring executer, IProgressIndicator pi, bool hasConflictsWithDeclarations,
                                    IRefactoringDriver driver)
        {
            if (!myModel.ShouldAddFormerlySerializedAs)
            {
                return;
            }

            var fieldDeclaration = GetFieldDeclaration(myPointer.FindDeclaredElement() as IField);

            if (fieldDeclaration == null)
            {
                return;
            }

            RemoveExistingAttributesWithNewName(fieldDeclaration);

            if (HasExistingFormerlySerializedAsAttribute(fieldDeclaration))
            {
                // Make sure textual occurrence rename doesn't rename the existing attribute parameter
                RemoveFromTextualOccurrences(executer, fieldDeclaration);
                return;
            }

            var attribute = CreateFormerlySerializedAsAttribute(fieldDeclaration.GetPsiModule());

            if (attribute != null)
            {
                fieldDeclaration.AddAttributeAfter(attribute, null);
            }
        }
        public override void Rename(IRenameRefactoring executer, IProgressIndicator pi, bool hasConflictsWithDeclarations,
                                    IRefactoringDriver driver)
        {
            // Rename the "declaration"
            var declaredElement  = myPointer.FindDeclaredElement();
            var originalTreeNode = declaredElement?.GetTreeNode();

            if (originalTreeNode == null)
            {
                return;
            }

            var originalRange     = originalTreeNode.GetDocumentRange();
            var factory           = JavaScriptElementFactory.GetInstance(originalTreeNode);
            var literalExpression = factory.CreateExpression("\"$0\"", NewName);
            var newExpression     = originalTreeNode.ReplaceBy(literalExpression);

            RemoveFromTextualOccurrences(executer, originalRange);

            var references = executer.Workflow.GetElementReferences(declaredElement);

            if (!Enumerable.Any(references))
            {
                return;
            }

            pi.Start(references.Count);

            // Create a new declared element (other implementations don't appear to cache this, either)
            var element = new AsmDefNameDeclaredElement(declaredElement.GetJsServices(), NewName,
                                                        declaredElement.SourceFile, newExpression.GetTreeStartOffset().Offset);

            // Rename/bind the references
            foreach (var pair in LanguageUtil.SortReferences(references.Where(r => r.IsValid())))
            {
                foreach (var sortedReference in LanguageUtil.GetSortedReferences(pair.Value))
                {
                    InterruptableActivityCookie.CheckAndThrow(pi);

                    var referenceRange = sortedReference.GetDocumentRange();

                    if (sortedReference.IsValid())
                    {
                        sortedReference.BindTo(element);
                    }

                    RemoveFromTextualOccurrences(executer, referenceRange);

                    pi.Advance();
                }
            }

            element.GetPsiServices().Caches.Update();
            myNewPointer = element.CreateElementPointer();
        }
        // ReSharper disable once IdentifierTypo
        public override void Rename(IRenameRefactoring executer, IProgressIndicator pi, bool hasConflictsWithDeclarations,
                                    IRefactoringDriver driver)
        {
            if (myElementsToRename == null)
            {
                return;
            }

            var workflow = (executer.Workflow as RenameWorkflowBase).NotNull("workflow != null");

            foreach (var textOccurrence in myElementsToRename)
            {
                workflow.DataModel.AddExtraTextOccurrence(new AssetTextOccurrence(textOccurrence, OldName, NewName, myIsProperty));
            }
        }
Пример #5
0
        // ReSharper disable once IdentifierTypo
        public override void Rename(IRenameRefactoring executer, IProgressIndicator pi, bool hasConflictsWithDeclarations,
                                    IRefactoringDriver driver)
        {
            if (myElementsToRename == null)
            {
                return;
            }

            var workflow = (executer.Workflow as RenameWorkflowBase).NotNull("workflow != null");

            var persistentIndexManager = mySolution.GetComponent <IPersistentIndexManager>();

            foreach (var textOccurrence in myElementsToRename)
            {
                var sourceFile = persistentIndexManager[textOccurrence.MethodUsages.TextRangeOwner];
                if (sourceFile == null)
                {
                    continue;
                }
                workflow.DataModel.AddExtraTextOccurrence(new AssetTextOccurrence(textOccurrence, sourceFile, OldName, NewName, myIsProperty));
            }
        }
Пример #6
0
 public NHRename(RenameWorkflow workflow, ISolution solution, IRefactoringDriver driver)
     : base(workflow, solution, driver)
 {
 }
 public IntoduceNsAliasRefactoring(IntoduceNsAliasWorkflow workFlow, ISolution solution, IRefactoringDriver driver)
     : base(workFlow, solution, driver)
 {
     _workFlow = workFlow;
 }
 public CSharpMakeMethodGeneric(MakeMethodGenericWorkflow workflow, ISolution solution, IRefactoringDriver driver)
     : base(workflow, solution, driver)
 {
 }
Пример #9
0
 public virtual MakeMethodGenericBase CreateMakeMethodGeneric(MakeMethodGenericWorkflow workflow, ISolution solution,
                                                              IRefactoringDriver driver)
 {
     return(null);
 }
 public override MakeMethodGenericBase CreateMakeMethodGeneric(MakeMethodGenericWorkflow workflow, ISolution solution,
                                                               IRefactoringDriver driver)
 {
   return new CSharpMakeMethodGeneric(workflow, solution, driver);
 }
 /// <summary>
 /// Returns refactoring class that executed PSI transaction.
 /// </summary>
 public override IRefactoringExecuter CreateRefactoring(IRefactoringDriver driver)
 {
   return new MakeMethodGenericRefactoring(this, Solution, driver, mySearchDomainFactory);
 }
Пример #12
0
 public ConvertWebFormsToRazorRefactoringExecutor(ConvertWebFormsToRazorRefactoringWorkflow workflow, IRefactoringDriver driver)
     : base(workflow, workflow.Solution, driver)
 {
 }
Пример #13
0
 protected MakeMethodGenericBase(MakeMethodGenericWorkflow workflow, ISolution solution, IRefactoringDriver driver)
     : base(workflow, solution, driver)
 {
 }
Пример #14
0
 public override RenameBase CreateRename(RenameWorkflow workflow, ISolution solution, IRefactoringDriver driver)
 {
     return new NHRename(workflow, solution, driver);
 }
 public virtual MakeMethodGenericBase CreateMakeMethodGeneric(MakeMethodGenericWorkflow workflow, ISolution solution,
                                                              IRefactoringDriver driver)
 {
   return null;
 }
    public override void Rename(RenameRefactoring executer, IProgressIndicator pi, bool hasConflictsWithDeclarations, IRefactoringDriver driver)
    {
      BuildDeclarations();

      //Logger.Assert(myDeclarations.Count > 0, "myDeclarations.Count > 0");

      IDeclaredElement declaredElement = myOriginalElementPointer.FindDeclaredElement();
      if (declaredElement == null)
      {
        return;
      }

      IPsiServices psiServices = declaredElement.GetPsiServices();

      IList<IReference> primaryReferences = executer.Workflow.GetElementReferences(PrimaryDeclaredElement);
      List<Pair<IDeclaredElement, IList<IReference>>> secondaryElementWithReferences = SecondaryDeclaredElements.Select(x => Pair.Of(x, executer.Workflow.GetElementReferences(x))).ToList();
      pi.Start(myDeclarations.Count + primaryReferences.Count);

      foreach (IDeclaration declaration in myDeclarations)
      {
        InterruptableActivityCookie.CheckAndThrow(pi);
        declaration.SetName(myNewName);
        pi.Advance();
      }

      psiServices.PsiManager.UpdateCaches();

      IDeclaredElement newDeclaredElement = null;
      if (myDeclarations.Count > 0)
      {
        newDeclaredElement = myDeclarations[0].DeclaredElement;
      }

      Assertion.Assert(newDeclaredElement != null, "The condition (newDeclaredElement != null) is false.");

      myNewElementPointer = newDeclaredElement.CreateElementPointer();
      Assertion.Assert(newDeclaredElement.IsValid(), "myNewDeclaredElement.IsValid()");


      myNewReferences.Clear();
      OneToSetMap<PsiLanguageType, IReference> references = LanguageUtil.SortReferences(primaryReferences.Where(x => x.IsValid()));
      IList<IReference> referencesToRename = new List<IReference>();
      foreach (var pair in references)
      {
        List<IReference> sortedReferences = LanguageUtil.GetSortedReferences(pair.Value);
        foreach (IReference reference in sortedReferences)
        {
          IReference oldReferenceForConflict = reference;
          InterruptableActivityCookie.CheckAndThrow(pi);
          if (reference.IsValid()) // reference may invalidate during additional reference processing
          {
            RenameHelperBase rename = executer.Workflow.LanguageSpecific[reference.GetTreeNode().Language];
            IReference reference1 = rename.TransformProjectedInitializer(reference);
            DeclaredElementInstance subst = GetSubst(newDeclaredElement, executer);
            IReference newReference;
            if (subst != null)
            {
              if (subst.Substitution.Domain.IsEmpty())
              {
                newReference = reference1.BindTo(subst.Element);
              }
              else
              {
                newReference = reference1.BindTo(subst.Element, subst.Substitution);
              }
            }
            else
            {
              newReference = reference1.BindTo(newDeclaredElement);
            }
            if (!(newReference is IImplicitReference))
            {
              IDeclaredElement element = newReference.Resolve().DeclaredElement;
              if (!hasConflictsWithDeclarations && !myDoNotShowBindingConflicts && (element == null || !element.Equals(newDeclaredElement)) && !rename.IsAlias(newDeclaredElement))
              {
                driver.AddLateConflict(() => new Conflict(newReference.GetTreeNode().GetSolution(), "Usage {0} can not be updated correctly.", ConflictSeverity.Error, oldReferenceForConflict), "not bound");
              }
              referencesToRename.Add(newReference);
            }
            myNewReferences.Insert(0, newReference);
            rename.AdditionalReferenceProcessing(newDeclaredElement, newReference, myNewReferences);
          }

          pi.Advance();
        }
      }

      foreach (var pair in secondaryElementWithReferences)
      {
        IDeclaredElement element = pair.First;
        IList<IReference> secondaryReferences = pair.Second;
        foreach (IReference reference in secondaryReferences)
        {
          InterruptableActivityCookie.CheckAndThrow(pi);
          if (reference.IsValid())
          {
            reference.BindTo(element);
          }
        }
      }
    }
Пример #17
0
 public MakeMethodGenericRefactoring(MakeMethodGenericWorkflow workFlow, ISolution solution,
                                     IRefactoringDriver driver,
                                     SearchDomainFactory searchDomainFactory) : base(workFlow, solution, driver)
 {
     mySearchDomainFactory = searchDomainFactory;
 }
 public SharedToExtensionRefactoring(SharedToExtensionWorkflow sharedToExtensionWorkflow, ISolution solution, IRefactoringDriver driver, SharedToExtensionWorkflow.WorkflowDirection direction)
     : base(sharedToExtensionWorkflow, solution, driver)
 {
     Direction = direction;
         ReferencePointers = new List<IReferencePointer>();
 }
Пример #19
0
 public SharedToExtensionRefactoring(SharedToExtensionWorkflow sharedToExtensionWorkflow, ISolution solution, IRefactoringDriver driver, SharedToExtensionWorkflow.WorkflowDirection direction)
     : base(sharedToExtensionWorkflow, solution, driver)
 {
     Direction         = direction;
     ReferencePointers = new List <IReferencePointer>();
 }
 public MakeMethodGenericUnsupported(MakeMethodGenericWorkflow workflow, ISolution solution,
                                     IRefactoringDriver driver) : base(workflow, solution, driver)
 {
 }
 public override IRefactoringExecuter CreateRefactoring(IRefactoringDriver driver)
 {
     return new IntoduceNsAliasRefactoring(this, Solution, driver);
 }
        public override void Rename(IRenameRefactoring executer, IProgressIndicator pi, bool hasConflictsWithDeclarations, IRefactoringDriver driver)
        {
            BuildDeclarations();

            //Logger.Assert(myDeclarations.Count > 0, "myDeclarations.Count > 0");

            IDeclaredElement declaredElement = myOriginalElementPointer.FindDeclaredElement();

            if (declaredElement == null)
            {
                return;
            }

            IPsiServices psiServices = declaredElement.GetPsiServices();

            IList <IReference> primaryReferences = executer.Workflow.GetElementReferences(PrimaryDeclaredElement);
            List <Pair <IDeclaredElement, IList <IReference> > > secondaryElementWithReferences = SecondaryDeclaredElements.Select(x => Pair.Of(x, executer.Workflow.GetElementReferences(x))).ToList();

            pi.Start(myDeclarations.Count + primaryReferences.Count);

            foreach (IDeclaration declaration in myDeclarations)
            {
                InterruptableActivityCookie.CheckAndThrow(pi);
                declaration.SetName(myNewName);
                pi.Advance();
            }

            psiServices.Caches.Update();

            IDeclaredElement newDeclaredElement;

            if (myDeclarations.Count > 0)
            {
                newDeclaredElement = myDeclarations[0].DeclaredElement;
            }
            else
            {
                if (myElement is RoleDeclaredElement)
                {
                    newDeclaredElement = myElement;
                    ((RoleDeclaredElement)myElement).ChangeName = true;
                    ((RoleDeclaredElement)myElement).NewName    = NewName;
                    ((RoleDeclaredElement)newDeclaredElement).SetName(NewName);
                }
                else
                {
                    newDeclaredElement = null;
                }
            }
            Assertion.Assert(newDeclaredElement != null, "The condition (newDeclaredElement != null) is false.");

            myNewElementPointer = newDeclaredElement.CreateElementPointer();
            Assertion.Assert(newDeclaredElement.IsValid(), "myNewDeclaredElement.IsValid()");


            myNewReferences.Clear();
            OneToSetMap <PsiLanguageType, IReference> references = LanguageUtil.SortReferences(primaryReferences.Where(x => x.IsValid()));
            IList <IReference> referencesToRename = new List <IReference>();

            foreach (var pair in references)
            {
                List <IReference> sortedReferences = pair.Value.ToList();//LanguageUtil.GetSortedReferences(pair.Value);
                foreach (IReference reference in sortedReferences)
                {
                    IReference oldReferenceForConflict = reference;
                    InterruptableActivityCookie.CheckAndThrow(pi);
                    if (reference.IsValid()) // reference may invalidate during additional reference processing
                    {
                        RenameHelperBase        rename     = executer.Workflow.LanguageSpecific[reference.GetTreeNode().Language];
                        IReference              reference1 = rename.TransformProjectedInitializer(reference);
                        DeclaredElementInstance subst      = GetSubst(newDeclaredElement, executer);
                        IReference              newReference;
                        if (subst != null)
                        {
                            if (subst.Substitution.Domain.IsEmpty())
                            {
                                newReference = reference1.BindTo(subst.Element);
                            }
                            else
                            {
                                newReference = reference1.BindTo(subst.Element, subst.Substitution);
                            }
                        }
                        else
                        {
                            newReference = reference1.BindTo(newDeclaredElement);
                        }
                        if (!(newReference is IImplicitReference))
                        {
                            IDeclaredElement element = newReference.Resolve().DeclaredElement;
                            if (!hasConflictsWithDeclarations && !myDoNotShowBindingConflicts && (element == null || !element.Equals(newDeclaredElement)) && !rename.IsAlias(newDeclaredElement))
                            {
                                driver.AddLateConflict(() => new Conflict(newReference.GetTreeNode().GetSolution(), "Usage {0} can not be updated correctly.", ConflictSeverity.Error, oldReferenceForConflict), "not bound");
                            }
                            referencesToRename.Add(newReference);
                        }
                        myNewReferences.Insert(0, newReference);
                        rename.AdditionalReferenceProcessing(newDeclaredElement, newReference, myNewReferences);
                    }

                    pi.Advance();
                }
            }

            foreach (var pair in secondaryElementWithReferences)
            {
                IDeclaredElement   element             = pair.First;
                IList <IReference> secondaryReferences = pair.Second;
                foreach (IReference reference in secondaryReferences)
                {
                    InterruptableActivityCookie.CheckAndThrow(pi);
                    if (reference.IsValid())
                    {
                        reference.BindTo(element);
                    }
                }
            }

            if (myElement is RoleDeclaredElement)
            {
                ((RoleDeclaredElement)myElement).ChangeName = false;
                ((RoleDeclaredElement)myElement).SetName(NewName);
                foreach (IReference reference in referencesToRename)
                {
                    ((PsiRoleReference)reference).SetName(NewName);
                    reference.CurrentResolveResult = null;
                    ((PsiFile)((RoleDeclaredElement)myElement).File).ClearTables();
                }
            }
        }
 public CSharpMakeMethodGeneric(MakeMethodGenericWorkflow workflow, ISolution solution, IRefactoringDriver driver)
   : base(workflow, solution, driver)
 {
 }
 public override MakeMethodGenericBase CreateMakeMethodGeneric(MakeMethodGenericWorkflow workflow, ISolution solution, IRefactoringDriver driver)
 {
     return(new CSharpMakeMethodGeneric(workflow, solution, driver));
 }
 // ReSharper disable once IdentifierTypo
 public override void Rename(IRenameRefactoring executer, IProgressIndicator pi, bool hasConflictsWithDeclarations,
                             IRefactoringDriver driver)
 {
     // Do nothing. We just want to hook into the UI process
 }
 public MakeMethodGenericUnsupported(MakeMethodGenericWorkflow workflow, ISolution solution,
                                     IRefactoringDriver driver) : base(workflow, solution, driver)
 {
 }
 public override IRefactoringExecuter CreateRefactoring(IRefactoringDriver driver)
 {
     return new SharedToExtensionRefactoring(this, Solution, driver, Direction);
 }
 /// <summary>
 /// Returns refactoring class that executed PSI transaction.
 /// </summary>
 public override IRefactoringExecuter CreateRefactoring(IRefactoringDriver driver)
 {
     return(new MakeMethodGenericRefactoring(this, Solution, driver, mySearchDomainFactory));
 }
Пример #29
0
 public override IRefactoringExecuter CreateRefactoring(IRefactoringDriver driver)
 {
     return(new ConvertWebFormsToRazorRefactoringExecutor(this, driver));
 }
 public MappingFileRename(RenameWorkflow workflow, ISolution solution, IRefactoringDriver driver)
     : base(workflow, solution, driver) {
     Logger.LogMessage("NHibernatePlugin: MappingFileRename ctor called");
 }
Пример #31
0
 public override IRefactoringExecuter CreateRefactoring(IRefactoringDriver driver)
 {
     return(new SharedToExtensionRefactoring(this, Solution, driver, Direction));
 }