private static IIntermediateClassMethodMember BuildMethodOn(IType returnType, IIntermediateInterfaceType visitorInterface, IType voidType, IIntermediateInterfaceMethodMember method, IIntermediateClassType ruleClass, bool skipBody = false) { var ruleVisit = ruleClass.Methods.Add( new TypedName("Accept", returnType), new TypedNameSeries(new TypedName("visitor", visitorInterface))); if (returnType.IsGenericTypeParameter) { ruleVisit.TypeParameters.Add(returnType.Name); } ruleVisit.AccessLevel = AccessLevelModifiers.Public; ruleVisit.IsOverride = true; if (!skipBody) { if (returnType != voidType) { ruleVisit.Return(method.GetReference(ruleVisit.Parameters["visitor"].GetReference()).Invoke(new SpecialReferenceExpression(SpecialReferenceKind.This))); } else { ruleVisit.Call(method.GetReference(ruleVisit.Parameters["visitor"].GetReference()).Invoke(new SpecialReferenceExpression(SpecialReferenceKind.This))); } } return(ruleVisit); }
private static IIntermediateClassMethodMember AddVisitMethodToClass(IType returnType, IType voidType, IIntermediateInterfaceType visitorInterface, IIntermediateClassType visitedClass, bool isAbstract, IIntermediateInterfaceMethodMember memberToVisit) { var rootVisit = visitedClass.Methods.Add( new TypedName("Accept", returnType), new TypedNameSeries(new TypedName("visitor", visitorInterface))); if (returnType.IsGenericTypeParameter) { rootVisit.TypeParameters.Add(returnType.Name); } rootVisit.SummaryText = "Invokes the appropriate overload for the current @p:visitor;."; rootVisit.AccessLevel = AccessLevelModifiers.Public; var invocation = isAbstract ? null : memberToVisit.GetReference(rootVisit.Parameters["visitor"].GetReference()).Invoke(new SpecialReferenceExpression(SpecialReferenceKind.This)); if (isAbstract) { rootVisit.IsAbstract = true; } else if (returnType != voidType) { rootVisit.Return(invocation); } else { rootVisit.Call(invocation); } return(rootVisit); }