private XmlNode GetDetails(IDeclaredElement element) { var xmlDocNode = element.GetXMLDoc(true); if (xmlDocNode != null) { return(xmlDocNode); } var description = myEventFunction.Description; if (!string.IsNullOrWhiteSpace(myParameterName)) { description = myEventFunction.GetParameter(myParameterName)?.Description; } var details = CreateMemberElement(element); if (string.IsNullOrWhiteSpace(description)) { return(details); } details.CreateLeafElementWithValue("summary", description); if (!element.GetPsiServices().Solution.HasComponent <IXmlDocLinkAppender>()) { return(details); } var uri = element.GetPsiServices().Solution.GetComponent <UnityOnlineHelpProvider>().GetUrl(element); element.GetPsiServices().Solution.GetComponent <IXmlDocLinkAppender>().AppendExternalDocumentationLink(uri, element.ShortName, details); return(details); }
public override ISearchDomain GetDeclaredElementSearchDomain(IDeclaredElement declaredElement) { if (!(declaredElement is IMethod methodDeclaration)) { return(base.GetDeclaredElementSearchDomain(declaredElement)); } var specflowStepsUsagesCache = declaredElement.GetPsiServices().GetComponent <SpecflowStepsUsagesCache>(); var specflowStepsDefinitionsCache = declaredElement.GetPsiServices().GetComponent <SpecflowStepsDefinitionsCache>(); var files = new List <IPsiSourceFile>(); foreach (var sourceFile in declaredElement.GetSourceFiles()) { var stepsInFile = specflowStepsDefinitionsCache.AllStepsPerFiles[sourceFile]; foreach (var step in stepsInFile.Where(x => x.MethodName == declaredElement.ShortName).Where(x => x.ClassFullName == methodDeclaration.GetContainingType()?.GetClrName().FullName)) { foreach (var(stepSourceFileUsage, stepsTexts) in specflowStepsUsagesCache.StepUsages[step.StepKind]) { foreach (var stepText in stepsTexts) { if (step.Regex?.IsMatch(stepText) == true) { files.Add(stepSourceFileUsage); } } } } } return(SearchDomainFactory.Instance.CreateSearchDomain(files)); }
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; } }
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); } }
private static List <ITreeNode> FindArrayUsages(IDeclaredElement declaredElement, IClassLikeDeclaration container, IDaemonProcess daemonProcess, DaemonProcessKind processKind) { var result = new List <ITreeNode>(); if (processKind != DaemonProcessKind.GLOBAL_WARNINGS) { var collectUsagesStageProcess = daemonProcess?.GetStageProcess <CollectUsagesStageProcess>(); if (collectUsagesStageProcess == null) { return(result); } foreach (var usage in collectUsagesStageProcess.GetDeclaredElementUsages(declaredElement) .Where(container.Contains)) { result.Add(usage); } return(result); } var finder = declaredElement.GetPsiServices().Finder; foreach (var reference in finder.FindAllReferences(declaredElement)) { result.Add(reference.GetTreeNode()); } return(result); }
public IEnumerable <FileRename> GetFileRenames(IDeclaredElement declaredElement, string name) { if (declaredElement is TDeclaredElement) { var sourceFile = declaredElement.GetSourceFiles().FirstOrDefault(); if (sourceFile != null) { var psiServices = declaredElement.GetPsiServices(); var projectFile = sourceFile.ToProjectFile(); return(new[] { new FileRename(psiServices, projectFile, name) }); } } return(EmptyList <FileRename> .Enumerable); }
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 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 override IEnumerable <string> GetAllPossibleWordsInFile(IDeclaredElement declaredElement) { if (!(declaredElement is IMethod methodDeclaration)) { return(base.GetAllPossibleWordsInFile(declaredElement)); } var specflowStepsDefinitionsCache = declaredElement.GetPsiServices().GetComponent <SpecflowStepsDefinitionsCache>(); var words = new HashSet <string>(); foreach (var sourceFile in declaredElement.GetSourceFiles()) { var stepsInFile = specflowStepsDefinitionsCache.AllStepsPerFiles[sourceFile]; foreach (var step in stepsInFile.Where(x => x.MethodName == declaredElement.ShortName).Where(x => x.ClassFullName == methodDeclaration.GetContainingType()?.GetClrName().FullName)) { words.AddRange(step.Pattern.SplitByWords()); } } return(words); }
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 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(); } } }
private static IDeclaredElement GetPrimaryDeclaredElementForVisitorMethod(IDeclaredElement declaredElement, IMethod method) { var cache = declaredElement.GetPsiServices().Solution.GetComponent<PsiCache>(); Dictionary<ITypeElement, IList<PsiOptionSymbol>> classesWithInfo = GetVisitorClasses(cache); if (classesWithInfo.Count > 0) { var parentClass = method.GetContainingType() as IClass; if (parentClass != null) { if (classesWithInfo.ContainsKey(parentClass)) { IList<PsiOptionSymbol> list = classesWithInfo[parentClass]; PsiOptionSymbol visitorName = list[0]; PsiOptionSymbol methodSuffix = list[1]; PsiOptionSymbol methodPrefix = list[2]; IPsiSourceFile sourceFile = visitorName.SourceFile; string name = method.ShortName; if (name.Length > methodPrefix.Value.Length + methodSuffix.Value.Length) { if (methodPrefix.Value.Length > 0) { name = name.Substring(methodPrefix.Value.Length, name.Length - methodPrefix.Value.Length); } if (methodSuffix.Value.Length > 0) { name = name.Substring(0, name.Length - methodSuffix.Value.Length); } IEnumerable<IPsiSymbol> elements = cache.GetSymbols(NameFromCamelCase(name)); foreach (IPsiSymbol psiSymbol in elements) { if (psiSymbol.SourceFile == sourceFile) { var psiFile = sourceFile.GetPsiFile<PsiLanguage>(new DocumentRange(psiSymbol.SourceFile.Document, 0)) as PsiFile; if (psiFile != null) { IList<ISymbolInfo> infos = psiFile.FileRuleSymbolTable.GetSymbolInfos(name); foreach (ISymbolInfo info in infos) { IDeclaredElement element = info.GetDeclaredElement(); if (element is RuleDeclaration) { var ruleDeclaration = element as RuleDeclaration; { return ruleDeclaration; } } } } } } } else { { return null; } } } } } { return null; } }
private static IDeclaredElement GetPrimaryDeclaredElementForVisitorMethod(IDeclaredElement declaredElement, IMethod method) { var cache = declaredElement.GetPsiServices().Solution.GetComponent <PsiCache>(); Dictionary <ITypeElement, IList <PsiOptionSymbol> > classesWithInfo = GetVisitorClasses(cache); if (classesWithInfo.Count > 0) { var parentClass = method.GetContainingType() as IClass; if (parentClass != null) { if (classesWithInfo.ContainsKey(parentClass)) { IList <PsiOptionSymbol> list = classesWithInfo[parentClass]; PsiOptionSymbol visitorName = list[0]; PsiOptionSymbol methodSuffix = list[1]; PsiOptionSymbol methodPrefix = list[2]; IPsiSourceFile sourceFile = visitorName.SourceFile; string name = method.ShortName; if (name.Length > methodPrefix.Value.Length + methodSuffix.Value.Length) { if (methodPrefix.Value.Length > 0) { name = name.Substring(methodPrefix.Value.Length, name.Length - methodPrefix.Value.Length); } if (methodSuffix.Value.Length > 0) { name = name.Substring(0, name.Length - methodSuffix.Value.Length); } IEnumerable <IPsiSymbol> elements = cache.GetSymbols(NameFromCamelCase(name)); foreach (IPsiSymbol psiSymbol in elements) { if (psiSymbol.SourceFile == sourceFile) { var psiFile = sourceFile.GetPsiFile <PsiLanguage>(new DocumentRange(psiSymbol.SourceFile.Document, 0)) as PsiFile; if (psiFile != null) { IList <ISymbolInfo> infos = psiFile.FileRuleSymbolTable.GetSymbolInfos(name); foreach (ISymbolInfo info in infos) { IDeclaredElement element = info.GetDeclaredElement(); if (element is RuleDeclaration) { var ruleDeclaration = element as RuleDeclaration; { return(ruleDeclaration); } } } } } } } else { { return(null); } } } } } { return(null); } }
public ISearchDomain GetDeclaredElementSearchDomain(IDeclaredElement declaredElement) { return(_searchDomainFactory.CreateSearchDomain(declaredElement.GetPsiServices().Solution, false)); }
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; } }