Skip to content

Commit

Permalink
Back out d9bdfdfda06e to dd17e0758a00 (bug 913985) due to incorrect a…
Browse files Browse the repository at this point in the history
…uthor on some of the patches. r=backout
  • Loading branch information
staktrace committed Sep 27, 2013
1 parent fadd50c commit ac10421
Show file tree
Hide file tree
Showing 79 changed files with 2,112 additions and 4,528 deletions.
117 changes: 16 additions & 101 deletions build/annotationProcessors/AnnotationProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@

package org.mozilla.gecko.annotationProcessors;

import org.mozilla.gecko.annotationProcessors.classloader.AnnotatableEntity;
import org.mozilla.gecko.annotationProcessors.classloader.ClassWithOptions;
import org.mozilla.gecko.annotationProcessors.classloader.IterableJarLoadingURLClassLoader;
import org.mozilla.gecko.annotationProcessors.utils.GeneratableElementIterator;
import org.mozilla.gecko.annotationProcessors.utils.GeneratableEntryPointIterator;

import java.io.FileOutputStream;
import java.io.IOException;
Expand All @@ -18,12 +16,6 @@ public class AnnotationProcessor {
public static final String OUTFILE = "GeneratedJNIWrappers.cpp";
public static final String HEADERFILE = "GeneratedJNIWrappers.h";

public static final String GENERATED_COMMENT =
"// GENERATED CODE\n" +
"// Generated by the Java program at /build/annotationProcessors at compile time from\n" +
"// annotations on Java methods. To update, change the annotations on the corresponding Java\n" +
"// methods and rerun the build. Manually updating this file will cause your build to fail.\n\n";

public static void main(String[] args) {
// We expect a list of jars on the commandline. If missing, whinge about it.
if (args.length <= 1) {
Expand All @@ -41,121 +33,44 @@ public static void main(String[] args) {
long s = System.currentTimeMillis();

// Get an iterator over the classes in the jar files given...
Iterator<ClassWithOptions> jarClassIterator = IterableJarLoadingURLClassLoader.getIteratorOverJars(args);

StringBuilder headerFile = new StringBuilder(GENERATED_COMMENT);
headerFile.append("#ifndef GeneratedJNIWrappers_h__\n" +
"#define GeneratedJNIWrappers_h__\n\n" +
"#include \"nsXPCOMStrings.h\"\n" +
"#include \"AndroidJavaWrappers.h\"\n" +
"\n" +
"namespace mozilla {\n" +
"namespace widget {\n" +
"namespace android {\n" +
"void InitStubs(JNIEnv *jEnv);\n\n");

StringBuilder implementationFile = new StringBuilder(GENERATED_COMMENT);
implementationFile.append("#include \"GeneratedJNIWrappers.h\"\n" +
"#include \"AndroidBridgeUtilities.h\"\n" +
"#include \"nsXPCOMStrings.h\"\n" +
"#include \"AndroidBridge.h\"\n" +
"\n" +
"namespace mozilla {\n" +
"namespace widget {\n" +
"namespace android {\n");

// Used to track the calls to the various class-specific initialisation functions.
StringBuilder stubInitialiser = new StringBuilder();
stubInitialiser.append("void InitStubs(JNIEnv *jEnv) {\n");
Iterator<Class<?>> jarClassIterator = IterableJarLoadingURLClassLoader.getIteratorOverJars(args);

while (jarClassIterator.hasNext()) {
ClassWithOptions aClassTuple = jarClassIterator.next();
CodeGenerator generatorInstance = new CodeGenerator();

CodeGenerator generatorInstance;
while (jarClassIterator.hasNext()) {
Class<?> aClass = jarClassIterator.next();

// Get an iterator over the appropriately generated methods of this class
Iterator<AnnotatableEntity> methodIterator = new GeneratableElementIterator(aClassTuple.wrappedClass);

if (!methodIterator.hasNext()) {
continue;
}
generatorInstance = new CodeGenerator(aClassTuple.wrappedClass, aClassTuple.generatedName);

stubInitialiser.append(" ").append(aClassTuple.generatedName).append("::InitStubs(jEnv);\n");
Iterator<MethodWithAnnotationInfo> methodIterator = new GeneratableEntryPointIterator(aClass.getDeclaredMethods());

// Iterate all annotated members in this class..
// Iterate all annotated methods in this class..
while (methodIterator.hasNext()) {
AnnotatableEntity aElementTuple = methodIterator.next();
switch (aElementTuple.mEntityType) {
case METHOD:
generatorInstance.generateMethod(aElementTuple);
break;
case FIELD:
generatorInstance.generateField(aElementTuple);
break;
case CONSTRUCTOR:
generatorInstance.generateConstructor(aElementTuple);
break;
}
MethodWithAnnotationInfo aMethodTuple = methodIterator.next();
generatorInstance.generateMethod(aMethodTuple, aClass);
}

headerFile.append(generatorInstance.getHeaderFileContents());
implementationFile.append(generatorInstance.getWrapperFileContents());
}

implementationFile.append('\n');
stubInitialiser.append("}");
implementationFile.append(stubInitialiser);

implementationFile.append("\n} /* android */\n" +
"} /* widget */\n" +
"} /* mozilla */\n");

headerFile.append("\n} /* android */\n" +
"} /* widget */\n" +
"} /* mozilla */\n" +
"#endif\n");

writeOutputFiles(headerFile, implementationFile);
writeOutputFiles(generatorInstance);
long e = System.currentTimeMillis();
System.out.println("Annotation processing complete in " + (e - s) + "ms");
}

private static void writeOutputFiles(StringBuilder aHeaderFile, StringBuilder aImplementationFile) {
FileOutputStream headerStream = null;
private static void writeOutputFiles(CodeGenerator aGenerator) {
try {
headerStream = new FileOutputStream(OUTFILE);
headerStream.write(aImplementationFile.toString().getBytes());
FileOutputStream outStream = new FileOutputStream(OUTFILE);
outStream.write(aGenerator.getWrapperFileContents());
} catch (IOException e) {
System.err.println("Unable to write " + OUTFILE + ". Perhaps a permissions issue?");
e.printStackTrace(System.err);
} finally {
if (headerStream != null) {
try {
headerStream.close();
} catch (IOException e) {
System.err.println("Unable to close headerStream due to "+e);
e.printStackTrace(System.err);
}
}
}

FileOutputStream outStream = null;
try {
outStream = new FileOutputStream(HEADERFILE);
outStream.write(aHeaderFile.toString().getBytes());
FileOutputStream headerStream = new FileOutputStream(HEADERFILE);
headerStream.write(aGenerator.getHeaderFileContents());
} catch (IOException e) {
System.err.println("Unable to write " + HEADERFILE + ". Perhaps a permissions issue?");
System.err.println("Unable to write " + OUTFILE + ". Perhaps a permissions issue?");
e.printStackTrace(System.err);
} finally {
if (outStream != null) {
try {
outStream.close();
} catch (IOException e) {
System.err.println("Unable to close outStream due to "+e);
e.printStackTrace(System.err);
}
}
}
}
}
Loading

0 comments on commit ac10421

Please sign in to comment.