* @param typeDeclaration org.eclipse.jdt.internal.compiler.ast.TypeDeclaration
* @param unitResult org.eclipse.jdt.internal.compiler.CompilationUnitResult
*/
public static void createProblemType(TypeDeclaration typeDeclaration, CompilationResult unitResult) {
SourceTypeBinding typeBinding = typeDeclaration.binding;
ClassFile classFile = new CodeSnippetClassFile(typeBinding, null, true);
// inner attributes
if (typeBinding.hasMemberTypes()) {
// see bug 180109
ReferenceBinding[] members = typeBinding.memberTypes;
for (int i = 0, l = members.length; i < l; i++)
classFile.recordInnerClasses(members[i]);
}
// TODO (olivier) handle cases where a field cannot be generated (name too long)
// TODO (olivier) handle too many methods
// inner attributes
if (typeBinding.isNestedType()) {
classFile.recordInnerClasses(typeBinding);
}
TypeVariableBinding[] typeVariables = typeBinding.typeVariables();
for (int i = 0, max = typeVariables.length; i < max; i++) {
TypeVariableBinding typeVariableBinding = typeVariables[i];
if ((typeVariableBinding.tagBits & TagBits.ContainsNestedTypeReferences) != 0) {
Util.recordNestedType(classFile, typeVariableBinding);
}
}
// add its fields
FieldBinding[] fields = typeBinding.fields();
if ((fields != null) && (fields != Binding.NO_FIELDS)) {
classFile.addFieldInfos();
} else {
// we have to set the number of fields to be equals to 0
classFile.contents[classFile.contentsOffset++] = 0;
classFile.contents[classFile.contentsOffset++] = 0;
}
// leave some space for the methodCount
classFile.setForMethodInfos();
// add its user defined methods
int problemsLength;
CategorizedProblem[] problems = unitResult.getErrors();
if (problems == null) {
problems = new CategorizedProblem[0];
}
CategorizedProblem[] problemsCopy = new CategorizedProblem[problemsLength = problems.length];
System.arraycopy(problems, 0, problemsCopy, 0, problemsLength);
AbstractMethodDeclaration[] methodDecls = typeDeclaration.methods;
if (methodDecls != null) {
if (typeBinding.isInterface()) {
// we cannot create problem methods for an interface. So we have to generate a clinit
// which should contain all the problem
classFile.addProblemClinit(problemsCopy);
for (int i = 0, length = methodDecls.length; i < length; i++) {
AbstractMethodDeclaration methodDecl = methodDecls[i];
MethodBinding method = methodDecl.binding;
if (method == null || method.isConstructor()) continue;
method.modifiers = ClassFileConstants.AccPublic | ClassFileConstants.AccAbstract;
classFile.addAbstractMethod(methodDecl, method);
}
} else {
for (int i = 0, length = methodDecls.length; i < length; i++) {
AbstractMethodDeclaration methodDecl = methodDecls[i];
MethodBinding method = methodDecl.binding;
if (method == null) continue;
if (method.isConstructor()) {
classFile.addProblemConstructor(methodDecl, method, problemsCopy);
} else if (method.isAbstract()) {
classFile.addAbstractMethod(methodDecl, method);
} else {
classFile.addProblemMethod(methodDecl, method, problemsCopy);
}
}
}
// add abstract methods
classFile.addDefaultAbstractMethods();
}
// propagate generation of (problem) member types
if (typeDeclaration.memberTypes != null) {
for (int i = 0, max = typeDeclaration.memberTypes.length; i < max; i++) {
TypeDeclaration memberType = typeDeclaration.memberTypes[i];
if (memberType.binding != null) {
ClassFile.createProblemType(memberType, unitResult);
}
}
}
classFile.addAttributes();
unitResult.record(typeBinding.constantPoolName(), classFile);
}