Skip to content

Commit

Permalink
ClassGenerators now generates constructor exceptions. Stopped using a…
Browse files Browse the repository at this point in the history
…uto_ptr and using raw pointers instead.
  • Loading branch information
Nicolas Gramlich committed Apr 6, 2012
1 parent 0bfe91e commit dd8b1de
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 17 deletions.
Expand Up @@ -47,7 +47,7 @@ public class AndEngineScriptingExtensionGenerator {
private JavaFormatter mGenJavaFormatter;

@Option(required = false, name = "-gen-cpp-class-suffix")
private String mGenCppClassSuffix;
private String mGenCppClassSuffix = "";

@Option(required = false, name = "-gen-cpp-formatter")
private CppFormatter mGenCppFormatter;
Expand Down
Expand Up @@ -284,7 +284,21 @@ private void generateClassConstructor(final Class<?> pClass, final Constructor<?
pGenJavaClassFileWriter.append(GenJavaClassSourceFileSegment.CONSTRUCTORS, ", ");
pGenJavaClassFileWriter.append(GenJavaClassSourceFileSegment.CONSTRUCTORS, methodParamatersAsString);
}
pGenJavaClassFileWriter.append(GenJavaClassSourceFileSegment.CONSTRUCTORS, ") {").end();
pGenJavaClassFileWriter.append(GenJavaClassSourceFileSegment.CONSTRUCTORS, ") ");
final Class<?>[] exceptions = pConstructor.getExceptionTypes();
if(exceptions.length > 0) {
pGenJavaClassFileWriter.append(GenJavaClassSourceFileSegment.CONSTRUCTORS, "throws ");
for(int i = 0; i < exceptions.length; i++) {
final Class<?> exception = exceptions[i];
pGenJavaClassFileWriter.append(GenJavaClassSourceFileSegment.CONSTRUCTORS, exception.getSimpleName());
this.generateImports(pGenJavaClassFileWriter, exception);
final boolean isLastException = (i == (exceptions.length - 1));
if(!isLastException) {
pGenJavaClassFileWriter.append(GenJavaClassSourceFileSegment.CONSTRUCTORS, ", ");
}
}
}
pGenJavaClassFileWriter.append(GenJavaClassSourceFileSegment.CONSTRUCTORS, "{").end();
pGenJavaClassFileWriter.incrementIndent(GenJavaClassSourceFileSegment.CONSTRUCTORS);
/* Super call. */
pGenJavaClassFileWriter.append(GenJavaClassSourceFileSegment.CONSTRUCTORS, "super(");
Expand Down Expand Up @@ -541,7 +555,8 @@ private void generateClassMethod(final Class<?> pClass, final Method pMethod, fi
final String genCppStaticClassMemberName = this.mUtil.getGenCppStaticClassMemberName(pClass);
final String genCppStaticMethodIDFieldName = this.mUtil.getGenCppStaticMethodIDFieldName(pMethod);
final String jniMethodSignature = this.mUtil.getJNIMethodSignature(pMethod);
final String returnTypeGenCppParameterTypeName = this.mUtil.getGenCppParameterTypeName(pMethod.getReturnType(), true, true);
final String returnTypeGenCppParameterTypeName = this.mUtil.getGenCppParameterTypeName(pMethod.getReturnType(), true);
final String returnTypeGenCppParameterTypeNameWithoutPtr = this.mUtil.getGenCppParameterTypeName(pMethod.getReturnType(), false);
final String genCppClassName = this.mUtil.getGenCppClassName(pClass);
final String methodName = pMethod.getName();

Expand Down Expand Up @@ -575,8 +590,7 @@ private void generateClassMethod(final Class<?> pClass, final Method pMethod, fi
}
pGenCppClassFileWriter.append(GenCppClassSourceFileSegment.METHODS, "JNI_ENV()->").append(this.mUtil.getJNICallXYZMethodName(pMethod.getReturnType())).append("(this->mUnwrapped, ").append(genCppStaticMethodIDFieldName);
} else {
final String returnTypeGenCppParameterTypeNameWithoutAutoPtr = this.mUtil.getGenCppParameterTypeName(pMethod.getReturnType(), false, false);
pGenCppClassFileWriter.append(GenCppClassSourceFileSegment.METHODS, "return ").append(returnTypeGenCppParameterTypeName).append("(new ").append(returnTypeGenCppParameterTypeNameWithoutAutoPtr).append("(JNI_ENV()->").append(this.mUtil.getJNICallXYZMethodName(pMethod.getReturnType())).append("(this->mUnwrapped, ").append(genCppStaticMethodIDFieldName);
pGenCppClassFileWriter.append(GenCppClassSourceFileSegment.METHODS, "return new ").append(returnTypeGenCppParameterTypeNameWithoutPtr).append("(JNI_ENV()->").append(this.mUtil.getJNICallXYZMethodName(pMethod.getReturnType())).append("(this->mUnwrapped, ").append(genCppStaticMethodIDFieldName);
}
if(jniMethodCallParamatersAsString != null) {
pGenCppClassFileWriter.append(GenCppClassSourceFileSegment.METHODS, ", ");
Expand All @@ -585,7 +599,7 @@ private void generateClassMethod(final Class<?> pClass, final Method pMethod, fi
if(primitiveReturnType) {
pGenCppClassFileWriter.append(GenCppClassSourceFileSegment.METHODS, ");").end();
} else {
pGenCppClassFileWriter.append(GenCppClassSourceFileSegment.METHODS, ")));").end();
pGenCppClassFileWriter.append(GenCppClassSourceFileSegment.METHODS, "));").end();
}
pGenCppClassFileWriter.decrementIndent(GenCppClassSourceFileSegment.METHODS);
pGenCppClassFileWriter.append(GenCppClassSourceFileSegment.METHODS, "}").end(); // TODO Parameters?
Expand Down
Expand Up @@ -121,7 +121,7 @@ private void generateInterfaceMethod(final Class<?> pClass, final Method pMethod
final String genCppMethodHeaderParamatersAsString = this.mUtil.getGenCppMethodHeaderParamatersAsString(pMethod);
final String methodName = pMethod.getName();

final String returnTypeName = this.mUtil.getGenCppParameterTypeName(pMethod.getReturnType(), true, true);
final String returnTypeName = this.mUtil.getGenCppParameterTypeName(pMethod.getReturnType(), true);

pGenCppClassFileWriter.append(GenCppClassHeaderFileSegment.METHODS_PUBLIC, "virtual").space().append(returnTypeName).space().append(methodName);
pGenCppClassFileWriter.append(GenCppClassHeaderFileSegment.METHODS_PUBLIC, "(");
Expand All @@ -140,7 +140,7 @@ private void generateInterfaceCallback(final Class<?> pClass, final Method pMeth
if(pMethod.getReturnType() == Void.TYPE) {
returnTypeName = this.mUtil.getGenCppParameterTypeName(Boolean.TYPE);
} else {
returnTypeName = this.mUtil.getGenCppParameterTypeName(pMethod.getReturnType(), true, true);
returnTypeName = this.mUtil.getGenCppParameterTypeName(pMethod.getReturnType(), true);
}

pGenCppClassFileWriter.append(GenCppClassHeaderFileSegment.METHODS_PUBLIC, "virtual").space().append(returnTypeName).space().append(methodName);
Expand Down
14 changes: 5 additions & 9 deletions src/org/andengine/extension/scripting/generator/util/Util.java
Expand Up @@ -535,10 +535,10 @@ public String getJNICallXYZMethodName(final Class<?> pType) {
}

public String getGenCppParameterTypeName(final Class<?> pParameterType) {
return this.getGenCppParameterTypeName(pParameterType, false, true);
return this.getGenCppParameterTypeName(pParameterType, true);
}

public String getGenCppParameterTypeName(final Class<?> pParameterType, final boolean pAutoPtrObjects, final boolean pPointerObjects) {
public String getGenCppParameterTypeName(final Class<?> pParameterType, final boolean pPointerObjects) {
if(pParameterType.isArray()) {
final Class<?> componentType = pParameterType.getComponentType();
if(componentType == Boolean.TYPE) {
Expand Down Expand Up @@ -589,14 +589,10 @@ public String getGenCppParameterTypeName(final Class<?> pParameterType, final bo
return "jobject";
} else {
// TODO Add import, when name != simplename.
if(pAutoPtrObjects) {
return "std::auto_ptr<" + pParameterType.getSimpleName() + this.mGenCppClassSuffix + ">";
if(pPointerObjects) {
return pParameterType.getSimpleName() + this.mGenCppClassSuffix + "*";
} else {
if(pPointerObjects) {
return pParameterType.getSimpleName() + this.mGenCppClassSuffix + "*";
} else {
return pParameterType.getSimpleName() + this.mGenCppClassSuffix;
}
return pParameterType.getSimpleName() + this.mGenCppClassSuffix;
}
}
}
Expand Down

0 comments on commit dd8b1de

Please sign in to comment.