alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Scala example source code file (MethodBuilder.scala)

This example Scala source code file (MethodBuilder.scala) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Scala tags/keywords

array, declaringtype, getilgenerator, ilgenerator, ilgenerator, int, int, io, no, parameterbuilder, parameterbuilder, runtimeexception, string, string, type

The Scala MethodBuilder.scala source code

/*
 * System.Reflection.Emit-like API for writing .NET assemblies to MSIL
 */


package ch.epfl.lamp.compiler.msil.emit

import ch.epfl.lamp.compiler.msil.MethodInfo
import ch.epfl.lamp.compiler.msil.ParameterInfo
import ch.epfl.lamp.compiler.msil.Type
import ch.epfl.lamp.compiler.msil.ConstructorInfo
import java.io.IOException

/**
 * Defines and represents a method of a dynamic class.
 *
 * @author Nikolay Mihaylov
 * @version 1.0
 */
class MethodBuilder(name: String, declType: Type, attrs: Int, returnType: Type, paramTypes: Array[Type])
      extends MethodInfo(name, declType, attrs, returnType, paramTypes)
      with ICustomAttributeSetter
      with Visitable
{

    //##########################################################################
    // public interface

    /** Defines a parameter of this method. TODO: Parameters are indexed staring
     *  from number 1 for the first parameter
     */
    def DefineParameter(pos: Int, attr: Int, name: String): ParameterBuilder = {
	val param = new ParameterBuilder(name, params(pos).ParameterType, attr, pos)
	params(pos) = param
	return param
    }

    /** Returns an ILGenerator for this method. */
    def GetILGenerator(): ILGenerator = {
	if (ilGenerator == null)
	    throw new RuntimeException
		("No code generator available for this method: " + this)
	return ilGenerator
    }

    /** Sets a custom attribute. */
    def SetCustomAttribute(constr: ConstructorInfo, value: Array[Byte]) {
	addCustomAttribute(constr, value)
    }

    //##########################################################################

    /** The apply method for a visitor. */
    @throws(classOf[IOException])
    def apply(v: Visitor) {
	v.caseMethodBuilder(this)
    }

    //##########################################################################

    // the Intermediate Language Generator
    // it contains the method's body
    protected final val ilGenerator : ILGenerator =
	  if (DeclaringType == null // global method
	      || !DeclaringType.IsInterface())
	      new ILGenerator(this)
	  else null

    //##########################################################################
}

Other Scala examples (source code examples)

Here is a short list of links related to this Scala MethodBuilder.scala source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.