// Protected Methods protected void MethodTranslation(string module, string xClass, string methodName, Translator translator) { if (methodName == null) { throw new ArgumentNullException("methodName"); } string expectedCode, translatedCode, shortFilename; { // translator = PrepareTranslator(); Console.WriteLine("We have module " + translator.Modules.First().Name.Name); var mod = translator.Modules.First(i => i.Name.Name == module); var cl = mod.Classes[0]; Assert.True(cl.Name.FullName == xClass, "Invalid class name translation - attribute ScriptName"); PhpClassMethodDefinition method = cl.Methods.First(i => i.Name == methodName); translatedCode = GetCode(method); } { shortFilename = string.Format("{0}_{1}.txt", xClass.Replace("\\", ""), methodName); expectedCode = GetExpectedCode(shortFilename, translatedCode); } if (expectedCode != translatedCode) { Save(translatedCode, shortFilename); } Assert.True(expectedCode == translatedCode, "Invalid translation"); }
private void Tranlate_MethodOrProperty(PhpClassDefinition phpClass, MethodInfo info, IStatement body, string overrideName) { _state.Principles.CurrentMethod = info; try { var mti = _state.Principles.GetOrMakeTranslationInfo(info); var phpMethod = new PhpClassMethodDefinition(string.IsNullOrEmpty(overrideName) ? mti.ScriptName : overrideName); phpClass.Methods.Add(phpMethod); if (info.IsPublic) { phpMethod.Visibility = Visibility.Public; } else if (info.IsPrivate) { phpMethod.Visibility = Visibility.Private; } else { phpMethod.Visibility = Visibility.Protected; } phpMethod.IsStatic = info.IsStatic; { var declaredParameters = info.GetParameters(); foreach (var parameter in declaredParameters) { var phpParameter = new PhpMethodArgument(); phpParameter.Name = parameter.Name; phpMethod.Arguments.Add(phpParameter); if (parameter.HasDefaultValue) { phpParameter.DefaultValue = new PhpConstValue(parameter.DefaultValue); } } } if (body != null) { phpMethod.Statements.AddRange(TranslateStatement(body)); } } finally { _state.Principles.CurrentMethod = null; } }
private void TranslateConstructor(PhpClassDefinition phpClass, ConstructorDeclaration md) { // state.Principles.CurrentMethod = md.Info; try { // MethodTranslationInfo mti = MethodTranslationInfo.FromMethodInfo(md.Info); // state.Principles.CurrentMethod = var phpMethod = new PhpClassMethodDefinition("__construct"); phpClass.Methods.Add(phpMethod); if (md.Info.IsPublic) { phpMethod.Visibility = Visibility.Public; } else if (md.Info.IsPrivate) { phpMethod.Visibility = Visibility.Private; } else { phpMethod.Visibility = Visibility.Protected; } phpMethod.IsStatic = md.Info.IsStatic; { var declaredParameters = md.Info.GetParameters(); foreach (var parameter in declaredParameters) { var phpParameter = new PhpMethodArgument(); phpParameter.Name = parameter.Name; phpMethod.Arguments.Add(phpParameter); if (parameter.HasDefaultValue) { phpParameter.DefaultValue = new PhpConstValue(parameter.DefaultValue); } } } if (md.Body != null) { phpMethod.Statements.AddRange(TranslateStatement(md.Body)); } } finally { _state.Principles.CurrentMethod = null; } }