diff --git a/src/java/org/lwjgl/util/generator/GeneratorProcessorFactory.java b/src/java/org/lwjgl/util/generator/GeneratorProcessorFactory.java index 02e13468..1a8faa4b 100644 --- a/src/java/org/lwjgl/util/generator/GeneratorProcessorFactory.java +++ b/src/java/org/lwjgl/util/generator/GeneratorProcessorFactory.java @@ -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; + } } -} +} \ No newline at end of file diff --git a/src/java/org/lwjgl/util/generator/GeneratorVisitor.java b/src/java/org/lwjgl/util/generator/GeneratorVisitor.java index ebdfe9bb..446e5a96 100644 --- a/src/java/org/lwjgl/util/generator/GeneratorVisitor.java +++ b/src/java/org/lwjgl/util/generator/GeneratorVisitor.java @@ -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) { diff --git a/src/java/org/lwjgl/util/generator/NativeMethodStubsGenerator.java b/src/java/org/lwjgl/util/generator/NativeMethodStubsGenerator.java index 6cced101..858df19f 100644 --- a/src/java/org/lwjgl/util/generator/NativeMethodStubsGenerator.java +++ b/src/java/org/lwjgl/util/generator/NativeMethodStubsGenerator.java @@ -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 ");