*/
@Override
public boolean visit(ConstructorDeclaration ctorDecl, ClassScope scope) {
try {
MethodBinding b = ctorDecl.binding;
JClassType enclosingType = (JClassType) typeMap.get(scope.enclosingSourceType());
String name = enclosingType.getShortName();
SourceInfo info = makeSourceInfo(ctorDecl, enclosingType);
JMethod newMethod = program.createMethod(info, name.toCharArray(),
enclosingType, enclosingType, false, false, true, b.isPrivate(),
false);
// Enums have hidden arguments for name and value
if (enclosingType.isEnumOrSubclass() != null) {
program.createParameter(info, "enum$name".toCharArray(),
program.getTypeJavaLangString(), true, false, newMethod);
program.createParameter(info, "enum$ordinal".toCharArray(),
program.getTypePrimitiveInt(), true, false, newMethod);
}
// user args
mapParameters(newMethod, ctorDecl);
// original params are now frozen
info.addCorrelation(program.getCorrelator().by(newMethod));
int syntheticParamCount = 0;
ReferenceBinding declaringClass = b.declaringClass;
if (declaringClass.isNestedType() && !declaringClass.isStatic()) {
// add synthetic args for outer this and locals
NestedTypeBinding nestedBinding = (NestedTypeBinding) declaringClass;
Set<String> alreadyNamedVariables = new HashSet<String>();
if (nestedBinding.enclosingInstances != null) {
for (int i = 0; i < nestedBinding.enclosingInstances.length; ++i) {
SyntheticArgumentBinding arg = nestedBinding.enclosingInstances[i];
String argName = String.valueOf(arg.name);
if (alreadyNamedVariables.contains(argName)) {
argName += "_" + i;
}
createParameter(arg, argName, newMethod);
++syntheticParamCount;
alreadyNamedVariables.add(argName);
}
}
if (nestedBinding.outerLocalVariables != null) {
for (int i = 0; i < nestedBinding.outerLocalVariables.length; ++i) {
SyntheticArgumentBinding arg = nestedBinding.outerLocalVariables[i];
String argName = String.valueOf(arg.name);
if (alreadyNamedVariables.contains(argName)) {
argName += "_" + i;
}
createParameter(arg, argName, newMethod);
++syntheticParamCount;
alreadyNamedVariables.add(argName);
}
}
}
typeMap.put(b, newMethod);
// Now let's implicitly create a static function called 'new' that will
// allow construction from JSNI methods
if (!enclosingType.isAbstract()) {
ReferenceBinding enclosingBinding = ctorDecl.binding.declaringClass.enclosingType();
JReferenceType outerType = enclosingBinding == null ? null
: (JReferenceType) typeMap.get(enclosingBinding);
createSyntheticConstructor(newMethod,
ctorDecl.binding.declaringClass.isStatic(), outerType);