org.datanucleus.enhancer.ClassMethod Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of datanucleus-core Show documentation
Show all versions of datanucleus-core Show documentation
DataNucleus Core provides the primary components of a heterogenous Java persistence solution.
It supports persistence API's being layered on top of the core functionality.
/**********************************************************************
Copyright (c) 2007 Andy Jefferson and others. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Contributors:
...
**********************************************************************/
package org.datanucleus.enhancer;
import java.util.Arrays;
import org.datanucleus.enhancer.asm.ClassVisitor;
import org.datanucleus.enhancer.asm.MethodVisitor;
import org.datanucleus.enhancer.asm.Type;
import org.datanucleus.util.Localiser;
/**
* Representation of a method that an enhanced class requires.
*/
public abstract class ClassMethod
{
/** The parent enhancer. */
protected ClassEnhancer enhancer;
/** Name of the method. */
protected String methodName;
/** Access flags for the method (public, protected etc). */
protected int access;
/** Return type for the method */
protected Object returnType;
/** Types of the arguments. */
protected Object[] argTypes;
/** Names of the arguments. */
protected String[] argNames;
/** Exceptions that can be thrown. */
protected String[] exceptions;
/** Visitor for use in updating the method of the class (set in initialise). */
protected MethodVisitor visitor;
/**
* Constructor.
* @param enhancer ClassEnhancer
* @param name Name of the method
* @param access Access for the method (PUBLIC, PROTECTED etc)
* @param returnType Return type
* @param argTypes Argument type(s)
* @param argNames Argument name(s)
*/
public ClassMethod(ClassEnhancer enhancer, String name, int access,
Object returnType, Object[] argTypes, String[] argNames)
{
this(enhancer, name, access, returnType, argTypes, argNames, null);
}
/**
* Constructor.
* @param enhancer ClassEnhancer
* @param name Name of the method
* @param access Access for the method (PUBLIC, PROTECTED etc)
* @param returnType Return type
* @param argTypes Argument type(s)
* @param argNames Argument name(s)
* @param exceptions Exceptions that can be thrown
*/
public ClassMethod(ClassEnhancer enhancer, String name, int access,
Object returnType, Object[] argTypes, String[] argNames, String[] exceptions)
{
this.enhancer = enhancer;
this.methodName = name;
this.access = access;
this.returnType = returnType;
this.argTypes = argTypes;
this.argNames = argNames;
this.exceptions = exceptions;
}
/**
* Default implementation of initialise, specifying the method based on the ClassMethod info.
*/
public void initialise()
{
// Do nothing. Already set up in initialise(ClassVisitor)
}
/**
* Method to initialise the class method.
* @param classVisitor Visitor for the class
*/
public void initialise(ClassVisitor classVisitor)
{
// Add the method to the class using the ClassMethod info
Type type = null;
Type[] argtypes = null;
if (returnType != null)
{
type = Type.getType((Class)returnType);
}
else
{
type = Type.VOID_TYPE;
}
if (argTypes != null)
{
argtypes = new Type[argTypes.length];
for (int i=0;i 0)
{
for (int i=0;i