public IEnumerable<RelatedFileOccurence> GetRelatedFiles(IProjectFile projectFile) { var typeNamesInFile = GetTypeNamesDefinedInFile(projectFile).ToList(); // Look for the candidate types in the solution. var solution = projectFile.GetSolution(); var candidateTypes = new LocalList<IClrDeclaredElement>(); foreach (var candidateTypeName in GetTypeCandidates(typeNamesInFile)) { var types = FindTypesByShortName(solution, candidateTypeName); candidateTypes.AddRange(types); } // Get the source files for each of the candidate types. var sourceFiles = new LocalList<IPsiSourceFile>(); foreach (var type in candidateTypes) { var sourceFilesForCandidateType = type.GetSourceFiles(); sourceFiles.AddRange(sourceFilesForCandidateType.ResultingList()); } var elementCollector = new RecursiveElementCollector<ITypeDeclaration>(); foreach (var psiSourceFile in sourceFiles) foreach (var file in psiSourceFile.EnumerateDominantPsiFiles()) { elementCollector.ProcessElement(file); } var elements = elementCollector.GetResults(); var projectFiles = elements.Select(declaration => declaration.GetSourceFile().ToProjectFile()); var thisProjectName = projectFile.GetProject()?.Name; var occurences = new LocalList<RelatedFileOccurence>(); foreach (var file in projectFiles.OfType<ProjectFileImpl>().Distinct(x => x.Location.FullPath)) { // Remove all extensions (e.g.: .xaml.cs). var fileName = file.Name; var dotPos = fileName.IndexOf('.'); if (dotPos != -1) { fileName = fileName.Substring(0, dotPos); } var relationKind = fileName.EndsWith("ViewModel") ? "ViewModel" : "View"; var projectName = file.GetProject()?.Name; if (projectName != null && !string.Equals(thisProjectName, projectName, StringComparison.OrdinalIgnoreCase)) { relationKind += $" (in {projectName})"; } occurences.Add(new RelatedFileOccurence(file, relationKind, projectFile)); } return occurences.ReadOnlyList(); }
public IEnumerable <JetTuple <IProjectFile, string, IProjectFile> > GetRelatedFiles(IProjectFile projectFile) { var typeNamesInFile = GetTypeNamesDefinedInFile(projectFile).ToList(); var candidateTypeNames = GetTypeCandidates(typeNamesInFile); // Look for the candidate types throught the solution. var solution = projectFile.GetSolution(); var candidateTypes = new List <IClrDeclaredElement>(); foreach (var candidateTypeName in candidateTypeNames) { var types = FindType(solution, candidateTypeName); candidateTypes.AddRange(types); } // Get the source files for each of the candidate types. var sourceFiles = new List <IPsiSourceFile>(); foreach (var type in candidateTypes) { var sourceFilesForCandidateType = type.GetSourceFiles(); sourceFiles.AddRange(sourceFilesForCandidateType); } var elementCollector = new RecursiveElementCollector <ITypeDeclaration>(); foreach (var psiSourceFile in sourceFiles) { foreach (var file in psiSourceFile.EnumerateDominantPsiFiles()) { elementCollector.ProcessElement(file); } } var elements = elementCollector.GetResults(); IEnumerable <IProjectFile> projectFiles = elements.Select(declaration => declaration.GetSourceFile().ToProjectFile()); var rval = new List <JetTuple <IProjectFile, string, IProjectFile> >(); foreach (var file in projectFiles.OfType <ProjectFileImpl>().Distinct(pf => pf.Location.FullPath)) { // Remove all extensions (e.g.: .xaml.cs). var fn = file.Name; var dotPos = fn.IndexOf('.'); if (dotPos != -1) { fn = fn.Substring(0, dotPos); } var display = fn.EndsWith("ViewModel") ? "ViewModel" : "View"; var tuple = JetTuple.Of((IProjectFile)file, display, projectFile); rval.Add(tuple); } return(rval); }
private static bool IsOrCanBecameIterator([NotNull] ICSharpFunctionDeclaration declaration, [NotNull] IType returnType) { if (declaration.IsIterator) { return(true); } if (declaration.IsAsync) { return(false); } if (returnType.IsGenericIEnumerable() || returnType.IsIEnumerable() || returnType.IsGenericIEnumerator() || returnType.IsIEnumerator()) { var collector = new RecursiveElementCollector <IReturnStatement>(); collector.ProcessElement(declaration); return(collector.GetResults().Count == 0); } return(false); }
private static ICSharpExpression FixExpression( [NotNull] ICSharpExpression expression, [CanBeNull] ITreeNode reference) { var referenceExpression = reference as IReferenceExpression; if (referenceExpression != null) { var marker = new TreeNodeMarker<IReferenceExpression>(referenceExpression); var exprCopy = expression.Copy(expression); var refCopy = marker.GetAndDispose(exprCopy); var exprToFix = refCopy.QualifierExpression.NotNull(); LowLevelModificationUtil.ReplaceChildRange(refCopy, refCopy, exprToFix); if (exprToFix.NextSibling is IErrorElement) LowLevelModificationUtil.DeleteChild(exprToFix.NextSibling); return exprCopy; } var referenceName = reference as IReferenceName; if (referenceName != null) { var marker = new TreeNodeMarker<IReferenceName>(referenceName); var exprCopy = expression.Copy(expression); var refCopy = marker.GetAndDispose(exprCopy); var exprToFix = refCopy.Qualifier.NotNull(); LowLevelModificationUtil.ReplaceChildRange(refCopy, refCopy, exprToFix); if (exprToFix.NextSibling is IErrorElement) LowLevelModificationUtil.DeleteChild(exprToFix.NextSibling); if (exprToFix.Parent != null && exprToFix.Parent.NextSibling is IErrorElement) LowLevelModificationUtil.DeleteChild(exprToFix.Parent.NextSibling); return exprCopy; } else { var errorsCollector = new RecursiveElementCollector<IErrorElement>(); expression.ProcessDescendants(errorsCollector); var errorElements = errorsCollector.GetResults().Select( errorElement => new TreeNodeMarker<IErrorElement>(errorElement)).ToList(); var exprCopy = expression.Copy(expression); foreach (var errorMarker in errorElements) { var element = errorMarker.GetAndDispose(exprCopy); LowLevelModificationUtil.DeleteChild(element); } return exprCopy; } }
public IEnumerable<Tuple<IProjectFile, string, IProjectFile>> GetRelatedFiles(IProjectFile projectFile) { var typeNamesInFile = GetTypeNamesDefinedInFile(projectFile).ToList(); var candidateTypeNames = GetTypeCandidates(typeNamesInFile); // Look for the candidate types in the solution. var solution = projectFile.GetSolution(); var candidateTypes = new List<IClrDeclaredElement>(); foreach (var candidateTypeName in candidateTypeNames) { var types = FindType(solution, candidateTypeName); candidateTypes.AddRange(types); } // Get the source files for each of the candidate types. var sourceFiles = new List<IPsiSourceFile>(); foreach (var type in candidateTypes) { var sourceFilesForCandidateType = type.GetSourceFiles(); sourceFiles.AddRange(sourceFilesForCandidateType); } var elementCollector = new RecursiveElementCollector<ITypeDeclaration>(); foreach (var psiSourceFile in sourceFiles) foreach (var file in psiSourceFile.EnumerateDominantPsiFiles()) elementCollector.ProcessElement(file); var elements = elementCollector.GetResults(); var projectFiles = elements.Select(declaration => declaration.GetSourceFile().ToProjectFile()); var thisProjectName = projectFile.GetProject()?.Name; var rval = new List<Tuple<IProjectFile, string, IProjectFile>>(); foreach (var file in projectFiles.OfType<ProjectFileImpl>().Distinct(pf => pf.Location.FullPath)) { // Remove all extensions (e.g.: .xaml.cs). var fn = file.Name; var dotPos = fn.IndexOf('.'); if (dotPos != -1) { fn = fn.Substring(0, dotPos); } var display = fn.EndsWith("ViewModel") ? "ViewModel" : "View"; var projectName = file.GetProject()?.Name; if (projectName != null && !string.Equals(thisProjectName, projectName, StringComparison.OrdinalIgnoreCase)) { display += $" (in {projectName})"; } var tuple = Tuple.Create((IProjectFile)file, display, projectFile); rval.Add(tuple); } return rval; }