示例#1
0
        public Action <ITextControl> ExecutePsiTransaction(ICSharpContextActionDataProvider dataProvider, ISolution solution, IClassLikeDeclaration classDeclaration, IEnumerable <IInterface> interfaces)
        {
            IInterface[] interfacesArray = interfaces.ToArray();
            IInterface   firstInterface  = interfacesArray[0];
            string       typeParameters  = firstInterface.TypeParameters.AggregateString(",", (builder, parameter) => builder.Append(parameter.ShortName));

            if (firstInterface.TypeParameters.Count != 0)
            {
                typeParameters = "<" + typeParameters + ">";
            }
            string className = classDeclaration.DeclaredName;

            classDeclaration.AddClassMemberDeclaration((IClassMemberDeclaration)dataProvider.ElementFactory.CreateTypeMemberDeclaration($"private {className}(){{}}"));

            IClassLikeDeclaration builderClass = BuildMethod(dataProvider, interfacesArray, className, typeParameters);

            ProcessInterface(dataProvider, classDeclaration, interfacesArray, builderClass);

            classDeclaration.AddClassMemberDeclaration(builderClass);

            return(textControl =>
            {
                IntentionTemplateUtil.ExecuteTemplate(solution, textControl, DocumentRange.InvalidRange);
            });
        }
示例#2
0
        public Action <ITextControl> ExecutePsiTransaction(ICSharpContextActionDataProvider dataProvider, ISolution solution, IClassLikeDeclaration classDeclaration, IInterface theInterface)
        {
            string typeParameters = theInterface.TypeParameters.AggregateString(",", (builder, parameter) => builder.Append(parameter.ShortName));

            if (theInterface.TypeParameters.Count != 0)
            {
                typeParameters = "<" + typeParameters + ">";
            }
            string interfaceName = theInterface.ShortName;
            string className     = $"Mock{interfaceName.Substring(1)}";

            classDeclaration.AddClassMemberDeclaration((IClassMemberDeclaration)dataProvider.ElementFactory.CreateTypeMemberDeclaration($"private {className}(){{}}"));
            foreach (IMethod node in theInterface.Methods)
            {
                ISignature methodSig = new MockMethod(node, theInterface);
                classDeclaration.AddClassMemberDeclaration((IClassMemberDeclaration)dataProvider.ElementFactory.CreateTypeMemberDeclaration(methodSig.Signature()));
                classDeclaration.AddClassMemberDeclaration((IClassMemberDeclaration)dataProvider.ElementFactory.CreateTypeMemberDeclaration(MockClassVariable(node, theInterface).Declaration()));
            }

            IClassLikeDeclaration builderClass = (IClassLikeDeclaration)dataProvider.ElementFactory.CreateTypeMemberDeclaration("public class Builder {}");

            BuildMethod(dataProvider, theInterface, builderClass, className, typeParameters);

            foreach (IMethod node in theInterface.Methods)
            {
                builderClass.AddClassMemberDeclaration((IClassMemberDeclaration)dataProvider.ElementFactory.CreateTypeMemberDeclaration(MockClassVariable(node, theInterface).BuilderDeclaration()));
                builderClass.AddClassMemberDeclaration((IClassMemberDeclaration)dataProvider.ElementFactory.CreateTypeMemberDeclaration(MockBuilderMethod(node, theInterface).Typed()));
                builderClass.AddClassMemberDeclaration((IClassMemberDeclaration)dataProvider.ElementFactory.CreateTypeMemberDeclaration(MockBuilderMethod(node, theInterface).Lambdad()));
            }
            classDeclaration.AddClassMemberDeclaration(builderClass);

            foreach (IMethod node in theInterface.Methods)
            {
                ISignature2 methodSig = MockAssertMethod(node, theInterface);
                methodSig.Signature(classDeclaration, dataProvider.ElementFactory);
            }
            return(textControl =>
            {
                IntentionTemplateUtil.ExecuteTemplate(solution, textControl, DocumentRange.InvalidRange);
            });
        }