public static List <KeyValuePair <IMethod, INode> > calledIMethods_getMappings(this O2MappedAstData o2MappedAstData, IMethod iMethod) { //"in Called IMETHODS".debug();\ var calledIMethodsMapping = new List <KeyValuePair <IMethod, INode> >(); if (iMethod != null) { // "-------------------".info(); var methodDeclaration = o2MappedAstData.methodDeclaration(iMethod); if (methodDeclaration == null) { return(calledIMethodsMapping); } // handle invocations via MemberReferenceExpression var memberReferenceExpressions = methodDeclaration.iNodes <INode, MemberReferenceExpression>(); foreach (var memberReferenceExpression in memberReferenceExpressions) { var iMethodFromRef = o2MappedAstData.iMethod(memberReferenceExpression); if (iMethodFromRef.notNull()) { calledIMethodsMapping.Add(iMethodFromRef.iMethodMapping(memberReferenceExpression)); } else { var iMethodOrProperty = o2MappedAstData.fromMemberReferenceExpressionGetIMethodOrProperty(memberReferenceExpression); if (iMethodOrProperty is IMethod) { calledIMethodsMapping.Add((iMethodOrProperty as IMethod).iMethodMapping(memberReferenceExpression)); } //else // "NOT Resolved for: {0}".error(memberReferenceExpression.MemberName); } } // calledIMethods.add(); // handle invocations via InvocationExpression var invocationExpressions = methodDeclaration.iNodes <INode, InvocationExpression>(); foreach (var invocationExpression in invocationExpressions) { calledIMethodsMapping.add(o2MappedAstData.iMethod(invocationExpression).iMethodMapping(invocationExpression)); } // handle contructors var objectCreateExpressions = methodDeclaration.iNodes <INode, ObjectCreateExpression>(); //"objectCreateExpressions: {0}".format(objectCreateExpressions.Count).info(); foreach (var objectCreateExpression in objectCreateExpressions) { calledIMethodsMapping.add(o2MappedAstData.iMethod(objectCreateExpression).iMethodMapping(objectCreateExpression)); } } //return calledIMethods; return(calledIMethodsMapping); }
public Location(O2MappedAstData astData, IMethod iMethod) { File = astData.file(iMethod); var methodDeclaration = astData.methodDeclaration(iMethod); if (methodDeclaration.notNull()) { Line = methodDeclaration.StartLocation.Line; Column = methodDeclaration.StartLocation.Column; Line_End = methodDeclaration.EndLocation.Line; Column_End = methodDeclaration.EndLocation.Column; } }
public static int getINodePosition(this O2MappedAstData astData, MethodMapping methodMapping) { var position = -1; var methodSignature = methodMapping.ParentMethod; var iMethod = astData.iMethod_withSignature(methodSignature); var methodDeclaration = astData.methodDeclaration(iMethod); var iNodes = methodDeclaration.iNodes(); if (iNodes.isNull()) { return(position); } var iNodeAtLocation = astData.iNode(methodMapping.File, methodMapping.Start_Line, methodMapping.Start_Column); for (int i = 0; i < iNodes.size(); i++) { if (iNodes[i] == iNodeAtLocation) { position = i; break; } } if (position.eq(-1)) { return(position); } //Hack to try to find the exact INode we had before if (position.typeName() != methodMapping.INodeType) { if (position > 0 && iNodes[position - 1].typeName() == methodMapping.INodeType) { position--; } else if (position < (iNodes.size() - 1) && iNodes[position + 1].typeName() == methodMapping.INodeType) { position++; } } return(position); }
public static Dictionary <string, List <KeyValuePair <INode, IMethodOrProperty> > > externalMethodsAndProperties(this O2MappedAstData astData, IMethod iMethod) { var externalMethods = new Dictionary <string, List <KeyValuePair <INode, IMethodOrProperty> > >(); // add the current method externalMethods.add(iMethod.DotNetName, new KeyValuePair <INode, IMethodOrProperty>(astData.methodDeclaration(iMethod), iMethod)); var iNodesAdded = new List <INode>(); foreach (var methodCalled in astData.calledINodesReferences(iMethod)) { if (methodCalled is MemberReferenceExpression) { var memberRef = (MemberReferenceExpression)methodCalled; { var methodOrProperty = astData.fromMemberReferenceExpressionGetIMethodOrProperty(memberRef); if (methodOrProperty.notNull()) { externalMethods.add(methodOrProperty.DotNetName, new KeyValuePair <INode, IMethodOrProperty>(memberRef, methodOrProperty)); iNodesAdded.Add(memberRef); } else { externalMethods.add(astData.getTextForINode(memberRef), new KeyValuePair <INode, IMethodOrProperty>(memberRef, null)); } } } } foreach (var mapping in astData.calledIMethods_getMappings(iMethod)) { var iMethodMapping = mapping.Key; var iNodeMapping = mapping.Value; if (iNodesAdded.Contains(iNodeMapping).isFalse()) { if (iNodeMapping is ObjectCreateExpression || ((iNodeMapping is InvocationExpression && (iNodeMapping as InvocationExpression).TargetObject.notNull() && iNodesAdded.Contains((iNodeMapping as InvocationExpression).TargetObject).isFalse()))) { var nodeText = (iMethodMapping.notNull()) ? iMethodMapping.DotNetName : astData.getTextForINode(iNodeMapping); externalMethods.add(nodeText, new KeyValuePair <INode, IMethodOrProperty>(iNodeMapping, iMethodMapping)); } } } return(externalMethods); }