Automatic code reformatting.

Nothing to see here, just a cleanup so that subsequent commits are cleaner.
This commit is contained in:
Ioannis Tsakpinis 2014-09-14 17:16:51 +03:00
parent 774bd17ece
commit 59323ff03f
28 changed files with 3122 additions and 3176 deletions

View File

@ -46,23 +46,23 @@ public class FieldsGenerator {
private static void validateField(VariableElement field) {
// Check if field is "public static final"
Set<Modifier> modifiers = field.getModifiers();
if (modifiers.size() != 3
if ( modifiers.size() != 3
|| !modifiers.contains(Modifier.PUBLIC)
|| !modifiers.contains(Modifier.STATIC)
|| !modifiers.contains(Modifier.FINAL)) {
|| !modifiers.contains(Modifier.FINAL) ) {
throw new RuntimeException("Field " + field.getSimpleName() + " is not declared public static final");
}
// Check suported types (int, long, float, String)
TypeMirror field_type = field.asType();
if ("java.lang.String".equals(field_type.toString())) {
} else if (field_type instanceof PrimitiveType) {
PrimitiveType field_type_prim = (PrimitiveType) field_type;
if ( "java.lang.String".equals(field_type.toString()) ) {
} else if ( field_type instanceof PrimitiveType ) {
PrimitiveType field_type_prim = (PrimitiveType)field_type;
TypeKind field_kind = field_type_prim.getKind();
if (field_kind != TypeKind.INT
if ( field_kind != TypeKind.INT
&& field_kind != TypeKind.LONG
&& field_kind != TypeKind.FLOAT
&& field_kind != TypeKind.BYTE) {
&& field_kind != TypeKind.BYTE ) {
throw new RuntimeException("Field " + field.getSimpleName() + " is not of type 'int', 'long', 'float' or 'byte' " + field_kind.toString());
}
} else {
@ -70,7 +70,7 @@ public class FieldsGenerator {
}
Object field_value = field.getConstantValue();
if (field_value == null) {
if ( field_value == null ) {
throw new RuntimeException("Field " + field.getSimpleName() + " has no initial value");
}
}
@ -81,15 +81,15 @@ public class FieldsGenerator {
Object value = field.getConstantValue();
String field_value_string;
Class field_value_class = value.getClass();
if (field_value_class.equals(Integer.class)) {
field_value_string = "0x" + Integer.toHexString((Integer) field.getConstantValue()).toUpperCase();
} else if (field_value_class.equals(Long.class)) {
field_value_string = "0x" + Long.toHexString((Long) field.getConstantValue()).toUpperCase() + 'L';
} else if (field_value_class.equals(Float.class)) {
if ( field_value_class.equals(Integer.class) ) {
field_value_string = "0x" + Integer.toHexString((Integer)field.getConstantValue()).toUpperCase();
} else if ( field_value_class.equals(Long.class) ) {
field_value_string = "0x" + Long.toHexString((Long)field.getConstantValue()).toUpperCase() + 'L';
} else if ( field_value_class.equals(Float.class) ) {
field_value_string = field.getConstantValue() + "f";
} else if (value.getClass().equals(Byte.class)) {
field_value_string = "0x" + Integer.toHexString((Byte) field.getConstantValue()).toUpperCase();
} else if (field_value_class.equals(String.class)) {
} else if ( value.getClass().equals(Byte.class) ) {
field_value_string = "0x" + Integer.toHexString((Byte)field.getConstantValue()).toUpperCase();
} else if ( field_value_class.equals(String.class) ) {
field_value_string = "\"" + field.getConstantValue() + "\"";
} else {
throw new RuntimeException("Field is of unexpected type. This means there is a bug in validateField().");
@ -100,8 +100,8 @@ public class FieldsGenerator {
boolean newBatch = prev_field == null || !prev_field.asType().equals(field.asType()) || (!hadDoc && env.getElementUtils().getDocComment(field) != null) || (hadDoc && hasDoc && !env.getElementUtils().getDocComment(prev_field).equals(env.getElementUtils().getDocComment(field)));
// Print field declaration
if (newBatch) {
if (prev_field != null) {
if ( newBatch ) {
if ( prev_field != null ) {
writer.println(";\n");
}
@ -113,10 +113,10 @@ public class FieldsGenerator {
}
public static void generateFields(ProcessingEnvironment env, PrintWriter writer, Collection<? extends VariableElement> fields) {
if (0 < fields.size()) {
if ( 0 < fields.size() ) {
writer.println();
VariableElement prev_field = null;
for (VariableElement field : fields) {
for ( VariableElement field : fields ) {
generateField(writer, field, prev_field, env);
prev_field = field;
}

View File

@ -36,11 +36,7 @@ import java.io.FileFilter;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.annotation.processing.SupportedOptions;
import javax.annotation.processing.SupportedSourceVersion;
import javax.annotation.processing.*;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;
@ -54,16 +50,16 @@ import javax.tools.Diagnostic;
* @author elias_naur <elias_naur@users.sourceforge.net>
* @version $Revision$ $Id$
*/
@SupportedAnnotationTypes({"*"})
@SupportedAnnotationTypes({ "*" })
@SupportedSourceVersion(SourceVersion.RELEASE_7)
@SupportedOptions({"binpath", "typemap", "generatechecks", "contextspecific"})
@SupportedOptions({ "binpath", "typemap", "generatechecks", "contextspecific" })
public class GeneratorProcessor extends AbstractProcessor {
private static boolean first_round = true;
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
if (roundEnv.processingOver() || !first_round) {
if ( roundEnv.processingOver() || !first_round ) {
System.exit(0);
return true;
}
@ -72,11 +68,11 @@ public class GeneratorProcessor extends AbstractProcessor {
String bin_path = options.get("binpath");
boolean generate_error_checks = options.containsKey("generatechecks");
boolean context_specific = options.containsKey("contextspecific");
if (bin_path == null) {
if ( bin_path == null ) {
throw new RuntimeException("No path specified for the bin directory with -Abinpath=<path>");
}
if (typemap_classname == null) {
if ( typemap_classname == null ) {
throw new RuntimeException("No TypeMap class name specified with -Atypemap=<class-name>");
}
@ -84,15 +80,15 @@ public class GeneratorProcessor extends AbstractProcessor {
processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, "annotations " + annotations.toString());
try {
long generatorLM = getGeneratorLastModified(bin_path);
TypeMap type_map = (TypeMap) (Class.forName(typemap_classname).newInstance());
for (Iterator<TypeElement> it = ElementFilter.typesIn(roundEnv.getRootElements()).iterator(); it.hasNext();) {
TypeMap type_map = (TypeMap)(Class.forName(typemap_classname).newInstance());
for ( Iterator<TypeElement> it = ElementFilter.typesIn(roundEnv.getRootElements()).iterator(); it.hasNext(); ) {
lastFile = it.next();
lastFile.accept(new GeneratorVisitor(processingEnv, type_map, generate_error_checks, context_specific, generatorLM), null);
}
first_round = false;
return true;
} catch (ClassNotFoundException | IllegalAccessException | InstantiationException e) {
if (lastFile == null) {
if ( lastFile == null ) {
throw new RuntimeException(e);
} else {
throw new RuntimeException("\n-- Failed to process template: " + lastFile.asType().toString() + " --", e);
@ -116,7 +112,7 @@ public class GeneratorProcessor extends AbstractProcessor {
private static long getDirectoryLastModified(final String bin_path, final String path) {
final File pck = new File(bin_path + path);
if (!pck.exists() || !pck.isDirectory()) {
if ( !pck.exists() || !pck.isDirectory() ) {
return Long.MAX_VALUE;
}
@ -126,15 +122,15 @@ public class GeneratorProcessor extends AbstractProcessor {
}
});
if (classes == null || classes.length == 0) {
if ( classes == null || classes.length == 0 ) {
return Long.MAX_VALUE;
}
long lastModified = 0;
for (File clazz : classes) {
for ( File clazz : classes ) {
long lm = clazz.lastModified();
if (lastModified < lm) {
if ( lastModified < lm ) {
lastModified = lm;
}
}

View File

@ -31,19 +31,18 @@
*/
package org.lwjgl.util.generator;
import java.io.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.lang.annotation.Annotation;
import java.nio.*;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.util.*;
import java.util.Collection;
import java.util.List;
import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.ElementKind;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.Modifier;
import javax.lang.model.element.TypeElement;
import javax.lang.model.element.VariableElement;
import javax.lang.model.element.*;
import javax.lang.model.type.TypeKind;
import javax.lang.model.type.TypeMirror;
import javax.lang.model.util.ElementKindVisitor7;
@ -53,7 +52,6 @@ import javax.tools.FileObject;
import javax.tools.StandardLocation;
/**
*
* Generator visitor for the generator tool
*
* @author elias_naur <elias_naur@users.sourceforge.net>
@ -76,36 +74,36 @@ public class GeneratorVisitor extends ElementKindVisitor7<Void, Void> {
}
private void validateMethod(ExecutableElement method) {
if (method.isVarArgs()) {
if ( method.isVarArgs() ) {
throw new RuntimeException("Method " + method.getSimpleName() + " is variadic");
}
Collection<Modifier> modifiers = method.getModifiers();
if (!modifiers.contains(Modifier.PUBLIC)) {
if ( !modifiers.contains(Modifier.PUBLIC) ) {
throw new RuntimeException("Method " + method.getSimpleName() + " is not public");
}
if (method.getThrownTypes().size() > 0) {
if ( method.getThrownTypes().size() > 0 ) {
throw new RuntimeException("Method " + method.getSimpleName() + " throws checked exceptions");
}
validateParameters(method);
StripPostfix strip_annotation = method.getAnnotation(StripPostfix.class);
if (strip_annotation != null && method.getAnnotation(Alternate.class) == null) {
if ( strip_annotation != null && method.getAnnotation(Alternate.class) == null ) {
String postfix_param_name = strip_annotation.value();
VariableElement postfix_param = Utils.findParameter(method, postfix_param_name);
if (Utils.isParameterMultiTyped(postfix_param)) {
if ( Utils.isParameterMultiTyped(postfix_param) ) {
throw new RuntimeException("Postfix parameter can't be the same as a multityped parameter in method " + method);
}
if (Utils.getNIOBufferType(postfix_param.asType()) == null) {
if ( Utils.getNIOBufferType(postfix_param.asType()) == null ) {
throw new RuntimeException("Postfix parameter type must be a nio Buffer");
}
}
if (Utils.getResultParameter(method) != null && !method.getReturnType().equals(env.getTypeUtils().getNoType(TypeKind.VOID))) {
if ( Utils.getResultParameter(method) != null && !method.getReturnType().equals(env.getTypeUtils().getNoType(TypeKind.VOID)) ) {
throw new RuntimeException(method + " return type is not void but a parameter is annotated with Result");
}
if (method.getAnnotation(CachedResult.class) != null) {
if (Utils.getNIOBufferType(Utils.getMethodReturnType(method)) == null) {
if ( method.getAnnotation(CachedResult.class) != null ) {
if ( Utils.getNIOBufferType(Utils.getMethodReturnType(method)) == null ) {
throw new RuntimeException(method + " return type is not a Buffer, but is annotated with CachedResult");
}
if (method.getAnnotation(AutoSize.class) == null) {
if ( method.getAnnotation(AutoSize.class) == null ) {
throw new RuntimeException(method + " is annotated with CachedResult but misses an AutoSize annotation");
}
}
@ -114,8 +112,8 @@ public class GeneratorVisitor extends ElementKindVisitor7<Void, Void> {
private void validateType(ExecutableElement method, Class<? extends Annotation> annotation_type, Class type) {
Class[] valid_types = type_map.getValidAnnotationTypes(type);
for (Class valid_type : valid_types) {
if (valid_type.equals(annotation_type)) {
for ( Class valid_type : valid_types ) {
if ( valid_type.equals(annotation_type) ) {
return;
}
}
@ -124,12 +122,12 @@ public class GeneratorVisitor extends ElementKindVisitor7<Void, Void> {
}
private void validateTypes(ExecutableElement method, List<? extends AnnotationMirror> annotations, TypeMirror type_mirror) {
for (AnnotationMirror annotation : annotations) {
for ( AnnotationMirror annotation : annotations ) {
NativeType native_type_annotation = NativeTypeTranslator.getAnnotation(annotation, NativeType.class);
if (native_type_annotation != null) {
if ( native_type_annotation != null ) {
Class<? extends Annotation> annotation_type = NativeTypeTranslator.getClassFromType(annotation.getAnnotationType());
Class type = Utils.getJavaType(type_mirror);
if (Buffer.class.equals(type)) {
if ( Buffer.class.equals(type) ) {
continue;
}
validateType(method, annotation_type, type);
@ -138,43 +136,43 @@ public class GeneratorVisitor extends ElementKindVisitor7<Void, Void> {
}
private void validateParameters(ExecutableElement method) {
for (VariableElement param : method.getParameters()) {
for ( VariableElement param : method.getParameters() ) {
validateTypes(method, param.getAnnotationMirrors(), param.asType());
Class<?> param_type = Utils.getJavaType(param.asType());
if (Utils.getNIOBufferType(param.asType()) != null && param_type != CharSequence.class && param_type != CharSequence[].class) {
if ( Utils.getNIOBufferType(param.asType()) != null && param_type != CharSequence.class && param_type != CharSequence[].class ) {
Check parameter_check_annotation = param.getAnnotation(Check.class);
NullTerminated null_terminated_annotation = param.getAnnotation(NullTerminated.class);
if (parameter_check_annotation == null && null_terminated_annotation == null) {
if ( parameter_check_annotation == null && null_terminated_annotation == null ) {
boolean found_auto_size_param = false;
for (VariableElement inner_param : method.getParameters()) {
for ( VariableElement inner_param : method.getParameters() ) {
AutoSize auto_size_annotation = inner_param.getAnnotation(AutoSize.class);
if (auto_size_annotation != null
&& auto_size_annotation.value().equals(param.getSimpleName().toString())) {
if ( auto_size_annotation != null
&& auto_size_annotation.value().equals(param.getSimpleName().toString()) ) {
found_auto_size_param = true;
break;
}
}
if (!found_auto_size_param
if ( !found_auto_size_param
&& param.getAnnotation(Result.class) == null
&& param.getAnnotation(Constant.class) == null
&& !Utils.isReturnParameter(method, param)) {
&& !Utils.isReturnParameter(method, param) ) {
throw new RuntimeException(param + " has no Check, Result nor Constant annotation, is not the return parameter and no other parameter has"
+ " an @AutoSize annotation on it in method " + method);
}
}
if (param.getAnnotation(CachedReference.class) != null && param.getAnnotation(Result.class) != null) {
if ( param.getAnnotation(CachedReference.class) != null && param.getAnnotation(Result.class) != null ) {
throw new RuntimeException(param + " can't be annotated with both CachedReference and Result");
}
if (param.getAnnotation(BufferObject.class) != null && param.getAnnotation(Result.class) != null) {
if ( param.getAnnotation(BufferObject.class) != null && param.getAnnotation(Result.class) != null ) {
throw new RuntimeException(param + " can't be annotated with both BufferObject and Result");
}
//if (param.getAnnotation(Constant.class) != null)
//throw new RuntimeException("Buffer parameter " + param + " cannot be Constant");
} else {
if (param.getAnnotation(BufferObject.class) != null) {
if ( param.getAnnotation(BufferObject.class) != null ) {
throw new RuntimeException(param + " type is not a buffer, but annotated as a BufferObject");
}
if (param.getAnnotation(CachedReference.class) != null) {
if ( param.getAnnotation(CachedReference.class) != null ) {
throw new RuntimeException(param + " type is not a buffer, but annotated as a CachedReference");
}
}
@ -182,15 +180,15 @@ public class GeneratorVisitor extends ElementKindVisitor7<Void, Void> {
}
private static void generateMethodsNativePointers(PrintWriter writer, Collection<? extends ExecutableElement> methods) {
for (ExecutableElement method : methods) {
if (method.getAnnotation(Alternate.class) == null) {
for ( ExecutableElement method : methods ) {
if ( method.getAnnotation(Alternate.class) == null ) {
generateMethodNativePointers(writer, method);
}
}
}
private static void generateMethodNativePointers(PrintWriter writer, ExecutableElement method) {
if (method.getAnnotation(Extern.class) == null) {
if ( method.getAnnotation(Extern.class) == null ) {
writer.print("static ");
}
writer.println(Utils.getTypedefName(method) + " " + method.getSimpleName() + ";");
@ -204,37 +202,37 @@ public class GeneratorVisitor extends ElementKindVisitor7<Void, Void> {
java_writer.println("import org.lwjgl.*;");
java_writer.println("import java.nio.*;");
Imports imports = d.getAnnotation(Imports.class);
if (imports != null) {
for (String i : imports.value()) {
if ( imports != null ) {
for ( String i : imports.value() ) {
java_writer.println("import " + i + ";");
}
}
java_writer.println();
Utils.printDocComment(java_writer, d, env);
if (d.getAnnotation(Private.class) == null) {
if ( d.getAnnotation(Private.class) == null ) {
java_writer.print("public ");
}
boolean is_final = Utils.isFinal(d);
if (is_final) {
if ( is_final ) {
java_writer.write("final ");
}
java_writer.print("class " + Utils.getSimpleClassName(d));
List<? extends TypeMirror> super_interfaces = d.getInterfaces();
if (super_interfaces.size() > 1) {
if ( super_interfaces.size() > 1 ) {
throw new RuntimeException(d + " extends more than one interface");
}
if (super_interfaces.size() == 1) {
if ( super_interfaces.size() == 1 ) {
TypeMirror super_interface = super_interfaces.iterator().next();
java_writer.print(" extends " + Utils.getSimpleClassName(env.getElementUtils().getTypeElement(super_interface.toString())));
}
java_writer.println(" {");
FieldsGenerator.generateFields(env, java_writer, Utils.getFields(d));
java_writer.println();
if (is_final) {
if ( is_final ) {
// Write private constructor to avoid instantiation
java_writer.println("\tprivate " + Utils.getSimpleClassName(d) + "() {}");
}
if (Utils.getMethods(d).size() > 0 && !context_specific) {
if ( Utils.getMethods(d).size() > 0 && !context_specific ) {
java_writer.println();
java_writer.println("\tstatic native void " + Utils.STUB_INITIALIZER_NAME + "() throws LWJGLException;");
}
@ -246,7 +244,7 @@ public class GeneratorVisitor extends ElementKindVisitor7<Void, Void> {
}
private void generateNativeSource(TypeElement d) throws IOException {
if (d.getKind().equals(ElementKind.ANNOTATION_TYPE)) {
if ( d.getKind().equals(ElementKind.ANNOTATION_TYPE) ) {
return;
}
String qualified_interface_name = Utils.getQualifiedClassName(d);
@ -259,12 +257,12 @@ public class GeneratorVisitor extends ElementKindVisitor7<Void, Void> {
native_writer.println();
TypedefsGenerator.generateNativeTypedefs(type_map, native_writer, Utils.getMethods(d));
native_writer.println();
if (!context_specific) {
if ( !context_specific ) {
generateMethodsNativePointers(native_writer, Utils.getMethods(d));
native_writer.println();
}
NativeMethodStubsGenerator.generateNativeMethodStubs(env, type_map, native_writer, d, generate_error_checks, context_specific);
if (!context_specific) {
if ( !context_specific ) {
native_writer.print("JNIEXPORT void JNICALL " + Utils.getQualifiedNativeMethodName(qualified_interface_name, Utils.STUB_INITIALIZER_NAME));
native_writer.println("(JNIEnv *env, jclass clazz) {");
native_writer.println("\tJavaMethodAndExtFunction functions[] = {");
@ -285,26 +283,26 @@ public class GeneratorVisitor extends ElementKindVisitor7<Void, Void> {
PrintWriter java_writer = null;
try {
final Collection<? extends ExecutableElement> methods = Utils.getMethods(e);
if (methods.isEmpty() && Utils.getFields(e).isEmpty()) {
if ( methods.isEmpty() && Utils.getFields(e).isEmpty() ) {
return DEFAULT_VALUE;
}
env.getMessager().printMessage(Kind.NOTE, "methods count : " + Utils.getMethods(e).size() + " fields count : " + Utils.getFields(e).size(), e);
for (final ExecutableElement method : methods) {
for ( final ExecutableElement method : methods ) {
validateMethod(method);
}
java_writer = new PrintWriter(env.getFiler().createSourceFile(Utils.getQualifiedClassName(e), env.getElementUtils().getPackageOf(e)).openWriter());
generateJavaSource(e, java_writer);
if (methods.size() > 0) {
if ( methods.size() > 0 ) {
boolean noNative = true;
for (final ExecutableElement method : methods) {
for ( final ExecutableElement method : methods ) {
Alternate alt_annotation = method.getAnnotation(Alternate.class);
if ((alt_annotation == null || alt_annotation.nativeAlt()) && method.getAnnotation(Reuse.class) == null) {
if ( (alt_annotation == null || alt_annotation.nativeAlt()) && method.getAnnotation(Reuse.class) == null ) {
noNative = false;
break;
}
}
if (noNative) {
if ( noNative ) {
return DEFAULT_VALUE;
}
@ -318,18 +316,18 @@ public class GeneratorVisitor extends ElementKindVisitor7<Void, Void> {
outputBackup = new File(fo_outputBackup.toUri());
outputBackupExists = outputBackup.exists();
} catch (IOException ex) {
if (outputNative == null) {
if ( outputNative == null ) {
outputNativeExists = false;
}
if (outputBackup == null) {
if ( outputBackup == null ) {
outputBackupExists = false;
}
} finally {
// If the native file exists, rename.
final ByteBuffer nativeBefore;
if (outputNativeExists) {
if ( outputNativeExists ) {
nativeBefore = readFile(outputNative);
if (outputBackupExists) {
if ( outputBackupExists ) {
outputBackup.delete();
}
outputNative.renameTo(outputBackup);
@ -341,17 +339,17 @@ public class GeneratorVisitor extends ElementKindVisitor7<Void, Void> {
// If the native file did exist, compare with the new file. If they're the same,
// reset the last modified time to avoid ridiculous C compilation times.
if (nativeBefore != null && outputNative.length() == nativeBefore.capacity()) {
if ( nativeBefore != null && outputNative.length() == nativeBefore.capacity() ) {
final ByteBuffer nativeAfter = readFile(outputNative);
boolean same = true;
for (int i = nativeBefore.position(); i < nativeBefore.limit(); i++) {
if (nativeBefore.get(i) != nativeAfter.get(i)) {
for ( int i = nativeBefore.position(); i < nativeBefore.limit(); i++ ) {
if ( nativeBefore.get(i) != nativeAfter.get(i) ) {
same = false;
break;
}
}
if (same) {
if ( same ) {
outputNative.delete();
outputBackup.renameTo(outputNative);
}
@ -359,7 +357,7 @@ public class GeneratorVisitor extends ElementKindVisitor7<Void, Void> {
} catch (IOException ex) {
throw new RuntimeException(ex);
} finally {
if (outputBackup.exists()) {
if ( outputBackup.exists() ) {
outputBackup.delete();
}
}
@ -368,7 +366,7 @@ public class GeneratorVisitor extends ElementKindVisitor7<Void, Void> {
return DEFAULT_VALUE;
} catch (Exception ex) {
// If anything goes wrong mid-gen, delete output to allow regen next time we run.
if (java_writer != null) {
if ( java_writer != null ) {
java_writer.close();
}
throw new RuntimeException(ex);
@ -379,12 +377,12 @@ public class GeneratorVisitor extends ElementKindVisitor7<Void, Void> {
final FileChannel channel = new FileInputStream(file).getChannel();
final long bytesTotal = channel.size();
final ByteBuffer buffer = ByteBuffer.allocateDirect((int) bytesTotal);
final ByteBuffer buffer = ByteBuffer.allocateDirect((int)bytesTotal);
long bytesRead = 0;
do {
bytesRead += channel.read(buffer);
} while (bytesRead < bytesTotal);
} while ( bytesRead < bytesTotal );
buffer.flip();
channel.close();

View File

@ -32,16 +32,16 @@
package org.lwjgl.util.generator;
import org.lwjgl.PointerBuffer;
import java.nio.Buffer;
import javax.lang.model.type.ArrayType;
import javax.lang.model.type.DeclaredType;
import javax.lang.model.type.NoType;
import javax.lang.model.type.PrimitiveType;
import javax.lang.model.util.SimpleTypeVisitor6;
import org.lwjgl.PointerBuffer;
/**
*
* A TypeVisitor that translates TypeMirrors to JNI
* type strings.
*
@ -88,7 +88,7 @@ public class JNITypeTranslator extends SimpleTypeVisitor6<Void, Void> {
@Override
public Void visitDeclared(DeclaredType t, Void o) {
if(t.asElement().getKind().isClass())
if ( t.asElement().getKind().isClass() )
visitClassType(t);
return DEFAULT_VALUE;
}
@ -96,7 +96,7 @@ public class JNITypeTranslator extends SimpleTypeVisitor6<Void, Void> {
@Override
public Void visitPrimitive(PrimitiveType t, Void o) {
String type;
switch (t.getKind()) {
switch ( t.getKind() ) {
case LONG:
type = "jlong";
break;

View File

@ -38,7 +38,10 @@ package org.lwjgl.util.generator;
* @author elias_naur <elias_naur@users.sourceforge.net>
* @version $Revision$ $Id$
*/
import java.io.*;
import org.lwjgl.PointerBuffer;
import org.lwjgl.util.generator.opengl.GLreturn;
import java.io.PrintWriter;
import java.nio.*;
import java.util.*;
import java.util.regex.Matcher;
@ -50,53 +53,49 @@ import javax.lang.model.element.TypeElement;
import javax.lang.model.element.VariableElement;
import javax.lang.model.type.TypeKind;
import javax.lang.model.type.TypeMirror;
import javax.tools.Diagnostic;
import org.lwjgl.PointerBuffer;
import org.lwjgl.util.generator.opengl.GLreturn;
public class JavaMethodsGenerator {
private static final String SAVED_PARAMETER_POSTFIX = "_saved";
public static void generateMethodsJava(ProcessingEnvironment env, TypeMap type_map, PrintWriter writer, TypeElement interface_decl, boolean generate_error_checks, boolean context_specific) {
for (ExecutableElement method : Utils.getMethods(interface_decl)) {
for ( ExecutableElement method : Utils.getMethods(interface_decl) ) {
generateMethodJava(env, type_map, writer, interface_decl, method, generate_error_checks, context_specific);
}
}
/**
* TODO : fix info multi-type methods print.
*
**/
*/
private static void generateMethodJava(ProcessingEnvironment env, TypeMap type_map, PrintWriter writer, TypeElement interface_decl, ExecutableElement method, boolean generate_error_checks, boolean context_specific) {
writer.println();
if (Utils.isMethodIndirect(generate_error_checks, context_specific, method)) {
if (method.getAnnotation(GenerateAutos.class) != null) {
if ( Utils.isMethodIndirect(generate_error_checks, context_specific, method) ) {
if ( method.getAnnotation(GenerateAutos.class) != null ) {
printMethodWithMultiType(env, type_map, writer, interface_decl, method, TypeInfo.getDefaultTypeInfoMap(method), Mode.AUTOS, generate_error_checks, context_specific);
}
Collection<Map<VariableElement, TypeInfo>> cross_product = TypeInfo.getTypeInfoCrossProduct(env, type_map, method);
for (Map<VariableElement, TypeInfo> typeinfos_instance : cross_product) {
for ( Map<VariableElement, TypeInfo> typeinfos_instance : cross_product ) {
printMethodWithMultiType(env, type_map, writer, interface_decl, method, typeinfos_instance, Mode.NORMAL, generate_error_checks, context_specific);
}
}
if (method.getAnnotation(CachedResult.class) != null && !method.getAnnotation(CachedResult.class).isRange()) {
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);
}
Reuse reuse_annotation = method.getAnnotation(Reuse.class);
Alternate alt_annotation = method.getAnnotation(Alternate.class);
if (alt_annotation == null || (alt_annotation.nativeAlt() && !alt_annotation.skipNative())) {
if (alt_annotation != null && method.getSimpleName().toString().equals(alt_annotation.value())) {
if ( alt_annotation == null || (alt_annotation.nativeAlt() && !alt_annotation.skipNative()) ) {
if ( alt_annotation != null && method.getSimpleName().toString().equals(alt_annotation.value()) ) {
throw new RuntimeException("An alternate function with native code should have a different name than the main function.");
}
if (reuse_annotation == null) {
if ( reuse_annotation == null ) {
printJavaNativeStub(env, writer, method, Mode.NORMAL, generate_error_checks, context_specific);
}
if (Utils.hasMethodBufferObjectParameter(method)) {
if ( Utils.hasMethodBufferObjectParameter(method) ) {
printMethodWithMultiType(env, type_map, writer, interface_decl, method, TypeInfo.getDefaultTypeInfoMap(method), Mode.BUFFEROBJECT, generate_error_checks, context_specific);
if (reuse_annotation == null) {
if ( reuse_annotation == null ) {
printJavaNativeStub(env, writer, method, Mode.BUFFEROBJECT, generate_error_checks, context_specific);
}
}
@ -104,7 +103,7 @@ public class JavaMethodsGenerator {
}
private static void printJavaNativeStub(ProcessingEnvironment env, PrintWriter writer, ExecutableElement method, Mode mode, boolean generate_error_checks, boolean context_specific) {
if (Utils.isMethodIndirect(generate_error_checks, context_specific, method)) {
if ( Utils.isMethodIndirect(generate_error_checks, context_specific, method) ) {
writer.print("\tstatic native ");
} else {
Utils.printDocComment(writer, method, env);
@ -112,13 +111,13 @@ public class JavaMethodsGenerator {
}
writer.print(getResultType(method, true));
writer.print(" " + Utils.getSimpleNativeMethodName(method, generate_error_checks, context_specific));
if (mode == Mode.BUFFEROBJECT) {
if ( mode == Mode.BUFFEROBJECT ) {
writer.print(Utils.BUFFER_OBJECT_METHOD_POSTFIX);
}
writer.print("(");
boolean first_parameter = generateParametersJava(env, writer, method, TypeInfo.getDefaultTypeInfoMap(method), true, true, mode);
if (context_specific) {
if (!first_parameter) {
if ( context_specific ) {
if ( !first_parameter ) {
writer.print(", ");
}
writer.print("long " + Utils.FUNCTION_POINTER_VAR_NAME);
@ -128,71 +127,71 @@ public class JavaMethodsGenerator {
private static boolean generateParametersJava(ProcessingEnvironment env, PrintWriter writer, ExecutableElement method, Map<VariableElement, TypeInfo> typeinfos_instance, boolean native_stub, final boolean printTypes, Mode mode) {
boolean first_parameter = true;
for (VariableElement param : method.getParameters()) {
if (native_stub && (param.getAnnotation(Helper.class) != null && !param.getAnnotation(Helper.class).passToNative())) {
for ( VariableElement param : method.getParameters() ) {
if ( native_stub && (param.getAnnotation(Helper.class) != null && !param.getAnnotation(Helper.class).passToNative()) ) {
continue;
}
final Constant constant_annotation = param.getAnnotation(Constant.class);
if (constant_annotation != null && constant_annotation.isNative()) {
if ( constant_annotation != null && constant_annotation.isNative() ) {
continue;
}
/*env.getMessager().printMessage(Diagnostic.Kind.NOTE, param.getAnnotationMirrors()
+ " (" + typeinfos_instance.get(param).getType() + ")", param);*/
AnnotationMirror auto_annotation_mirror = Utils.getParameterAutoAnnotation(param);
boolean hide_auto_parameter = mode == Mode.NORMAL && !native_stub && auto_annotation_mirror != null;
if (hide_auto_parameter) {
if ( hide_auto_parameter ) {
AutoType auto_type_annotation = param.getAnnotation(AutoType.class);
if (auto_type_annotation != null) {
if ( auto_type_annotation != null ) {
VariableElement 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) {
if ( auto_param_type_info.getSignedness() == Signedness.BOTH ) {
if ( !first_parameter ) {
writer.print(", ");
}
first_parameter = false;
if (printTypes) {
if ( printTypes ) {
writer.print("boolean ");
}
writer.print(TypeInfo.UNSIGNED_PARAMETER_NAME);
}
}
} else if (param.getAnnotation(Result.class) == null
} else if ( param.getAnnotation(Result.class) == null
&& (native_stub || ((param.getAnnotation(Constant.class) == null || param.getAnnotation(Constant.class).keepParam()) && !Utils.isReturnParameter(method, param)))
&& (mode != Mode.AUTOS || getAutoTypeParameter(method, param) == null)) {
&& (mode != Mode.AUTOS || getAutoTypeParameter(method, param) == null) ) {
first_parameter = generateParameterJava(writer, param, typeinfos_instance.get(param), native_stub, printTypes, first_parameter, mode);
}
}
CachedResult cached_result_annotation = method.getAnnotation(CachedResult.class);
TypeMirror result_type = Utils.getMethodReturnType(method);
if ((native_stub && Utils.getNIOBufferType(result_type) != null) || Utils.needResultSize(method)) {
if ( (native_stub && Utils.getNIOBufferType(result_type) != null) || Utils.needResultSize(method) ) {
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) {
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) {
if ( printTypes ) {
writer.print("long ");
}
writer.print(Utils.RESULT_SIZE_NAME);
}
}
}
if (cached_result_annotation != null) {
if (!first_parameter) {
if ( cached_result_annotation != null ) {
if ( !first_parameter ) {
writer.print(", ");
}
if (mode == Mode.CACHEDRESULT) {
if (printTypes) {
if ( mode == Mode.CACHEDRESULT ) {
if ( printTypes ) {
writer.print("long ");
}
writer.print(Utils.CACHED_BUFFER_LENGTH_NAME + ", ");
}
first_parameter = false;
if (printTypes) {
if ( printTypes ) {
writer.print(getResultType(method, native_stub));
}
writer.print(" " + Utils.CACHED_BUFFER_NAME);
@ -202,31 +201,31 @@ public class JavaMethodsGenerator {
private static boolean generateParameterJava(PrintWriter writer, VariableElement param, TypeInfo type_info, boolean native_stub, final boolean printTypes, boolean first_parameter, Mode mode) {
Class buffer_type = Utils.getNIOBufferType(param.asType());
if (!first_parameter) {
if ( !first_parameter ) {
writer.print(", ");
}
BufferObject bo_annotation = param.getAnnotation(BufferObject.class);
if (bo_annotation != null && mode == Mode.BUFFEROBJECT) {
if (buffer_type == null) {
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");
}
if (printTypes) {
if ( printTypes ) {
writer.print("long ");
}
writer.print(param.getSimpleName() + Utils.BUFFER_OBJECT_PARAMETER_POSTFIX);
} else {
if (native_stub && param.getAnnotation(PointerWrapper.class) != null) {
if ( native_stub && param.getAnnotation(PointerWrapper.class) != null ) {
writer.print("long ");
} else {
Class type = type_info.getType();
if (native_stub && (type == CharSequence.class || type == CharSequence[].class || type == PointerBuffer.class || Buffer.class.isAssignableFrom(type))) {
if ( native_stub && (type == CharSequence.class || type == CharSequence[].class || type == PointerBuffer.class || Buffer.class.isAssignableFrom(type)) ) {
writer.print("long ");
} else if (printTypes) {
} else if ( printTypes ) {
writer.print(type.getSimpleName() + " ");
}
}
AutoSize auto_size_annotation = param.getAnnotation(AutoSize.class);
if (auto_size_annotation != null) {
if ( auto_size_annotation != null ) {
writer.print(auto_size_annotation.value() + "_");
}
writer.print(param.getSimpleName());
@ -237,13 +236,13 @@ public class JavaMethodsGenerator {
private static void printBufferObjectCheck(PrintWriter writer, BufferKind kind, Mode mode, boolean context_specific) {
String bo_check_method_name = kind.toString();
writer.print("\t\t" + Utils.CHECKS_CLASS_NAME + ".ensure" + bo_check_method_name);
if (mode == Mode.BUFFEROBJECT) {
if ( mode == Mode.BUFFEROBJECT ) {
writer.print("enabled");
} else {
writer.print("disabled");
}
if (context_specific) {
if ( context_specific ) {
writer.println("(caps);");
} else {
writer.println("();");
@ -252,23 +251,23 @@ public class JavaMethodsGenerator {
private static void printBufferObjectChecks(PrintWriter writer, ExecutableElement method, Mode mode, boolean context_specific) {
EnumSet<BufferKind> check_set = EnumSet.noneOf(BufferKind.class);
for (VariableElement param : method.getParameters()) {
for ( VariableElement param : method.getParameters() ) {
BufferObject bo_annotation = param.getAnnotation(BufferObject.class);
if (bo_annotation != null) {
if ( bo_annotation != null ) {
check_set.add(bo_annotation.value());
}
}
for (BufferKind kind : check_set) {
for ( BufferKind kind : check_set ) {
printBufferObjectCheck(writer, kind, mode, context_specific);
}
}
private static void printMethodWithMultiType(ProcessingEnvironment env, TypeMap type_map, PrintWriter writer, TypeElement interface_decl, ExecutableElement method, Map<VariableElement, TypeInfo> typeinfos_instance, Mode mode, boolean generate_error_checks, boolean context_specific) {
Utils.printDocComment(writer, method, env);
if (method.getAnnotation(Deprecated.class) != null) {
if ( method.getAnnotation(Deprecated.class) != null ) {
writer.println("\t@Deprecated");
}
if (interface_decl.getAnnotation(Private.class) == null && method.getAnnotation(Private.class) == null) {
if ( interface_decl.getAnnotation(Private.class) == null && method.getAnnotation(Private.class) == null ) {
writer.print("\tpublic static ");
} else {
writer.print("\tstatic ");
@ -278,7 +277,7 @@ public class JavaMethodsGenerator {
String method_name;
Alternate alt_annotation = method.getAnnotation(Alternate.class);
method_name = alt_annotation == null || alt_annotation.javaAlt() ? method.getSimpleName().toString() : alt_annotation.value();
if (strip_annotation != null && mode == Mode.NORMAL) {
if ( strip_annotation != null && mode == Mode.NORMAL ) {
method_name = getPostfixStrippedName(type_map, interface_decl, method);
}
writer.print(" " + method_name + "(");
@ -289,9 +288,9 @@ public class JavaMethodsGenerator {
boolean has_result = !result_type.equals(env.getTypeUtils().getNoType(TypeKind.VOID));
final Reuse reuse_annotation = method.getAnnotation(Reuse.class);
if (reuse_annotation != null) {
if ( reuse_annotation != null ) {
writer.print("\t\t");
if (has_result || method.getAnnotation(GLreturn.class) != null) {
if ( has_result || method.getAnnotation(GLreturn.class) != null ) {
writer.print("return ");
}
@ -301,7 +300,7 @@ public class JavaMethodsGenerator {
return;
}
if (context_specific) {
if ( context_specific ) {
type_map.printCapabilitiesInit(writer);
writer.print("\t\tlong " + Utils.FUNCTION_POINTER_VAR_NAME + " = " + type_map.getCapabilities() + ".");
writer.println(Utils.getFunctionAddressName(interface_decl, method, true) + ";");
@ -309,73 +308,73 @@ public class JavaMethodsGenerator {
writer.println(Utils.FUNCTION_POINTER_VAR_NAME + ");");
}
final Code code_annotation = method.getAnnotation(Code.class);
if (code_annotation != null && code_annotation.value().length() > 0) {
if ( code_annotation != null && code_annotation.value().length() > 0 ) {
writer.println(code_annotation.value());
}
printBufferObjectChecks(writer, method, mode, context_specific);
printParameterChecks(writer, method, typeinfos_instance, mode, generate_error_checks);
printParameterCaching(writer, interface_decl, method, mode, context_specific);
if (code_annotation != null && code_annotation.javaBeforeNative().length() > 0) {
if ( code_annotation != null && code_annotation.javaBeforeNative().length() > 0 ) {
writer.println(code_annotation.javaBeforeNative());
}
writer.print("\t\t");
final PointerWrapper pointer_wrapper_annotation = method.getAnnotation(PointerWrapper.class);
if (has_result) {
if ( has_result ) {
writer.print(getResultType(method, false) + " " + Utils.RESULT_VAR_NAME);
if (code_annotation != null && code_annotation.tryBlock()) {
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) {
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) {
} else if ( method.getAnnotation(GLreturn.class) != null ) {
has_result = true;
Utils.printGLReturnPre(writer, method, method.getAnnotation(GLreturn.class), type_map);
}
writer.print(Utils.getSimpleNativeMethodName(method, generate_error_checks, context_specific));
if (mode == Mode.BUFFEROBJECT) {
if ( mode == Mode.BUFFEROBJECT ) {
writer.print(Utils.BUFFER_OBJECT_METHOD_POSTFIX);
}
writer.print("(");
boolean first_parameter = printMethodCallArguments(writer, method, typeinfos_instance, mode, type_map);
if (context_specific) {
if (!first_parameter) {
if ( context_specific ) {
if ( !first_parameter ) {
writer.print(", ");
}
writer.print(Utils.FUNCTION_POINTER_VAR_NAME);
}
if (has_result && pointer_wrapper_annotation != null) {
if ( has_result && pointer_wrapper_annotation != null ) {
writer.print(")");
if (pointer_wrapper_annotation.params().length() > 0) {
if ( pointer_wrapper_annotation.params().length() > 0 ) {
writer.print(", " + pointer_wrapper_annotation.params());
}
}
writer.println(");");
if (code_annotation != null && code_annotation.javaAfterNative().length() > 0) {
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";
if (generate_error_checks && method.getAnnotation(NoErrorCheck.class) == null) {
if ( generate_error_checks && method.getAnnotation(NoErrorCheck.class) == null ) {
type_map.printErrorCheckMethod(writer, method, tabs);
}
// DISABLED: indirect buffer support
//printNondirectParameterCopies(writer, method, mode);
if (has_result) {
if (method.getAnnotation(GLreturn.class) == null) {
if (ByteBuffer.class.equals(Utils.getJavaType(result_type))) {
if ( has_result ) {
if ( method.getAnnotation(GLreturn.class) == null ) {
if ( ByteBuffer.class.equals(Utils.getJavaType(result_type)) ) {
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.
} else {
writer.println(tabs + "return " + Utils.RESULT_VAR_NAME + ";");
@ -385,7 +384,7 @@ public class JavaMethodsGenerator {
}
}
if (code_annotation != null && code_annotation.tryBlock()) {
if ( code_annotation != null && code_annotation.tryBlock() ) {
writer.println("\t\t} finally {");
writer.println(code_annotation.javaFinally());
writer.println("\t\t}");
@ -396,9 +395,9 @@ public class JavaMethodsGenerator {
private static String getExtensionPostfix(TypeElement interface_decl) {
String interface_simple_name = interface_decl.getSimpleName().toString();
Extension extension_annotation = interface_decl.getAnnotation(Extension.class);
if (extension_annotation == null) {
if ( extension_annotation == null ) {
int underscore_index = interface_simple_name.indexOf("_");
if (underscore_index != -1) {
if ( underscore_index != -1 ) {
return interface_simple_name.substring(0, underscore_index);
} else {
return "";
@ -409,19 +408,19 @@ public class JavaMethodsGenerator {
}
private static VariableElement getAutoTypeParameter(ExecutableElement method, VariableElement target_parameter) {
for (VariableElement param : method.getParameters()) {
for ( VariableElement param : method.getParameters() ) {
AnnotationMirror auto_annotation = Utils.getParameterAutoAnnotation(param);
if (auto_annotation != null) {
if ( auto_annotation != null ) {
Class annotation_type = NativeTypeTranslator.getClassFromType(auto_annotation.getAnnotationType());
String parameter_name;
if (annotation_type.equals(AutoType.class)) {
if ( annotation_type.equals(AutoType.class) ) {
parameter_name = param.getAnnotation(AutoType.class).value();
} else if (annotation_type.equals(AutoSize.class)) {
} else if ( annotation_type.equals(AutoSize.class) ) {
parameter_name = param.getAnnotation(AutoSize.class).value();
} else {
throw new RuntimeException("Unknown annotation type " + annotation_type);
}
if (target_parameter.getSimpleName().toString().equals(parameter_name)) {
if ( target_parameter.getSimpleName().toString().equals(parameter_name) ) {
return param;
}
}
@ -430,11 +429,11 @@ public class JavaMethodsGenerator {
}
private static boolean hasAnyParameterAutoTypeAnnotation(ExecutableElement method, VariableElement target_param) {
for (VariableElement param : method.getParameters()) {
for ( VariableElement param : method.getParameters() ) {
AutoType auto_type_annotation = param.getAnnotation(AutoType.class);
if (auto_type_annotation != null) {
if ( auto_type_annotation != null ) {
VariableElement type_target_param = Utils.findParameter(method, auto_type_annotation.value());
if (target_param.equals(type_target_param)) {
if ( target_param.equals(type_target_param) ) {
return true;
}
}
@ -446,7 +445,7 @@ public class JavaMethodsGenerator {
private static Pattern getPostfixPattern(String regex) {
Pattern pattern = postfixPatterns.get(regex);
if (pattern == null) {
if ( pattern == null ) {
postfixPatterns.put(regex, pattern = Pattern.compile(regex));
}
return pattern;
@ -457,11 +456,11 @@ public class JavaMethodsGenerator {
VariableElement postfix_parameter = Utils.findParameter(method, strip_annotation.value());
String postfix = strip_annotation.postfix();
boolean postfixOverride = !("NULL".equals(postfix) && strip_annotation.hasPostfix());
if (!postfixOverride) {
if ( !postfixOverride ) {
PostfixTranslator translator = new PostfixTranslator(type_map, postfix_parameter);
postfix_parameter.asType().accept(translator, null);
postfix = translator.getSignature();
} else if (!strip_annotation.hasPostfix()) {
} else if ( !strip_annotation.hasPostfix() ) {
postfix = "";
}
@ -477,7 +476,7 @@ public class JavaMethodsGenerator {
: ("(?:" + postfix + "(?:v)?|i(?:64)?_v|v)" + extension_postfix + "$")
).matcher(method_name);
if (!matcher.find()) {
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'");
}
@ -485,17 +484,17 @@ public class JavaMethodsGenerator {
}
private static int getBufferElementSizeExponent(Class c) {
if (IntBuffer.class.equals(c)) {
if ( IntBuffer.class.equals(c) ) {
return 2;
} else if (LongBuffer.class.equals(c)) {
} else if ( LongBuffer.class.equals(c) ) {
return 3;
} else if (DoubleBuffer.class.equals(c)) {
} else if ( DoubleBuffer.class.equals(c) ) {
return 3;
} else if (ShortBuffer.class.equals(c)) {
} else if ( ShortBuffer.class.equals(c) ) {
return 1;
} else if (ByteBuffer.class.equals(c)) {
} else if ( ByteBuffer.class.equals(c) ) {
return 0;
} else if (FloatBuffer.class.equals(c)) {
} else if ( FloatBuffer.class.equals(c) ) {
return 2;
} else {
throw new RuntimeException(c + " is not allowed");
@ -503,45 +502,45 @@ public class JavaMethodsGenerator {
}
private static boolean printMethodCallArgument(PrintWriter writer, ExecutableElement method, VariableElement param, Map<VariableElement, TypeInfo> typeinfos_instance, Mode mode, boolean first_parameter, TypeMap type_map) {
if (!first_parameter) {
if ( !first_parameter ) {
writer.print(", ");
}
AnnotationMirror auto_annotation = Utils.getParameterAutoAnnotation(param);
Constant constant_annotation = param.getAnnotation(Constant.class);
if (constant_annotation != null) {
if ( constant_annotation != null ) {
writer.print(constant_annotation.value());
} else if (auto_annotation != null && mode == Mode.NORMAL) {
} else if ( auto_annotation != null && mode == Mode.NORMAL ) {
Class param_type = NativeTypeTranslator.getClassFromType(auto_annotation.getAnnotationType());
if (AutoType.class.equals(param_type)) {
if ( AutoType.class.equals(param_type) ) {
final AutoType auto_type_annotation = param.getAnnotation(AutoType.class);
final VariableElement auto_parameter = Utils.findParameter(method, auto_type_annotation.value());
final String auto_type = typeinfos_instance.get(auto_parameter).getAutoType();
if (auto_type == null) {
if ( auto_type == null ) {
throw new RuntimeException("No auto type for parameter " + param.getSimpleName() + " in method " + method);
}
writer.print(auto_type);
} else if (AutoSize.class.equals(param_type)) {
} else if ( AutoSize.class.equals(param_type) ) {
final AutoSize auto_size_annotation = param.getAnnotation(AutoSize.class);
if (!auto_size_annotation.useExpression()) {
if ( !auto_size_annotation.useExpression() ) {
final String auto_parameter_name = auto_size_annotation.value();
final VariableElement 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) {
if ( shift_remaining ) {
shifting = getBufferElementSizeExponent(auto_target_type_info.getType());
if (shifting > 0) {
if ( shifting > 0 ) {
writer.print("(");
}
}
if (auto_size_annotation.canBeNull()) {
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) {
if ( shift_remaining && shifting > 0 ) {
writer.print(" << " + shifting);
writer.print(")");
}
@ -551,41 +550,41 @@ public class JavaMethodsGenerator {
throw new RuntimeException("Unknown auto annotation " + param_type);
}
} else {
if (mode == Mode.BUFFEROBJECT && param.getAnnotation(BufferObject.class) != null) {
if ( mode == Mode.BUFFEROBJECT && param.getAnnotation(BufferObject.class) != null ) {
writer.print(param.getSimpleName() + Utils.BUFFER_OBJECT_PARAMETER_POSTFIX);
} else {
Class type = typeinfos_instance.get(param).getType();
Check check_annotation = param.getAnnotation(Check.class);
boolean hide_buffer = mode == Mode.AUTOS && getAutoTypeParameter(method, param) != null;
if (hide_buffer) {
if ( hide_buffer ) {
writer.print("0L");
} else {
if (type == CharSequence.class || type == CharSequence[].class) {
if ( type == CharSequence.class || type == CharSequence[].class ) {
final String offset = Utils.getStringOffset(method, param);
writer.print("APIUtil.getBuffer");
if (param.getAnnotation(NullTerminated.class) != null) {
if ( param.getAnnotation(NullTerminated.class) != null ) {
writer.print("NT");
}
writer.print('(');
writer.print(type_map.getAPIUtilParam(true));
writer.print(param.getSimpleName());
if (offset != null) {
if ( offset != null ) {
writer.print(", " + offset);
}
writer.print(")");
} else {
final AutoSize auto_size_annotation = param.getAnnotation(AutoSize.class);
if (auto_size_annotation != null) {
if ( auto_size_annotation != null ) {
writer.print(auto_size_annotation.value() + "_");
}
final Class buffer_type = Utils.getNIOBufferType(param.asType());
if (buffer_type == null) {
if ( buffer_type == null ) {
writer.print(param.getSimpleName());
} else {
writer.print("MemoryUtil.getAddress");
if (check_annotation != null && check_annotation.canBeNull()) {
if ( check_annotation != null && check_annotation.canBeNull() ) {
writer.print("Safe");
}
writer.print("(");
@ -594,10 +593,10 @@ public class JavaMethodsGenerator {
}
}
}
if (type != long.class) {
if ( type != long.class ) {
PointerWrapper pointer_annotation = param.getAnnotation(PointerWrapper.class);
if (pointer_annotation != null) {
if (pointer_annotation.canBeNull()) {
if ( pointer_annotation != null ) {
if ( pointer_annotation.canBeNull() ) {
writer.print(" == null ? 0 : " + param.getSimpleName());
}
writer.print(".getPointer()");
@ -610,32 +609,32 @@ public class JavaMethodsGenerator {
private static boolean printMethodCallArguments(PrintWriter writer, ExecutableElement method, Map<VariableElement, TypeInfo> typeinfos_instance, Mode mode, TypeMap type_map) {
boolean first_parameter = true;
for (VariableElement param : method.getParameters()) {
if (param.getAnnotation(Result.class) != null || (param.getAnnotation(Helper.class) != null && !param.getAnnotation(Helper.class).passToNative())) {
for ( VariableElement param : method.getParameters() ) {
if ( param.getAnnotation(Result.class) != null || (param.getAnnotation(Helper.class) != null && !param.getAnnotation(Helper.class).passToNative()) ) {
continue;
}
final Constant constant_annotation = param.getAnnotation(Constant.class);
if (constant_annotation == null || !constant_annotation.isNative()) {
if ( constant_annotation == null || !constant_annotation.isNative() ) {
first_parameter = printMethodCallArgument(writer, method, param, typeinfos_instance, mode, first_parameter, type_map);
}
}
if (Utils.getNIOBufferType(Utils.getMethodReturnType(method)) != null) {
if (method.getAnnotation(CachedResult.class) != null && method.getAnnotation(CachedResult.class).isRange()) {
if ( Utils.getNIOBufferType(Utils.getMethodReturnType(method)) != null ) {
if ( method.getAnnotation(CachedResult.class) != null && method.getAnnotation(CachedResult.class).isRange() ) {
first_parameter = false;
Utils.printExtraCallArguments(writer, method, "");
} else {
AutoSize auto_size_annotation = method.getAnnotation(AutoSize.class);
if (auto_size_annotation == null || !auto_size_annotation.isNative()) {
if (!first_parameter) {
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) {
if ( mode == Mode.CACHEDRESULT ) {
result_size_expression = Utils.CACHED_BUFFER_LENGTH_NAME;
} else if (auto_size_annotation == null) {
} else if ( auto_size_annotation == null ) {
result_size_expression = Utils.RESULT_SIZE_NAME;
} else {
result_size_expression = auto_size_annotation.value();
@ -649,25 +648,25 @@ public class JavaMethodsGenerator {
}
private static void printParameterCaching(PrintWriter writer, TypeElement interface_decl, ExecutableElement method, Mode mode, boolean context_specific) {
for (VariableElement param : method.getParameters()) {
for ( VariableElement param : method.getParameters() ) {
Class java_type = Utils.getJavaType(param.asType());
CachedReference cachedReference = param.getAnnotation(CachedReference.class);
if (Buffer.class.isAssignableFrom(java_type)
if ( Buffer.class.isAssignableFrom(java_type)
&& cachedReference != null
&& (mode != Mode.BUFFEROBJECT || param.getAnnotation(BufferObject.class) == null)
&& param.getAnnotation(Result.class) == null) {
&& param.getAnnotation(Result.class) == null ) {
writer.print("\t\tif ( LWJGLUtil.CHECKS ) StateTracker.");
if (context_specific) {
if ( context_specific ) {
writer.print("getReferences(caps).");
} else {
writer.print("getTracker().");
}
if (cachedReference.name().length() > 0) {
if ( cachedReference.name().length() > 0 ) {
writer.print(cachedReference.name());
} else {
writer.print(Utils.getReferenceName(interface_decl, method, param));
}
if (cachedReference.index().length() > 0) {
if ( cachedReference.index().length() > 0 ) {
writer.print("[" + cachedReference.index() + "]");
}
writer.println(" = " + param.getSimpleName() + ";");
@ -676,17 +675,17 @@ public class JavaMethodsGenerator {
}
private static void printParameterChecks(PrintWriter writer, ExecutableElement method, Map<VariableElement, TypeInfo> typeinfos, Mode mode, final boolean generate_error_checks) {
if (mode == Mode.NORMAL) {
if ( mode == Mode.NORMAL ) {
final GenerateAutos gen_autos_annotation = method.getAnnotation(GenerateAutos.class);
if (gen_autos_annotation != null && gen_autos_annotation.sizeVariables().length > 0) {
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 VariableElement param : method.getParameters()) {
if (Arrays.binarySearch(gen_autos_annotation.sizeVariables(), param.getSimpleName().toString()) >= 0) {
for ( final VariableElement param : method.getParameters() ) {
if ( Arrays.binarySearch(gen_autos_annotation.sizeVariables(), param.getSimpleName().toString()) >= 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()) {
if ( check_annotation == null || !check_annotation.canBeNull() ) {
writer.println(param.getSimpleName() + ".remaining() << " + shifting + ";");
} else {
writer.println(param.getSimpleName() + " == null ? 0 : " + param.getSimpleName() + ".remaining() << " + shifting + ";");
@ -696,44 +695,44 @@ public class JavaMethodsGenerator {
}
}
for (VariableElement param : method.getParameters()) {
for ( VariableElement param : method.getParameters() ) {
Class java_type = Utils.getJavaType(param.asType());
if (java_type.isArray() || (Utils.isAddressableType((Class) java_type)
if ( java_type.isArray() || (Utils.isAddressableType((Class)java_type)
&& (mode != Mode.BUFFEROBJECT || param.getAnnotation(BufferObject.class) == null)
&& (mode != Mode.AUTOS || getAutoTypeParameter(method, param) == null)
&& param.getAnnotation(Result.class) == null
&& !Utils.isReturnParameter(method, param))) {
&& !Utils.isReturnParameter(method, param)) ) {
String check_value = null;
boolean can_be_null = false;
Check check_annotation = param.getAnnotation(Check.class);
if (check_annotation != null) {
if ( check_annotation != null ) {
check_value = check_annotation.value();
can_be_null = check_annotation.canBeNull();
}
if ((Buffer.class.isAssignableFrom(java_type) || PointerBuffer.class.isAssignableFrom(java_type)) && param.getAnnotation(Constant.class) == null) {
if ( (Buffer.class.isAssignableFrom(java_type) || PointerBuffer.class.isAssignableFrom(java_type)) && param.getAnnotation(Constant.class) == null ) {
boolean out_parameter = param.getAnnotation(OutParameter.class) != null;
TypeInfo typeinfo = typeinfos.get(param);
printParameterCheck(writer, method, param.getSimpleName().toString(), typeinfo.getType().getSimpleName(), check_value, can_be_null, param.getAnnotation(NullTerminated.class), out_parameter, generate_error_checks);
} else if (String.class.equals(java_type)) {
if (!can_be_null) {
} else if ( String.class.equals(java_type) ) {
if ( !can_be_null ) {
writer.println("\t\tBufferChecks.checkNotNull(" + param.getSimpleName() + ");");
}
} else if (java_type.isArray()) {
} else if ( java_type.isArray() ) {
final TypeInfo typeinfo = typeinfos.get(param);
printArrayParameterCheck(writer, param.getSimpleName().toString(), typeinfo.getType().getSimpleName(), check_value, can_be_null);
}
}
}
if (method.getAnnotation(CachedResult.class) != null) {
if ( method.getAnnotation(CachedResult.class) != null ) {
printParameterCheck(writer, method, Utils.CACHED_BUFFER_NAME, null, null, true, null, false, generate_error_checks);
}
}
private static void printParameterCheck(PrintWriter writer, ExecutableElement method, String name, String type, String check_value, boolean can_be_null, NullTerminated null_terminated, boolean out_parameter, boolean generate_error_checks) {
String tabs;
if (can_be_null) {
if ( can_be_null ) {
writer.print("\t\tif (" + name + " != null)");
if (null_terminated != null) {
if ( null_terminated != null ) {
writer.println(" {");
} else {
writer.println();
@ -743,9 +742,9 @@ public class JavaMethodsGenerator {
tabs = "\t\t";
}
writer.print(tabs + "BufferChecks.check");
if (check_value != null && check_value.length() > 0) {
if ( check_value != null && check_value.length() > 0 ) {
writer.print("Buffer");
if ("Buffer".equals(type)) {
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);
@ -753,22 +752,22 @@ public class JavaMethodsGenerator {
writer.print("Direct(" + name);
}
writer.println(");");
if (can_be_null && generate_error_checks) {
if ( can_be_null && generate_error_checks ) {
final Check check_annotation = method.getAnnotation(Check.class);
if (check_annotation != null && check_annotation.value().equals(name)) {
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
}
}
if (null_terminated != null) {
if ( null_terminated != null ) {
writer.print(tabs + "BufferChecks.checkNullTerminated(");
writer.print(name);
if (null_terminated.value().length() > 0) {
if ( null_terminated.value().length() > 0 ) {
writer.print(", ");
writer.print(null_terminated.value());
}
writer.println(");");
if (can_be_null) {
if ( can_be_null ) {
writer.println("\t\t}");
}
}
@ -776,7 +775,7 @@ public class JavaMethodsGenerator {
private static void printArrayParameterCheck(PrintWriter writer, String name, String type, String check_value, boolean can_be_null) {
String tabs;
if (can_be_null) {
if ( can_be_null ) {
writer.println("\t\tif (" + name + " != null)");
tabs = "\t\t\t";
} else {
@ -784,16 +783,16 @@ public class JavaMethodsGenerator {
}
writer.print(tabs + "BufferChecks.checkArray(" + name);
if (check_value != null && check_value.length() > 0) {
if ( check_value != null && check_value.length() > 0 ) {
writer.print(", " + check_value);
}
writer.println(");");
}
private static String getResultType(ExecutableElement method, boolean native_stub) {
if (native_stub && method.getAnnotation(PointerWrapper.class) != null) {
if ( native_stub && method.getAnnotation(PointerWrapper.class) != null ) {
return "long";
} else if (!native_stub && method.getAnnotation(GLreturn.class) != null) {
} else if ( !native_stub && method.getAnnotation(GLreturn.class) != null ) {
return Utils.getMethodReturnType(method, method.getAnnotation(GLreturn.class), false);
} else {
return Utils.getJavaType(Utils.getMethodReturnType(method)).getSimpleName();
@ -801,19 +800,19 @@ public class JavaMethodsGenerator {
}
private static String getDefaultResultValue(ExecutableElement method) {
if (method.getAnnotation(GLreturn.class) != null) {
if ( method.getAnnotation(GLreturn.class) != null ) {
final String type = Utils.getMethodReturnType(method, method.getAnnotation(GLreturn.class), false);
if ("boolean".equals(type)) {
if ( "boolean".equals(type) ) {
return "false";
} else if (Character.isLowerCase(type.charAt(0))) {
} 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) {
if ( type.isPrimitive() ) {
if ( type == boolean.class ) {
return "false";
} else {
return "0";

View File

@ -32,19 +32,7 @@
package org.lwjgl.util.generator;
import java.nio.ByteBuffer;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.lang.model.type.ArrayType;
import javax.lang.model.type.DeclaredType;
import javax.lang.model.type.NoType;
import javax.lang.model.type.PrimitiveType;
import javax.lang.model.type.TypeKind;
import static javax.lang.model.type.TypeKind.BOOLEAN;
import static javax.lang.model.type.TypeKind.BYTE;
import static javax.lang.model.type.TypeKind.DOUBLE;
import static javax.lang.model.type.TypeKind.FLOAT;
import static javax.lang.model.type.TypeKind.INT;
import javax.lang.model.type.TypeMirror;
import javax.lang.model.type.*;
import javax.lang.model.util.SimpleTypeVisitor6;
/**
@ -67,15 +55,15 @@ public class JavaTypeTranslator extends SimpleTypeVisitor6<Void, Void> {
final TypeMirror componentType = t.getComponentType();
try {
final Class c = Class.forName(t.getComponentType().toString());
if (CharSequence.class.isAssignableFrom(c) || ByteBuffer.class.isAssignableFrom(c) || org.lwjgl.PointerWrapper.class.isAssignableFrom(c)) {
if ( CharSequence.class.isAssignableFrom(c) || ByteBuffer.class.isAssignableFrom(c) || org.lwjgl.PointerWrapper.class.isAssignableFrom(c) ) {
type = Class.forName("[L" + t.getComponentType() + ";");
}
} catch (ClassNotFoundException ex) {
type = null;
} finally {
if (type == null) {
if (componentType instanceof PrimitiveType) {
type = getPrimitiveArrayClassFromKind(((PrimitiveType) componentType).getKind());
if ( type == null ) {
if ( componentType instanceof PrimitiveType ) {
type = getPrimitiveArrayClassFromKind(((PrimitiveType)componentType).getKind());
} else {
throw new RuntimeException(t + " is not allowed");
}
@ -85,7 +73,7 @@ public class JavaTypeTranslator extends SimpleTypeVisitor6<Void, Void> {
}
public static Class getPrimitiveClassFromKind(TypeKind kind) {
switch (kind) {
switch ( kind ) {
case LONG:
return long.class;
case INT:
@ -106,7 +94,7 @@ public class JavaTypeTranslator extends SimpleTypeVisitor6<Void, Void> {
}
private static Class getPrimitiveArrayClassFromKind(TypeKind kind) {
switch (kind) {
switch ( kind ) {
case LONG:
return long[].class;
case INT:
@ -134,9 +122,9 @@ public class JavaTypeTranslator extends SimpleTypeVisitor6<Void, Void> {
@Override
public Void visitDeclared(DeclaredType t, Void o) {
if (t.asElement().getKind().isClass()) {
if ( t.asElement().getKind().isClass() ) {
visitClassType(t);
} else if (t.asElement().getKind().isInterface()) {
} else if ( t.asElement().getKind().isInterface() ) {
visitInterfaceType(t);
} else {
throw new RuntimeException(t.asElement().getKind() + " is not allowed");

View File

@ -41,9 +41,11 @@ package org.lwjgl.util.generator;
* $Id$
*/
import java.io.*;
import java.nio.*;
import java.util.*;
import org.lwjgl.PointerBuffer;
import java.io.PrintWriter;
import java.nio.Buffer;
import java.util.List;
import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.element.Element;
import javax.lang.model.element.ExecutableElement;
@ -51,7 +53,6 @@ import javax.lang.model.element.TypeElement;
import javax.lang.model.element.VariableElement;
import javax.lang.model.type.TypeKind;
import javax.lang.model.type.TypeMirror;
import org.lwjgl.PointerBuffer;
public class NativeMethodStubsGenerator {
private static final String BUFFER_ADDRESS_POSTFIX = "_address";
@ -60,18 +61,18 @@ public class NativeMethodStubsGenerator {
private static final String POINTER_LIST_NAME = "_ptr";
public static void generateNativeMethodStubs(ProcessingEnvironment env, TypeMap type_map, PrintWriter writer, TypeElement d, boolean generate_error_checks, boolean context_specific) {
for (ExecutableElement method : Utils.getMethods( d)) {
for ( ExecutableElement method : Utils.getMethods(d) ) {
Alternate alt_annotation = method.getAnnotation(Alternate.class);
if ( (alt_annotation != null && (!alt_annotation.nativeAlt() || alt_annotation.skipNative())) || method.getAnnotation(Reuse.class) != null )
continue;
generateMethodStub(env, type_map, writer, Utils.getQualifiedClassName(d), method, Mode.NORMAL, generate_error_checks, context_specific);
if (Utils.hasMethodBufferObjectParameter(method))
if ( Utils.hasMethodBufferObjectParameter(method) )
generateMethodStub(env, type_map, writer, Utils.getQualifiedClassName(d), method, Mode.BUFFEROBJECT, generate_error_checks, context_specific);
}
}
private static void generateParameters(PrintWriter writer, List<? extends VariableElement> params, Mode mode) {
for (VariableElement param : params) {
for ( VariableElement param : params ) {
if ( param.getAnnotation(Result.class) != null || (param.getAnnotation(Helper.class) != null && !param.getAnnotation(Helper.class).passToNative()) )
continue;
final Constant constant_annotation = param.getAnnotation(Constant.class);
@ -82,7 +83,7 @@ public class NativeMethodStubsGenerator {
private static void generateParameter(PrintWriter writer, VariableElement param, Mode mode) {
writer.print(", ");
if (mode == Mode.BUFFEROBJECT && param.getAnnotation(BufferObject.class) != null) {
if ( mode == Mode.BUFFEROBJECT && param.getAnnotation(BufferObject.class) != null ) {
writer.print("jlong " + param.getSimpleName() + Utils.BUFFER_OBJECT_PARAMETER_POSTFIX);
} else if ( param.getAnnotation(PointerWrapper.class) != null ) {
writer.print("jlong " + param.getSimpleName());
@ -113,24 +114,24 @@ public class NativeMethodStubsGenerator {
writer.print(" JNICALL ");
writer.print(Utils.getQualifiedNativeMethodName(interface_name, method, generate_error_checks, context_specific));
if (mode == Mode.BUFFEROBJECT)
if ( mode == Mode.BUFFEROBJECT )
writer.print(Utils.BUFFER_OBJECT_METHOD_POSTFIX);
writer.print("(JNIEnv *env, jclass clazz");
generateParameters(writer, method.getParameters(), mode);
if (Utils.getNIOBufferType(result_type) != null) {
if ( Utils.getNIOBufferType(result_type) != null ) {
if ( (cached_result_annotation == null || !cached_result_annotation.isRange()) && (auto_size_annotation == null || !auto_size_annotation.isNative()) )
writer.print(", jlong " + Utils.RESULT_SIZE_NAME);
if (cached_result_annotation != null)
if ( cached_result_annotation != null )
writer.print(", jobject " + Utils.CACHED_BUFFER_NAME);
}
if (context_specific) {
if ( context_specific ) {
writer.print(", jlong " + Utils.FUNCTION_POINTER_VAR_NAME);
}
writer.println(") {");
generateBufferParameterAddresses(type_map, writer, method, mode);
Alternate alt_annotation = method.getAnnotation(Alternate.class);
if (context_specific) {
if ( context_specific ) {
String typedef_name = Utils.getTypedefName(method);
writer.print("\t" + typedef_name + " " + (alt_annotation == null ? method.getSimpleName() : alt_annotation.value()));
writer.print(" = (" + typedef_name + ")((intptr_t)");
@ -166,21 +167,21 @@ public class NativeMethodStubsGenerator {
writer.println(code_annotation.nativeAfterCall());
generateStringDeallocations(writer, method.getParameters());
if (!result_type.equals(env.getTypeUtils().getNoType(TypeKind.VOID))) {
if ( !result_type.equals(env.getTypeUtils().getNoType(TypeKind.VOID)) ) {
writer.print("\treturn ");
Class java_result_type = Utils.getJavaType(result_type);
if (Buffer.class.isAssignableFrom(java_result_type)) {
if (cached_result_annotation != null)
if ( Buffer.class.isAssignableFrom(java_result_type) ) {
if ( cached_result_annotation != null )
writer.print("safeNewBufferCached(env, ");
else
writer.print("safeNewBuffer(env, ");
} else if (String.class.equals(java_result_type)) {
} else if ( String.class.equals(java_result_type) ) {
writer.print("NewStringNativeUnsigned(env, ");
} else if ( method.getAnnotation(PointerWrapper.class) != null ) {
writer.print("(intptr_t)");
}
writer.print(Utils.RESULT_VAR_NAME);
if (Buffer.class.isAssignableFrom(java_result_type)) {
if ( Buffer.class.isAssignableFrom(java_result_type) ) {
final String size_parameter_name;
if ( auto_size_annotation != null && (auto_size_annotation.isNative() || (cached_result_annotation != null && cached_result_annotation.isRange())) )
size_parameter_name = auto_size_annotation.value();
@ -190,8 +191,8 @@ public class NativeMethodStubsGenerator {
writer.print(", ");
Utils.printExtraCallArguments(writer, method, size_parameter_name);
}
if (Buffer.class.isAssignableFrom(java_result_type) ||
String.class.equals(java_result_type))
if ( Buffer.class.isAssignableFrom(java_result_type) ||
String.class.equals(java_result_type) )
writer.print(")");
writer.println(";");
}
@ -207,14 +208,14 @@ public class NativeMethodStubsGenerator {
if ( preDeclare )
writer.print("\t");
writer.print(result_translator.getSignature() + " " + Utils.RESULT_VAR_NAME);
if ( preDeclare)
if ( preDeclare )
writer.println(";");
else
writer.print(result_param == null ? " = " : ";\n\t");
}
private static void generateCallParameters(PrintWriter writer, TypeMap type_map, List<? extends VariableElement> params) {
if (params.size() > 0) {
if ( params.size() > 0 ) {
boolean first = true;
for ( VariableElement param : params ) {
if ( param.getAnnotation(Helper.class) != null )
@ -241,7 +242,7 @@ public class NativeMethodStubsGenerator {
}
boolean is_indirect = param.getAnnotation(Indirect.class) != null;
if (is_indirect || param.getAnnotation(PointerArray.class) != null) {
if ( is_indirect || param.getAnnotation(PointerArray.class) != null ) {
writer.print("(");
final NativeTypeTranslator translator = new NativeTypeTranslator(type_map, param);
param.asType().accept(translator, null);
@ -250,7 +251,7 @@ public class NativeMethodStubsGenerator {
}
if ( param.getAnnotation(PointerWrapper.class) != null )
writer.print("(" + param.getAnnotation(PointerWrapper.class).value() + ")(intptr_t)");
if (param.getAnnotation(Result.class) != null || is_indirect)
if ( param.getAnnotation(Result.class) != null || is_indirect )
writer.print("&");
if ( param.getAnnotation(Result.class) != null ) {
@ -265,11 +266,11 @@ public class NativeMethodStubsGenerator {
}
private static void generateStringDeallocations(PrintWriter writer, List<? extends VariableElement> params) {
for (VariableElement param : params) {
for ( VariableElement param : params ) {
final Class java_type = Utils.getJavaType(param.asType());
if ( java_type.equals(String.class) && param.getAnnotation(Result.class) == null )
writer.println("\tfree(" + param.getSimpleName() + BUFFER_ADDRESS_POSTFIX + ");");
else if (param.getAnnotation(PointerArray.class) != null ) // Free the string array mem
else if ( param.getAnnotation(PointerArray.class) != null ) // Free the string array mem
writer.println("\tfree(" + param.getSimpleName() + getPointerArrayName(java_type) + ");");
}
}
@ -279,7 +280,7 @@ public class NativeMethodStubsGenerator {
ptrLoopDeclared = false;
for ( VariableElement param : method.getParameters() ) {
final Constant constant_annotation = param.getAnnotation(Constant.class);
if ( param.getAnnotation(Result.class) == null && (constant_annotation == null || !constant_annotation.isNative()) && Utils.isAddressableType(param.asType()))
if ( param.getAnnotation(Result.class) == null && (constant_annotation == null || !constant_annotation.isNative()) && Utils.isAddressableType(param.asType()) )
generateBufferParameterAddress(type_map, writer, method, param, mode);
}
}
@ -302,12 +303,12 @@ public class NativeMethodStubsGenerator {
writer.print(native_type);
writer.print(")(intptr_t)");
if (mode == Mode.BUFFEROBJECT && param.getAnnotation(BufferObject.class) != null) {
if ( mode == Mode.BUFFEROBJECT && param.getAnnotation(BufferObject.class) != null ) {
writer.print("offsetToPointer(" + param.getSimpleName() + Utils.BUFFER_OBJECT_PARAMETER_POSTFIX + ")");
} else {
if (Buffer.class.isAssignableFrom(java_type) || java_type.equals(CharSequence.class) || java_type.equals(CharSequence[].class) || PointerBuffer.class.isAssignableFrom(java_type) ) {
if ( Buffer.class.isAssignableFrom(java_type) || java_type.equals(CharSequence.class) || java_type.equals(CharSequence[].class) || PointerBuffer.class.isAssignableFrom(java_type) ) {
writer.print(param.getSimpleName());
} else if (java_type.equals(String.class)) {
} else if ( java_type.equals(String.class) ) {
writer.print("GetStringNativeChars(env, " + param.getSimpleName() + ")");
} else if ( array_annotation == null )
throw new RuntimeException("Illegal type " + java_type);

View File

@ -39,21 +39,17 @@ package org.lwjgl.util.generator;
* @author elias_naur <elias_naur@users.sourceforge.net>
* @version $Revision$ $Id$
*/
import org.lwjgl.PointerBuffer;
import java.lang.annotation.Annotation;
import java.nio.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.Element;
import javax.lang.model.type.ArrayType;
import javax.lang.model.type.DeclaredType;
import javax.lang.model.type.NoType;
import javax.lang.model.type.PrimitiveType;
import javax.lang.model.type.TypeKind;
import javax.lang.model.type.*;
import javax.lang.model.util.SimpleTypeVisitor6;
import org.lwjgl.PointerBuffer;
/**
* $Id$
@ -81,27 +77,27 @@ public class NativeTypeTranslator extends SimpleTypeVisitor6<Void, Void> {
public String getSignature(final boolean skipConst) {
StringBuilder signature = new StringBuilder();
if (!skipConst && declaration.getAnnotation(Const.class) != null) {
if ( !skipConst && declaration.getAnnotation(Const.class) != null ) {
signature.append("const ");
}
if (declaration.getAnnotation(PointerWrapper.class) != null) {
if ( declaration.getAnnotation(PointerWrapper.class) != null ) {
signature.append(declaration.getAnnotation(PointerWrapper.class).value());
} else if (declaration.getAnnotation(NativeType.class) != null) {
} else if ( declaration.getAnnotation(NativeType.class) != null ) {
signature.append(declaration.getAnnotation(NativeType.class).value());
} else {
// Use the name of the native type annotation as the C type name
signature.append(getAnnotationType().getSimpleName());
}
if (is_indirect) {
if ( is_indirect ) {
signature.append(" *");
}
return signature.toString();
}
public Class getAnnotationType() {
if (native_types.size() != 1) {
if ( native_types.size() != 1 ) {
throw new RuntimeException("Expected only one native type for declaration " + declaration
+ ", but got " + native_types.size());
}
@ -112,15 +108,15 @@ public class NativeTypeTranslator extends SimpleTypeVisitor6<Void, Void> {
public Void visitArray(ArrayType t, Void o) {
final Class<?> type = Utils.getJavaType(t).getComponentType();
if (CharSequence.class.isAssignableFrom(type)) {
if ( CharSequence.class.isAssignableFrom(type) ) {
is_indirect = true;
native_types = new ArrayList<>();
native_types.add(type_map.getStringArrayType());
} else if (Buffer.class.isAssignableFrom(type)) {
} else if ( Buffer.class.isAssignableFrom(type) ) {
is_indirect = true;
native_types = new ArrayList<>();
native_types.add(type_map.getByteBufferArrayType());
} else if (org.lwjgl.PointerWrapper.class.isAssignableFrom(type)) {
} else if ( org.lwjgl.PointerWrapper.class.isAssignableFrom(type) ) {
is_indirect = false;
} else {
throw new RuntimeException(t + " is not allowed");
@ -129,17 +125,17 @@ public class NativeTypeTranslator extends SimpleTypeVisitor6<Void, Void> {
}
public static TypeKind getPrimitiveKindFromBufferClass(Class c) {
if (IntBuffer.class.equals(c)) {
if ( IntBuffer.class.equals(c) ) {
return TypeKind.INT;
} else if (DoubleBuffer.class.equals(c)) {
} else if ( DoubleBuffer.class.equals(c) ) {
return TypeKind.DOUBLE;
} else if (ShortBuffer.class.equals(c)) {
} else if ( ShortBuffer.class.equals(c) ) {
return TypeKind.SHORT;
} else if (ByteBuffer.class.equals(c) || PointerBuffer.class.equals(c)) {
} else if ( ByteBuffer.class.equals(c) || PointerBuffer.class.equals(c) ) {
return TypeKind.BYTE;
} else if (FloatBuffer.class.equals(c)) {
} else if ( FloatBuffer.class.equals(c) ) {
return TypeKind.FLOAT;
} else if (LongBuffer.class.equals(c)) {
} else if ( LongBuffer.class.equals(c) ) {
return TypeKind.LONG;
} else {
throw new RuntimeException(c + " is not allowed");
@ -149,7 +145,7 @@ public class NativeTypeTranslator extends SimpleTypeVisitor6<Void, Void> {
@SuppressWarnings("unchecked")
public static Class<? extends Annotation> getClassFromType(DeclaredType t) {
try {
return (Class<? extends Annotation>) Class.forName(t.toString());
return (Class<? extends Annotation>)Class.forName(t.toString());
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
@ -157,7 +153,7 @@ public class NativeTypeTranslator extends SimpleTypeVisitor6<Void, Void> {
private void getNativeTypeFromAnnotatedPrimitiveType(TypeKind kind) {
native_types = translateAnnotations();
if (native_types.isEmpty()) {
if ( native_types.isEmpty() ) {
native_types.add(type_map.getNativeTypeFromPrimitiveType(kind));
}
}
@ -166,16 +162,16 @@ public class NativeTypeTranslator extends SimpleTypeVisitor6<Void, Void> {
is_indirect = true;
Class<?> c = getClassFromType(t);
if (String.class.equals(c)) {
if ( String.class.equals(c) ) {
native_types = new ArrayList<>();
native_types.add(type_map.getStringElementType());
} else if (Buffer.class.equals(c)) {
} else if ( Buffer.class.equals(c) ) {
native_types = new ArrayList<>();
native_types.add(type_map.getVoidType());
} else if (Buffer.class.isAssignableFrom(c) || PointerBuffer.class.isAssignableFrom(c)) {
} else if ( Buffer.class.isAssignableFrom(c) || PointerBuffer.class.isAssignableFrom(c) ) {
TypeKind kind = getPrimitiveKindFromBufferClass(c);
getNativeTypeFromAnnotatedPrimitiveType(kind);
} else if (org.lwjgl.PointerWrapper.class.isAssignableFrom(c)) {
} else if ( org.lwjgl.PointerWrapper.class.isAssignableFrom(c) ) {
native_types = new ArrayList<>();
native_types.add(PointerWrapper.class);
@ -194,7 +190,7 @@ public class NativeTypeTranslator extends SimpleTypeVisitor6<Void, Void> {
private void visitInterfaceType(DeclaredType t) {
// See ARB_debug_label.glObjectPtrLabel
Class<?> c = getClassFromType(t);
if (org.lwjgl.PointerWrapper.class.isAssignableFrom(c)) {
if ( org.lwjgl.PointerWrapper.class.isAssignableFrom(c) ) {
native_types = new ArrayList<>();
native_types.add(PointerWrapper.class);
@ -206,9 +202,9 @@ public class NativeTypeTranslator extends SimpleTypeVisitor6<Void, Void> {
@Override
public Void visitDeclared(DeclaredType t, Void p) {
if (t.asElement().getKind().isInterface()) {
if ( t.asElement().getKind().isInterface() ) {
visitInterfaceType(t);
} else if (t.asElement().getKind().isClass()) {
} else if ( t.asElement().getKind().isClass() ) {
visitClassType(t);
}
return DEFAULT_VALUE;
@ -223,7 +219,7 @@ public class NativeTypeTranslator extends SimpleTypeVisitor6<Void, Void> {
private static Class translateAnnotation(AnnotationMirror annotation) {
NativeType native_type = getAnnotation(annotation, NativeType.class);
if (native_type != null) {
if ( native_type != null ) {
return getClassFromType(annotation.getAnnotationType());
} else {
return null;
@ -232,9 +228,9 @@ public class NativeTypeTranslator extends SimpleTypeVisitor6<Void, Void> {
private List<Class> translateAnnotations() {
List<Class> result = new ArrayList<>();
for (AnnotationMirror annotation : Utils.getSortedAnnotations(declaration.getAnnotationMirrors())) {
for ( AnnotationMirror annotation : Utils.getSortedAnnotations(declaration.getAnnotationMirrors()) ) {
Class translated_result = translateAnnotation(annotation);
if (translated_result != null) {
if ( translated_result != null ) {
result.add(translated_result);
}
}
@ -244,7 +240,7 @@ public class NativeTypeTranslator extends SimpleTypeVisitor6<Void, Void> {
@Override
public Void visitNoType(NoType t, Void p) {
native_types = translateAnnotations();
if (native_types.isEmpty()) {
if ( native_types.isEmpty() ) {
native_types.add(void.class);
}
return DEFAULT_VALUE;

View File

@ -51,7 +51,7 @@ import javax.lang.model.type.PrimitiveType;
import javax.lang.model.type.TypeKind;
import javax.lang.model.util.SimpleTypeVisitor6;
public class PostfixTranslator extends SimpleTypeVisitor6<Void,Void> {
public class PostfixTranslator extends SimpleTypeVisitor6<Void, Void> {
private final StringBuilder signature = new StringBuilder();
private final Element declaration;
private final TypeMap type_map;
@ -66,17 +66,17 @@ public class PostfixTranslator extends SimpleTypeVisitor6<Void,Void> {
}
private static TypeKind getPrimitiveKindFromBufferClass(Class c) {
if (IntBuffer.class.equals(c) || int.class.equals(c) )
if ( IntBuffer.class.equals(c) || int.class.equals(c) )
return TypeKind.INT;
else if (DoubleBuffer.class.equals(c) || double.class.equals(c) )
else if ( DoubleBuffer.class.equals(c) || double.class.equals(c) )
return TypeKind.DOUBLE;
else if (ShortBuffer.class.equals(c) || short.class.equals(c) )
else if ( ShortBuffer.class.equals(c) || short.class.equals(c) )
return TypeKind.SHORT;
else if (ByteBuffer.class.equals(c) || byte.class.equals(c) )
else if ( ByteBuffer.class.equals(c) || byte.class.equals(c) )
return TypeKind.BYTE;
else if (FloatBuffer.class.equals(c) || float.class.equals(c))
else if ( FloatBuffer.class.equals(c) || float.class.equals(c) )
return TypeKind.FLOAT;
else if (LongBuffer.class.equals(c) || long.class.equals(c) )
else if ( LongBuffer.class.equals(c) || long.class.equals(c) )
return TypeKind.LONG;
else
throw new RuntimeException(c + " is not allowed");
@ -90,14 +90,14 @@ public class PostfixTranslator extends SimpleTypeVisitor6<Void,Void> {
@Override
public Void visitDeclared(DeclaredType t, Void o) {
if(t.asElement().getKind().isClass())
if ( t.asElement().getKind().isClass() )
visitClassType(t);
return DEFAULT_VALUE;
}
private boolean translateAnnotation(AnnotationMirror annotation) {
NativeType native_type = NativeTypeTranslator.getAnnotation(annotation, NativeType.class);
if (native_type != null) {
if ( native_type != null ) {
Class<? extends Annotation> annotation_class = NativeTypeTranslator.getClassFromType(annotation.getAnnotationType());
signature.append(type_map.translateAnnotation(annotation_class));
return true;
@ -107,9 +107,9 @@ public class PostfixTranslator extends SimpleTypeVisitor6<Void,Void> {
private boolean translateAnnotations() {
boolean result = false;
for (AnnotationMirror annotation : Utils.getSortedAnnotations(declaration.getAnnotationMirrors()))
if (translateAnnotation(annotation)) {
if (result)
for ( AnnotationMirror annotation : Utils.getSortedAnnotations(declaration.getAnnotationMirrors()) )
if ( translateAnnotation(annotation) ) {
if ( result )
throw new RuntimeException("Multiple native types");
result = true;
}
@ -124,11 +124,11 @@ public class PostfixTranslator extends SimpleTypeVisitor6<Void,Void> {
private void visitPrimitiveTypeKind(TypeKind kind) {
boolean annotated_translation = translateAnnotations();
if (annotated_translation)
if ( annotated_translation )
return;
// No annotation type was specified, fall back to default
String type;
switch (kind) {
switch ( kind ) {
case INT:
type = "i";
break;

View File

@ -38,8 +38,11 @@ package org.lwjgl.util.generator;
* @author elias_naur <elias_naur@users.sourceforge.net>
* @version $Revision$ $Id$
*/
import java.io.*;
import java.util.*;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.Iterator;
import java.util.List;
import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.TypeElement;
@ -49,25 +52,25 @@ import javax.lang.model.type.TypeMirror;
public class RegisterStubsGenerator {
public static void generateMethodsNativeStubBind(ProcessingEnvironment env, PrintWriter writer, TypeElement d, boolean generate_error_checks, boolean context_specific) {
Iterator<? extends ExecutableElement> it = Utils.getMethods( d).iterator();
while (it.hasNext()) {
Iterator<? extends ExecutableElement> it = Utils.getMethods(d).iterator();
while ( it.hasNext() ) {
ExecutableElement method = it.next();
Alternate alt_annotation = method.getAnnotation(Alternate.class);
if ((alt_annotation != null && (!alt_annotation.nativeAlt() || alt_annotation.skipNative())) || method.getAnnotation(Reuse.class) != null) {
if ( (alt_annotation != null && (!alt_annotation.nativeAlt() || alt_annotation.skipNative())) || method.getAnnotation(Reuse.class) != null ) {
continue;
}
EnumSet<Platform> platforms;
PlatformDependent platform_annotation = method.getAnnotation(PlatformDependent.class);
if (platform_annotation != null) {
if ( platform_annotation != null ) {
platforms = EnumSet.copyOf(Arrays.asList(platform_annotation.value()));
} else {
platforms = EnumSet.of(Platform.ALL);
}
for (Platform platform : platforms) {
for ( Platform platform : platforms ) {
platform.printPrologue(writer);
boolean has_buffer_parameter = Utils.hasMethodBufferObjectParameter(method);
printMethodNativeStubBind(writer, d, method, platform, Mode.NORMAL, it.hasNext() || has_buffer_parameter, generate_error_checks, context_specific);
if (has_buffer_parameter) {
if ( has_buffer_parameter ) {
printMethodNativeStubBind(writer, d, method, platform, Mode.BUFFEROBJECT, it.hasNext(), generate_error_checks, context_specific);
}
platform.printEpilogue(writer);
@ -85,17 +88,17 @@ public class RegisterStubsGenerator {
private static String getMethodSignature(ExecutableElement method, Mode mode) {
List<? extends VariableElement> params = method.getParameters();
String signature = "(";
for (VariableElement param : params) {
if (param.getAnnotation(Result.class) != null || (param.getAnnotation(Helper.class) != null && !param.getAnnotation(Helper.class).passToNative())) {
for ( VariableElement param : params ) {
if ( param.getAnnotation(Result.class) != null || (param.getAnnotation(Helper.class) != null && !param.getAnnotation(Helper.class).passToNative()) ) {
continue;
}
final Constant constant_annotation = param.getAnnotation(Constant.class);
if (constant_annotation != null && constant_annotation.isNative()) {
if ( constant_annotation != null && constant_annotation.isNative() ) {
continue;
}
if (mode == Mode.BUFFEROBJECT && param.getAnnotation(BufferObject.class) != null) {
if ( mode == Mode.BUFFEROBJECT && param.getAnnotation(BufferObject.class) != null ) {
signature += "J";
} else {
signature += getTypeSignature(param.asType(), true);
@ -107,12 +110,12 @@ public class RegisterStubsGenerator {
final AutoSize auto_size_annotation = method.getAnnotation(AutoSize.class);
final boolean isNIOBuffer = Utils.getNIOBufferType(result_type) != null;
if (isNIOBuffer && (auto_size_annotation == null || !auto_size_annotation.isNative())) {
if ( isNIOBuffer && (auto_size_annotation == null || !auto_size_annotation.isNative()) ) {
signature += "J";
}
final String result_type_signature = isNIOBuffer ? "Ljava/nio/ByteBuffer;" : getTypeSignature(result_type, false);
if (cached_result_annotation != null) {
if ( cached_result_annotation != null ) {
signature += result_type_signature;
}
@ -123,12 +126,12 @@ public class RegisterStubsGenerator {
private static void printMethodNativeStubBind(PrintWriter writer, TypeElement d, ExecutableElement method, Platform platform, Mode mode, boolean has_more, boolean generate_error_checks, boolean context_specific) {
writer.print("\t\t{\"" + Utils.getSimpleNativeMethodName(method, generate_error_checks, context_specific));
if (mode == Mode.BUFFEROBJECT) {
if ( mode == Mode.BUFFEROBJECT ) {
writer.print(Utils.BUFFER_OBJECT_METHOD_POSTFIX);
}
writer.print("\", \"" + getMethodSignature(method, mode) + "\", (void *)&");
writer.print(Utils.getQualifiedNativeMethodName(Utils.getQualifiedClassName(d), method, generate_error_checks, context_specific));
if (mode == Mode.BUFFEROBJECT) {
if ( mode == Mode.BUFFEROBJECT ) {
writer.print(Utils.BUFFER_OBJECT_METHOD_POSTFIX);
}
@ -136,7 +139,7 @@ public class RegisterStubsGenerator {
final String methodName = alt_annotation == null ? method.getSimpleName().toString() : alt_annotation.value();
String opengl_handle_name = methodName.replaceFirst("gl", platform.getPrefix());
writer.print(", \"" + opengl_handle_name + "\", (void *)&" + methodName + ", " + (method.getAnnotation(Optional.class) == null ? "false" : "true") + "}");
if (has_more) {
if ( has_more ) {
writer.println(",");
}
}

View File

@ -41,22 +41,15 @@ package org.lwjgl.util.generator;
* $Id$
*/
import org.lwjgl.PointerBuffer;
import java.nio.*;
import javax.annotation.processing.ProcessingEnvironment;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import javax.lang.model.type.ArrayType;
import javax.lang.model.type.DeclaredType;
import javax.lang.model.type.NoType;
import javax.lang.model.type.PrimitiveType;
import static javax.lang.model.type.TypeKind.BOOLEAN;
import static javax.lang.model.type.TypeKind.BYTE;
import static javax.lang.model.type.TypeKind.DOUBLE;
import static javax.lang.model.type.TypeKind.FLOAT;
import static javax.lang.model.type.TypeKind.INT;
import static javax.lang.model.type.TypeKind.LONG;
import static javax.lang.model.type.TypeKind.SHORT;
import javax.lang.model.util.SimpleTypeVisitor6;
import org.lwjgl.PointerBuffer;
class SignatureTranslator extends SimpleTypeVisitor6<Void, Void> {
private final boolean add_position_signature;
@ -108,9 +101,9 @@ class SignatureTranslator extends SimpleTypeVisitor6<Void, Void> {
@Override
public Void visitDeclared(DeclaredType t, Void o) {
if(t.asElement().getKind().isClass())
if ( t.asElement().getKind().isClass() )
visitClassType(t);
else if(t.asElement().getKind().isInterface())
else if ( t.asElement().getKind().isInterface() )
visitInterfaceType(t);
return DEFAULT_VALUE;
}
@ -125,7 +118,7 @@ class SignatureTranslator extends SimpleTypeVisitor6<Void, Void> {
@Override
public Void visitPrimitive(PrimitiveType t, Void o) {
switch (t.getKind()) {
switch ( t.getKind() ) {
case BOOLEAN:
signature.append("Z");
break;

View File

@ -39,19 +39,18 @@ package org.lwjgl.util.generator;
* @author elias_naur <elias_naur@users.sourceforge.net>
* @version $Revision$ $Id$
*/
import org.lwjgl.PointerBuffer;
import org.lwjgl.util.generator.opengl.GLvoid;
import java.lang.annotation.Annotation;
import java.nio.*;
import java.util.*;
import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.Element;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.VariableElement;
import javax.lang.model.type.TypeKind;
import javax.lang.model.type.TypeMirror;
import javax.tools.Diagnostic;
import org.lwjgl.PointerBuffer;
import org.lwjgl.util.generator.opengl.GLvoid;
public class TypeInfo {
@ -76,7 +75,7 @@ public class TypeInfo {
}
public String getAutoType() {
if (auto_type == null) {
if ( auto_type == null ) {
throw new RuntimeException("No auto type assigned");
}
return auto_type;
@ -84,7 +83,7 @@ public class TypeInfo {
private static Class getTypeFromPrimitiveKind(TypeKind kind) {
Class type;
switch (kind) {
switch ( kind ) {
case LONG:
type = long.class;
break;
@ -114,7 +113,7 @@ public class TypeInfo {
private static Class getBufferTypeFromPrimitiveKind(TypeKind kind, AnnotationMirror annotation) {
Class type;
switch (kind) {
switch ( kind ) {
case INT:
type = IntBuffer.class;
break;
@ -128,7 +127,7 @@ public class TypeInfo {
type = ShortBuffer.class;
break;
case LONG:
if (annotation.getAnnotationType().asElement().getAnnotation(PointerType.class) != null) {
if ( annotation.getAnnotationType().asElement().getAnnotation(PointerType.class) != null ) {
type = PointerBuffer.class;
} else {
type = LongBuffer.class;
@ -152,7 +151,7 @@ public class TypeInfo {
public static Map<VariableElement, TypeInfo> getDefaultTypeInfoMap(ExecutableElement method) {
Map<VariableElement, TypeInfo> map = new HashMap<>();
for (VariableElement param : method.getParameters()) {
for ( VariableElement param : method.getParameters() ) {
TypeInfo type_info = getDefaultTypeInfo(param.asType());
map.put(param, type_info);
}
@ -166,16 +165,16 @@ public class TypeInfo {
Map<Class, TypeInfo> types = new HashMap<>();
Collection<TypeInfo> multityped_result = new ArrayList<>();
boolean add_default_type = true;
for (AnnotationMirror annotation : annotations) {
for ( AnnotationMirror annotation : annotations ) {
NativeType native_type_annotation = NativeTypeTranslator.getAnnotation(annotation, NativeType.class);
if (native_type_annotation != null) {
if ( native_type_annotation != null ) {
Class<? extends Annotation> annotation_type = NativeTypeTranslator.getClassFromType(annotation.getAnnotationType());
/*env.getMessager().printMessage(Diagnostic.Kind.NOTE, "annotation_type " + annotation_type, param, annotation);*/
Signedness signedness = type_map.getSignednessFromType(annotation_type);
Class inverse_type = type_map.getInverseType(annotation_type);
String auto_type = type_map.getAutoTypeFromAnnotation(annotation);
if (inverse_type != null) {
if (types.containsKey(inverse_type)) {
if ( inverse_type != null ) {
if ( types.containsKey(inverse_type) ) {
TypeInfo inverse_type_info = types.get(inverse_type);
String inverse_auto_type = inverse_type_info.getAutoType();
auto_type = signedness == Signedness.UNSIGNED ? auto_type + " : " + inverse_auto_type
@ -189,7 +188,7 @@ public class TypeInfo {
Class type;
TypeKind kind;
kind = void_annotation == null ? type_map.getPrimitiveTypeFromNativeType(annotation_type) : void_annotation.value();
if (Utils.getNIOBufferType(param.asType()) != null) {
if ( Utils.getNIOBufferType(param.asType()) != null ) {
type = getBufferTypeFromPrimitiveKind(kind, annotation);
} else {
type = getTypeFromPrimitiveKind(kind);
@ -200,7 +199,7 @@ public class TypeInfo {
add_default_type = false;
}
}
if (add_default_type) {
if ( add_default_type ) {
TypeInfo default_type_info = getDefaultTypeInfo(param.asType());
Collection<TypeInfo> result = new ArrayList<>();
result.add(default_type_info);
@ -212,7 +211,7 @@ public class TypeInfo {
private static Map<VariableElement, Collection<TypeInfo>> getTypeInfoMap(ProcessingEnvironment env, TypeMap type_map, ExecutableElement method) {
Map<VariableElement, Collection<TypeInfo>> map = new HashMap<>();
for (VariableElement param : method.getParameters()) {
for ( VariableElement param : method.getParameters() ) {
Collection<TypeInfo> types = getTypeInfos(env, type_map, param);
map.put(param, types);
}
@ -228,7 +227,7 @@ public class TypeInfo {
}
private static void getCrossProductRecursive(int index, List<? extends VariableElement> parameters, Map<VariableElement, Collection<TypeInfo>> typeinfos_map, Map<VariableElement, TypeInfo> current_instance, Collection<Map<VariableElement, TypeInfo>> cross_product) {
if (index == parameters.size()) {
if ( index == parameters.size() ) {
/**
* the last parameter is treated as multi-type only
*/
@ -237,8 +236,8 @@ public class TypeInfo {
}
VariableElement param = parameters.get(index);
Collection<TypeInfo> typeinfos = typeinfos_map.get(param);
if (typeinfos != null) {
for (TypeInfo typeinfo : typeinfos) {
if ( typeinfos != null ) {
for ( TypeInfo typeinfo : typeinfos ) {
Map<VariableElement, TypeInfo> instance = new HashMap<>(current_instance);
instance.put(param, typeinfo);
getCrossProductRecursive(index + 1, parameters, typeinfos_map, instance, cross_product);

View File

@ -41,8 +41,7 @@ package org.lwjgl.util.generator;
* $Id$
*/
import java.io.*;
import java.io.PrintWriter;
import java.lang.annotation.Annotation;
import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.ExecutableElement;

View File

@ -41,9 +41,8 @@ package org.lwjgl.util.generator;
* $Id$
*/
import java.io.*;
import java.util.*;
import java.io.PrintWriter;
import java.util.Collection;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.VariableElement;
import javax.lang.model.type.TypeMirror;
@ -64,7 +63,7 @@ public class TypedefsGenerator {
}
private static void generateNativeTypedefsParameters(TypeMap type_map, PrintWriter writer, Collection<? extends VariableElement> params) {
if (params.size() > 0) {
if ( params.size() > 0 ) {
boolean first = true;
for ( VariableElement param : params ) {
if ( param.getAnnotation(Helper.class) != null )
@ -84,13 +83,13 @@ public class TypedefsGenerator {
NativeTypeTranslator translator = new NativeTypeTranslator(type_map, param);
param.asType().accept(translator, null);
writer.print(translator.getSignature());
if (param.getAnnotation(Result.class) != null || param.getAnnotation(Indirect.class) != null || param.getAnnotation(PointerArray.class) != null)
if ( param.getAnnotation(Result.class) != null || param.getAnnotation(Indirect.class) != null || param.getAnnotation(PointerArray.class) != null )
writer.print("*");
writer.print(" " + param.getSimpleName());
}
public static void generateNativeTypedefs(TypeMap type_map, PrintWriter writer, Collection<? extends ExecutableElement> methods) {
for (ExecutableElement method : methods) {
for ( ExecutableElement method : methods ) {
if ( method.getAnnotation(Alternate.class) == null && method.getAnnotation(Reuse.class) == null )
generateNativeTypedefs(type_map, writer, method);
}

View File

@ -38,27 +38,23 @@ package org.lwjgl.util.generator;
* @author elias_naur <elias_naur@users.sourceforge.net>
* @version $Revision$ $Id$
*/
import java.io.PrintWriter;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.util.*;
import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.Element;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.TypeElement;
import javax.lang.model.element.VariableElement;
import javax.lang.model.type.TypeKind;
import javax.lang.model.type.TypeMirror;
import javax.lang.model.type.TypeVisitor;
import javax.lang.model.util.ElementFilter;
import javax.tools.Diagnostic;
import org.lwjgl.PointerBuffer;
import org.lwjgl.util.generator.opengl.GLboolean;
import org.lwjgl.util.generator.opengl.GLchar;
import org.lwjgl.util.generator.opengl.GLcharARB;
import org.lwjgl.util.generator.opengl.GLreturn;
import java.io.PrintWriter;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.util.*;
import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.element.*;
import javax.lang.model.type.TypeKind;
import javax.lang.model.type.TypeMirror;
import javax.lang.model.type.TypeVisitor;
import javax.lang.model.util.ElementFilter;
public class Utils {
public static final String TYPEDEF_POSTFIX = "PROC";
@ -94,7 +90,7 @@ public class Utils {
else
return interfaceName + "_" + alt_annotation.value() + FUNCTION_POINTER_POSTFIX;
*/
if (alt_annotation == null || (alt_annotation.nativeAlt() && !forceAlt)) {
if ( alt_annotation == null || (alt_annotation.nativeAlt() && !forceAlt) ) {
return method.getSimpleName().toString();
} else {
return alt_annotation.value();
@ -139,7 +135,7 @@ public class Utils {
}
public static boolean isAddressableType(Class type) {
if (type.isArray()) {
if ( type.isArray() ) {
final Class component_type = type.getComponentType();
return isAddressableTypeImpl(component_type) || org.lwjgl.PointerWrapper.class.isAssignableFrom(component_type);
}
@ -152,14 +148,14 @@ public class Utils {
public static Class getJavaType(TypeMirror type_mirror) {
JavaTypeTranslator translator = new JavaTypeTranslator();
type_mirror.accept((TypeVisitor) translator, null);
type_mirror.accept((TypeVisitor)translator, null);
return translator.getType();
}
private static boolean hasParameterMultipleTypes(VariableElement param) {
int num_native_annotations = 0;
for (AnnotationMirror annotation : param.getAnnotationMirrors()) {
if (NativeTypeTranslator.getAnnotation(annotation, NativeType.class) != null) {
for ( AnnotationMirror annotation : param.getAnnotationMirrors() ) {
if ( NativeTypeTranslator.getAnnotation(annotation, NativeType.class) != null ) {
num_native_annotations++;
}
}
@ -168,15 +164,15 @@ public class Utils {
public static boolean isParameterMultiTyped(VariableElement param) {
boolean result = Buffer.class.equals(Utils.getJavaType(param.asType()));
if (!result && hasParameterMultipleTypes(param)) {
if ( !result && hasParameterMultipleTypes(param) ) {
throw new RuntimeException(param + " not defined as java.nio.Buffer but has multiple types");
}
return result;
}
public static VariableElement findParameter(ExecutableElement method, String name) {
for (VariableElement param : method.getParameters()) {
if (param.getSimpleName().toString().equals(name)) {
for ( VariableElement param : method.getParameters() ) {
if ( param.getSimpleName().toString().equals(name) ) {
return param;
}
}
@ -185,28 +181,28 @@ public class Utils {
public static void printDocComment(PrintWriter writer, Element decl, ProcessingEnvironment pe) {
final String overloadsComment;
if ((decl instanceof ExecutableElement) && decl.getAnnotation(Alternate.class) != null) {
if ( (decl instanceof ExecutableElement) && decl.getAnnotation(Alternate.class) != null ) {
overloadsComment = "Overloads " + decl.getAnnotation(Alternate.class).value() + ".";
} else {
overloadsComment = null;
}
String doc_comment = pe.getElementUtils().getDocComment(decl);
if (doc_comment != null) {
if ( doc_comment != null ) {
final String tab = (decl instanceof TypeElement) ? "" : "\t";
writer.println(tab + "/**");
if (overloadsComment != null) {
if ( overloadsComment != null ) {
writer.println("\t * " + overloadsComment);
writer.println("\t * <p>");
}
final StringTokenizer doc_lines = new StringTokenizer(doc_comment, "\n", true);
boolean lastWasNL = false;
while (doc_lines.hasMoreTokens()) {
while ( doc_lines.hasMoreTokens() ) {
final String t = doc_lines.nextToken();
if ("\n".equals(t)) {
if (lastWasNL) {
if ( "\n".equals(t) ) {
if ( lastWasNL ) {
writer.println(tab + " * <p>");
}
lastWasNL = true;
@ -217,14 +213,14 @@ public class Utils {
}
writer.println(tab + " */");
} else if (overloadsComment != null) {
} else if ( overloadsComment != null ) {
writer.println("\t/** " + overloadsComment + " */");
}
}
public static AnnotationMirror getParameterAutoAnnotation(VariableElement param) {
for (AnnotationMirror annotation : param.getAnnotationMirrors()) {
if (NativeTypeTranslator.getAnnotation(annotation, Auto.class) != null) {
for ( AnnotationMirror annotation : param.getAnnotationMirrors() ) {
if ( NativeTypeTranslator.getAnnotation(annotation, Auto.class) != null ) {
return annotation;
}
}
@ -253,7 +249,7 @@ public class Utils {
public static String getQualifiedNativeMethodName(String qualified_class_name, String method_name) {
// Escape '_' in method name
if (method_name.indexOf('_') != -1) {
if ( method_name.indexOf('_') != -1 ) {
method_name = method_name.replace("_", "_1");
}
@ -267,9 +263,9 @@ public class Utils {
public static VariableElement getResultParameter(ExecutableElement method) {
VariableElement result_param = null;
for (VariableElement param : method.getParameters()) {
if (param.getAnnotation(Result.class) != null) {
if (result_param != null) {
for ( VariableElement param : method.getParameters() ) {
if ( param.getAnnotation(Result.class) != null ) {
if ( result_param != null ) {
throw new RuntimeException("Multiple parameters annotated with Result in method " + method);
}
result_param = param;
@ -281,7 +277,7 @@ public class Utils {
public static TypeMirror getMethodReturnType(ExecutableElement method) {
TypeMirror result_type;
VariableElement result_param = getResultParameter(method);
if (result_param != null) {
if ( result_param != null ) {
result_type = result_param.asType();
} else {
result_type = method.getReturnType();
@ -291,22 +287,22 @@ public class Utils {
public static String getMethodReturnType(ExecutableElement method, GLreturn return_annotation, boolean buffer) {
VariableElement return_param = null;
for (VariableElement param : method.getParameters()) {
if (param.getSimpleName().toString().equals(return_annotation.value())) {
for ( VariableElement param : method.getParameters() ) {
if ( param.getSimpleName().toString().equals(return_annotation.value()) ) {
return_param = param;
break;
}
}
if (return_param == null) {
if ( return_param == null ) {
throw new RuntimeException("The @GLreturn parameter \"" + return_annotation.value() + "\" could not be found in method: " + method);
}
TypeKind kind = NativeTypeTranslator.getPrimitiveKindFromBufferClass(Utils.getJavaType(return_param.asType()));
if (return_param.getAnnotation(GLboolean.class) != null) {
if ( return_param.getAnnotation(GLboolean.class) != null ) {
kind = TypeKind.BOOLEAN;
}
if (kind == TypeKind.BYTE && (return_param.getAnnotation(GLchar.class) != null || return_param.getAnnotation(GLcharARB.class) != null)) {
if ( kind == TypeKind.BYTE && (return_param.getAnnotation(GLchar.class) != null || return_param.getAnnotation(GLcharARB.class) != null) ) {
return "String";
} else {
final String type = JavaTypeTranslator.getPrimitiveClassFromKind(kind).getName();
@ -320,20 +316,20 @@ public class Utils {
public static void printExtraCallArguments(PrintWriter writer, ExecutableElement method, String size_parameter_name) {
writer.print(size_parameter_name);
if (method.getAnnotation(CachedResult.class) != null) {
if ( method.getAnnotation(CachedResult.class) != null ) {
writer.print(", " + CACHED_BUFFER_NAME);
}
}
private static String getClassName(TypeElement interface_decl, String opengl_name) {
Extension extension_annotation = interface_decl.getAnnotation(Extension.class);
if (extension_annotation != null && !"".equals(extension_annotation.className())) {
if ( extension_annotation != null && !"".equals(extension_annotation.className()) ) {
return extension_annotation.className();
}
StringBuilder result = new StringBuilder();
for (int i = 0; i < opengl_name.length(); i++) {
for ( int i = 0; i < opengl_name.length(); i++ ) {
int ch = opengl_name.codePointAt(i);
if (ch == '_') {
if ( ch == '_' ) {
i++;
result.appendCodePoint(Character.toUpperCase(opengl_name.codePointAt(i)));
} else {
@ -344,8 +340,8 @@ public class Utils {
}
public static boolean hasMethodBufferObjectParameter(ExecutableElement method) {
for (VariableElement param : method.getParameters()) {
if (param.getAnnotation(BufferObject.class) != null) {
for ( VariableElement param : method.getParameters() ) {
if ( param.getAnnotation(BufferObject.class) != null ) {
return true;
}
}
@ -362,9 +358,9 @@ public class Utils {
public static Class<?> getNIOBufferType(TypeMirror t) {
Class<?> param_type = getJavaType(t);
if (Buffer.class.isAssignableFrom(param_type)) {
if ( Buffer.class.isAssignableFrom(param_type) ) {
return param_type;
} else if (param_type == CharSequence.class || param_type == CharSequence[].class || param_type == PointerBuffer.class) {
} else if ( param_type == CharSequence.class || param_type == CharSequence[].class || param_type == PointerBuffer.class ) {
return ByteBuffer.class;
} else {
return null;
@ -375,7 +371,7 @@ public class Utils {
String method_name;
Alternate alt_annotation = method.getAnnotation(Alternate.class);
method_name = alt_annotation == null || alt_annotation.nativeAlt() ? method.getSimpleName().toString() : alt_annotation.value();
if (isMethodIndirect(generate_error_checks, context_specific, method)) {
if ( isMethodIndirect(generate_error_checks, context_specific, method) ) {
method_name = OVERLOADED_METHOD_PREFIX + method_name;
}
return method_name;
@ -383,19 +379,19 @@ public class Utils {
static boolean isReturnParameter(ExecutableElement method, VariableElement param) {
GLreturn string_annotation = method.getAnnotation(GLreturn.class);
if (string_annotation == null || !string_annotation.value().equals(param.getSimpleName().toString())) {
if ( string_annotation == null || !string_annotation.value().equals(param.getSimpleName().toString()) ) {
return false;
}
if (param.getAnnotation(OutParameter.class) == null) {
if ( param.getAnnotation(OutParameter.class) == null ) {
throw new RuntimeException("The parameter specified in @GLreturn is not annotated with @OutParameter in method: " + method);
}
if (param.getAnnotation(Check.class) != null) {
if ( param.getAnnotation(Check.class) != null ) {
throw new RuntimeException("The parameter specified in @GLreturn is annotated with @Check in method: " + method);
}
if (param.getAnnotation(GLchar.class) != null && Utils.getJavaType(param.asType()).equals(ByteBuffer.class) && string_annotation.maxLength().length() == 0) {
if ( param.getAnnotation(GLchar.class) != null && Utils.getJavaType(param.asType()).equals(ByteBuffer.class) && string_annotation.maxLength().length() == 0 ) {
throw new RuntimeException("The @GLreturn annotation is missing a maxLength parameter in method: " + method);
}
@ -404,25 +400,25 @@ public class Utils {
static String getStringOffset(ExecutableElement method, VariableElement param) {
String offset = null;
for (VariableElement p : method.getParameters()) {
if (param != null && p.getSimpleName().equals(param.getSimpleName())) {
for ( VariableElement p : method.getParameters() ) {
if ( param != null && p.getSimpleName().equals(param.getSimpleName()) ) {
break;
}
if (p.getAnnotation(NullTerminated.class) != null) {
if ( p.getAnnotation(NullTerminated.class) != null ) {
continue;
}
final Class type = Utils.getJavaType(p.asType());
if (type.equals(CharSequence.class)) {
if (offset == null) {
if ( type.equals(CharSequence.class) ) {
if ( offset == null ) {
offset = p.getSimpleName() + ".length()";
} else {
offset += " + " + p.getSimpleName() + ".length()";
}
//if ( p.getAnnotation(NullTerminated.class) != null ) offset += " + 1";
} else if (type.equals(CharSequence[].class)) {
if (offset == null) {
} else if ( type.equals(CharSequence[].class) ) {
if ( offset == null ) {
offset = "APIUtil.getTotalLength(" + p.getSimpleName() + ")";
} else {
offset += " + APIUtil.getTotalLength(" + p.getSimpleName() + ")";
@ -437,8 +433,8 @@ public class Utils {
static void printGLReturnPre(PrintWriter writer, ExecutableElement method, GLreturn return_annotation, TypeMap type_map) {
final String return_type = getMethodReturnType(method, return_annotation, true);
if ("String".equals(return_type)) {
if (!return_annotation.forceMaxLength()) {
if ( "String".equals(return_type) ) {
if ( !return_annotation.forceMaxLength() ) {
writer.println("IntBuffer " + return_annotation.value() + "_length = APIUtil.getLengths(" + type_map.getAPIUtilParam(false) + ");");
writer.print("\t\t");
}
@ -449,21 +445,21 @@ public class Utils {
large enough to hold everything, so that no re-allocations happen while filling.
*/
final String offset = getStringOffset(method, null);
if (offset != null) {
if ( offset != null ) {
writer.print(" + " + offset);
}
writer.println(");");
} else {
final String buffer_type = "Boolean".equals(return_type) ? "Byte" : return_type;
writer.print(buffer_type + "Buffer " + return_annotation.value() + " = APIUtil.getBuffer" + buffer_type + "(" + type_map.getAPIUtilParam(false));
if ("Byte".equals(buffer_type)) {
if ( "Byte".equals(buffer_type) ) {
writer.print((type_map.getAPIUtilParam(false).length() > 0 ? ", " : "") + "1");
}
writer.println(");");
}
final Code code_annotation = method.getAnnotation(Code.class);
if (code_annotation != null && code_annotation.tryBlock()) {
if ( code_annotation != null && code_annotation.tryBlock() ) {
writer.println("\t\ttry {");
writer.print("\t\t\t");
} else {
@ -474,13 +470,13 @@ public class Utils {
static void printGLReturnPost(PrintWriter writer, ExecutableElement method, GLreturn return_annotation, TypeMap type_map) {
final String return_type = getMethodReturnType(method, return_annotation, true);
if ("String".equals(return_type)) {
if ( "String".equals(return_type) ) {
writer.print("\t\t" + return_annotation.value() + ".limit(");
final String offset = getStringOffset(method, null);
if (offset != null) {
if ( offset != null ) {
writer.print(offset + " + ");
}
if (return_annotation.forceMaxLength()) {
if ( return_annotation.forceMaxLength() ) {
writer.print(return_annotation.maxLength());
} else {
writer.print(return_annotation.value() + "_length.get(0)");
@ -489,7 +485,7 @@ public class Utils {
writer.println("\t\treturn APIUtil.getString(" + type_map.getAPIUtilParam(true) + return_annotation.value() + ");");
} else {
writer.print("\t\treturn " + return_annotation.value() + ".get(0)");
if ("Boolean".equals(return_type)) {
if ( "Boolean".equals(return_type) ) {
writer.print(" == 1");
}
writer.println(";");

View File

@ -41,16 +41,17 @@ package org.lwjgl.util.generator.openal;
* $Id: ALTypeMap.java 2983 2008-04-07 18:36:09Z matzon $
*/
import org.lwjgl.util.generator.Signedness;
import org.lwjgl.util.generator.TypeMap;
import java.io.*;
import java.io.PrintWriter;
import java.lang.annotation.Annotation;
import java.nio.*;
import java.util.*;
import java.util.HashMap;
import java.util.Map;
import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.type.TypeKind;
import org.lwjgl.util.generator.Signedness;
import org.lwjgl.util.generator.TypeMap;
public class ALTypeMap implements TypeMap {
private static final Map<Class, TypeKind> native_types_to_primitive;
@ -73,20 +74,20 @@ public class ALTypeMap implements TypeMap {
@Override
public TypeKind getPrimitiveTypeFromNativeType(Class native_type) {
TypeKind kind = native_types_to_primitive.get(native_type);
if (kind == null)
if ( kind == null )
throw new RuntimeException("Unsupported type " + native_type);
return kind;
}
@Override
public Signedness getSignednessFromType(Class type) {
if (ALuint.class.equals(type))
if ( ALuint.class.equals(type) )
return Signedness.UNSIGNED;
else if (ALint.class.equals(type))
else if ( ALint.class.equals(type) )
return Signedness.SIGNED;
else if (ALshort.class.equals(type))
else if ( ALshort.class.equals(type) )
return Signedness.SIGNED;
else if (ALbyte.class.equals(type))
else if ( ALbyte.class.equals(type) )
return Signedness.SIGNED;
else
return Signedness.NONE;
@ -94,19 +95,19 @@ public class ALTypeMap implements TypeMap {
@Override
public String translateAnnotation(Class annotation_type) {
if (annotation_type.equals(ALuint.class))
if ( annotation_type.equals(ALuint.class) )
return "i";
else if (annotation_type.equals(ALint.class))
else if ( annotation_type.equals(ALint.class) )
return "i";
else if (annotation_type.equals(ALshort.class))
else if ( annotation_type.equals(ALshort.class) )
return "s";
else if (annotation_type.equals(ALbyte.class))
else if ( annotation_type.equals(ALbyte.class) )
return "b";
else if (annotation_type.equals(ALfloat.class))
else if ( annotation_type.equals(ALfloat.class) )
return "f";
else if (annotation_type.equals(ALdouble.class))
else if ( annotation_type.equals(ALdouble.class) )
return "d";
else if (annotation_type.equals(ALboolean.class) || annotation_type.equals(ALvoid.class))
else if ( annotation_type.equals(ALboolean.class) || annotation_type.equals(ALvoid.class) )
return "";
else
throw new RuntimeException(annotation_type + " is not allowed");
@ -115,7 +116,7 @@ public class ALTypeMap implements TypeMap {
@Override
public Class getNativeTypeFromPrimitiveType(TypeKind kind) {
Class type;
switch (kind) {
switch ( kind ) {
case INT:
type = ALint.class;
break;
@ -141,37 +142,37 @@ public class ALTypeMap implements TypeMap {
}
private static Class[] getValidBufferTypes(Class type) {
if (type.equals(IntBuffer.class))
return new Class[]{ALenum.class, ALint.class, ALsizei.class, ALuint.class};
else if (type.equals(FloatBuffer.class))
return new Class[]{ALfloat.class};
else if (type.equals(ByteBuffer.class))
return new Class[]{ALboolean.class, ALbyte.class, ALvoid.class};
else if (type.equals(ShortBuffer.class))
return new Class[]{ALshort.class};
else if (type.equals(DoubleBuffer.class))
return new Class[]{ALdouble.class};
if ( type.equals(IntBuffer.class) )
return new Class[] { ALenum.class, ALint.class, ALsizei.class, ALuint.class };
else if ( type.equals(FloatBuffer.class) )
return new Class[] { ALfloat.class };
else if ( type.equals(ByteBuffer.class) )
return new Class[] { ALboolean.class, ALbyte.class, ALvoid.class };
else if ( type.equals(ShortBuffer.class) )
return new Class[] { ALshort.class };
else if ( type.equals(DoubleBuffer.class) )
return new Class[] { ALdouble.class };
else
return new Class[]{};
return new Class[] { };
}
private static Class[] getValidPrimitiveTypes(Class type) {
if (type.equals(int.class))
return new Class[]{ALenum.class, ALint.class, ALsizei.class, ALuint.class};
else if (type.equals(double.class))
return new Class[]{ALdouble.class};
else if (type.equals(float.class))
return new Class[]{ALfloat.class};
else if (type.equals(short.class))
return new Class[]{ALshort.class};
else if (type.equals(byte.class))
return new Class[]{ALbyte.class};
else if (type.equals(boolean.class))
return new Class[]{ALboolean.class};
else if (type.equals(void.class))
return new Class[]{ALvoid.class};
if ( type.equals(int.class) )
return new Class[] { ALenum.class, ALint.class, ALsizei.class, ALuint.class };
else if ( type.equals(double.class) )
return new Class[] { ALdouble.class };
else if ( type.equals(float.class) )
return new Class[] { ALfloat.class };
else if ( type.equals(short.class) )
return new Class[] { ALshort.class };
else if ( type.equals(byte.class) )
return new Class[] { ALbyte.class };
else if ( type.equals(boolean.class) )
return new Class[] { ALboolean.class };
else if ( type.equals(void.class) )
return new Class[] { ALvoid.class };
else
return new Class[]{};
return new Class[] { };
}
@Override
@ -232,14 +233,14 @@ public class ALTypeMap implements TypeMap {
@Override
public Class[] getValidAnnotationTypes(Class type) {
Class[] valid_types;
if (Buffer.class.isAssignableFrom(type))
if ( Buffer.class.isAssignableFrom(type) )
valid_types = getValidBufferTypes(type);
else if (type.isPrimitive())
else if ( type.isPrimitive() )
valid_types = getValidPrimitiveTypes(type);
else if (type.equals(String.class))
valid_types = new Class[]{ALubyte.class};
else if ( type.equals(String.class) )
valid_types = new Class[] { ALubyte.class };
else
valid_types = new Class[]{};
valid_types = new Class[] { };
return valid_types;
}
@ -250,9 +251,9 @@ public class ALTypeMap implements TypeMap {
@Override
public Class<? extends Annotation> getInverseType(Class type) {
if (ALuint.class.equals(type))
if ( ALuint.class.equals(type) )
return ALint.class;
else if (ALint.class.equals(type))
else if ( ALint.class.equals(type) )
return ALuint.class;
else
return null;

View File

@ -31,13 +31,14 @@
*/
package org.lwjgl.util.generator.opencl;
import org.lwjgl.util.generator.*;
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.Set;
import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.TypeElement;
import org.lwjgl.util.generator.*;
/**
* CLCapabilities generator.
@ -52,33 +53,33 @@ public class CLCapabilitiesGenerator {
}
static void generateSymbolAddresses(ProcessingEnvironment env, final PrintWriter writer, final TypeElement d) {
if (d.getAnnotation(CLPlatformExtension.class) == null && d.getAnnotation(CLDeviceExtension.class) == null && !d.getSimpleName().toString().startsWith("CL")) {
if ( d.getAnnotation(CLPlatformExtension.class) == null && d.getAnnotation(CLDeviceExtension.class) == null && !d.getSimpleName().toString().startsWith("CL") ) {
throw new RuntimeException("An OpenCL extension is missing an extension type annotation: " + d.getSimpleName());
}
final Alias alias_annotation = d.getAnnotation(Alias.class);
final boolean aliased = alias_annotation != null && alias_annotation.postfix().length() > 0;
boolean foundNative = false;
for (final ExecutableElement method : Utils.getMethods( d)) {
if (method.getAnnotation(Alternate.class) != null || method.getAnnotation(Reuse.class) != null) {
for ( final ExecutableElement method : Utils.getMethods(d) ) {
if ( method.getAnnotation(Alternate.class) != null || method.getAnnotation(Reuse.class) != null ) {
continue;
}
if (!foundNative) {
if ( !foundNative ) {
//writer.println("\t// " + d.getSimpleName());
writer.println("\tstatic final boolean " + CLGeneratorProcessor.getExtensionName(d.getSimpleName().toString() + ";"));
foundNative = true;
}
writer.print("\tstatic final long " + Utils.getFunctionAddressName(d, method) + " = CL.getFunctionAddress(");
if (aliased) {
if ( aliased ) {
writer.println("new String [] {\"" + Utils.getFunctionAddressName(d, method) + "\",\"" + method.getSimpleName() + alias_annotation.postfix() + "\"});");
} else {
writer.println("\"" + Utils.getFunctionAddressName(d, method) + "\");");
}
}
if (foundNative) {
if ( foundNative ) {
writer.println();
}
}
@ -88,9 +89,9 @@ public class CLCapabilitiesGenerator {
writer.println();
writer.println("\tstatic {");
for (final TypeElement d : interface_decls) {
if (d.getKind().isInterface()) {
if (Utils.getMethods( d).isEmpty()) {
for ( final TypeElement d : interface_decls ) {
if ( d.getKind().isInterface() ) {
if ( Utils.getMethods(d).isEmpty() ) {
continue;
}
@ -104,8 +105,8 @@ public class CLCapabilitiesGenerator {
}
static void generateExtensionChecks(ProcessingEnvironment env, final PrintWriter writer, TypeElement d) {
Iterator<? extends ExecutableElement> methods = Utils.getMethods( d).iterator();
if (!methods.hasNext()) {
Iterator<? extends ExecutableElement> methods = Utils.getMethods(d).iterator();
if ( !methods.hasNext() ) {
return;
}
@ -113,13 +114,13 @@ public class CLCapabilitiesGenerator {
writer.println("\t\treturn ");
boolean first = true;
while (methods.hasNext()) {
while ( methods.hasNext() ) {
ExecutableElement method = methods.next();
if (method.getAnnotation(Alternate.class) != null) {
if ( method.getAnnotation(Alternate.class) != null ) {
continue;
}
if (!first) {
if ( !first ) {
writer.println(" &");
} else {
first = false;
@ -128,11 +129,11 @@ public class CLCapabilitiesGenerator {
final boolean optional = method.getAnnotation(Optional.class) != null;
writer.print("\t\t\t");
if (optional) {
if ( optional ) {
writer.print('(');
}
writer.print(Utils.getFunctionAddressName(d, method) + " != 0");
if (optional) {
if ( optional ) {
writer.print(" || true)");
}
}

View File

@ -31,30 +31,27 @@
*/
package org.lwjgl.util.generator.opencl;
import org.lwjgl.PointerWrapper;
import org.lwjgl.opencl.CLDevice;
import org.lwjgl.opencl.CLPlatform;
import java.io.IOException;
import java.io.PrintWriter;
import java.lang.annotation.Annotation;
import java.util.Set;
import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.annotation.processing.SupportedOptions;
import javax.annotation.processing.SupportedSourceVersion;
import javax.annotation.processing.*;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.TypeElement;
import javax.lang.model.util.ElementFilter;
import org.lwjgl.PointerWrapper;
import org.lwjgl.opencl.CLDevice;
import org.lwjgl.opencl.CLPlatform;
/**
* Generator tool for creating the OpenCL capabilities classes
*
* @author Spasi
*/
@SupportedAnnotationTypes({"*"})
@SupportedAnnotationTypes({ "*" })
@SupportedSourceVersion(SourceVersion.RELEASE_7)
@SupportedOptions({"generatechecks", "contextspecific"})
@SupportedOptions({ "generatechecks", "contextspecific" })
public class CLGeneratorProcessor extends AbstractProcessor {
public static final String CLCAPS_CLASS_NAME = "CLCapabilities";
@ -67,7 +64,7 @@ public class CLGeneratorProcessor extends AbstractProcessor {
private static boolean first_round = true;
static String getExtensionName(String interface_name) {
if (interface_name.startsWith("CL")) {
if ( interface_name.startsWith("CL") ) {
return CORE_PREFIX + interface_name;
} else {
return EXTENSION_PREFIX + interface_name;
@ -76,7 +73,7 @@ public class CLGeneratorProcessor extends AbstractProcessor {
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
if (roundEnv.processingOver() || !first_round) {
if ( roundEnv.processingOver() || !first_round ) {
System.exit(0);
return true;
}
@ -108,8 +105,8 @@ public class CLGeneratorProcessor extends AbstractProcessor {
printHeader(writer);
CLCapabilitiesGenerator.generateClassPrologue(writer);
for (TypeElement d : templates) {
if (d.getKind().isInterface()) {
for ( TypeElement d : templates ) {
if ( d.getKind().isInterface() ) {
CLCapabilitiesGenerator.generateSymbolAddresses(processingEnv, writer, d);
}
}
@ -118,8 +115,8 @@ public class CLGeneratorProcessor extends AbstractProcessor {
CLCapabilitiesGenerator.generateConstructor(processingEnv, writer, templates);
CLCapabilitiesGenerator.generateCapabilitiesGetters(writer);
for (TypeElement d : templates) {
if (d.getKind().isInterface()) {
for ( TypeElement d : templates ) {
if ( d.getKind().isInterface() ) {
CLCapabilitiesGenerator.generateExtensionChecks(processingEnv, writer, d);
}
}
@ -136,9 +133,9 @@ public class CLGeneratorProcessor extends AbstractProcessor {
CLPDCapabilitiesGenerator.generateClassPrologue(writer, capsName);
for (TypeElement t : templates) {
if (t.getKind().isInterface() && t.getAnnotation(capsType) != null) {
CLPDCapabilitiesGenerator.generateExtensions(writer, (TypeElement) t);
for ( TypeElement t : templates ) {
if ( t.getKind().isInterface() && t.getAnnotation(capsType) != null ) {
CLPDCapabilitiesGenerator.generateExtensions(writer, (TypeElement)t);
}
}
writer.println();

View File

@ -32,15 +32,16 @@
package org.lwjgl.util.generator.opencl;
import org.lwjgl.PointerWrapper;
import org.lwjgl.util.generator.Extension;
import org.lwjgl.util.generator.Private;
import org.lwjgl.util.generator.Utils;
import java.io.PrintWriter;
import java.lang.annotation.Annotation;
import java.util.Set;
import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.element.TypeElement;
import org.lwjgl.PointerWrapper;
import org.lwjgl.util.generator.Extension;
import org.lwjgl.util.generator.Private;
import org.lwjgl.util.generator.Utils;
/**
* CL platform/device capabilities generator.
@ -114,7 +115,7 @@ public class CLPDCapabilitiesGenerator {
nativeName = ext.nativeName();
writer.print("\t\t" + extName + " = extensions.contains(\"" + nativeName + "\")");
if ( !Utils.getMethods( t).isEmpty() )
if ( !Utils.getMethods(t).isEmpty() )
writer.print(" && CLCapabilities." + extName);
writer.println(";");
}

View File

@ -39,6 +39,10 @@ package org.lwjgl.util.generator.opencl;
* @author Spasi
*/
import org.lwjgl.PointerBuffer;
import org.lwjgl.util.generator.*;
import org.lwjgl.util.generator.opengl.GLreturn;
import java.io.PrintWriter;
import java.lang.annotation.Annotation;
import java.nio.*;
@ -48,10 +52,6 @@ import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.VariableElement;
import javax.lang.model.type.TypeKind;
import org.lwjgl.PointerBuffer;
import org.lwjgl.util.generator.*;
import org.lwjgl.util.generator.opengl.GLreturn;
public class CLTypeMap implements TypeMap {

View File

@ -32,19 +32,17 @@
package org.lwjgl.util.generator.opengl;
import org.lwjgl.util.generator.*;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Collection;
import java.util.EnumSet;
import java.util.Iterator;
import java.util.List;
import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.TypeElement;
import javax.lang.model.type.DeclaredType;
import javax.lang.model.type.TypeMirror;
import org.lwjgl.util.generator.*;
/**
* Generator visitor for the context capabilities generator tool
@ -166,14 +164,14 @@ public class GLCapabilitiesGenerator {
}
public static void generateUnloadStubs(ProcessingEnvironment env, PrintWriter writer, TypeElement d) {
if ( Utils.getMethods( d).size() > 0 ) {
if ( Utils.getMethods(d).size() > 0 ) {
writer.print("\t\tGLContext.resetNativeStubs(" + Utils.getSimpleClassName(d));
writer.println(".class);");
}
}
public static void generateInitStubs(ProcessingEnvironment env, PrintWriter writer, TypeElement d, boolean context_specific) {
if ( Utils.getMethods( d).size() > 0 ) {
if ( Utils.getMethods(d).size() > 0 ) {
if ( context_specific ) {
final Alias alias_annotation = d.getAnnotation(Alias.class);
@ -219,7 +217,7 @@ public class GLCapabilitiesGenerator {
}
public static void generateAddressesInitializers(ProcessingEnvironment env, PrintWriter writer, TypeElement d) {
Iterator<? extends ExecutableElement> methods = Utils.getMethods( d).iterator();
Iterator<? extends ExecutableElement> methods = Utils.getMethods(d).iterator();
if ( !methods.hasNext() )
return;
@ -313,7 +311,7 @@ public class GLCapabilitiesGenerator {
public static void generateSymbolAddresses(ProcessingEnvironment env, PrintWriter writer, TypeElement d) {
boolean first = true;
for ( final ExecutableElement method : Utils.getMethods( d) ) {
for ( final ExecutableElement method : Utils.getMethods(d) ) {
if ( method.getAnnotation(Alternate.class) != null || method.getAnnotation(Reuse.class) != null )
continue;

View File

@ -32,6 +32,7 @@
package org.lwjgl.util.generator.opengl;
import org.lwjgl.util.generator.*;
import java.io.PrintWriter;
import java.util.Arrays;
@ -41,9 +42,7 @@ import java.util.List;
import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.TypeElement;
import javax.lang.model.type.DeclaredType;
import javax.lang.model.type.TypeMirror;
import org.lwjgl.util.generator.*;
/**
* Generator visitor for the context capabilities generator tool
@ -95,7 +94,7 @@ public class GLESCapabilitiesGenerator {
}
}
public static void generateInitializer(PrintWriter writer, TypeElement d,ProcessingEnvironment env) {
public static void generateInitializer(PrintWriter writer, TypeElement d, ProcessingEnvironment env) {
String translated_field_name = translateFieldName(d.getSimpleName().toString());
writer.print("\t\tthis." + translated_field_name + " = ");
writer.print(CACHED_EXTS_VAR_NAME + ".contains(\"");
@ -156,14 +155,14 @@ public class GLESCapabilitiesGenerator {
public static void generateUnloadStubs(ProcessingEnvironment env, PrintWriter writer, TypeElement d) {
// TODO: Remove GLES
if (Utils.getMethods( d).size() > 0 && !d.getSimpleName().toString().startsWith("GLES") ) {
if ( Utils.getMethods(d).size() > 0 && !d.getSimpleName().toString().startsWith("GLES") ) {
writer.print("\t\tGLContext.resetNativeStubs(" + Utils.getSimpleClassName(d));
writer.println(".class);");
}
}
public static void generateInitStubs(ProcessingEnvironment env, PrintWriter writer, TypeElement d, boolean context_specific) {
if ( Utils.getMethods( d).size() > 0 ) {
if ( Utils.getMethods(d).size() > 0 ) {
if ( context_specific ) {
final Alias alias_annotation = d.getAnnotation(Alias.class);
@ -204,7 +203,7 @@ public class GLESCapabilitiesGenerator {
}
public static void generateAddressesInitializers(ProcessingEnvironment env, PrintWriter writer, TypeElement d) {
Iterator<? extends ExecutableElement> methods = Utils.getMethods( d).iterator();
Iterator<? extends ExecutableElement> methods = Utils.getMethods(d).iterator();
if ( !methods.hasNext() )
return;
@ -290,7 +289,7 @@ public class GLESCapabilitiesGenerator {
public static void generateSymbolAddresses(ProcessingEnvironment env, PrintWriter writer, TypeElement d) {
boolean first = true;
for ( final ExecutableElement method : Utils.getMethods( d) ) {
for ( final ExecutableElement method : Utils.getMethods(d) ) {
if ( method.getAnnotation(Alternate.class) != null || method.getAnnotation(Reuse.class) != null )
continue;

View File

@ -31,19 +31,16 @@
*/
package org.lwjgl.util.generator.opengl;
import org.lwjgl.util.generator.Utils;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;
import java.util.Set;
import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.annotation.processing.SupportedOptions;
import javax.annotation.processing.SupportedSourceVersion;
import javax.annotation.processing.*;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.TypeElement;
import javax.lang.model.util.ElementFilter;
import org.lwjgl.util.generator.Utils;
/**
* Generator tool for creating the ContexCapabilities class
@ -52,16 +49,16 @@ import org.lwjgl.util.generator.Utils;
* @version $Revision: 3316 $ $Id: ContextGeneratorProcessorFactory.java 3316
* 2010-04-09 23:57:40Z spasi $
*/
@SupportedAnnotationTypes({"*"})
@SupportedAnnotationTypes({ "*" })
@SupportedSourceVersion(SourceVersion.RELEASE_7)
@SupportedOptions({"contextspecific", "generatechecks"})
@SupportedOptions({ "contextspecific", "generatechecks" })
public class GLESGeneratorProcessor extends AbstractProcessor {
private static boolean first_round = true;
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
if (roundEnv.processingOver() || !first_round) {
if ( roundEnv.processingOver() || !first_round ) {
System.exit(0);
return true;
}
@ -89,30 +86,30 @@ public class GLESGeneratorProcessor extends AbstractProcessor {
writer.println("import java.util.HashSet;");
writer.println();
GLESCapabilitiesGenerator.generateClassPrologue(writer, context_specific, generate_error_checks);
for (TypeElement interface_decl : templates) {
if (interface_decl.getKind().isInterface()) {
if (Utils.isFinal(interface_decl)) {
for ( TypeElement interface_decl : templates ) {
if ( interface_decl.getKind().isInterface() ) {
if ( Utils.isFinal(interface_decl) ) {
GLESCapabilitiesGenerator.generateField(writer, interface_decl);
}
}
}
writer.println();
if (context_specific) {
for (TypeElement interface_decl : templates) {
if (interface_decl.getKind().isInterface()) {
if ( context_specific ) {
for ( TypeElement interface_decl : templates ) {
if ( interface_decl.getKind().isInterface() ) {
GLESCapabilitiesGenerator.generateSymbolAddresses(processingEnv, writer, interface_decl);
}
}
writer.println();
for (TypeElement interface_decl : templates) {
if (interface_decl.getKind().isInterface()) {
for ( TypeElement interface_decl : templates ) {
if ( interface_decl.getKind().isInterface() ) {
GLESCapabilitiesGenerator.generateAddressesInitializers(processingEnv, writer, interface_decl);
}
}
writer.println();
}
if (context_specific) {
if ( context_specific ) {
writer.println("\tprivate static void remove(Set supported_extensions, String extension) {");
writer.println("\t\tLWJGLUtil.log(extension + \" was reported as available but an entry point is missing\");");
writer.println("\t\tsupported_extensions.remove(extension);");
@ -120,14 +117,14 @@ public class GLESGeneratorProcessor extends AbstractProcessor {
}
GLESCapabilitiesGenerator.generateInitStubsPrologue(writer, context_specific);
for (TypeElement interface_decl : templates) {
if (interface_decl.getKind().isInterface()) {
for ( TypeElement interface_decl : templates ) {
if ( interface_decl.getKind().isInterface() ) {
GLESCapabilitiesGenerator.generateSuperClassAdds(writer, interface_decl, processingEnv);
}
}
for (TypeElement interface_decl : templates) {
if (interface_decl.getKind().isInterface()) {
if ("GLES20".equals(interface_decl.getSimpleName().toString())) {
for ( TypeElement interface_decl : templates ) {
if ( interface_decl.getKind().isInterface() ) {
if ( "GLES20".equals(interface_decl.getSimpleName().toString()) ) {
continue;
}
GLESCapabilitiesGenerator.generateInitStubs(processingEnv, writer, interface_decl, context_specific);
@ -136,11 +133,11 @@ public class GLESGeneratorProcessor extends AbstractProcessor {
GLESCapabilitiesGenerator.generateInitStubsEpilogue(writer, context_specific);
writer.println();
writer.println("\tstatic void unloadAllStubs() {");
if (!context_specific) {
if ( !context_specific ) {
writer.println("\t\tif (!loaded_stubs)");
writer.println("\t\t\treturn;");
for (TypeElement interface_decl : templates) {
if (interface_decl.getKind().isInterface()) {
for ( TypeElement interface_decl : templates ) {
if ( interface_decl.getKind().isInterface() ) {
GLESCapabilitiesGenerator.generateUnloadStubs(processingEnv, writer, interface_decl);
}
}
@ -149,9 +146,9 @@ public class GLESGeneratorProcessor extends AbstractProcessor {
writer.println("\t}");
writer.println();
GLESCapabilitiesGenerator.generateInitializerPrologue(writer);
for (TypeElement interface_decl : templates) {
if (interface_decl.getKind().isInterface()) {
if (Utils.isFinal(interface_decl)) {
for ( TypeElement interface_decl : templates ) {
if ( interface_decl.getKind().isInterface() ) {
if ( Utils.isFinal(interface_decl) ) {
GLESCapabilitiesGenerator.generateInitializer(writer, interface_decl, processingEnv);
}
}

View File

@ -41,6 +41,11 @@ package org.lwjgl.util.generator.opengl;
* $Id: GLTypeMap.java 3287 2010-03-14 23:24:40Z spasi $
*/
import org.lwjgl.util.generator.NativeTypeTranslator;
import org.lwjgl.util.generator.PointerWrapper;
import org.lwjgl.util.generator.Signedness;
import org.lwjgl.util.generator.TypeMap;
import java.io.PrintWriter;
import java.lang.annotation.Annotation;
import java.nio.*;
@ -49,10 +54,6 @@ import java.util.Map;
import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.type.TypeKind;
import org.lwjgl.util.generator.NativeTypeTranslator;
import org.lwjgl.util.generator.PointerWrapper;
import org.lwjgl.util.generator.Signedness;
import org.lwjgl.util.generator.TypeMap;
public class GLESTypeMap implements TypeMap {

View File

@ -31,38 +31,34 @@
*/
package org.lwjgl.util.generator.opengl;
import org.lwjgl.util.generator.Utils;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;
import java.util.Set;
import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.annotation.processing.SupportedOptions;
import javax.annotation.processing.SupportedSourceVersion;
import javax.annotation.processing.*;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.TypeElement;
import javax.lang.model.util.ElementFilter;
import org.lwjgl.util.generator.Utils;
/**
*
* Generator tool for creating the ContexCapabilities class
*
* @author elias_naur <elias_naur@users.sourceforge.net>
* @version $Revision: 3316 $ $Id: ContextGeneratorProcessorFactory.java 3316
* 2010-04-09 23:57:40Z spasi $
*/
@SupportedAnnotationTypes({"*"})
@SupportedAnnotationTypes({ "*" })
@SupportedSourceVersion(SourceVersion.RELEASE_7)
@SupportedOptions({"generatechecks", "contextspecific"})
@SupportedOptions({ "generatechecks", "contextspecific" })
public class GLGeneratorProcessor extends AbstractProcessor {
private static boolean first_round = true;
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
if (roundEnv.processingOver() || !first_round) {
if ( roundEnv.processingOver() || !first_round ) {
System.exit(0);
return true;
}
@ -90,23 +86,23 @@ public class GLGeneratorProcessor extends AbstractProcessor {
writer.println("import java.util.HashSet;");
writer.println();
GLCapabilitiesGenerator.generateClassPrologue(writer, context_specific, generate_error_checks);
for (TypeElement interface_decl : templates) {
if (interface_decl.getKind().isInterface()) {
if (Utils.isFinal(interface_decl)) {
for ( TypeElement interface_decl : templates ) {
if ( interface_decl.getKind().isInterface() ) {
if ( Utils.isFinal(interface_decl) ) {
GLCapabilitiesGenerator.generateField(writer, interface_decl);
}
}
}
writer.println();
for (TypeElement interface_decl : templates) {
if (interface_decl.getKind().isInterface()) {
for ( TypeElement interface_decl : templates ) {
if ( interface_decl.getKind().isInterface() ) {
GLCapabilitiesGenerator.generateSymbolAddresses(processingEnv, writer, interface_decl);
}
}
writer.println();
if (context_specific) {
for (TypeElement interface_decl : templates) {
if (interface_decl.getKind().isInterface()) {
if ( context_specific ) {
for ( TypeElement interface_decl : templates ) {
if ( interface_decl.getKind().isInterface() ) {
GLCapabilitiesGenerator.generateAddressesInitializers(processingEnv, writer, interface_decl);
}
}
@ -119,15 +115,15 @@ public class GLGeneratorProcessor extends AbstractProcessor {
writer.println("\t}\n");
GLCapabilitiesGenerator.generateInitStubsPrologue(writer, context_specific);
for (TypeElement interface_decl : templates) {
if (interface_decl.getKind().isInterface()) {
for ( TypeElement interface_decl : templates ) {
if ( interface_decl.getKind().isInterface() ) {
GLCapabilitiesGenerator.generateSuperClassAdds(writer, interface_decl, processingEnv);
}
}
for (TypeElement interface_decl : templates) {
if (interface_decl.getKind().isInterface()) {
for ( TypeElement interface_decl : templates ) {
if ( interface_decl.getKind().isInterface() ) {
String simple_name = interface_decl.getSimpleName().toString();
if ("GL11".equals(simple_name)) {
if ( "GL11".equals(simple_name) ) {
continue;
}
GLCapabilitiesGenerator.generateInitStubs(processingEnv, writer, interface_decl, context_specific);
@ -136,11 +132,11 @@ public class GLGeneratorProcessor extends AbstractProcessor {
GLCapabilitiesGenerator.generateInitStubsEpilogue(writer, context_specific);
writer.println();
writer.println("\tstatic void unloadAllStubs() {");
if (!context_specific) {
if ( !context_specific ) {
writer.println("\t\tif (!loaded_stubs)");
writer.println("\t\t\treturn;");
for (TypeElement interface_decl : templates) {
if (interface_decl.getKind().isInterface()) {
for ( TypeElement interface_decl : templates ) {
if ( interface_decl.getKind().isInterface() ) {
GLCapabilitiesGenerator.generateUnloadStubs(processingEnv, writer, interface_decl);
}
}
@ -149,9 +145,9 @@ public class GLGeneratorProcessor extends AbstractProcessor {
writer.println("\t}");
writer.println();
GLCapabilitiesGenerator.generateInitializerPrologue(writer);
for (TypeElement interface_decl : templates) {
if (interface_decl.getKind().isInterface()) {
if (Utils.isFinal(interface_decl)) {
for ( TypeElement interface_decl : templates ) {
if ( interface_decl.getKind().isInterface() ) {
if ( Utils.isFinal(interface_decl) ) {
GLCapabilitiesGenerator.generateInitializer(writer, interface_decl, processingEnv);
}
}

View File

@ -31,35 +31,30 @@
*/
package org.lwjgl.util.generator.opengl;
import org.lwjgl.util.generator.Alternate;
import org.lwjgl.util.generator.CachedReference;
import org.lwjgl.util.generator.Utils;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Set;
import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.ProcessingEnvironment;
import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.annotation.processing.SupportedOptions;
import javax.annotation.processing.SupportedSourceVersion;
import javax.annotation.processing.*;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.TypeElement;
import javax.lang.model.element.VariableElement;
import javax.lang.model.util.ElementFilter;
import org.lwjgl.util.generator.Alternate;
import org.lwjgl.util.generator.CachedReference;
import org.lwjgl.util.generator.Utils;
/**
*
* Generator tool for creating the References class
*
* @author elias_naur <elias_naur@users.sourceforge.net>
* @version $Revision: 3237 $ $Id: ReferencesGeneratorProcessorFactory.java 3237
* 2009-09-08 15:07:15Z spasi $
*/
@SupportedAnnotationTypes({"*"})
@SupportedAnnotationTypes({ "*" })
@SupportedSourceVersion(SourceVersion.RELEASE_7)
@SupportedOptions({"generatechecks", "contextspecific"})
@SupportedOptions({ "generatechecks", "contextspecific" })
public class GLReferencesGeneratorProcessor extends AbstractProcessor {
private static final String REFERENCES_CLASS_NAME = "References";
@ -69,7 +64,7 @@ public class GLReferencesGeneratorProcessor extends AbstractProcessor {
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
if (roundEnv.processingOver() || !first_round) {
if ( roundEnv.processingOver() || !first_round ) {
System.exit(0);
return true;
}
@ -83,9 +78,9 @@ public class GLReferencesGeneratorProcessor extends AbstractProcessor {
}
private static void generateClearsFromParameters(PrintWriter writer, TypeElement interface_decl, ExecutableElement method) {
for (VariableElement param : method.getParameters()) {
for ( VariableElement param : method.getParameters() ) {
CachedReference cached_reference_annotation = param.getAnnotation(CachedReference.class);
if (cached_reference_annotation != null && cached_reference_annotation.name().length() == 0) {
if ( cached_reference_annotation != null && cached_reference_annotation.name().length() == 0 ) {
Class nio_type = Utils.getNIOBufferType(param.asType());
String reference_name = Utils.getReferenceName(interface_decl, method, param);
writer.println("\t\tthis." + reference_name + " = null;");
@ -94,9 +89,9 @@ public class GLReferencesGeneratorProcessor extends AbstractProcessor {
}
private static void generateCopiesFromParameters(PrintWriter writer, TypeElement interface_decl, ExecutableElement method) {
for (VariableElement param : method.getParameters()) {
for ( VariableElement param : method.getParameters() ) {
CachedReference cached_reference_annotation = param.getAnnotation(CachedReference.class);
if (cached_reference_annotation != null && cached_reference_annotation.name().length() == 0) {
if ( cached_reference_annotation != null && cached_reference_annotation.name().length() == 0 ) {
Class nio_type = Utils.getNIOBufferType(param.asType());
String reference_name = Utils.getReferenceName(interface_decl, method, param);
writer.print("\t\t\tthis." + reference_name + " = ");
@ -106,8 +101,8 @@ public class GLReferencesGeneratorProcessor extends AbstractProcessor {
}
private static void generateClearsFromMethods(ProcessingEnvironment env, PrintWriter writer, TypeElement interface_decl) {
for (ExecutableElement method : Utils.getMethods( interface_decl)) {
if (method.getAnnotation(Alternate.class) != null) {
for ( ExecutableElement method : Utils.getMethods(interface_decl) ) {
if ( method.getAnnotation(Alternate.class) != null ) {
continue;
}
@ -116,8 +111,8 @@ public class GLReferencesGeneratorProcessor extends AbstractProcessor {
}
private static void generateCopiesFromMethods(ProcessingEnvironment env, PrintWriter writer, TypeElement interface_decl) {
for (ExecutableElement method : Utils.getMethods( interface_decl)) {
if (method.getAnnotation(Alternate.class) != null) {
for ( ExecutableElement method : Utils.getMethods(interface_decl) ) {
if ( method.getAnnotation(Alternate.class) != null ) {
continue;
}
@ -126,11 +121,11 @@ public class GLReferencesGeneratorProcessor extends AbstractProcessor {
}
private static void generateReferencesFromParameters(PrintWriter writer, TypeElement interface_decl, ExecutableElement method) {
for (VariableElement param : method.getParameters()) {
for ( VariableElement param : method.getParameters() ) {
CachedReference cached_reference_annotation = param.getAnnotation(CachedReference.class);
if (cached_reference_annotation != null && cached_reference_annotation.name().length() == 0) {
if ( cached_reference_annotation != null && cached_reference_annotation.name().length() == 0 ) {
Class nio_type = Utils.getNIOBufferType(param.asType());
if (nio_type == null) {
if ( nio_type == null ) {
throw new RuntimeException(param + " in method " + method + " in " + interface_decl + " is annotated with "
+ cached_reference_annotation.annotationType().getSimpleName() + " but the parameter is not a NIO buffer");
}
@ -141,8 +136,8 @@ public class GLReferencesGeneratorProcessor extends AbstractProcessor {
}
private static void generateReferencesFromMethods(ProcessingEnvironment env, PrintWriter writer, TypeElement interface_decl) {
for (ExecutableElement method : Utils.getMethods( interface_decl)) {
if (method.getAnnotation(Alternate.class) != null) {
for ( ExecutableElement method : Utils.getMethods(interface_decl) ) {
if ( method.getAnnotation(Alternate.class) != null ) {
continue;
}
@ -160,8 +155,8 @@ public class GLReferencesGeneratorProcessor extends AbstractProcessor {
writer.println("\t" + REFERENCES_CLASS_NAME + "(ContextCapabilities caps) {");
writer.println("\t\tsuper(caps);");
writer.println("\t}");
for (TypeElement interface_decl : templates) {
if (interface_decl.getKind().isInterface()) {
for ( TypeElement interface_decl : templates ) {
if ( interface_decl.getKind().isInterface() ) {
generateReferencesFromMethods(env, writer, interface_decl);
}
}
@ -169,8 +164,8 @@ public class GLReferencesGeneratorProcessor extends AbstractProcessor {
writer.println("\tvoid copy(" + REFERENCES_CLASS_NAME + " " + REFERENCES_PARAMETER_NAME + ", int mask) {");
writer.println("\t\tsuper.copy(" + REFERENCES_PARAMETER_NAME + ", mask);");
writer.println("\t\tif ( (mask & GL11.GL_CLIENT_VERTEX_ARRAY_BIT) != 0 ) {");
for (TypeElement interface_decl : templates) {
if (interface_decl.getKind().isInterface()) {
for ( TypeElement interface_decl : templates ) {
if ( interface_decl.getKind().isInterface() ) {
generateCopiesFromMethods(processingEnv, writer, interface_decl);
}
}
@ -178,8 +173,8 @@ public class GLReferencesGeneratorProcessor extends AbstractProcessor {
writer.println("\t}");
writer.println("\tvoid clear() {");
writer.println("\t\tsuper.clear();");
for (TypeElement interface_decl : templates) {
if (interface_decl.getKind().isInterface()) {
for ( TypeElement interface_decl : templates ) {
if ( interface_decl.getKind().isInterface() ) {
generateClearsFromMethods(processingEnv, writer, interface_decl);
}
}

View File

@ -53,13 +53,6 @@ import java.util.Map;
import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.type.TypeKind;
import static javax.lang.model.type.TypeKind.BOOLEAN;
import static javax.lang.model.type.TypeKind.BYTE;
import static javax.lang.model.type.TypeKind.DOUBLE;
import static javax.lang.model.type.TypeKind.FLOAT;
import static javax.lang.model.type.TypeKind.INT;
import static javax.lang.model.type.TypeKind.LONG;
import static javax.lang.model.type.TypeKind.SHORT;
public class GLTypeMap implements TypeMap {
@ -99,7 +92,7 @@ public class GLTypeMap implements TypeMap {
@Override
public TypeKind getPrimitiveTypeFromNativeType(Class native_type) {
TypeKind kind = native_types_to_primitive.get(native_type);
if (kind == null) {
if ( kind == null ) {
throw new RuntimeException("Unsupported type " + native_type);
}
return kind;
@ -132,25 +125,25 @@ public class GLTypeMap implements TypeMap {
@Override
public Signedness getSignednessFromType(Class type) {
if (GLuint.class.equals(type)) {
if ( GLuint.class.equals(type) ) {
return Signedness.UNSIGNED;
} else if (GLint.class.equals(type)) {
} else if ( GLint.class.equals(type) ) {
return Signedness.SIGNED;
} else if (GLushort.class.equals(type)) {
} else if ( GLushort.class.equals(type) ) {
return Signedness.UNSIGNED;
} else if (GLshort.class.equals(type)) {
} else if ( GLshort.class.equals(type) ) {
return Signedness.SIGNED;
} else if (GLubyte.class.equals(type)) {
} else if ( GLubyte.class.equals(type) ) {
return Signedness.UNSIGNED;
} else if (GLbyte.class.equals(type)) {
} else if ( GLbyte.class.equals(type) ) {
return Signedness.SIGNED;
} else if (GLuint64EXT.class.equals(type)) {
} else if ( GLuint64EXT.class.equals(type) ) {
return Signedness.UNSIGNED;
} else if (GLint64EXT.class.equals(type)) {
} else if ( GLint64EXT.class.equals(type) ) {
return Signedness.SIGNED;
} else if (GLuint64.class.equals(type)) {
} else if ( GLuint64.class.equals(type) ) {
return Signedness.UNSIGNED;
} else if (GLint64.class.equals(type)) {
} else if ( GLint64.class.equals(type) ) {
return Signedness.SIGNED;
} else {
return Signedness.NONE;
@ -159,21 +152,21 @@ public class GLTypeMap implements TypeMap {
@Override
public String translateAnnotation(Class annotation_type) {
if (annotation_type.equals(GLuint.class) || annotation_type.equals(GLint.class)) {
if ( annotation_type.equals(GLuint.class) || annotation_type.equals(GLint.class) ) {
return "i";
} else if (annotation_type.equals(GLushort.class) || annotation_type.equals(GLshort.class)) {
} else if ( annotation_type.equals(GLushort.class) || annotation_type.equals(GLshort.class) ) {
return "s";
} else if (annotation_type.equals(GLubyte.class) || annotation_type.equals(GLbyte.class)) {
} else if ( annotation_type.equals(GLubyte.class) || annotation_type.equals(GLbyte.class) ) {
return "b";
} else if (annotation_type.equals(GLfloat.class) || annotation_type.equals(GLclampf.class)) {
} else if ( annotation_type.equals(GLfloat.class) || annotation_type.equals(GLclampf.class) ) {
return "f";
} else if (annotation_type.equals(GLdouble.class) || annotation_type.equals(GLclampd.class)) {
} else if ( annotation_type.equals(GLdouble.class) || annotation_type.equals(GLclampd.class) ) {
return "d";
} else if (annotation_type.equals(GLhalf.class)) {
} else if ( annotation_type.equals(GLhalf.class) ) {
return "h";
} else if (annotation_type.equals(GLuint64EXT.class) || annotation_type.equals(GLint64EXT.class) || annotation_type.equals(GLuint64.class) || annotation_type.equals(GLint64.class)) {
} else if ( annotation_type.equals(GLuint64EXT.class) || annotation_type.equals(GLint64EXT.class) || annotation_type.equals(GLuint64.class) || annotation_type.equals(GLint64.class) ) {
return "i64";
} else if (annotation_type.equals(GLboolean.class) || annotation_type.equals(GLvoid.class)) {
} else if ( annotation_type.equals(GLboolean.class) || annotation_type.equals(GLvoid.class) ) {
return "";
} else {
throw new RuntimeException(annotation_type + " is not allowed");
@ -183,7 +176,7 @@ public class GLTypeMap implements TypeMap {
@Override
public Class getNativeTypeFromPrimitiveType(TypeKind kind) {
Class type;
switch (kind) {
switch ( kind ) {
case INT:
type = GLint.class;
break;
@ -232,44 +225,44 @@ public class GLTypeMap implements TypeMap {
}
private static Class[] getValidBufferTypes(Class type) {
if (type.equals(IntBuffer.class)) {
return new Class[]{GLbitfield.class, GLenum.class, GLhandleARB.class, GLint.class,
GLsizei.class, GLuint.class, GLvoid.class};
} else if (type.equals(FloatBuffer.class)) {
return new Class[]{GLclampf.class, GLfloat.class};
} else if (type.equals(ByteBuffer.class)) {
return new Class[]{GLboolean.class, GLbyte.class, GLcharARB.class, GLchar.class, GLubyte.class, GLvoid.class};
} else if (type.equals(ShortBuffer.class)) {
return new Class[]{GLhalf.class, GLshort.class, GLushort.class};
} else if (type.equals(DoubleBuffer.class)) {
return new Class[]{GLclampd.class, GLdouble.class};
} else if (type.equals(LongBuffer.class)) {
return new Class[]{GLint64EXT.class, GLuint64EXT.class, GLint64.class, GLuint64.class};
if ( type.equals(IntBuffer.class) ) {
return new Class[] { GLbitfield.class, GLenum.class, GLhandleARB.class, GLint.class,
GLsizei.class, GLuint.class, GLvoid.class };
} else if ( type.equals(FloatBuffer.class) ) {
return new Class[] { GLclampf.class, GLfloat.class };
} else if ( type.equals(ByteBuffer.class) ) {
return new Class[] { GLboolean.class, GLbyte.class, GLcharARB.class, GLchar.class, GLubyte.class, GLvoid.class };
} else if ( type.equals(ShortBuffer.class) ) {
return new Class[] { GLhalf.class, GLshort.class, GLushort.class };
} else if ( type.equals(DoubleBuffer.class) ) {
return new Class[] { GLclampd.class, GLdouble.class };
} else if ( type.equals(LongBuffer.class) ) {
return new Class[] { GLint64EXT.class, GLuint64EXT.class, GLint64.class, GLuint64.class };
} else {
return new Class[]{};
return new Class[] { };
}
}
private static Class[] getValidPrimitiveTypes(Class type) {
if (type.equals(long.class)) {
return new Class[]{GLintptrARB.class, GLuint.class, GLintptr.class, GLsizeiptrARB.class, GLsizeiptr.class, GLint64EXT.class, GLuint64EXT.class, GLint64.class, GLuint64.class};
} else if (type.equals(int.class)) {
return new Class[]{GLbitfield.class, GLenum.class, GLhandleARB.class, GLint.class, GLuint.class,
GLsizei.class};
} else if (type.equals(double.class)) {
return new Class[]{GLclampd.class, GLdouble.class};
} else if (type.equals(float.class)) {
return new Class[]{GLclampf.class, GLfloat.class};
} else if (type.equals(short.class)) {
return new Class[]{GLhalf.class, GLshort.class, GLushort.class};
} else if (type.equals(byte.class)) {
return new Class[]{GLbyte.class, GLcharARB.class, GLchar.class, GLubyte.class};
} else if (type.equals(boolean.class)) {
return new Class[]{GLboolean.class};
} else if (type.equals(void.class)) {
return new Class[]{GLvoid.class, GLreturn.class};
if ( type.equals(long.class) ) {
return new Class[] { GLintptrARB.class, GLuint.class, GLintptr.class, GLsizeiptrARB.class, GLsizeiptr.class, GLint64EXT.class, GLuint64EXT.class, GLint64.class, GLuint64.class };
} else if ( type.equals(int.class) ) {
return new Class[] { GLbitfield.class, GLenum.class, GLhandleARB.class, GLint.class, GLuint.class,
GLsizei.class };
} else if ( type.equals(double.class) ) {
return new Class[] { GLclampd.class, GLdouble.class };
} else if ( type.equals(float.class) ) {
return new Class[] { GLclampf.class, GLfloat.class };
} else if ( type.equals(short.class) ) {
return new Class[] { GLhalf.class, GLshort.class, GLushort.class };
} else if ( type.equals(byte.class) ) {
return new Class[] { GLbyte.class, GLcharARB.class, GLchar.class, GLubyte.class };
} else if ( type.equals(boolean.class) ) {
return new Class[] { GLboolean.class };
} else if ( type.equals(void.class) ) {
return new Class[] { GLvoid.class, GLreturn.class };
} else {
return new Class[]{};
return new Class[] { };
}
}
@ -291,45 +284,45 @@ public class GLTypeMap implements TypeMap {
@Override
public Class[] getValidAnnotationTypes(Class type) {
Class[] valid_types;
if (Buffer.class.isAssignableFrom(type)) {
if ( Buffer.class.isAssignableFrom(type) ) {
valid_types = getValidBufferTypes(type);
} else if (type.isPrimitive()) {
} else if ( type.isPrimitive() ) {
valid_types = getValidPrimitiveTypes(type);
} else if (String.class.equals(type)) {
valid_types = new Class[]{GLubyte.class};
} else if (org.lwjgl.PointerWrapper.class.isAssignableFrom(type)) {
valid_types = new Class[]{PointerWrapper.class};
} else if (void.class.equals(type)) {
valid_types = new Class[]{GLreturn.class};
} else if (PointerBuffer.class.equals(type)) {
valid_types = new Class[]{GLintptr.class, GLintptrARB.class, GLsizeiptr.class, GLsizeiptrARB.class};
} else if ( String.class.equals(type) ) {
valid_types = new Class[] { GLubyte.class };
} else if ( org.lwjgl.PointerWrapper.class.isAssignableFrom(type) ) {
valid_types = new Class[] { PointerWrapper.class };
} else if ( void.class.equals(type) ) {
valid_types = new Class[] { GLreturn.class };
} else if ( PointerBuffer.class.equals(type) ) {
valid_types = new Class[] { GLintptr.class, GLintptrARB.class, GLsizeiptr.class, GLsizeiptrARB.class };
} else {
valid_types = new Class[]{};
valid_types = new Class[] { };
}
return valid_types;
}
@Override
public Class<? extends Annotation> getInverseType(Class type) {
if (GLuint.class.equals(type)) {
if ( GLuint.class.equals(type) ) {
return GLint.class;
} else if (GLint.class.equals(type)) {
} else if ( GLint.class.equals(type) ) {
return GLuint.class;
} else if (GLushort.class.equals(type)) {
} else if ( GLushort.class.equals(type) ) {
return GLshort.class;
} else if (GLshort.class.equals(type)) {
} else if ( GLshort.class.equals(type) ) {
return GLushort.class;
} else if (GLubyte.class.equals(type)) {
} else if ( GLubyte.class.equals(type) ) {
return GLbyte.class;
} else if (GLbyte.class.equals(type)) {
} else if ( GLbyte.class.equals(type) ) {
return GLubyte.class;
} else if (GLuint64EXT.class.equals(type)) {
} else if ( GLuint64EXT.class.equals(type) ) {
return GLint64EXT.class;
} else if (GLint64EXT.class.equals(type)) {
} else if ( GLint64EXT.class.equals(type) ) {
return GLuint64EXT.class;
} else if (GLuint64.class.equals(type)) {
} else if ( GLuint64.class.equals(type) ) {
return GLint64.class;
} else if (GLint64.class.equals(type)) {
} else if ( GLint64.class.equals(type) ) {
return GLuint64.class;
} else {
return null;
@ -339,22 +332,22 @@ public class GLTypeMap implements TypeMap {
@Override
public String getAutoTypeFromAnnotation(AnnotationMirror annotation) {
Class annotation_class = NativeTypeTranslator.getClassFromType(annotation.getAnnotationType());
if (annotation_class.equals(GLint.class)) {
if ( annotation_class.equals(GLint.class) ) {
return "GL11.GL_INT";
} else if (annotation_class.equals(GLbyte.class)) {
} else if ( annotation_class.equals(GLbyte.class) ) {
return "GL11.GL_BYTE";
} else if (annotation_class.equals(GLshort.class)) {
} else if ( annotation_class.equals(GLshort.class) ) {
return "GL11.GL_SHORT";
}
if (annotation_class.equals(GLuint.class)) {
if ( annotation_class.equals(GLuint.class) ) {
return "GL11.GL_UNSIGNED_INT";
} else if (annotation_class.equals(GLubyte.class)) {
} else if ( annotation_class.equals(GLubyte.class) ) {
return "GL11.GL_UNSIGNED_BYTE";
} else if (annotation_class.equals(GLushort.class)) {
} else if ( annotation_class.equals(GLushort.class) ) {
return "GL11.GL_UNSIGNED_SHORT";
} else if (annotation_class.equals(GLfloat.class)) {
} else if ( annotation_class.equals(GLfloat.class) ) {
return "GL11.GL_FLOAT";
} else if (annotation_class.equals(GLdouble.class)) {
} else if ( annotation_class.equals(GLdouble.class) ) {
return "GL11.GL_DOUBLE";
} else {
return null;

View File

@ -40,12 +40,12 @@ package org.lwjgl.util.generator.opengl;
import org.lwjgl.util.generator.NativeType;
import java.lang.annotation.Target;
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
import javax.lang.model.type.TypeKind;
@NativeType
@Target({ElementType.PARAMETER, ElementType.METHOD})
@Target({ ElementType.PARAMETER, ElementType.METHOD })
public @interface GLvoid {
TypeKind value() default TypeKind.BYTE;
}