public GeneratedClassSearchRequest(IDeclaredElement declaredElement)
        {
            if (declaredElement == null)
            {
                throw new ArgumentNullException("declaredElement");
            }
            Logger.Assert(declaredElement.IsValid(), "declaredElement should be valid");

            mySolution = declaredElement.GetPsiServices().Solution;
            var ruleDeclaration = declaredElement as RuleDeclaration;

            if (ruleDeclaration == null)
            {
                throw new ArgumentNullException("ruleDeclaration");
            }

            if (ruleDeclaration.DerivedClasses.Count() > 0)
            {
                myTarget = new DeclaredElementEnvoy <IDeclaredElement>(ruleDeclaration.DerivedClasses.First());
            }
            else
            {
                myTarget = new DeclaredElementEnvoy <IDeclaredElement>(declaredElement);
            }
        }
Esempio n. 2
0
            private bool EvalTestPartPredicate(IDeclaredElement element, Predicate <TestPart> predicate)
            {
#if RESHARPER_45_OR_NEWER
                using (ReadLockCookie.Create())
#endif
                {
                    if (!element.IsValid())
                    {
                        return(false);
                    }

                    try
                    {
                        PsiReflectionPolicy reflectionPolicy = new PsiReflectionPolicy(element.GetManager());
                        ICodeElementInfo    elementInfo      = reflectionPolicy.Wrap(element);
                        if (elementInfo == null)
                        {
                            return(false);
                        }

                        ITestDriver      driver    = CreateTestDriver();
                        IList <TestPart> testParts = driver.GetTestParts(reflectionPolicy, elementInfo);
                        return(GenericCollectionUtils.Exists(testParts, predicate));
                    }
                    catch (Exception ex)
                    {
                        HandleEmbeddedProcessCancelledException(ex);
                        throw;
                    }
                }
            }
Esempio n. 3
0
            private bool EvalTestPartPredicate(IDeclaredElement element, Predicate <TestPart> predicate)
            {
                if (!element.IsValid())
                {
                    return(false);
                }

                try
                {
#if RESHARPER_60
                    var reflectionPolicy = new PsiReflectionPolicy(element.GetPsiServices().PsiManager);
#else
                    var reflectionPolicy = new PsiReflectionPolicy(element.GetPsiServices().PsiManager, provider.CacheManager);
#endif
                    var elementInfo = reflectionPolicy.Wrap(element);
                    if (elementInfo == null)
                    {
                        return(false);
                    }

                    var driver    = CreateTestDriver();
                    var testParts = driver.GetTestParts(reflectionPolicy, elementInfo);
                    return(GenericCollectionUtils.Exists(testParts, predicate));
                }
                catch (Exception ex)
                {
                    HandleEmbeddedProcessCancelledException(ex);
                    throw;
                }
            }
Esempio n. 4
0
        public override IList <IProjectFile> GetProjectFiles()
        {
            IDeclaredElement declaredElement = GetDeclaredElement();

            if (declaredElement != null && declaredElement.IsValid())
            {
                return(declaredElement.GetProjectFiles());
            }

            return(Common.Collections.EmptyArray <IProjectFile> .Instance);
        }
Esempio n. 5
0
        public override IList <IProjectItem> GetProjectItems()
        {
            IDeclaredElement declaredElement = GetDeclaredElement();

            if (declaredElement != null && declaredElement.IsValid())
            {
                return(declaredElement.GetProjectFiles());
            }

            return(EmptyArrays.ProjectItems);
        }
Esempio n. 6
0
        private HighlightingInfo[] GetHighlightings()
        {
#if RESHARPER_60_OR_NEWER
            var projectFile = DaemonProcess.SourceFile.ToProjectFile();
            if (projectFile == null || !projectFile.IsValid())
#else
            IProjectFile projectFile = DaemonProcess.ProjectFile;
            if (!projectFile.IsValid)
#endif
            { return(EmptyArray <HighlightingInfo> .Instance); }

            var state = ProjectFileState.GetFileState(projectFile);
            if (state == null)
            {
                return(EmptyArray <HighlightingInfo> .Instance);
            }

            var highlightings = new List <HighlightingInfo>();

            foreach (AnnotationState annotation in state.Annotations)
            {
                IDeclaredElement declaredElement = annotation.GetDeclaredElement();
                if (declaredElement != null && declaredElement.IsValid())
                {
#if RESHARPER_60_OR_NEWER
                    foreach (IDeclaration declaration in declaredElement.GetDeclarationsIn(DaemonProcess.SourceFile))
#else
                    foreach (IDeclaration declaration in declaredElement.GetDeclarationsIn(projectFile))
#endif
                    {
                        if (declaration.IsValid())
                        {
                            ReSharperDocumentRange range = declaration.GetNameDocumentRange();
#if RESHARPER_31 || RESHARPER_40 || RESHARPER_41
                            if (range.IsValid)
#else
                            if (range.IsValid())
#endif
                            {
                                var annotationHighlighting = AnnotationHighlighting.CreateHighlighting(annotation);
#if RESHARPER_60_OR_NEWER
                                var highlightingInfo = new HighlightingInfo(range, annotationHighlighting, null, null);
#else
                                var highlightingInfo = new HighlightingInfo(range, annotationHighlighting);
#endif
                                highlightings.Add(highlightingInfo);
                            }
                        }
                    }
                }
            }

            return(highlightings.ToArray());
        }
        public virtual UnitTestElementDisposition GetDisposition()
        {
            IDeclaredElement element = this.GetDeclaredElement();

            if (element == null || !element.IsValid())
            {
                return(UnitTestElementDisposition.InvalidDisposition);
            }

            IEnumerable <UnitTestElementLocation> locations = this.GetLocations(element);

            return(new UnitTestElementDisposition(locations, this));
        }
Esempio n. 8
0
        public override UnitTestElementDisposition GetDisposition()
        {
            IDeclaredElement element = GetDeclaredElement();

            if (element == null || !element.IsValid())
            {
#if RESHARPER_31 || RESHARPER_40 || RESHARPER_41
                return(UnitTestElementDisposition.ourInvalidDisposition);
#else
                return(UnitTestElementDisposition.InvalidDisposition);
#endif
            }

            List <UnitTestElementLocation> locations = new List <UnitTestElementLocation>();

            foreach (IDeclaration declaration in element.GetDeclarations())
            {
                if (declaration.IsValid())
                {
                    IFile file = declaration.GetContainingFile();

                    if (file != null && file.IsValid())
                    {
#if !RESHARPER_50_OR_NEWER
                        var nameRange = declaration.GetNameRange();
#else
                        var nameRange = declaration.GetNameDocumentRange().TextRange;
#endif
                        var containingRange = declaration.GetDocumentRange().TextRange;
#if RESHARPER_31 || RESHARPER_40 || RESHARPER_41
                        if (nameRange.IsValid && containingRange.IsValid)
#elif RESHARPER_45
                        if (nameRange.IsValid() && containingRange.IsValid())
#else
                        if (nameRange.IsValid && containingRange.IsValid)
#endif
                        {
                            locations.Add(new UnitTestElementLocation(
#if RESHARPER_31
                                              file.ProjectItem,
#else
                                              file.ProjectFile,
#endif
                                              nameRange, containingRange));
                        }
                    }
                }
            }

            return(new UnitTestElementDisposition(locations, this));
        }
        public string Format(DeclaredElementPresenterStyle style, IDeclaredElement declaredElement, ISubstitution substitution, out DeclaredElementPresenterMarking marking)
        {
            if (!declaredElement.IsValid())
            throw new ArgumentException("declaredElement should be valid", "declaredElement");

              var nitraDeclaredElement = declaredElement as NitraDeclaredElement;
              if (nitraDeclaredElement == null)
            throw new ArgumentException("declaredElement should have language supported by Nitra", "declaredElement");

              var result = new StringBuilder();
              marking = new DeclaredElementPresenterMarking();

              if (style.ShowEntityKind != EntityKindForm.NONE)
              {
            string entityKind = GetEntityKindStr(nitraDeclaredElement);
            if (entityKind != "")
            {
              if (style.ShowEntityKind == EntityKindForm.NORMAL_IN_BRACKETS)
            entityKind = "(" + entityKind + ")";
              marking.EntityKindRange = AppendString(result, entityKind);
              result.Append(" ");
            }
              }

              if (style.ShowNameInQuotes)
            result.Append("\'");

              if (style.ShowName != NameStyle.NONE)
              {
            var elementName = nitraDeclaredElement.ShortName;

            if (elementName == SharedImplUtil.MISSING_DECLARATION_NAME)
              elementName = "<unknown name>";

            marking.NameRange = AppendString(result, elementName);
              }

              if (style.ShowNameInQuotes)
              {
            if (result[result.Length - 1] == '\'')
              result.Remove(result.Length - 1, 1);
            else
            {
              TrimString(result);
              result.Append("\' ");
            }
              }

              TrimString(result);
              return result.ToString();
        }
        public override UnitTestElementDisposition GetDisposition()
        {
            if (this.Behavior == null)
            {
                return(UnitTestElementDisposition.InvalidDisposition);
            }

            IDeclaredElement behaviorElement = this.Behavior.GetDeclaredElement();

            if (behaviorElement == null || !behaviorElement.IsValid())
            {
                return(UnitTestElementDisposition.InvalidDisposition);
            }

            return(base.GetDisposition());
        }
        public CSharpToPsiSearchRequest(IDeclaredElement declaredElement)
        {
            if (declaredElement == null)
            {
                throw new ArgumentNullException("declaredElement");
            }
            Logger.Assert(declaredElement.IsValid(), "declaredElement should be valid");

            mySolution = declaredElement.GetPsiServices().Solution;


            var @class = declaredElement as IClass;

            if (@class != null)
            {
                myTarget = new DeclaredElementEnvoy <IDeclaredElement>(DerivedDeclaredElementUtil.GetPrimaryDeclaredElementForClass(@class));
            }

            var @method = declaredElement as IMethod;

            if (@method != null)
            {
                myTarget = new DeclaredElementEnvoy <IDeclaredElement>(DerivedDeclaredElementUtil.GetPrimaryDeclaredElementForMethod(@method));
            }

            var @interface = declaredElement as IInterface;

            if (@interface != null)
            {
                myTarget = new DeclaredElementEnvoy <IDeclaredElement>(DerivedDeclaredElementUtil.GetPrimaryDeclaredElementForInterface(@interface));
            }

            var @constructor = declaredElement as IConstructor;

            if (@constructor != null)
            {
                @class = @constructor.GetContainingType() as IClass;

                if (@class != null)
                {
                    myTarget = new DeclaredElementEnvoy <IDeclaredElement>(DerivedDeclaredElementUtil.GetPrimaryDeclaredElementForClass(@class));
                }
            }
        }
        public override UnitTestElementDisposition GetDisposition()
        {
            IDeclaredElement element = GetDeclaredElement();

            if (element != null && element.IsValid())
            {
                var locations = new List <UnitTestElementLocation>();
                foreach (IDeclaration declaration in element.GetDeclarations())
                {
                    IFile file = declaration.GetContainingFile();
                    if (file != null)
                    {
                        locations.Add(new UnitTestElementLocation(file.ProjectFile, declaration.GetNameDocumentRange().TextRange, declaration.GetDocumentRange().TextRange));
                    }
                }
                return(new UnitTestElementDisposition(locations, this));
            }
            return(UnitTestElementDisposition.InvalidDisposition);
        }
    public GeneratedClassSearchRequest(IDeclaredElement declaredElement)
    {
      if (declaredElement == null)
        throw new ArgumentNullException("declaredElement");
      Logger.Assert(declaredElement.IsValid(), "declaredElement should be valid");

      mySolution = declaredElement.GetPsiServices().Solution;
      var ruleDeclaration = declaredElement as RuleDeclaration;
      if( ruleDeclaration == null)
        throw new ArgumentNullException("ruleDeclaration");

      if (ruleDeclaration.DerivedClasses.Count() > 0)
      {
        myTarget = new DeclaredElementEnvoy<IDeclaredElement>(ruleDeclaration.DerivedClasses.First());
      }
      else
      {
        myTarget = new DeclaredElementEnvoy<IDeclaredElement>(declaredElement);
      }
    }
    public CSharpToPsiSearchRequest(IDeclaredElement declaredElement)
    {
      if (declaredElement == null)
        throw new ArgumentNullException("declaredElement");
      Logger.Assert(declaredElement.IsValid(), "declaredElement should be valid");

      mySolution = declaredElement.GetPsiServices().Solution;


      var @class = declaredElement as IClass;
      if (@class != null)
      {
        myTarget = new DeclaredElementEnvoy<IDeclaredElement>(DerivedDeclaredElementUtil.GetPrimaryDeclaredElementForClass(@class));
      }

      var @method = declaredElement as IMethod;
      if (@method != null)
      {
        myTarget = new DeclaredElementEnvoy<IDeclaredElement>(DerivedDeclaredElementUtil.GetPrimaryDeclaredElementForMethod(@method));
      }

      var @interface = declaredElement as IInterface;
      if (@interface != null)
      {
        myTarget = new DeclaredElementEnvoy<IDeclaredElement>(DerivedDeclaredElementUtil.GetPrimaryDeclaredElementForInterface(@interface));
      }

      var @constructor = declaredElement as IConstructor;

      if(@constructor != null)
      {
        @class = @constructor.GetContainingType() as IClass;

        if(@class != null)
        {
          myTarget = new DeclaredElementEnvoy<IDeclaredElement>(DerivedDeclaredElementUtil.GetPrimaryDeclaredElementForClass(@class));
        }
      }
    }
Esempio n. 15
0
        public override UnitTestElementDisposition GetDisposition()
        {
            IDeclaredElement element = GetDeclaredElement();

            if (element == null || !element.IsValid())
            {
                return(UnitTestElementDisposition.InvalidDisposition);
            }

            var locations = new List <UnitTestElementLocation>();

            element.GetDeclarations().ForEach(declaration =>
            {
                IFile file = declaration.GetContainingFile();
                if (file != null)
                {
                    locations.Add(new UnitTestElementLocation(file.ProjectFile,
                                                              declaration.GetNavigationRange().TextRange,
                                                              declaration.GetDocumentRange().TextRange));
                }
            });

            return(new UnitTestElementDisposition(locations, this));
        }
Esempio n. 16
0
 private static bool IsClrPresentableElement([NotNull] IDeclaredElement element)
 {
     return(element.IsValid() &&
            element is IClrDeclaredElement &&
            element.GetElementType().IsPresentable(CSharpLanguage.Instance));
 }
Esempio n. 17
0
        public string Format(DeclaredElementPresenterStyle style, IDeclaredElement declaredElement, ISubstitution substitution, out DeclaredElementPresenterMarking marking)
        {
            if (!declaredElement.IsValid())
            {
                throw new ArgumentException("declaredElement should be valid", "declaredElement");
            }

            var nitraDeclaredElement = declaredElement as NitraDeclaredElement;

            if (nitraDeclaredElement == null)
            {
                throw new ArgumentException("declaredElement should have language supported by Nitra", "declaredElement");
            }

            var result = new StringBuilder();

            marking = new DeclaredElementPresenterMarking();

            if (style.ShowEntityKind != EntityKindForm.NONE)
            {
                string entityKind = GetEntityKindStr(nitraDeclaredElement);
                if (entityKind != "")
                {
                    if (style.ShowEntityKind == EntityKindForm.NORMAL_IN_BRACKETS)
                    {
                        entityKind = "(" + entityKind + ")";
                    }
                    marking.EntityKindRange = AppendString(result, entityKind);
                    result.Append(" ");
                }
            }

            if (style.ShowNameInQuotes)
            {
                result.Append("\'");
            }

            if (style.ShowName != NameStyle.NONE)
            {
                var elementName = nitraDeclaredElement.ShortName;

                if (elementName == SharedImplUtil.MISSING_DECLARATION_NAME)
                {
                    elementName = "<unknown name>";
                }

                marking.NameRange = AppendString(result, elementName);
            }

            if (style.ShowNameInQuotes)
            {
                if (result[result.Length - 1] == '\'')
                {
                    result.Remove(result.Length - 1, 1);
                }
                else
                {
                    TrimString(result);
                    result.Append("\' ");
                }
            }

            TrimString(result);
            return(result.ToString());
        }
			private bool EvalTestPartPredicate(IDeclaredElement element, Predicate<TestPart> predicate)
			{
				if (!element.IsValid())
					return false;

				try
				{
#if RESHARPER_60
					var reflectionPolicy = new PsiReflectionPolicy(element.GetPsiServices().PsiManager);
#else
					var reflectionPolicy = new PsiReflectionPolicy(element.GetPsiServices().PsiManager, provider.CacheManager);
#endif
					var elementInfo = reflectionPolicy.Wrap(element);
					if (elementInfo == null)
						return false;

					var driver = CreateTestDriver();
					var testParts = driver.GetTestParts(reflectionPolicy, elementInfo);
					return GenericCollectionUtils.Exists(testParts, predicate);
				}
				catch (Exception ex)
				{
					HandleEmbeddedProcessCancelledException(ex);
					throw;
				}
			}
Esempio n. 19
0
            private bool EvalTestPartPredicate(IDeclaredElement element, Predicate<TestPart> predicate)
            {
#if RESHARPER_45_OR_NEWER
                using (ReadLockCookie.Create())
#endif
                {
                    if (!element.IsValid())
                        return false;

                    try
                    {
                        PsiReflectionPolicy reflectionPolicy = new PsiReflectionPolicy(element.GetManager());
                        ICodeElementInfo elementInfo = reflectionPolicy.Wrap(element);
                        if (elementInfo == null)
                            return false;

                        ITestDriver driver = CreateTestDriver();
                        IList<TestPart> testParts = driver.GetTestParts(reflectionPolicy, elementInfo);
                        return GenericCollectionUtils.Exists(testParts, predicate);
                    }
                    catch (Exception ex)
                    {
                        HandleEmbeddedProcessCancelledException(ex);
                        throw;
                    }
                }
            }
        public override void Rename(
            RenameRefactoring executer, IProgressIndicator pi, bool hasConflictsWithDeclarations, IRefactoringDriver driver)
        {
            this.BuildDeclarations();

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

            IDeclaredElement declaredElement = this.myOriginalElementPointer.FindDeclaredElement();

            if (declaredElement == null)
            {
                return;
            }

            IPsiServices psiServices = declaredElement.GetPsiServices();

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

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

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

            psiServices.Caches.Update();

            NTriplesCache cache = null;

            if (this.myDeclarations.Any())
            {
                cache = this.myDeclarations[0].GetSolution().GetComponent <NTriplesCache>();
            }

            foreach (var declaration in this.myDeclarations)
            {
                var file = (NTriplesFile)declaration.Root();
                file.ClearTables();
                //cache.MarkAsDirty(declaration.GetSourceFile());
            }

            /*if (cache != null)
             * {
             *  cache.SyncUpdate(true);
             * }*/

            IDeclaredElement newDeclaredElement = null;

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

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

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


            this.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 && !this.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);
                        }
                        this.myNewReferences.Insert(0, newReference);
                        rename.AdditionalReferenceProcessing(newDeclaredElement, newReference, this.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);
                    }
                }
            }
        }