internal ISet <TypeDescriptor> GetPotentialTypes(PropGraphNodeDescriptor n, MethodCallInfo callInfo, IProjectCodeProvider codeProvider) { return(GetPotentialTypesAsync(n, callInfo, codeProvider).Result); //var result = new HashSet<TypeDescriptor>(); //var types = this.GetTypes(n); //if (types.Count() == 0) //{ // /// We get the instantiated type that are compatible with the receiver type // types.UnionWith( // callInfo.InstantiatedTypes // .Where(type => codeProvider.IsSubtype(type, callInfo.Receiver.Type))); //} //if (types.Count() == 0) //{ // types.Add(callInfo.Receiver.Type); //} //foreach (var typeDescriptor in types) //{ // // TO-DO fix by adding a where T: AnalysisType // if (typeDescriptor.IsConcreteType) // { // result.Add(typeDescriptor); // } // else // { // // If it is a declaredTyped it means we were not able to compute a concrete type // // Therefore, we instantiate all compatible types for the set of instantiated types // //result.UnionWith(this.InstatiatedTypes.Where(iType => iType.IsSubtype(typeDescriptor))); // Contract.Assert(callInfo.InstantiatedTypes != null); // // Diego: This requires a Code Provider. Now it will simply fail. // result.UnionWith(callInfo.InstantiatedTypes.Where(candidateTypeDescriptor // => codeProvider.IsSubtype(candidateTypeDescriptor, typeDescriptor))); // } //} //return result; }
internal void SetCodeProvider(IProjectCodeProvider codeProvider) { this.codeProvider = codeProvider; }
public static async Task <IEnumerable <FileResponse> > GetDocumentEntitiesAsync(IProjectCodeProvider projectProvider, OrleansClient.Analysis.DocumentInfo documentInfo) { var result = CodeGraphHelper.CreateFileResponse(documentInfo.Document); result.declarationAnnotation = new List <DeclarationAnnotation>(); result.referenceAnnotation = new List <ReferenceAnnotation>(); foreach (var entry in documentInfo.DeclaredMethods) { var methodDescriptor = entry.Key; var methodInfo = entry.Value; var methodEntity = await projectProvider.GetMethodEntityAsync(methodDescriptor); var annotations = await methodEntity.GetAnnotationsAsync(); // Add method declaration var methodDeclaration = GetMethodDeclarationInfo(methodInfo.DeclarationSyntaxNode, methodInfo.MethodSymbol); result.declarationAnnotation.Add(methodDeclaration); //var span = GetSpan(methodInfo.DeclarationSyntaxNode); //var baseRange = GetRange(span); // Annotations are relative to method declaration. Here we make it absolute var baseRange = methodDeclaration.range; foreach (var anotation in annotations) { anotation.range = GetAbsoluteRange(anotation.range, baseRange); } var declarations = annotations.OfType <DeclarationAnnotation>(); var references = annotations.OfType <ReferenceAnnotation>(); result.declarationAnnotation.AddRange(declarations); result.referenceAnnotation.AddRange(references); } return(new List <FileResponse>() { result }); }
internal ProjectCodeProviderWithCache(IProjectCodeProvider codeProvider) { this.codeProvider = codeProvider; }
/// <summary> /// Generates a dictionary invocationNode -> potential callees /// This is used for example by the demo to get the caller / callee info /// </summary> /// <returns></returns> internal static async Task <IDictionary <AnalysisCallNode, ISet <MethodDescriptor> > > GetCalleesInfo(MethodEntity methodEntity, IProjectCodeProvider codeProvider) { var calleesPerEntity = new Dictionary <AnalysisCallNode, ISet <MethodDescriptor> >(); foreach (var calleeNode in methodEntity.PropGraph.CallNodes) { calleesPerEntity[calleeNode] = await GetCalleesAsync(methodEntity, calleeNode, codeProvider); } return(calleesPerEntity); }
/// <summary> /// Compute all the calless of this method entities /// </summary> /// <returns></returns> //internal static async Task<ISet<MethodDescriptor>> GetCalleesAsync(MethodEntity methodEntity, IProjectCodeProvider codeProvider) //{ // var result = new HashSet<MethodDescriptor>(); // foreach (var callNode in methodEntity.PropGraph.CallNodes) // { // result.UnionWith(await GetCalleesAsync(methodEntity, callNode, codeProvider)); // } // return result; //} /// <summary> /// Computes all the potential callees for a particular method invocation /// </summary> /// <param name="node"></param> /// <returns></returns> internal static async Task <ISet <MethodDescriptor> > GetCalleesAsync(MethodEntity methodEntity, AnalysisCallNode node, IProjectCodeProvider codeProvider) { var stopWatch = Stopwatch.StartNew(); ISet <MethodDescriptor> result; var calleesForNode = new HashSet <MethodDescriptor>(); var invExp = methodEntity.PropGraph.GetInvocationInfo((AnalysisCallNode)node); Meausure("ME.PG.GetInvocationInfo", stopWatch); Contract.Assert(invExp != null); Contract.Assert(codeProvider != null); var calleeResult = await methodEntity.PropGraph.ComputeCalleesForNodeAsync(invExp, codeProvider); Meausure("ME.PG.ComputeCalleesForNode", stopWatch); calleesForNode.UnionWith(calleeResult); //calleesForNode.UnionWith(invExp.ComputeCalleesForNode(this.MethodEntity.PropGraph,this.codeProvider)); result = calleesForNode; return(result); }