コード例 #1
0
        public static API_IKVMC_Java_Metadata javaMetadata(this string file)
        {
            API_IKVMC_Java_Metadata javaMetadata = null;

            try
            {
                javaMetadata = (API_IKVMC_Java_Metadata)O2LiveObjects.get(file);                        // try first to get a cached version of this file
            }
            catch
            {}
            if (javaMetadata.isNull() && file.fileExists())
            {
                "Cached version not found, loading from disk".info();
                if (file.extension(".xml"))
                {
                    javaMetadata = file.load <API_IKVMC_Java_Metadata>();
                }
                else
                {
                    javaMetadata = new API_IKVMC().create_JavaMetadata(file);
                }
                O2LiveObjects.set(file, javaMetadata);
            }
            return(javaMetadata);
        }
コード例 #2
0
 public static object createClassFile(this API_IKVMC ikvmc, byte[] bytes)
 {
     // 0 = ClassFileParseOptions.None,
     // 1 = ClassFileParseOptions.LocalVariableTable ,
     // 2 = ClassFileParseOptions.LineNumberTable
     return(ikvmc.createClassFile(bytes, 0));
 }
コード例 #3
0
        public static IDictionary getRawClassesData_FromFile_ClassesOrJar(this API_IKVMC ikvmc, string classOrJar)
        {
            var targets = typeof(List <>).MakeGenericType(new System.Type[] { ikvmc.CompilerOptions.type() }).ctor();
            var args    = classOrJar.wrapOnList().GetEnumerator();

            ikvmc.IkvmcCompiler.invoke("ParseCommandLine", args, targets, ikvmc.CompilerOptions);
            var compilerOptions = (targets as IEnumerable).first();
            //var classes =   (Dictionary<string, byte[]>) compilerOptions.field("classes");
            var classes = (IDictionary)compilerOptions.field("classes");

            return(classes);
        }
コード例 #4
0
        public static object createClassFile(this API_IKVMC ikvmc, byte[] bytes, int classFileParseOptions)
        {
            var classFileType = ikvmc.IkvmcAssembly.type("ClassFile");
            var ctor          = classFileType.ctors().first();

            var classFile = ctor.Invoke(new object[] { bytes, 0, bytes.Length, null, classFileParseOptions });

            if (classFile.notNull())
            {
                return(classFile);
            }
            "[API_IKVMC] in createClassObject failed to create class".info();
            return(null);
        }
コード例 #5
0
        public static API_IKVMC_Java_Metadata create_JavaMetadata(this API_IKVMC ikvmc, string fileToProcess)
        {
            var o2Timer      = new O2Timer("Created JavaData for {0}".format(fileToProcess)).start();
            var javaMetaData = new API_IKVMC_Java_Metadata();

            javaMetaData.FileProcessed = fileToProcess;
            var classes = ikvmc.getRawClassesData_FromFile_ClassesOrJar(fileToProcess);

            foreach (DictionaryEntry item in classes)
            {
                var name      = item.Key.str();
                var bytes     = (byte[])item.Value.field("data");
                var classFile = ikvmc.createClassFile(bytes, 1);                                        // value of 1 gets the local variables
                var javaClass = new Java_Class {
                    Signature   = name,
                    Name        = name.contains(".") ? name.split(".").last() : name,
                    SourceFile  = classFile.prop("SourceFileAttribute").str(),
                    IsAbstract  = classFile.prop("IsAbstract").str().toBool(),
                    IsInterface = classFile.prop("IsInterface").str().toBool(),
                    IsInternal  = classFile.prop("IsInternal").str().toBool(),
                    IsPublic    = classFile.prop("IsPublic").str().toBool(),
                    SuperClass  = classFile.prop("SuperClass").str()
                };

                if (classFile.prop("GenericSignature").notNull())
                {
                    javaClass.GenericSignature = classFile.prop("GenericSignature").str();
                }

                javaClass.ConstantsPool = classFile.getConstantPoolEntries();
                javaClass.map_Annotations(classFile)
                .map_Interfaces(classFile)
                .map_Fields(classFile)
                .map_Methods(classFile)
                .map_EnclosingMethod(classFile);

                javaClass.map_LineNumbers(ikvmc.createClassFile(bytes, 2));                // for this we need to call createClassFile with the value of 2 (to get the source code references)

                javaMetaData.Classes.Add(javaClass);
                //break; //
            }
            o2Timer.stop();
            return(javaMetaData);
        }
コード例 #6
0
        public static string createAssembly_FromFile_ClasssesOrJar(this API_IKVMC ikvmc, string classOrJar)
        {
            var console    = "IKVM Stored Console out and error".capture_Console();
            var targetFile = "_IKVM_Dlls".tempDir(false).pathCombine("{0}.dll".format(classOrJar.fileName()));

            var args = new List <string> {
                classOrJar,
                "-out:{0}".format(targetFile)
            }.GetEnumerator();
            //return args.toList();
            var targets = typeof(List <>).MakeGenericType(new System.Type[] { ikvmc.CompilerOptions.type() }).ctor();

            ikvmc.IkvmcCompiler.invoke("ParseCommandLine", args, targets, ikvmc.CompilerOptions);

            //ikvmcCompiler.details();
            var compilerClassLoader = ikvmc.IkvmcAssembly.type("CompilerClassLoader");
            var compile             = compilerClassLoader.method("Compile");

            var createCompiler = compilerClassLoader.method("CreateCompiler");

            PublicDI.reflection.invokeMethod_Static(compile, new object[] { null, targets });
            //ikvmcCompiler.details();
            return(console.readToEnd());
        }
コード例 #7
0
		public static API_IKVMC_Java_Metadata javaMetadata(this string file)
		{
			API_IKVMC_Java_Metadata javaMetadata = null;
			try
			{	
				javaMetadata = (API_IKVMC_Java_Metadata)O2LiveObjects.get(file);	// try first to get a cached version of this file
			}
			catch
			{}
			if (javaMetadata.isNull() && file.fileExists())
			{
				"Cached version not found, loading from disk".info();
				if (file.extension(".xml"))
					javaMetadata =  file.load<API_IKVMC_Java_Metadata>();
				else
					javaMetadata =  new API_IKVMC().create_JavaMetadata(file);						
				O2LiveObjects.set(file, javaMetadata);
			}
			return javaMetadata;
		}