return methodDeclaration;
}
private TypeDeclaration convert(IType type, IType alreadyComputedMember,TypeDeclaration alreadyComputedMemberDeclaration) throws JavaModelException {
/* create type declaration - can be member type */
TypeDeclaration typeDeclaration = new TypeDeclaration(this.compilationResult);
if (type.getDeclaringType() != null) {
typeDeclaration.bits |= ASTNode.IsMemberType;
}
typeDeclaration.name = type.getElementName().toCharArray();
typeDeclaration.modifiers = type.getFlags();
/* set superclass and superinterfaces */
if (type.getSuperclassName() != null) {
TypeReference typeReference = createTypeReference(type.getSuperclassTypeSignature());
if (typeReference != null) {
typeDeclaration.superclass = typeReference;
typeDeclaration.superclass.bits |= ASTNode.IsSuperType;
}
}
String[] interfaceTypes = type.getSuperInterfaceTypeSignatures();
int interfaceCount = interfaceTypes == null ? 0 : interfaceTypes.length;
typeDeclaration.superInterfaces = new TypeReference[interfaceCount];
int count = 0;
for (int i = 0; i < interfaceCount; i++) {
TypeReference typeReference = createTypeReference(interfaceTypes[i]);
if (typeReference != null) {
typeDeclaration.superInterfaces[count] = typeReference;
typeDeclaration.superInterfaces[count++].bits |= ASTNode.IsSuperType;
}
}
if (count != interfaceCount) {
System.arraycopy(typeDeclaration.fields, 0, typeDeclaration.superInterfaces = new TypeReference[interfaceCount], 0, interfaceCount);
}
// convert 1.5 specific constructs only if compliance is 1.5 or above
if (this.has1_5Compliance) {
/* convert type parameters */
ITypeParameter[] typeParameters = type.getTypeParameters();
if (typeParameters != null && typeParameters.length > 0) {
int parameterCount = typeParameters.length;
org.eclipse.jdt.internal.compiler.ast.TypeParameter[] typeParams = new org.eclipse.jdt.internal.compiler.ast.TypeParameter[parameterCount];
for (int i = 0; i < parameterCount; i++) {
ITypeParameter typeParameter = typeParameters[i];
typeParams[i] =
createTypeParameter(
typeParameter.getElementName().toCharArray(),
stringArrayToCharArray(typeParameter.getBounds()),
0,
0);
}
typeDeclaration.typeParameters = typeParams;
}
}
/* convert member types */
IType[] memberTypes = type.getTypes();
int memberTypeCount = memberTypes == null ? 0 : memberTypes.length;
typeDeclaration.memberTypes = new TypeDeclaration[memberTypeCount];
for (int i = 0; i < memberTypeCount; i++) {
if(alreadyComputedMember != null && alreadyComputedMember.getFullyQualifiedName().equals(memberTypes[i].getFullyQualifiedName())) {
typeDeclaration.memberTypes[i] = alreadyComputedMemberDeclaration;
} else {
typeDeclaration.memberTypes[i] = convert(memberTypes[i], null, null);
}
typeDeclaration.memberTypes[i].enclosingType = typeDeclaration;
}
/* convert fields */
IField[] fields = type.getFields();
int fieldCount = fields == null ? 0 : fields.length;
typeDeclaration.fields = new FieldDeclaration[fieldCount];
count = 0;
for (int i = 0; i < fieldCount; i++) {
FieldDeclaration fieldDeclaration = convert(fields[i], type);
if (fieldDeclaration != null) {
typeDeclaration.fields[count++] = fieldDeclaration;
}
}
if (count != fieldCount) {
System.arraycopy(typeDeclaration.fields, 0, typeDeclaration.fields = new FieldDeclaration[count], 0, count);
}
/* convert methods - need to add default constructor if necessary */
IMethod[] methods = type.getMethods();
int methodCount = methods == null ? 0 : methods.length;
/* source type has a constructor ? */
/* by default, we assume that one is needed. */
int neededCount = 1;
for (int i = 0; i < methodCount; i++) {
if (methods[i].isConstructor()) {
neededCount = 0;
// Does not need the extra constructor since one constructor already exists.
break;
}
}
boolean isInterface = type.isInterface();
neededCount = isInterface ? 0 : neededCount;
typeDeclaration.methods = new AbstractMethodDeclaration[methodCount + neededCount];
if (neededCount != 0) { // add default constructor in first position
typeDeclaration.methods[0] = typeDeclaration.createDefaultConstructor(false, false);
}
boolean hasAbstractMethods = false;
count = 0;
for (int i = 0; i < methodCount; i++) {
AbstractMethodDeclaration method = convert(methods[i], type);