2005-02-15 06:05:36 -05:00
/ *
2008-04-07 14:36:09 -04:00
* Copyright ( c ) 2002 - 2008 LWJGL Project
2005-02-15 06:05:36 -05:00
* All rights reserved .
*
* Redistribution and use in source and binary forms , with or without
* modification , are permitted provided that the following conditions are
* met :
*
* * Redistributions of source code must retain the above copyright
* notice , this list of conditions and the following disclaimer .
*
* * Redistributions in binary form must reproduce the above copyright
* notice , this list of conditions and the following disclaimer in the
* documentation and / or other materials provided with the distribution .
*
* * Neither the name of ' LWJGL ' nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission .
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* " AS IS " AND ANY EXPRESS OR IMPLIED WARRANTIES , INCLUDING , BUT NOT LIMITED
* TO , THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED . IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT , INDIRECT , INCIDENTAL , SPECIAL ,
* EXEMPLARY , OR CONSEQUENTIAL DAMAGES ( INCLUDING , BUT NOT LIMITED TO ,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES ; LOSS OF USE , DATA , OR
* PROFITS ; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY , WHETHER IN CONTRACT , STRICT LIABILITY , OR TORT ( INCLUDING
* NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE , EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE .
* /
2005-02-20 14:28:34 -05:00
package org.lwjgl.util.generator ;
2005-02-15 06:05:36 -05:00
/ * *
*
* This class generates the methods in the generated java source files .
*
* @author elias_naur < elias_naur @users.sourceforge.net >
* @version $Revision$
2006-03-23 14:32:21 -05:00
* $Id$
2005-02-15 06:05:36 -05:00
* /
2010-09-26 19:43:24 -04:00
import org.lwjgl.PointerBuffer ;
import org.lwjgl.util.generator.opengl.GLreturn ;
2005-02-15 06:05:36 -05:00
import com.sun.mirror.apt.* ;
import com.sun.mirror.declaration.* ;
import com.sun.mirror.type.* ;
import java.io.* ;
import java.nio.* ;
2014-08-16 08:39:04 -04:00
import java.util.* ;
import java.util.regex.* ;
2005-02-15 06:05:36 -05:00
public class JavaMethodsGenerator {
2010-09-26 19:43:24 -04:00
private static final String SAVED_PARAMETER_POSTFIX = " _saved " ;
2007-04-23 16:17:42 -04:00
2005-02-16 11:04:29 -05:00
public static void generateMethodsJava ( AnnotationProcessorEnvironment env , TypeMap type_map , PrintWriter writer , InterfaceDeclaration interface_decl , boolean generate_error_checks , boolean context_specific ) {
2005-02-15 06:05:36 -05:00
for ( MethodDeclaration method : interface_decl . getMethods ( ) )
2005-02-16 11:04:29 -05:00
generateMethodJava ( env , type_map , writer , interface_decl , method , generate_error_checks , context_specific ) ;
2005-02-15 06:05:36 -05:00
}
2005-02-16 11:04:29 -05:00
private static void generateMethodJava ( AnnotationProcessorEnvironment env , TypeMap type_map , PrintWriter writer , InterfaceDeclaration interface_decl , MethodDeclaration method , boolean generate_error_checks , boolean context_specific ) {
2005-02-15 06:05:36 -05:00
writer . println ( ) ;
2005-02-16 11:04:29 -05:00
if ( Utils . isMethodIndirect ( generate_error_checks , context_specific , method ) ) {
2005-02-15 06:05:36 -05:00
if ( method . getAnnotation ( GenerateAutos . class ) ! = null ) {
2005-02-16 11:04:29 -05:00
printMethodWithMultiType ( env , type_map , writer , interface_decl , method , TypeInfo . getDefaultTypeInfoMap ( method ) , Mode . AUTOS , generate_error_checks , context_specific ) ;
2005-02-15 06:05:36 -05:00
}
Collection < Map < ParameterDeclaration , TypeInfo > > cross_product = TypeInfo . getTypeInfoCrossProduct ( type_map , method ) ;
for ( Map < ParameterDeclaration , TypeInfo > typeinfos_instance : cross_product ) {
2005-02-16 11:04:29 -05:00
printMethodWithMultiType ( env , type_map , writer , interface_decl , method , typeinfos_instance , Mode . NORMAL , generate_error_checks , context_specific ) ;
2005-02-15 06:05:36 -05:00
}
}
2010-01-04 13:47:49 -05:00
if ( method . getAnnotation ( CachedResult . class ) ! = null & & ! method . getAnnotation ( CachedResult . class ) . isRange ( ) ) {
printMethodWithMultiType ( env , type_map , writer , interface_decl , method , TypeInfo . getDefaultTypeInfoMap ( method ) , Mode . CACHEDRESULT , generate_error_checks , context_specific ) ;
}
2010-09-26 19:43:24 -04:00
Reuse reuse_annotation = method . getAnnotation ( Reuse . class ) ;
2010-03-12 16:55:13 -05:00
Alternate alt_annotation = method . getAnnotation ( Alternate . class ) ;
2010-09-26 19:43:24 -04:00
if ( alt_annotation = = null | | ( alt_annotation . nativeAlt ( ) & & ! alt_annotation . skipNative ( ) ) ) {
2010-03-16 13:58:48 -04:00
if ( alt_annotation ! = null & & method . getSimpleName ( ) . equals ( alt_annotation . value ( ) ) )
throw new RuntimeException ( " An alternate function with native code should have a different name than the main function. " ) ;
2010-11-05 13:13:56 -04:00
if ( reuse_annotation = = null )
printJavaNativeStub ( writer , method , Mode . NORMAL , generate_error_checks , context_specific ) ;
2010-03-11 16:06:49 -05:00
if ( Utils . hasMethodBufferObjectParameter ( method ) ) {
printMethodWithMultiType ( env , type_map , writer , interface_decl , method , TypeInfo . getDefaultTypeInfoMap ( method ) , Mode . BUFFEROBJECT , generate_error_checks , context_specific ) ;
2010-11-05 13:13:56 -04:00
if ( reuse_annotation = = null )
printJavaNativeStub ( writer , method , Mode . BUFFEROBJECT , generate_error_checks , context_specific ) ;
2010-03-11 16:06:49 -05:00
}
2005-02-15 06:05:36 -05:00
}
}
2005-02-16 11:04:29 -05:00
private static void printJavaNativeStub ( PrintWriter writer , MethodDeclaration method , Mode mode , boolean generate_error_checks , boolean context_specific ) {
if ( Utils . isMethodIndirect ( generate_error_checks , context_specific , method ) ) {
2010-09-30 13:21:50 -04:00
writer . print ( " \ tstatic native " ) ;
2005-02-15 06:05:36 -05:00
} else {
Utils . printDocComment ( writer , method ) ;
writer . print ( " \ tpublic static native " ) ;
}
2010-09-26 19:43:24 -04:00
writer . print ( getResultType ( method , true ) ) ;
2005-02-16 11:04:29 -05:00
writer . print ( " " + Utils . getSimpleNativeMethodName ( method , generate_error_checks , context_specific ) ) ;
2005-02-15 06:05:36 -05:00
if ( mode = = Mode . BUFFEROBJECT )
writer . print ( Utils . BUFFER_OBJECT_METHOD_POSTFIX ) ;
writer . print ( " ( " ) ;
2010-09-26 19:43:24 -04:00
boolean first_parameter = generateParametersJava ( writer , method , TypeInfo . getDefaultTypeInfoMap ( method ) , true , true , mode ) ;
2005-02-16 11:04:29 -05:00
if ( context_specific ) {
if ( ! first_parameter )
writer . print ( " , " ) ;
writer . print ( " long " + Utils . FUNCTION_POINTER_VAR_NAME ) ;
}
2005-02-15 06:05:36 -05:00
writer . println ( " ); " ) ;
}
2010-09-26 19:43:24 -04:00
private static boolean generateParametersJava ( PrintWriter writer , MethodDeclaration method , Map < ParameterDeclaration , TypeInfo > typeinfos_instance , boolean native_stub , final boolean printTypes , Mode mode ) {
2005-02-15 06:05:36 -05:00
boolean first_parameter = true ;
for ( ParameterDeclaration param : method . getParameters ( ) ) {
2010-09-28 17:11:35 -04:00
if ( native_stub & & ( param . getAnnotation ( Helper . class ) ! = null & & ! param . getAnnotation ( Helper . class ) . passToNative ( ) ) )
2010-09-26 19:43:24 -04:00
continue ;
final Constant constant_annotation = param . getAnnotation ( Constant . class ) ;
if ( constant_annotation ! = null & & constant_annotation . isNative ( ) )
continue ;
2005-02-15 06:05:36 -05:00
AnnotationMirror auto_annotation_mirror = Utils . getParameterAutoAnnotation ( param ) ;
boolean hide_auto_parameter = mode = = Mode . NORMAL & & ! native_stub & & auto_annotation_mirror ! = null ;
if ( hide_auto_parameter ) {
AutoType auto_type_annotation = param . getAnnotation ( AutoType . class ) ;
if ( auto_type_annotation ! = null ) {
ParameterDeclaration auto_parameter = Utils . findParameter ( method , auto_type_annotation . value ( ) ) ;
TypeInfo auto_param_type_info = typeinfos_instance . get ( auto_parameter ) ;
if ( auto_param_type_info . getSignedness ( ) = = Signedness . BOTH ) {
if ( ! first_parameter )
writer . print ( " , " ) ;
2005-02-16 11:04:29 -05:00
first_parameter = false ;
2010-09-26 19:43:24 -04:00
if ( printTypes )
writer . print ( " boolean " ) ;
2010-10-04 13:04:46 -04:00
writer . print ( TypeInfo . UNSIGNED_PARAMETER_NAME ) ;
2005-02-15 06:05:36 -05:00
}
}
2010-03-12 16:55:13 -05:00
} else if (
param . getAnnotation ( Result . class ) = = null
2010-03-14 19:24:40 -04:00
& & ( native_stub | | ( ( param . getAnnotation ( Constant . class ) = = null | | param . getAnnotation ( Constant . class ) . keepParam ( ) ) & & ! Utils . isReturnParameter ( method , param ) ) )
2010-09-26 19:43:24 -04:00
& & ( mode ! = Mode . AUTOS | | getAutoTypeParameter ( method , param ) = = null )
) {
first_parameter = generateParameterJava ( writer , param , typeinfos_instance . get ( param ) , native_stub , printTypes , first_parameter , mode ) ;
2005-02-15 06:05:36 -05:00
}
}
2010-01-04 13:47:49 -05:00
CachedResult cached_result_annotation = method . getAnnotation ( CachedResult . class ) ;
2005-02-15 06:05:36 -05:00
TypeMirror result_type = Utils . getMethodReturnType ( method ) ;
2005-02-16 11:04:29 -05:00
if ( ( native_stub & & Utils . getNIOBufferType ( result_type ) ! = null ) | | Utils . needResultSize ( method ) ) {
2010-09-26 19:43:24 -04:00
AutoSize auto_size_annotation = method . getAnnotation ( AutoSize . class ) ;
if ( auto_size_annotation = = null | | ! auto_size_annotation . isNative ( ) ) {
if ( cached_result_annotation = = null | | ! cached_result_annotation . isRange ( ) ) {
if ( ! first_parameter )
writer . print ( " , " ) ;
first_parameter = false ;
if ( printTypes )
writer . print ( " long " ) ;
writer . print ( Utils . RESULT_SIZE_NAME ) ;
}
2010-01-04 13:47:49 -05:00
}
2006-12-20 14:19:56 -05:00
}
2010-01-04 13:47:49 -05:00
if ( cached_result_annotation ! = null ) {
2006-12-20 14:19:56 -05:00
if ( ! first_parameter )
2005-02-15 06:05:36 -05:00
writer . print ( " , " ) ;
2010-01-04 13:47:49 -05:00
2010-09-26 19:43:24 -04:00
if ( mode = = Mode . CACHEDRESULT ) {
if ( printTypes )
writer . print ( " long " ) ;
writer . print ( Utils . CACHED_BUFFER_LENGTH_NAME + " , " ) ;
}
2010-01-04 13:47:49 -05:00
2006-12-20 14:19:56 -05:00
first_parameter = false ;
2010-09-26 19:43:24 -04:00
if ( printTypes )
writer . print ( getResultType ( method , native_stub ) ) ;
2006-12-20 14:19:56 -05:00
writer . print ( " " + Utils . CACHED_BUFFER_NAME ) ;
2005-02-15 06:05:36 -05:00
}
2005-02-16 11:04:29 -05:00
return first_parameter ;
2005-02-15 06:05:36 -05:00
}
2010-09-26 19:43:24 -04:00
private static boolean generateParameterJava ( PrintWriter writer , ParameterDeclaration param , TypeInfo type_info , boolean native_stub , final boolean printTypes , boolean first_parameter , Mode mode ) {
2005-02-15 06:05:36 -05:00
Class buffer_type = Utils . getNIOBufferType ( param . getType ( ) ) ;
if ( ! first_parameter )
writer . print ( " , " ) ;
BufferObject bo_annotation = param . getAnnotation ( BufferObject . class ) ;
if ( bo_annotation ! = null & & mode = = Mode . BUFFEROBJECT ) {
if ( buffer_type = = null )
throw new RuntimeException ( " type of " + param + " is not a nio Buffer parameter but is annotated as buffer object " ) ;
2010-09-26 19:43:24 -04:00
if ( printTypes )
writer . print ( " long " ) ;
writer . print ( param . getSimpleName ( ) + Utils . BUFFER_OBJECT_PARAMETER_POSTFIX ) ;
2005-02-15 06:05:36 -05:00
} else {
2010-09-26 19:43:24 -04:00
if ( native_stub & & param . getAnnotation ( PointerWrapper . class ) ! = null )
writer . print ( " long " ) ;
2010-03-12 16:55:13 -05:00
else {
Class type = type_info . getType ( ) ;
2011-07-16 12:05:37 -04:00
if ( native_stub & & ( type = = CharSequence . class | | type = = CharSequence [ ] . class | | type = = PointerBuffer . class | | Buffer . class . isAssignableFrom ( type ) ) )
writer . print ( " long " ) ;
2010-09-26 19:43:24 -04:00
else if ( printTypes )
writer . print ( type_info . getType ( ) . getSimpleName ( ) + " " ) ;
2010-03-12 16:55:13 -05:00
}
2010-09-26 19:43:24 -04:00
AutoSize auto_size_annotation = param . getAnnotation ( AutoSize . class ) ;
if ( auto_size_annotation ! = null )
writer . print ( auto_size_annotation . value ( ) + " _ " ) ;
writer . print ( param . getSimpleName ( ) ) ;
2005-02-15 06:05:36 -05:00
}
return false ;
}
2011-05-17 12:53:57 -04:00
private static void printBufferObjectCheck ( PrintWriter writer , BufferKind kind , Mode mode , boolean context_specific ) {
2005-02-15 06:05:36 -05:00
String bo_check_method_name = kind . toString ( ) ;
2005-03-21 03:27:45 -05:00
writer . print ( " \ t \ t " + Utils . CHECKS_CLASS_NAME + " .ensure " + bo_check_method_name ) ;
2005-02-15 06:05:36 -05:00
if ( mode = = Mode . BUFFEROBJECT )
writer . print ( " enabled " ) ;
else
writer . print ( " disabled " ) ;
2011-05-17 12:53:57 -04:00
if ( context_specific )
writer . println ( " (caps); " ) ;
else
writer . println ( " (); " ) ;
2005-02-15 06:05:36 -05:00
}
2011-05-17 12:53:57 -04:00
private static void printBufferObjectChecks ( PrintWriter writer , MethodDeclaration method , Mode mode , boolean context_specific ) {
2005-02-15 06:05:36 -05:00
EnumSet < BufferKind > check_set = EnumSet . noneOf ( BufferKind . class ) ;
for ( ParameterDeclaration param : method . getParameters ( ) ) {
BufferObject bo_annotation = param . getAnnotation ( BufferObject . class ) ;
if ( bo_annotation ! = null )
check_set . add ( bo_annotation . value ( ) ) ;
}
for ( BufferKind kind : check_set )
2011-05-17 12:53:57 -04:00
printBufferObjectCheck ( writer , kind , mode , context_specific ) ;
2005-02-15 06:05:36 -05:00
}
2005-02-16 11:04:29 -05:00
private static void printMethodWithMultiType ( AnnotationProcessorEnvironment env , TypeMap type_map , PrintWriter writer , InterfaceDeclaration interface_decl , MethodDeclaration method , Map < ParameterDeclaration , TypeInfo > typeinfos_instance , Mode mode , boolean generate_error_checks , boolean context_specific ) {
2005-02-15 06:05:36 -05:00
Utils . printDocComment ( writer , method ) ;
2012-12-12 12:18:35 -05:00
if ( method . getAnnotation ( Deprecated . class ) ! = null )
writer . println ( " \ t@Deprecated " ) ;
2010-09-26 19:43:24 -04:00
if ( interface_decl . getAnnotation ( Private . class ) = = null & & method . getAnnotation ( Private . class ) = = null )
writer . print ( " \ tpublic static " ) ;
else
writer . print ( " \ tstatic " ) ;
writer . print ( getResultType ( method , false ) ) ;
2005-02-15 06:05:36 -05:00
StripPostfix strip_annotation = method . getAnnotation ( StripPostfix . class ) ;
2010-03-11 16:06:49 -05:00
String method_name ;
Alternate alt_annotation = method . getAnnotation ( Alternate . class ) ;
2010-03-23 08:43:44 -04:00
method_name = alt_annotation = = null | | alt_annotation . javaAlt ( ) ? method . getSimpleName ( ) : alt_annotation . value ( ) ;
2005-02-16 11:04:29 -05:00
if ( strip_annotation ! = null & & mode = = Mode . NORMAL )
method_name = getPostfixStrippedName ( type_map , interface_decl , method ) ;
2005-02-15 06:05:36 -05:00
writer . print ( " " + method_name + " ( " ) ;
2010-09-26 19:43:24 -04:00
generateParametersJava ( writer , method , typeinfos_instance , false , true , mode ) ;
2005-02-15 06:05:36 -05:00
writer . println ( " ) { " ) ;
2010-09-26 19:43:24 -04:00
final TypeMirror result_type = Utils . getMethodReturnType ( method ) ;
boolean has_result = ! result_type . equals ( env . getTypeUtils ( ) . getVoidType ( ) ) ;
final Reuse reuse_annotation = method . getAnnotation ( Reuse . class ) ;
if ( reuse_annotation ! = null ) {
writer . print ( " \ t \ t " ) ;
if ( has_result | | method . getAnnotation ( GLreturn . class ) ! = null )
writer . print ( " return " ) ;
2012-08-19 02:56:25 -04:00
writer . print ( reuse_annotation . value ( ) + " . " + ( reuse_annotation . method ( ) . length ( ) > 0 ? reuse_annotation . method ( ) : method_name ) + " ( " ) ;
2010-09-26 19:43:24 -04:00
generateParametersJava ( writer , method , typeinfos_instance , false , false , mode ) ;
writer . println ( " ); \ n \ t} " ) ;
return ;
}
2005-02-16 11:04:29 -05:00
if ( context_specific ) {
2010-09-26 19:43:24 -04:00
type_map . printCapabilitiesInit ( writer ) ;
writer . print ( " \ t \ tlong " + Utils . FUNCTION_POINTER_VAR_NAME + " = " + type_map . getCapabilities ( ) + " . " ) ;
2010-03-12 16:55:13 -05:00
writer . println ( Utils . getFunctionAddressName ( interface_decl , method , true ) + " ; " ) ;
2005-02-16 11:04:29 -05:00
writer . print ( " \ t \ tBufferChecks.checkFunctionAddress( " ) ;
writer . println ( Utils . FUNCTION_POINTER_VAR_NAME + " ); " ) ;
}
2010-09-26 19:43:24 -04:00
final Code code_annotation = method . getAnnotation ( Code . class ) ;
if ( code_annotation ! = null & & code_annotation . value ( ) . length ( ) > 0 )
2006-11-19 08:33:45 -05:00
writer . println ( code_annotation . value ( ) ) ;
2011-05-17 12:53:57 -04:00
printBufferObjectChecks ( writer , method , mode , context_specific ) ;
2010-09-26 19:43:24 -04:00
printParameterChecks ( writer , method , typeinfos_instance , mode , generate_error_checks ) ;
2011-05-17 12:53:57 -04:00
printParameterCaching ( writer , interface_decl , method , mode , context_specific ) ;
2010-09-26 19:43:24 -04:00
if ( code_annotation ! = null & & code_annotation . javaBeforeNative ( ) . length ( ) > 0 )
writer . println ( code_annotation . javaBeforeNative ( ) ) ;
2005-02-15 06:05:36 -05:00
writer . print ( " \ t \ t " ) ;
2010-09-26 19:43:24 -04:00
final PointerWrapper pointer_wrapper_annotation = method . getAnnotation ( PointerWrapper . class ) ;
2005-02-15 06:05:36 -05:00
if ( has_result ) {
2010-09-26 19:43:24 -04:00
writer . print ( getResultType ( method , false ) + " " + Utils . RESULT_VAR_NAME ) ;
2009-08-12 09:06:11 -04:00
2010-09-26 19:43:24 -04:00
if ( code_annotation ! = null & & code_annotation . tryBlock ( ) ) {
writer . print ( " = " + getDefaultResultValue ( method ) ) ;
writer . println ( " ; \ n \ t \ ttry { " ) ;
writer . print ( " \ t \ t \ t " + Utils . RESULT_VAR_NAME ) ;
}
writer . print ( " = " ) ;
if ( pointer_wrapper_annotation ! = null ) {
if ( pointer_wrapper_annotation . factory ( ) . length ( ) > 0 )
writer . print ( pointer_wrapper_annotation . factory ( ) + " ( " ) ;
else
writer . print ( " new " + getResultType ( method , false ) + " ( " ) ;
}
} else if ( method . getAnnotation ( GLreturn . class ) ! = null ) {
2010-03-12 16:55:13 -05:00
has_result = true ;
2011-07-16 18:26:46 -04:00
Utils . printGLReturnPre ( writer , method , method . getAnnotation ( GLreturn . class ) , type_map ) ;
2010-03-12 16:55:13 -05:00
}
2005-02-16 11:04:29 -05:00
writer . print ( Utils . getSimpleNativeMethodName ( method , generate_error_checks , context_specific ) ) ;
2005-02-15 06:05:36 -05:00
if ( mode = = Mode . BUFFEROBJECT )
writer . print ( Utils . BUFFER_OBJECT_METHOD_POSTFIX ) ;
writer . print ( " ( " ) ;
2011-07-16 18:26:46 -04:00
boolean first_parameter = printMethodCallArguments ( writer , method , typeinfos_instance , mode , type_map ) ;
2005-02-16 11:04:29 -05:00
if ( context_specific ) {
if ( ! first_parameter )
writer . print ( " , " ) ;
writer . print ( Utils . FUNCTION_POINTER_VAR_NAME ) ;
}
2010-09-26 19:43:24 -04:00
if ( has_result & & pointer_wrapper_annotation ! = null ) {
2009-08-12 09:06:11 -04:00
writer . print ( " ) " ) ;
2010-09-26 19:43:24 -04:00
if ( pointer_wrapper_annotation . params ( ) . length ( ) > 0 )
writer . print ( " , " + pointer_wrapper_annotation . params ( ) ) ;
}
2005-02-15 06:05:36 -05:00
writer . println ( " ); " ) ;
2010-09-26 19:43:24 -04:00
if ( code_annotation ! = null & & code_annotation . javaAfterNative ( ) . length ( ) > 0 )
writer . println ( code_annotation . javaAfterNative ( ) ) ;
final String tabs = code_annotation ! = null & & code_annotation . tryBlock ( ) ? " \ t \ t \ t " : " \ t \ t " ;
2005-02-15 06:05:36 -05:00
if ( generate_error_checks & & method . getAnnotation ( NoErrorCheck . class ) = = null )
2010-09-26 19:43:24 -04:00
type_map . printErrorCheckMethod ( writer , method , tabs ) ;
2010-01-31 11:40:51 -05:00
// DISABLED: indirect buffer support
//printNondirectParameterCopies(writer, method, mode);
2010-03-12 16:55:13 -05:00
if ( has_result ) {
2010-04-22 19:21:48 -04:00
if ( method . getAnnotation ( GLreturn . class ) = = null ) {
if ( ByteBuffer . class . equals ( Utils . getJavaType ( result_type ) ) )
2010-09-26 19:43:24 -04:00
writer . println ( tabs + " return LWJGLUtil.CHECKS && " + Utils . RESULT_VAR_NAME + " == null ? null : " + Utils . RESULT_VAR_NAME + " .order(ByteOrder.nativeOrder()); " ) ; // safeNewBuffer returns a direct ByteBuffer with BIG_ENDIAN order.
2010-04-22 19:21:48 -04:00
else
2010-09-26 19:43:24 -04:00
writer . println ( tabs + " return " + Utils . RESULT_VAR_NAME + " ; " ) ;
2010-04-22 19:21:48 -04:00
} else
2011-07-16 18:26:46 -04:00
Utils . printGLReturnPost ( writer , method , method . getAnnotation ( GLreturn . class ) , type_map ) ;
2010-03-12 16:55:13 -05:00
}
2010-09-26 19:43:24 -04:00
if ( code_annotation ! = null & & code_annotation . tryBlock ( ) ) {
writer . println ( " \ t \ t} finally { " ) ;
writer . println ( code_annotation . javaFinally ( ) ) ;
writer . println ( " \ t \ t} " ) ;
}
2005-02-15 06:05:36 -05:00
writer . println ( " \ t} " ) ;
}
private static String getExtensionPostfix ( InterfaceDeclaration interface_decl ) {
String interface_simple_name = interface_decl . getSimpleName ( ) ;
Extension extension_annotation = interface_decl . getAnnotation ( Extension . class ) ;
if ( extension_annotation = = null ) {
int underscore_index = interface_simple_name . indexOf ( " _ " ) ;
if ( underscore_index ! = - 1 )
return interface_simple_name . substring ( 0 , underscore_index ) ;
else
return " " ;
} else
return extension_annotation . postfix ( ) ;
}
private static ParameterDeclaration getAutoTypeParameter ( MethodDeclaration method , ParameterDeclaration target_parameter ) {
for ( ParameterDeclaration param : method . getParameters ( ) ) {
AnnotationMirror auto_annotation = Utils . getParameterAutoAnnotation ( param ) ;
if ( auto_annotation ! = null ) {
Class annotation_type = NativeTypeTranslator . getClassFromType ( auto_annotation . getAnnotationType ( ) ) ;
String parameter_name ;
if ( annotation_type . equals ( AutoType . class ) )
parameter_name = param . getAnnotation ( AutoType . class ) . value ( ) ;
else if ( annotation_type . equals ( AutoSize . class ) )
parameter_name = param . getAnnotation ( AutoSize . class ) . value ( ) ;
else
2010-09-26 19:43:24 -04:00
throw new RuntimeException ( " Unknown annotation type " + annotation_type ) ;
2005-02-15 06:05:36 -05:00
if ( target_parameter . getSimpleName ( ) . equals ( parameter_name ) )
return param ;
}
}
return null ;
}
2005-02-15 12:13:05 -05:00
2005-02-15 06:05:36 -05:00
private static boolean hasAnyParameterAutoTypeAnnotation ( MethodDeclaration method , ParameterDeclaration target_param ) {
for ( ParameterDeclaration param : method . getParameters ( ) ) {
AutoType auto_type_annotation = param . getAnnotation ( AutoType . class ) ;
if ( auto_type_annotation ! = null ) {
ParameterDeclaration type_target_param = Utils . findParameter ( method , auto_type_annotation . value ( ) ) ;
if ( target_param . equals ( type_target_param ) )
return true ;
}
}
return false ;
}
2014-08-16 08:39:04 -04:00
private static final Map < String , Pattern > postfixPatterns = new HashMap < String , Pattern > ( ) ;
private static Pattern getPostfixPattern ( String regex ) {
Pattern pattern = postfixPatterns . get ( regex ) ;
if ( pattern = = null )
postfixPatterns . put ( regex , pattern = Pattern . compile ( regex ) ) ;
return pattern ;
}
2005-02-15 06:05:36 -05:00
private static String getPostfixStrippedName ( TypeMap type_map , InterfaceDeclaration interface_decl , MethodDeclaration method ) {
StripPostfix strip_annotation = method . getAnnotation ( StripPostfix . class ) ;
ParameterDeclaration postfix_parameter = Utils . findParameter ( method , strip_annotation . value ( ) ) ;
2009-11-30 22:37:27 -05:00
String postfix = strip_annotation . postfix ( ) ;
2014-08-16 08:39:04 -04:00
boolean postfixOverride = ! ( " NULL " . equals ( postfix ) & & strip_annotation . hasPostfix ( ) ) ;
if ( ! postfixOverride ) {
2009-11-30 22:37:27 -05:00
PostfixTranslator translator = new PostfixTranslator ( type_map , postfix_parameter ) ;
postfix_parameter . getType ( ) . accept ( translator ) ;
postfix = translator . getSignature ( ) ;
2014-08-16 08:39:04 -04:00
} else if ( ! strip_annotation . hasPostfix ( ) )
postfix = " " ;
2010-03-11 16:06:49 -05:00
String method_name ;
Alternate alt_annotation = method . getAnnotation ( Alternate . class ) ;
2010-03-23 08:43:44 -04:00
method_name = alt_annotation = = null | | alt_annotation . javaAlt ( ) ? method . getSimpleName ( ) : alt_annotation . value ( ) ;
2010-03-11 16:06:49 -05:00
2009-03-26 07:08:43 -04:00
String extension_postfix = " NULL " . equals ( strip_annotation . extension ( ) ) ? getExtensionPostfix ( interface_decl ) : strip_annotation . extension ( ) ;
2009-11-30 22:37:27 -05:00
2014-08-16 08:39:04 -04:00
Matcher matcher = getPostfixPattern (
postfixOverride
? ( postfix + " (?:v)? " + extension_postfix + " $ " )
: ( " (?: " + postfix + " (?:v)?|i(?:64)?_v|v) " + extension_postfix + " $ " )
) . matcher ( method_name ) ;
if ( ! matcher . find ( ) )
throw new RuntimeException ( method_name + " is specified as being postfix stripped on parameter " + postfix_parameter + " , but it's postfix is neither ' " + postfix + " ' nor 'v' " ) ;
return method_name . substring ( 0 , matcher . start ( ) ) + extension_postfix ;
2005-02-15 06:05:36 -05:00
}
private static int getBufferElementSizeExponent ( Class c ) {
if ( IntBuffer . class . equals ( c ) )
return 2 ;
else if ( LongBuffer . class . equals ( c ) )
return 3 ;
else if ( DoubleBuffer . class . equals ( c ) )
return 3 ;
else if ( ShortBuffer . class . equals ( c ) )
return 1 ;
else if ( ByteBuffer . class . equals ( c ) )
return 0 ;
else if ( FloatBuffer . class . equals ( c ) )
return 2 ;
else
throw new RuntimeException ( c + " is not allowed " ) ;
}
2011-07-16 18:26:46 -04:00
private static boolean printMethodCallArgument ( PrintWriter writer , MethodDeclaration method , ParameterDeclaration param , Map < ParameterDeclaration , TypeInfo > typeinfos_instance , Mode mode , boolean first_parameter , TypeMap type_map ) {
2005-02-15 06:05:36 -05:00
if ( ! first_parameter )
writer . print ( " , " ) ;
2010-09-26 19:43:24 -04:00
2005-02-15 06:05:36 -05:00
AnnotationMirror auto_annotation = Utils . getParameterAutoAnnotation ( param ) ;
Constant constant_annotation = param . getAnnotation ( Constant . class ) ;
if ( constant_annotation ! = null ) {
writer . print ( constant_annotation . value ( ) ) ;
} else if ( auto_annotation ! = null & & mode = = Mode . NORMAL ) {
Class param_type = NativeTypeTranslator . getClassFromType ( auto_annotation . getAnnotationType ( ) ) ;
if ( AutoType . class . equals ( param_type ) ) {
2010-09-26 19:43:24 -04:00
final AutoType auto_type_annotation = param . getAnnotation ( AutoType . class ) ;
final ParameterDeclaration auto_parameter = Utils . findParameter ( method , auto_type_annotation . value ( ) ) ;
final String auto_type = typeinfos_instance . get ( auto_parameter ) . getAutoType ( ) ;
if ( auto_type = = null )
2005-02-15 06:05:36 -05:00
throw new RuntimeException ( " No auto type for parameter " + param . getSimpleName ( ) + " in method " + method ) ;
writer . print ( auto_type ) ;
} else if ( AutoSize . class . equals ( param_type ) ) {
2010-09-26 19:43:24 -04:00
final AutoSize auto_size_annotation = param . getAnnotation ( AutoSize . class ) ;
2011-07-29 07:30:14 -04:00
if ( ! auto_size_annotation . useExpression ( ) ) {
final String auto_parameter_name = auto_size_annotation . value ( ) ;
final ParameterDeclaration auto_target_param = Utils . findParameter ( method , auto_parameter_name ) ;
final TypeInfo auto_target_type_info = typeinfos_instance . get ( auto_target_param ) ;
final boolean shift_remaining = ! hasAnyParameterAutoTypeAnnotation ( method , auto_target_param ) & & Utils . isParameterMultiTyped ( auto_target_param ) ;
int shifting = 0 ;
if ( shift_remaining ) {
shifting = getBufferElementSizeExponent ( auto_target_type_info . getType ( ) ) ;
if ( shifting > 0 )
writer . print ( " ( " ) ;
}
if ( auto_size_annotation . canBeNull ( ) )
writer . print ( " ( " + auto_parameter_name + " == null ? 0 : " + auto_parameter_name + " .remaining()) " ) ;
else
writer . print ( auto_parameter_name + " .remaining() " ) ;
// Shift the remaining if the target parameter is multityped and there's no AutoType to track type
if ( shift_remaining & & shifting > 0 ) {
writer . print ( " << " + shifting ) ;
writer . print ( " ) " ) ;
}
2005-02-15 06:05:36 -05:00
}
2010-09-26 19:43:24 -04:00
writer . print ( auto_size_annotation . expression ( ) ) ;
2005-02-15 06:05:36 -05:00
} else
throw new RuntimeException ( " Unknown auto annotation " + param_type ) ;
} else {
if ( mode = = Mode . BUFFEROBJECT & & param . getAnnotation ( BufferObject . class ) ! = null ) {
writer . print ( param . getSimpleName ( ) + Utils . BUFFER_OBJECT_PARAMETER_POSTFIX ) ;
} else {
2010-03-14 19:24:40 -04:00
Class type = typeinfos_instance . get ( param ) . getType ( ) ;
2010-09-26 19:43:24 -04:00
Check check_annotation = param . getAnnotation ( Check . class ) ;
2005-02-15 06:05:36 -05:00
boolean hide_buffer = mode = = Mode . AUTOS & & getAutoTypeParameter ( method , param ) ! = null ;
2010-09-26 19:43:24 -04:00
if ( hide_buffer ) {
2011-07-16 12:05:37 -04:00
writer . print ( " 0L " ) ;
2010-09-26 19:43:24 -04:00
} else {
2010-03-12 16:55:13 -05:00
if ( type = = CharSequence . class | | type = = CharSequence [ ] . class ) {
2010-03-14 19:24:40 -04:00
final String offset = Utils . getStringOffset ( method , param ) ;
2010-03-12 16:55:13 -05:00
2010-09-26 19:43:24 -04:00
writer . print ( " APIUtil.getBuffer " ) ;
2010-03-12 16:55:13 -05:00
if ( param . getAnnotation ( NullTerminated . class ) ! = null )
writer . print ( " NT " ) ;
2011-07-16 18:26:46 -04:00
writer . print ( '(' ) ;
writer . print ( type_map . getAPIUtilParam ( true ) ) ;
writer . print ( param . getSimpleName ( ) ) ;
2010-03-14 19:24:40 -04:00
if ( offset ! = null )
writer . print ( " , " + offset ) ;
2010-03-12 16:55:13 -05:00
writer . print ( " ) " ) ;
2010-09-26 19:43:24 -04:00
} else {
final AutoSize auto_size_annotation = param . getAnnotation ( AutoSize . class ) ;
if ( auto_size_annotation ! = null )
writer . print ( auto_size_annotation . value ( ) + " _ " ) ;
2011-07-16 12:05:37 -04:00
final Class buffer_type = Utils . getNIOBufferType ( param . getType ( ) ) ;
if ( buffer_type = = null )
writer . print ( param . getSimpleName ( ) ) ;
else {
writer . print ( " MemoryUtil.getAddress " ) ;
2010-09-26 19:43:24 -04:00
if ( check_annotation ! = null & & check_annotation . canBeNull ( ) )
2011-07-16 12:05:37 -04:00
writer . print ( " Safe " ) ;
writer . print ( " ( " ) ;
writer . print ( param . getSimpleName ( ) ) ;
writer . print ( " ) " ) ;
2010-09-26 19:43:24 -04:00
}
}
2010-03-12 16:55:13 -05:00
}
2011-07-16 12:05:37 -04:00
if ( type ! = long . class ) {
2010-09-26 19:43:24 -04:00
PointerWrapper pointer_annotation = param . getAnnotation ( PointerWrapper . class ) ;
2010-05-27 18:56:29 -04:00
if ( pointer_annotation ! = null ) {
if ( pointer_annotation . canBeNull ( ) )
writer . print ( " == null ? 0 : " + param . getSimpleName ( ) ) ;
writer . print ( " .getPointer() " ) ;
}
2005-02-15 06:05:36 -05:00
}
}
}
return false ;
}
2011-07-16 18:26:46 -04:00
private static boolean printMethodCallArguments ( PrintWriter writer , MethodDeclaration method , Map < ParameterDeclaration , TypeInfo > typeinfos_instance , Mode mode , TypeMap type_map ) {
2005-02-15 06:05:36 -05:00
boolean first_parameter = true ;
2010-09-26 19:43:24 -04:00
for ( ParameterDeclaration param : method . getParameters ( ) ) {
2010-09-28 17:11:35 -04:00
if ( param . getAnnotation ( Result . class ) ! = null | | ( param . getAnnotation ( Helper . class ) ! = null & & ! param . getAnnotation ( Helper . class ) . passToNative ( ) ) )
2010-09-26 19:43:24 -04:00
continue ;
final Constant constant_annotation = param . getAnnotation ( Constant . class ) ;
if ( constant_annotation = = null | | ! constant_annotation . isNative ( ) )
2011-07-16 18:26:46 -04:00
first_parameter = printMethodCallArgument ( writer , method , param , typeinfos_instance , mode , first_parameter , type_map ) ;
2010-09-26 19:43:24 -04:00
}
2005-02-16 11:04:29 -05:00
if ( Utils . getNIOBufferType ( Utils . getMethodReturnType ( method ) ) ! = null ) {
2010-01-04 13:47:49 -05:00
if ( method . getAnnotation ( CachedResult . class ) ! = null & & method . getAnnotation ( CachedResult . class ) . isRange ( ) ) {
first_parameter = false ;
Utils . printExtraCallArguments ( writer , method , " " ) ;
} else {
2010-09-26 19:43:24 -04:00
AutoSize auto_size_annotation = method . getAnnotation ( AutoSize . class ) ;
if ( auto_size_annotation = = null | | ! auto_size_annotation . isNative ( ) ) {
if ( ! first_parameter )
writer . print ( " , " ) ;
first_parameter = false ;
String result_size_expression ;
if ( mode = = Mode . CACHEDRESULT )
result_size_expression = Utils . CACHED_BUFFER_LENGTH_NAME ;
else if ( auto_size_annotation = = null )
2010-01-04 13:47:49 -05:00
result_size_expression = Utils . RESULT_SIZE_NAME ;
else
2010-09-26 19:43:24 -04:00
result_size_expression = auto_size_annotation . value ( ) ;
Utils . printExtraCallArguments ( writer , method , result_size_expression ) ;
2010-01-04 13:47:49 -05:00
}
}
2005-02-15 06:05:36 -05:00
}
2005-02-16 11:04:29 -05:00
return first_parameter ;
2005-02-15 06:05:36 -05:00
}
2011-05-17 12:53:57 -04:00
private static void printParameterCaching ( PrintWriter writer , InterfaceDeclaration interface_decl , MethodDeclaration method , Mode mode , boolean context_specific ) {
2005-03-21 03:27:45 -05:00
for ( ParameterDeclaration param : method . getParameters ( ) ) {
Class java_type = Utils . getJavaType ( param . getType ( ) ) ;
2007-05-22 18:30:21 -04:00
CachedReference cachedReference = param . getAnnotation ( CachedReference . class ) ;
2005-03-21 03:27:45 -05:00
if ( Buffer . class . isAssignableFrom ( java_type ) & &
2007-05-22 18:30:21 -04:00
cachedReference ! = null & &
2005-03-21 03:27:45 -05:00
( mode ! = Mode . BUFFEROBJECT | | param . getAnnotation ( BufferObject . class ) = = null ) & &
param . getAnnotation ( Result . class ) = = null ) {
2011-05-17 12:53:57 -04:00
writer . print ( " \ t \ tif ( LWJGLUtil.CHECKS ) StateTracker. " ) ;
if ( context_specific )
writer . print ( " getReferences(caps). " ) ;
else
writer . print ( " getTracker(). " ) ;
2007-05-22 18:30:21 -04:00
if ( cachedReference . name ( ) . length ( ) > 0 ) {
writer . print ( cachedReference . name ( ) ) ;
} else {
writer . print ( Utils . getReferenceName ( interface_decl , method , param ) ) ;
}
if ( cachedReference . index ( ) . length ( ) > 0 ) {
writer . print ( " [ " + cachedReference . index ( ) + " ] " ) ;
}
writer . println ( " = " + param . getSimpleName ( ) + " ; " ) ;
2005-03-21 03:27:45 -05:00
}
}
}
2010-09-26 19:43:24 -04:00
private static void printParameterChecks ( PrintWriter writer , MethodDeclaration method , Map < ParameterDeclaration , TypeInfo > typeinfos , Mode mode , final boolean generate_error_checks ) {
if ( mode = = Mode . NORMAL ) {
final GenerateAutos gen_autos_annotation = method . getAnnotation ( GenerateAutos . class ) ;
if ( gen_autos_annotation ! = null & & gen_autos_annotation . sizeVariables ( ) . length > 0 ) {
// For the auto-generated parameters, declare and init a size variable (that can be reused by @Code)
for ( final ParameterDeclaration param : method . getParameters ( ) ) {
if ( Arrays . binarySearch ( gen_autos_annotation . sizeVariables ( ) , param . getSimpleName ( ) ) > = 0 ) {
final int shifting = getBufferElementSizeExponent ( typeinfos . get ( param ) . getType ( ) ) ;
final Check check_annotation = param . getAnnotation ( Check . class ) ;
writer . print ( " \ t \ tlong " + param . getSimpleName ( ) + " _size = " ) ;
if ( check_annotation = = null | | ! check_annotation . canBeNull ( ) )
writer . println ( param . getSimpleName ( ) + " .remaining() << " + shifting + " ; " ) ;
else
writer . println ( param . getSimpleName ( ) + " == null ? 0 : " + param . getSimpleName ( ) + " .remaining() << " + shifting + " ; " ) ;
}
}
}
}
2005-02-15 06:05:36 -05:00
for ( ParameterDeclaration param : method . getParameters ( ) ) {
Class java_type = Utils . getJavaType ( param . getType ( ) ) ;
2010-09-26 19:43:24 -04:00
if ( java_type . isArray ( ) | | ( Utils . isAddressableType ( java_type ) & &
2005-02-15 06:05:36 -05:00
( mode ! = Mode . BUFFEROBJECT | | param . getAnnotation ( BufferObject . class ) = = null ) & &
( mode ! = Mode . AUTOS | | getAutoTypeParameter ( method , param ) = = null ) & &
2010-03-12 16:55:13 -05:00
param . getAnnotation ( Result . class ) = = null & &
2010-09-26 19:43:24 -04:00
! Utils . isReturnParameter ( method , param ) ) ) {
2005-02-15 06:05:36 -05:00
String check_value = null ;
boolean can_be_null = false ;
Check check_annotation = param . getAnnotation ( Check . class ) ;
if ( check_annotation ! = null ) {
check_value = check_annotation . value ( ) ;
can_be_null = check_annotation . canBeNull ( ) ;
}
2010-09-26 19:43:24 -04:00
if ( ( Buffer . class . isAssignableFrom ( java_type ) | | PointerBuffer . class . isAssignableFrom ( java_type ) ) & & param . getAnnotation ( Constant . class ) = = null ) {
2007-04-23 16:17:42 -04:00
boolean out_parameter = param . getAnnotation ( OutParameter . class ) ! = null ;
TypeInfo typeinfo = typeinfos . get ( param ) ;
2013-10-30 11:20:28 -04:00
printParameterCheck ( writer , method , param . getSimpleName ( ) , typeinfo . getType ( ) . getSimpleName ( ) , check_value , can_be_null , param . getAnnotation ( NullTerminated . class ) , out_parameter , generate_error_checks ) ;
2009-12-03 23:49:19 -05:00
} else if ( String . class . equals ( java_type ) ) {
2005-02-15 06:05:36 -05:00
if ( ! can_be_null )
writer . println ( " \ t \ tBufferChecks.checkNotNull( " + param . getSimpleName ( ) + " ); " ) ;
2010-09-26 19:43:24 -04:00
} else if ( java_type . isArray ( ) ) {
final TypeInfo typeinfo = typeinfos . get ( param ) ;
printArrayParameterCheck ( writer , param . getSimpleName ( ) , typeinfo . getType ( ) . getSimpleName ( ) , check_value , can_be_null ) ;
2005-02-15 06:05:36 -05:00
}
}
}
if ( method . getAnnotation ( CachedResult . class ) ! = null )
2013-10-30 11:20:28 -04:00
printParameterCheck ( writer , method , Utils . CACHED_BUFFER_NAME , null , null , true , null , false , generate_error_checks ) ;
2005-02-15 06:05:36 -05:00
}
2013-10-30 11:20:28 -04:00
private static void printParameterCheck ( PrintWriter writer , MethodDeclaration method , String name , String type , String check_value , boolean can_be_null , NullTerminated null_terminated , boolean out_parameter , boolean generate_error_checks ) {
2010-09-26 19:43:24 -04:00
String tabs ;
2007-04-15 15:43:35 -04:00
if ( can_be_null ) {
2010-09-26 19:43:24 -04:00
writer . print ( " \ t \ tif ( " + name + " != null) " ) ;
if ( null_terminated ! = null )
writer . println ( " { " ) ;
else
writer . println ( ) ;
tabs = " \ t \ t \ t " ;
} else
tabs = " \ t \ t " ;
2013-10-30 11:20:28 -04:00
writer . print ( tabs + " BufferChecks.check " ) ;
2010-09-26 19:43:24 -04:00
if ( check_value ! = null & & check_value . length ( ) > 0 ) {
writer . print ( " Buffer " ) ;
if ( " Buffer " . equals ( type ) )
writer . print ( " Size " ) ; // Check size only, Buffer.isDirect() was added in 1.6, cannot use yet. TODO: Remove?
writer . print ( " ( " + name + " , " + check_value ) ;
2005-02-15 06:05:36 -05:00
} else {
2007-04-15 15:43:35 -04:00
writer . print ( " Direct( " + name ) ;
2005-02-15 06:05:36 -05:00
}
writer . println ( " ); " ) ;
2010-09-26 19:43:24 -04:00
if ( can_be_null & & generate_error_checks ) {
final Check check_annotation = method . getAnnotation ( Check . class ) ;
if ( check_annotation ! = null & & check_annotation . value ( ) . equals ( name ) ) {
writer . println ( " \ t \ telse " ) ;
writer . println ( " \ t \ t \ t " + name + " = APIUtil.getBufferIntDebug(); " ) ; // Use an exclusive buffer here
}
}
2009-12-03 23:49:19 -05:00
if ( null_terminated ! = null ) {
2010-09-26 19:43:24 -04:00
writer . print ( tabs + " BufferChecks.checkNullTerminated( " ) ;
2009-12-03 23:49:19 -05:00
writer . print ( name ) ;
if ( null_terminated . value ( ) . length ( ) > 0 ) {
writer . print ( " , " ) ;
writer . print ( null_terminated . value ( ) ) ;
}
writer . println ( " ); " ) ;
2010-09-26 19:43:24 -04:00
if ( can_be_null )
writer . println ( " \ t \ t} " ) ;
2009-12-03 23:49:19 -05:00
}
2005-02-15 06:05:36 -05:00
}
2010-09-26 19:43:24 -04:00
private static void printArrayParameterCheck ( PrintWriter writer , String name , String type , String check_value , boolean can_be_null ) {
String tabs ;
if ( can_be_null ) {
writer . println ( " \ t \ tif ( " + name + " != null) " ) ;
tabs = " \ t \ t \ t " ;
} else
tabs = " \ t \ t " ;
writer . print ( tabs + " BufferChecks.checkArray( " + name ) ;
if ( check_value ! = null & & check_value . length ( ) > 0 )
writer . print ( " , " + check_value ) ;
writer . println ( " ); " ) ;
}
private static String getResultType ( MethodDeclaration method , boolean native_stub ) {
if ( native_stub & & method . getAnnotation ( PointerWrapper . class ) ! = null )
return " long " ;
2010-03-14 19:24:40 -04:00
else if ( ! native_stub & & method . getAnnotation ( GLreturn . class ) ! = null )
2010-09-26 19:43:24 -04:00
return Utils . getMethodReturnType ( method , method . getAnnotation ( GLreturn . class ) , false ) ;
2009-08-12 09:06:11 -04:00
else
2010-09-26 19:43:24 -04:00
return Utils . getJavaType ( Utils . getMethodReturnType ( method ) ) . getSimpleName ( ) ;
2005-02-15 06:05:36 -05:00
}
2010-09-26 19:43:24 -04:00
private static String getDefaultResultValue ( MethodDeclaration method ) {
if ( method . getAnnotation ( GLreturn . class ) ! = null ) {
final String type = Utils . getMethodReturnType ( method , method . getAnnotation ( GLreturn . class ) , false ) ;
if ( " boolean " . equals ( type ) )
return " false " ;
else if ( Character . isLowerCase ( type . charAt ( 0 ) ) )
return " 0 " ;
else
return " null " ;
} else {
final Class type = Utils . getJavaType ( Utils . getMethodReturnType ( method ) ) ;
if ( type . isPrimitive ( ) ) {
if ( type = = boolean . class )
return " false " ;
else
return " 0 " ;
} else
return " null " ;
}
}
2005-02-15 06:05:36 -05:00
}