public void GenerateMethod() { JavaCodeMemberMethod method = new JavaCodeMemberMethod() { Name = "someMethod" }; string code = GenerateMember(TestContext, method); Assert.IsTrue(code.Contains("private final void someMethod() {"), code); method.Name = "someOtherMethod"; method.Attributes = MemberAttributes.Public | JavaAttributes.StaticOnly; method.ReturnType = new CodeTypeReference(typeof(int)); code = GenerateMember(TestContext, method); Assert.IsTrue(code.Contains("public static int someOtherMethod() {"), code); method.Name = "someYetOtherMethod"; method.Attributes = MemberAttributes.Family | JavaAttributes.StaticFinal; code = GenerateMember(TestContext, method); Assert.IsTrue(code.Contains("protected static final int someYetOtherMethod() {"), code); method.Attributes = MemberAttributes.FamilyAndAssembly | JavaAttributes.StaticFinal; code = GenerateMember(TestContext, method); Assert.IsTrue(code.Contains("protected static final int someYetOtherMethod() {"), code); method.Attributes = MemberAttributes.FamilyOrAssembly | JavaAttributes.StaticFinal; code = GenerateMember(TestContext, method); Assert.IsTrue(code.Contains("protected static final int someYetOtherMethod() {"), code); method.Attributes = MemberAttributes.Assembly | JavaAttributes.StaticFinal; code = GenerateMember(TestContext, method); Assert.IsTrue(code.Contains("static final int someYetOtherMethod() {"), code); method.Attributes = MemberAttributes.Assembly; code = GenerateMember(TestContext, method); Assert.IsTrue(code.Contains("int someYetOtherMethod() {"), code); method.Attributes = MemberAttributes.Abstract; method.ReturnType = new CodeTypeReference(typeof(void)); code = GenerateMember(TestContext, method); Assert.IsTrue(code.Contains("abstract void someYetOtherMethod();"), code); method.Attributes = MemberAttributes.Abstract | MemberAttributes.Public; code = GenerateMember(TestContext, method); Assert.IsTrue(code.Contains("public abstract void someYetOtherMethod();"), code); method.Attributes = MemberAttributes.Abstract | MemberAttributes.Assembly; code = GenerateMember(TestContext, method); Assert.IsTrue(code.Contains("abstract void someYetOtherMethod();"), code); method.Name = "method"; method.Attributes = MemberAttributes.Public; method.ThrowsExceptions.Add("IOException"); code = GenerateMember(TestContext, method); Assert.IsTrue(code.Contains("public void method() throws IOException {"), code); method.ThrowsExceptions.Add("Exception"); code = GenerateMember(TestContext, method); Assert.IsTrue(code.Contains("public void method() throws IOException, Exception {"), code); }
protected JavaCodeMemberMethod NewMethod(string name, string returnType, MemberAttributes attributes, params Parameter[] parameters) { JavaCodeMemberMethod method = new JavaCodeMemberMethod() { Name = name, ReturnType = NewTypeReference(returnType), Attributes = attributes }; if (parameters != null) { foreach (Parameter param in parameters) { method.Parameters.Add(NewParameter(param.TypeName, param.Name)); } } return(method); }