ClassUnit classUnit= project.getClassUnit(method.getMethodBinding().getDeclaringClass().getClassName());
classUnit.addNotReversibleMethod(Pass1.extractMethodNameSignature(method.getMethodBinding()));
}
MethodBinding methodBinding= method.getMethodBinding();
ProcedureUnit unit= project.getProcedureUnit(methodBinding);
if (method.getBody() == null && Modifier.isNative(method.getAccess()))
{
if (Modifier.isNative(method.getAccess()) || Modifier.isAbstract(method.getAccess()) || Modifier.isInterface(typeDecl.getAccess()))
{
return;
}
throw new RuntimeException("Method " + method + " with access " + method.getAccess() + " may not have empty body");
}
// if (!dragomeJsCompiler.compiler.isCompression())
// {
// println("/* " + unit.getAbsoluteSignature() + " */");
// }
String closingString;
Signature signature= Project.getSingleton().getSignature(methodBinding.toString()).relative();
String signatureReplaced= normalizeExpression(signature);
if (typeDecl.getClassName().equals("java.lang.String") && method.isInstanceConstructor())
{
Block body= method.getBody();
body.removeChild(body.getFirstChild());
MethodInvocation consume= (MethodInvocation) body.getLastChild();
body.removeChild(consume);
ReturnStatement r= new ReturnStatement(0, 0);
r.setExpression((Expression) consume.getArguments().get(0));
body.appendChild(r);
print("_dragomeJs.StringInit" + signatureReplaced + " = function(");
closingString= "};\n";
}
else
{
if (Modifier.isStatic(method.getAccess()))
{
String className= normalizeExpression(method.getMethodBinding().getDeclaringClass().getClassName());
print(ClassUnit.STATIC_MEMBER);
// print(className + ".");
}
else
{
// if (typeDecl.getClassName().equals("java.lang.String"))
// print("String.prototype." + signatureReplaced + "=");
// print("this.");
}
print(signatureReplaced);
print(": ");
String alias= method.getAnnotationsValues().get(MethodAlias.class.getName() + "#" + "alias");
if (alias != null)
print(alias + "= ");
print("function (");
closingString= "}";
}
Iterator<VariableDeclaration> iterator= method.getParameters().iterator();
while (iterator.hasNext())
{
VariableDeclaration decl= iterator.next();
if ("function".equals(decl.getName()))
print("_");
decl.visit(this);
print(iterator.hasNext() ? ", " : "");
}
println(")");
println("{");
depth= 1;
Collection<VariableDeclaration> localVariables= method.getLocalVariables();
if (localVariables.size() > 0)
print("var ");
int i= 0;
for (VariableDeclaration decl : localVariables)
{
decl.visit(this);
if (++i < localVariables.size())
print(",");
}
if (localVariables.size() > 0)
println(";");
depth= 0;
if (method.getBody() != null)
visit_(method.getBody());
// println ("//llamar al servidor");
if (method.isInstanceConstructor())
print("return this;\n");
print(closingString);
String local_alias= method.getAnnotationsValues().get(MethodAlias.class.getName() + "#" + "local_alias");
if (local_alias != null)
{
print(", \n");
print(local_alias + ": function() {return this." + signatureReplaced + "(arguments)}");
}
//println(",");
unit.setData(reset());
Log.getLogger().debug("Generating JavaScript for " + unit);
}