public void Test() { string projectType = TestUtil.PackageMemberParse("public interface Calendar { void getTime(); }"); string program = TestUtil.PackageMemberParse(@"import java.util.Calendar; public class MyCalendar { public Calendar getCalendar() { return Calendar.getInstance(); } }"); string expected = TestUtil.NamespaceMemberParse(@"public class MyCalendar { public java.util.Calendar getCalendar() { return java.util.Calendar.getInstance(); } }"); TypesVisitor typesVisitor = new TypesVisitor(); typesVisitor.CodeBase = CodeBase; CompilationUnit cu1 = TestUtil.ParseProgram(projectType); typesVisitor.VisitCompilationUnit(cu1, null); CompilationUnit cu2 = TestUtil.ParseProgram(program); typesVisitor.VisitCompilationUnit(cu2, null); VisitCompilationUnit(cu2, null); TestUtil.CodeEqual(expected, TestUtil.GenerateCode(cu2)); }
public void CallingInheritedInterfaceFromInterfaceFields() { string program = TestUtil.GetInput(); string expected = TestUtil.GetExpected(); string program2 = @" package Atom; public interface IMaterial { } public class IMaterial_Fields { public static int Atomic_Number; } public interface ISolid extends IMaterial { }"; CompilationUnit cv = TestUtil.ParseProgram(program2); CompilationUnit cu = TestUtil.ParseProgram(program); TypesVisitor typesVisitor = new TypesVisitor(); typesVisitor.CodeBase = CodeBase; typesVisitor.VisitCompilationUnit(cu, null); typesVisitor.VisitCompilationUnit(cv, null); ImportTransformer im = new ImportTransformer(); im.VisitCompilationUnit(cu, null); CodeBase.References.Add("Atom.IMaterial", "Atom.IMaterial_Fields"); VisitCompilationUnit(cu, null); TestUtil.CodeEqual(expected, TestUtil.GenerateCode(cu)); }
public void Test() { string projectType = TestUtil.PackageMemberParse("public interface Calendar { void getTime(); }"); string program = TestUtil.PackageMemberParse(@"import java.util.Calendar; public class MyCalendar { public Calendar getCalendar() { return Calendar.getInstance(); } }" ); string expected = TestUtil.NamespaceMemberParse(@"public class MyCalendar { public java.util.Calendar getCalendar() { return java.util.Calendar.getInstance(); } }" ); TypesVisitor typesVisitor = new TypesVisitor(); typesVisitor.CodeBase = CodeBase; CompilationUnit cu1 = TestUtil.ParseProgram(projectType); typesVisitor.VisitCompilationUnit(cu1, null); CompilationUnit cu2 = TestUtil.ParseProgram(program); typesVisitor.VisitCompilationUnit(cu2, null); VisitCompilationUnit(cu2, null); TestUtil.CodeEqual(expected, TestUtil.GenerateCode(cu2)); }
public void InnerClassConstructors() { string program = TestUtil.GetInput(); CompilationUnit cu = TestUtil.ParseProgram(program); TypesVisitor typesVisitor = new TypesVisitor(); typesVisitor.CodeBase = CodeBase; typesVisitor.VisitCompilationUnit(cu, null); VisitCompilationUnit(cu, null); Assert.AreEqual(1, CodeBase.References.Count); Assert.IsTrue(CodeBase.References.Contains("Cons:Test.A$B")); }
public void Polymorphism() { string program = TestUtil.GetInput(); string expected = TestUtil.GetExpected(); CompilationUnit cu = TestUtil.ParseProgram(program); TypesVisitor typesVisitor = new TypesVisitor(); typesVisitor.CodeBase = CodeBase; typesVisitor.VisitCompilationUnit(cu, null); VisitCompilationUnit(cu, null); TestUtil.CodeEqual(expected, TestUtil.GenerateCode(cu)); }
public void CallingInheritedInterfaceFromInterfaceFields() { string program = TestUtil.GetInput(); string expected = TestUtil.GetExpected(); string program2 = @" package Atom; public interface IMaterial { } public class IMaterial_Fields { public static int Atomic_Number; } public interface ISolid extends IMaterial { }" ; CompilationUnit cv = TestUtil.ParseProgram(program2); CompilationUnit cu = TestUtil.ParseProgram(program); TypesVisitor typesVisitor = new TypesVisitor(); typesVisitor.CodeBase = CodeBase; typesVisitor.VisitCompilationUnit(cu, null); typesVisitor.VisitCompilationUnit(cv, null); ImportTransformer im = new ImportTransformer(); im.VisitCompilationUnit(cu, null); CodeBase.References.Add("Atom.IMaterial", "Atom.IMaterial_Fields"); VisitCompilationUnit(cu, null); TestUtil.CodeEqual(expected, TestUtil.GenerateCode(cu)); }
public void InnerClassUsesEnclosingInheritedInterfaceField() { string program = TestUtil.GetInput(); string expected = TestUtil.GetExpected(); CompilationUnit cu = TestUtil.ParseProgram(program); TypesVisitor typesVisitor = new TypesVisitor(); typesVisitor.CodeBase = CodeBase; typesVisitor.VisitCompilationUnit(cu, null); CodeBase.References.Add("Test.IDocument", "Test.IDocument_Fields"); VisitCompilationUnit(cu, null); TestUtil.CodeEqual(expected, TestUtil.GenerateCode(cu)); }
public void InterfaceFieldsUseParentInterfaceFields() { string program = TestUtil.GetInput(); string expected = TestUtil.GetExpected(); CompilationUnit cu = TestUtil.ParseProgram(program); TypesVisitor typesVisitor = new TypesVisitor(); typesVisitor.CodeBase = CodeBase; typesVisitor.VisitCompilationUnit(cu, null); CodeBase.References.Add("Test.Constants", "Test.Constants_Fields"); CodeBase.References.Add("Test.SystemConstants", "Test.SystemConstants_Fields"); VisitCompilationUnit(cu, null); TestUtil.CodeEqual(expected, TestUtil.GenerateCode(cu)); }
public void InheritedFromMultiInterfaceWithFields() { string program = TestUtil.GetInput(); string expected = TestUtil.GetExpected(); CompilationUnit cu = TestUtil.ParseProgram(program); TypesVisitor typesVisitor = new TypesVisitor(); typesVisitor.CodeBase = CodeBase; typesVisitor.VisitCompilationUnit(cu, null); CodeBase.References.Add("Test.IName", "Test.IName_Fields"); CodeBase.References.Add("Test.IFamily", "Test.IFamily_Fields"); VisitCompilationUnit(cu, null); TestUtil.CodeEqual(expected, TestUtil.GenerateCode(cu)); }
public void PublicMethodInheritedProtected() { string program = TestUtil.GetInput(); string expected = TestUtil.GetExpected(); CompilationUnit cu = TestUtil.ParseProgram(program); TypesVisitor typesVisitor = new TypesVisitor(); typesVisitor.CodeBase = CodeBase; typesVisitor.VisitCompilationUnit(cu, null); CodeBase.Inheritors.Add("Test.Shape", "Test.SimpleShape"); CodeBase.Inheritors.Add("Test.Shape", "Test.PolygonShape"); CodeBase.Inheritors.Add("Test.SimpleShape", "Test.Rectangle"); CodeBase.Inheritors.Add("Test.PolygonShape", "Test.ComplexShape"); VisitCompilationUnit(cu, null); TestUtil.CodeEqual(expected, TestUtil.GenerateCode(cu)); }
public void InternalConstructor() { string programBase = TestUtil.TypeMemberParse("protected Test(String name, int index) {}"); string usageProgram = TestUtil.GetInput(); string expected = TestUtil.GetExpected(); TypesVisitor typesVisitor = new TypesVisitor(); typesVisitor.CodeBase = CodeBase; CompilationUnit cu1 = TestUtil.ParseProgram(programBase); NamespaceDeclaration ns = (NamespaceDeclaration) cu1.Children[0]; TypeDeclaration ty = (TypeDeclaration) ns.Children[0]; CompilationUnit cu2 = TestUtil.ParseProgram(usageProgram, SupportedLanguage.CSharp); CodeBase.Types.Add("Test.Test", ty); typesVisitor.VisitCompilationUnit(cu2, null); VisitCompilationUnit(cu2, null); TestUtil.CodeEqual(expected, TestUtil.GenerateCode(cu2)); }
public void InternalConstructor() { string programBase = TestUtil.TypeMemberParse("protected Test(String name, int index) {}"); string usageProgram = TestUtil.GetInput(); string expected = TestUtil.GetExpected(); TypesVisitor typesVisitor = new TypesVisitor(); typesVisitor.CodeBase = CodeBase; CompilationUnit cu1 = TestUtil.ParseProgram(programBase); NamespaceDeclaration ns = (NamespaceDeclaration)cu1.Children[0]; TypeDeclaration ty = (TypeDeclaration)ns.Children[0]; CompilationUnit cu2 = TestUtil.ParseProgram(usageProgram, SupportedLanguage.CSharp); CodeBase.Types.Add("Test.Test", ty); typesVisitor.VisitCompilationUnit(cu2, null); VisitCompilationUnit(cu2, null); TestUtil.CodeEqual(expected, TestUtil.GenerateCode(cu2)); }
public void ProjectAndLibraryTypeWithSameName() { string program = TestUtil.PackageMemberParse(@" import java.util.Calendar; public class A { int h = Calendar.HOUR; } public class Calendar_Fields {public static int Month = 0;}" ); string expected = TestUtil.NamespaceMemberParse(@" using java.util.Calendar; public class A { int h = Calendar.HOUR; } public class Calendar_Fields {public static int Month = 0;}" ); CompilationUnit cu = TestUtil.ParseProgram(program); CodeBase.References.Add("Test.Calendar", "Test.Calendar_Fields"); TypesVisitor typesVisitor = new TypesVisitor(); typesVisitor.CodeBase = CodeBase; typesVisitor.VisitCompilationUnit(cu, null); VisitCompilationUnit(cu, null); TestUtil.CodeEqual(expected, TestUtil.GenerateCode(cu)); }
public void ProjectAndLibraryTypeWithSameName() { string program = TestUtil.PackageMemberParse(@" import java.util.Calendar; public class A { int h = Calendar.HOUR; } public class Calendar_Fields {public static int Month = 0;}"); string expected = TestUtil.NamespaceMemberParse(@" using java.util.Calendar; public class A { int h = Calendar.HOUR; } public class Calendar_Fields {public static int Month = 0;}"); CompilationUnit cu = TestUtil.ParseProgram(program); CodeBase.References.Add("Test.Calendar", "Test.Calendar_Fields"); TypesVisitor typesVisitor = new TypesVisitor(); typesVisitor.CodeBase = CodeBase; typesVisitor.VisitCompilationUnit(cu, null); VisitCompilationUnit(cu, null); TestUtil.CodeEqual(expected, TestUtil.GenerateCode(cu)); }
public void NestedAnonymousClass() { string program = TestUtil.PackageMemberParse(@" public class NestedAnon { public void exec(){} public void firstLevel() { String arg = null; Weight w = new Weight() { public void secondLevel() { exec(); Score s = new Score(arg) { public void thirdLevel() { } }; } }; } } public class Score { public Score(String arg){} }" ); string expected = TestUtil.NamespaceMemberParse(@" public class NestedAnon { public void exec(){} public void firstLevel() { String arg = null; Weight w = new AnonymousClassWeight1(this, arg); } private class AnonymousClassWeight1 : Weight { public AnonymousClassWeight1(NestedAnon enclosingInstance, String arg) { this.enclosingInstance = enclosingInstance; this.arg = arg; } public void secondLevel() { enclosingInstance.exec(); Score s = new AnonymousClassScore2(arg, this); } private NestedAnon enclosingInstance; private String arg; public NestedAnon Enclosing_Instance { get { return enclosingInstance; } } private class AnonymousClassScore2 : Score { public AnonymousClassScore2(String arg, AnonymousClassWeight1 enclosingInstance) : base(arg) { this.enclosingInstance = enclosingInstance; } public void thirdLevel() { } private AnonymousClassWeight1 enclosingInstance; public AnonymousClassWeight1 Enclosing_Instance { get { return enclosingInstance; } } } } } public class Score { public Score(String arg){} }" ); CompilationUnit cu = TestUtil.ParseProgram(program); TypesVisitor typesVisitor = new TypesVisitor(); typesVisitor.CodeBase = this.CodeBase; typesVisitor.VisitCompilationUnit(cu, null); VisitCompilationUnit(cu, null); TestUtil.CodeEqual(expected, TestUtil.GenerateCode(cu)); }
public void NestedAnonymousClass() { string program = TestUtil.PackageMemberParse(@" public class NestedAnon { public void exec(){} public void firstLevel() { String arg = null; Weight w = new Weight() { public void secondLevel() { exec(); Score s = new Score(arg) { public void thirdLevel() { } }; } }; } } public class Score { public Score(String arg){} }"); string expected = TestUtil.NamespaceMemberParse(@" public class NestedAnon { public void exec(){} public void firstLevel() { String arg = null; Weight w = new AnonymousClassWeight1(this, arg); } private class AnonymousClassWeight1 : Weight { public AnonymousClassWeight1(NestedAnon enclosingInstance, String arg) { this.enclosingInstance = enclosingInstance; this.arg = arg; } public void secondLevel() { enclosingInstance.exec(); Score s = new AnonymousClassScore2(arg, this); } private NestedAnon enclosingInstance; private String arg; public NestedAnon Enclosing_Instance { get { return enclosingInstance; } } private class AnonymousClassScore2 : Score { public AnonymousClassScore2(String arg, AnonymousClassWeight1 enclosingInstance) : base(arg) { this.enclosingInstance = enclosingInstance; } public void thirdLevel() { } private AnonymousClassWeight1 enclosingInstance; public AnonymousClassWeight1 Enclosing_Instance { get { return enclosingInstance; } } } } } public class Score { public Score(String arg){} }"); CompilationUnit cu = TestUtil.ParseProgram(program); TypesVisitor typesVisitor = new TypesVisitor(); typesVisitor.CodeBase = this.CodeBase; typesVisitor.VisitCompilationUnit(cu, null); VisitCompilationUnit(cu, null); TestUtil.CodeEqual(expected, TestUtil.GenerateCode(cu)); }