Added JNIEXPORT to AL alternate methods.

Now forcing full regen when any class in the Generator changes.
This commit is contained in:
Ioannis Tsakpinis 2010-03-16 19:05:19 +00:00
parent 3715e4b39d
commit b17aa7d21b
3 changed files with 40 additions and 5 deletions

View File

@ -35,6 +35,8 @@ package org.lwjgl.util.generator;
import com.sun.mirror.apt.*;
import com.sun.mirror.declaration.*;
import java.io.File;
import java.io.FileFilter;
import java.util.Collection;
import java.util.Set;
import java.util.Map;
@ -108,10 +110,11 @@ public class GeneratorProcessorFactory implements AnnotationProcessorFactory, Ro
TypeDeclaration lastFile = null;
try {
long generatorLM = getGeneratorLastModified();
TypeMap type_map = (TypeMap)(Class.forName(typemap_classname).newInstance());
for (TypeDeclaration typedecl : env.getSpecifiedTypeDeclarations()) {
lastFile = typedecl;
typedecl.accept(getDeclarationScanner(new GeneratorVisitor(env, type_map, generate_error_checks, context_specific), NO_OP));
typedecl.accept(getDeclarationScanner(new GeneratorVisitor(env, type_map, generate_error_checks, context_specific, generatorLM), NO_OP));
}
} catch (Exception e) {
if ( lastFile == null )
@ -120,5 +123,35 @@ public class GeneratorProcessorFactory implements AnnotationProcessorFactory, Ro
throw new RuntimeException("\n-- Failed to process template: " + lastFile.getQualifiedName() + " --", e);
}
}
/**
* Gets the time of the latest change on the Generator classes.
*
* @return time of the latest change
*/
private static long getGeneratorLastModified() {
final File pck = new File(System.getProperty("user.dir") + "/bin/org/lwjgl/util/generator");
if ( !pck.exists() || !pck.isDirectory() )
return Long.MAX_VALUE;
final File[] classes = pck.listFiles(new FileFilter() {
public boolean accept(final File pathname) {
return pathname.isFile() && pathname.getName().endsWith(".class");
}
});
if ( classes == null || classes.length == 0 )
return Long.MAX_VALUE;
long lastModified = 0;
for ( File clazz : classes ) {
long lm = clazz.lastModified();
if ( lastModified < lm )
lastModified = lm;
}
return lastModified;
}
}
}
}

View File

@ -58,12 +58,14 @@ public class GeneratorVisitor extends SimpleDeclarationVisitor {
private final TypeMap type_map;
private final boolean generate_error_checks;
private final boolean context_specific;
private final long generatorLM;
public GeneratorVisitor(AnnotationProcessorEnvironment env, TypeMap type_map, boolean generate_error_checks, boolean context_specific) {
public GeneratorVisitor(AnnotationProcessorEnvironment env, TypeMap type_map, boolean generate_error_checks, boolean context_specific, long generatorLM) {
this.env = env;
this.type_map = type_map;
this.generate_error_checks = generate_error_checks;
this.context_specific = context_specific;
this.generatorLM = generatorLM;
}
private void validateMethods(InterfaceDeclaration d) {
@ -254,7 +256,7 @@ public class GeneratorVisitor extends SimpleDeclarationVisitor {
try {
// Skip this class if the output exists and the input has not been modified.
if ( output.exists() && input.lastModified() < output.lastModified() )
if ( output.exists() && Math.max(input.lastModified(), generatorLM) < output.lastModified() )
return;
if (d.getMethods().size() > 0 || d.getFields().size() > 0) {

View File

@ -87,7 +87,7 @@ public class NativeMethodStubsGenerator {
}
private static void generateMethodStub(AnnotationProcessorEnvironment env, TypeMap type_map, PrintWriter writer, String interface_name, MethodDeclaration method, Mode mode, boolean generate_error_checks, boolean context_specific) {
if ( !context_specific )
if ( !context_specific && method.getAnnotation(Alternate.class) == null )
writer.print("static ");
else
writer.print("JNIEXPORT ");