Java Code Examples for org.eclipse.jdt.internal.compiler.ast.TypeDeclaration#kind()

The following examples show how to use org.eclipse.jdt.internal.compiler.ast.TypeDeclaration#kind() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Extractor.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@NonNull
public static ClassKind forType(@Nullable TypeDeclaration declaration) {
    if (declaration == null) {
        return CLASS;
    }
    switch (TypeDeclaration.kind(declaration.modifiers)) {
        case TypeDeclaration.INTERFACE_DECL:
            return INTERFACE;
        case TypeDeclaration.ANNOTATION_TYPE_DECL:
            return ANNOTATION;
        case TypeDeclaration.ENUM_DECL:
            return ENUM;
        default:
            return CLASS;
    }
}
 
Example 2
Source File: RecoveredType.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public RecoveredType(TypeDeclaration typeDeclaration, RecoveredElement parent, int bracketBalance){
	super(typeDeclaration, parent, bracketBalance);
	this.typeDeclaration = typeDeclaration;
	if(typeDeclaration.allocation != null && typeDeclaration.allocation.type == null) {
		// an enum constant body can not exist if there is no opening brace
		this.foundOpeningBrace = true;
	} else {
		this.foundOpeningBrace = !bodyStartsAtHeaderEnd();
	}
	this.insideEnumConstantPart = TypeDeclaration.kind(typeDeclaration.modifiers) == TypeDeclaration.ENUM_DECL;
	if(this.foundOpeningBrace) {
		this.bracketBalance++;
	}

	this.preserveContent = parser().methodRecoveryActivated || parser().statementRecoveryActivated;
}
 
Example 3
Source File: NameLookup.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns true if:<ul>
 *  <li>the given type is an existing class and the flag's <code>ACCEPT_CLASSES</code>
 *      bit is on
 *  <li>the given type is an existing interface and the <code>ACCEPT_INTERFACES</code>
 *      bit is on
 *  <li>neither the <code>ACCEPT_CLASSES</code> or <code>ACCEPT_INTERFACES</code>
 *      bit is on
 *  </ul>
 * Otherwise, false is returned.
 */
protected boolean acceptType(IType type, int acceptFlags, boolean isSourceType) {
	if (acceptFlags == 0 || acceptFlags == ACCEPT_ALL)
		return true; // no flags or all flags, always accepted
	try {
		int kind = isSourceType
				? TypeDeclaration.kind(((SourceTypeElementInfo) ((SourceType) type).getElementInfo()).getModifiers())
				: TypeDeclaration.kind(((IBinaryType) ((BinaryType) type).getElementInfo()).getModifiers());
		switch (kind) {
			case TypeDeclaration.CLASS_DECL :
				return (acceptFlags & ACCEPT_CLASSES) != 0;
			case TypeDeclaration.INTERFACE_DECL :
				return (acceptFlags & ACCEPT_INTERFACES) != 0;
			case TypeDeclaration.ENUM_DECL :
				return (acceptFlags & ACCEPT_ENUMS) != 0;
			default:
				//case IGenericType.ANNOTATION_TYPE :
				return (acceptFlags & ACCEPT_ANNOTATIONS) != 0;
		}
	} catch (JavaModelException npe) {
		return false; // the class is not present, do not accept.
	}
}
 
Example 4
Source File: JavaDerivedStateComputer.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public JvmDeclaredType createType(TypeDeclaration type, String packageName) {
	JvmDeclaredType jvmType = null;
	switch (TypeDeclaration.kind(type.modifiers)) {
	case TypeDeclaration.CLASS_DECL:
		jvmType = TypesFactory.eINSTANCE.createJvmGenericType();
		break;
	case TypeDeclaration.INTERFACE_DECL:
		jvmType = TypesFactory.eINSTANCE.createJvmGenericType();
		((JvmGenericType) jvmType).setInterface(true);
		break;
	case TypeDeclaration.ENUM_DECL:
		jvmType = TypesFactory.eINSTANCE.createJvmEnumerationType();
		break;
	case TypeDeclaration.ANNOTATION_TYPE_DECL:
		jvmType = TypesFactory.eINSTANCE.createJvmAnnotationType();
		break;
	default:
		throw new IllegalArgumentException("Cannot handle type " + type.toString());
	}
	jvmType.setPackageName(packageName);
	jvmType.setSimpleName(String.valueOf(type.name));
	if (jvmType instanceof JvmGenericType) {
		if (type.typeParameters != null) {
			for (TypeParameter typeParam : type.typeParameters) {
				JvmTypeParameter jvmTypeParam = TypesFactory.eINSTANCE.createJvmTypeParameter();
				jvmTypeParam.setName(String.valueOf(typeParam.name));
				((JvmGenericType) jvmType).getTypeParameters().add(jvmTypeParam);
			}
		}
	}
	if (type.memberTypes != null) {
		for (TypeDeclaration nestedType : type.memberTypes) {
			JvmDeclaredType nested = createType(nestedType, null);
			jvmType.getMembers().add(nested);
		}
	}
	return jvmType;
}
 
Example 5
Source File: RecoveredUnit.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public RecoveredElement add(AbstractMethodDeclaration methodDeclaration, int bracketBalanceValue) {

	/* attach it to last type - if any */
	if (this.typeCount > 0){
		RecoveredType type = this.types[this.typeCount -1];
		int start = type.bodyEnd;
		int end = type.typeDeclaration.bodyEnd;
		type.bodyEnd = 0; // reset position
		type.typeDeclaration.declarationSourceEnd = 0; // reset position
		type.typeDeclaration.bodyEnd = 0;

		int kind = TypeDeclaration.kind(type.typeDeclaration.modifiers);
		if(start > 0 &&
				start < end &&
				kind != TypeDeclaration.INTERFACE_DECL &&
				kind != TypeDeclaration.ANNOTATION_TYPE_DECL) {
			// the } of the last type can be considered as the end of an initializer
			Initializer initializer = new Initializer(new Block(0), 0);
			initializer.bodyStart = end;
			initializer.bodyEnd = end;
			initializer.declarationSourceStart = end;
			initializer.declarationSourceEnd = end;
			initializer.sourceStart = end;
			initializer.sourceEnd = end;
			type.add(initializer, bracketBalanceValue);
		}

		resetPendingModifiers();

		return type.add(methodDeclaration, bracketBalanceValue);
	}
	return this; // ignore
}
 
Example 6
Source File: SimpleDOMBuilder.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 */
public void enterType(TypeInfo typeInfo) {
	if (this.fBuildingType) {
		int[] sourceRange = {typeInfo.declarationStart, -1}; // will be fixed in the exit
		int[] nameRange = new int[] {typeInfo.nameSourceStart, typeInfo.nameSourceEnd};
		this.fNode = new DOMType(this.fDocument, sourceRange, new String(typeInfo.name), nameRange,
			typeInfo.modifiers, CharOperation.charArrayToStringArray(typeInfo.superinterfaces), TypeDeclaration.kind(typeInfo.modifiers) == TypeDeclaration.CLASS_DECL); // TODO (jerome) should pass in kind
		addChild(this.fNode);
		this.fStack.push(this.fNode);

		// type parameters not supported by JDOM
	}
}
 
Example 7
Source File: BinaryType.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public boolean isInterface() throws JavaModelException {
	IBinaryType info = (IBinaryType) getElementInfo();
	switch (TypeDeclaration.kind(info.getModifiers())) {
		case TypeDeclaration.INTERFACE_DECL:
		case TypeDeclaration.ANNOTATION_TYPE_DECL: // annotation is interface too
			return true;
	}
	return false;
}
 
Example 8
Source File: SourceType.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @see IType
 */
public boolean isInterface() throws JavaModelException {
	SourceTypeElementInfo info = (SourceTypeElementInfo) getElementInfo();
	switch (TypeDeclaration.kind(info.getModifiers())) {
		case TypeDeclaration.INTERFACE_DECL:
		case TypeDeclaration.ANNOTATION_TYPE_DECL: // annotation is interface too
			return true;
	}
	return false;
}
 
Example 9
Source File: HierarchyBuilder.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Looks up and returns a handle for the given binary info.
 */
protected IType lookupBinaryHandle(IBinaryType typeInfo) {
	int flag;
	String qualifiedName;
	switch (TypeDeclaration.kind(typeInfo.getModifiers())) {
		case TypeDeclaration.CLASS_DECL :
			flag = NameLookup.ACCEPT_CLASSES;
			break;
		case TypeDeclaration.INTERFACE_DECL :
			flag = NameLookup.ACCEPT_INTERFACES;
			break;
		case TypeDeclaration.ENUM_DECL :
			flag = NameLookup.ACCEPT_ENUMS;
			break;
		default:
			//case IGenericType.ANNOTATION :
			flag = NameLookup.ACCEPT_ANNOTATIONS;
			break;
	}
	char[] bName = typeInfo.getName();
	qualifiedName = new String(ClassFile.translatedName(bName));
	if (qualifiedName.equals(this.focusQualifiedName)) return getType();
	NameLookup.Answer answer = this.nameLookup.findType(qualifiedName,
		false,
		flag,
		true/* consider secondary types */,
		false/* do NOT wait for indexes */,
		false/*don't check restrictions*/,
		null);
	return answer == null || answer.type == null || !answer.type.isBinary() ? null : answer.type;

}
 
Example 10
Source File: HierarchyBinaryType.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public String toString() {
	StringBuffer buffer = new StringBuffer();
	if (this.modifiers == ClassFileConstants.AccPublic) {
		buffer.append("public "); //$NON-NLS-1$
	}
	switch (TypeDeclaration.kind(this.modifiers)) {
		case TypeDeclaration.CLASS_DECL :
			buffer.append("class "); //$NON-NLS-1$
			break;
		case TypeDeclaration.INTERFACE_DECL :
			buffer.append("interface "); //$NON-NLS-1$
			break;
		case TypeDeclaration.ENUM_DECL :
			buffer.append("enum "); //$NON-NLS-1$
			break;
	}
	if (this.name != null) {
		buffer.append(this.name);
	}
	if (this.superclass != null) {
		buffer.append("\n  extends "); //$NON-NLS-1$
		buffer.append(this.superclass);
	}
	int length;
	if (this.superInterfaces != null && (length = this.superInterfaces.length) != 0) {
		buffer.append("\n implements "); //$NON-NLS-1$
		for (int i = 0; i < length; i++) {
			buffer.append(this.superInterfaces[i]);
			if (i != length - 1) {
				buffer.append(", "); //$NON-NLS-1$
			}
		}
	}
	return buffer.toString();
}
 
Example 11
Source File: ClassFileMatchLocator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
boolean matchTypeDeclaration(TypeDeclarationPattern pattern, Object binaryInfo, IBinaryType enclosingBinaryType) {
	if (!(binaryInfo instanceof IBinaryType)) return false;

	IBinaryType type = (IBinaryType) binaryInfo;
	char[] fullyQualifiedTypeName = convertClassFileFormat(type.getName());
	boolean qualifiedPattern = pattern instanceof QualifiedTypeDeclarationPattern;
	if (pattern.enclosingTypeNames == null || qualifiedPattern) {
		char[] simpleName = (pattern.getMatchMode() == SearchPattern.R_PREFIX_MATCH)
			? CharOperation.concat(pattern.simpleName, IIndexConstants.ONE_STAR)
			: pattern.simpleName;
		char[] pkg = qualifiedPattern ? ((QualifiedTypeDeclarationPattern)pattern).qualification : pattern.pkg;
		if (!checkTypeName(simpleName, pkg, fullyQualifiedTypeName, pattern.isCaseSensitive(), pattern.isCamelCase())) return false;
	} else {
		char[] enclosingTypeName = CharOperation.concatWith(pattern.enclosingTypeNames, '.');
		char[] patternString = pattern.pkg == null
			? enclosingTypeName
			: CharOperation.concat(pattern.pkg, enclosingTypeName, '.');
		if (!checkTypeName(pattern.simpleName, patternString, fullyQualifiedTypeName, pattern.isCaseSensitive(), pattern.isCamelCase())) return false;
	}

	int kind  = TypeDeclaration.kind(type.getModifiers());
	switch (pattern.typeSuffix) {
		case CLASS_SUFFIX:
			return kind == TypeDeclaration.CLASS_DECL;
		case INTERFACE_SUFFIX:
			return kind == TypeDeclaration.INTERFACE_DECL;
		case ENUM_SUFFIX:
			return kind == TypeDeclaration.ENUM_DECL;
		case ANNOTATION_TYPE_SUFFIX:
			return kind == TypeDeclaration.ANNOTATION_TYPE_DECL;
		case CLASS_AND_INTERFACE_SUFFIX:
			return kind == TypeDeclaration.CLASS_DECL || kind == TypeDeclaration.INTERFACE_DECL;
		case CLASS_AND_ENUM_SUFFIX:
			return kind == TypeDeclaration.CLASS_DECL || kind == TypeDeclaration.ENUM_DECL;
		case INTERFACE_AND_ANNOTATION_SUFFIX:
			return kind == TypeDeclaration.INTERFACE_DECL || kind == TypeDeclaration.ANNOTATION_TYPE_DECL;
		case TYPE_SUFFIX: // nothing
	}
	return true;
}
 
Example 12
Source File: SourceType.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * @see IType
 */
public boolean isClass() throws JavaModelException {
	SourceTypeElementInfo info = (SourceTypeElementInfo) getElementInfo();
	return TypeDeclaration.kind(info.getModifiers()) == TypeDeclaration.CLASS_DECL;
}
 
Example 13
Source File: SourceType.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * @see IType#isEnum()
 * @since 3.0
 */
public boolean isEnum() throws JavaModelException {
	SourceTypeElementInfo info = (SourceTypeElementInfo) getElementInfo();
	return TypeDeclaration.kind(info.getModifiers()) == TypeDeclaration.ENUM_DECL;
}
 
Example 14
Source File: ClassScope.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private void buildMemberTypes(AccessRestriction accessRestriction) {
    SourceTypeBinding sourceType = this.referenceContext.binding;
	ReferenceBinding[] memberTypeBindings = Binding.NO_MEMBER_TYPES;
	if (this.referenceContext.memberTypes != null) {
		int length = this.referenceContext.memberTypes.length;
		memberTypeBindings = new ReferenceBinding[length];
		int count = 0;
		nextMember : for (int i = 0; i < length; i++) {
			TypeDeclaration memberContext = this.referenceContext.memberTypes[i];
			switch(TypeDeclaration.kind(memberContext.modifiers)) {
				case TypeDeclaration.INTERFACE_DECL :
				case TypeDeclaration.ANNOTATION_TYPE_DECL :
					if (sourceType.isNestedType()
							&& sourceType.isClass() // no need to check for enum, since implicitly static
							&& !sourceType.isStatic()) {
						problemReporter().illegalLocalTypeDeclaration(memberContext);
						continue nextMember;
					}
				break;
			}
			ReferenceBinding type = sourceType;
			// check that the member does not conflict with an enclosing type
			do {
				if (CharOperation.equals(type.sourceName, memberContext.name)) {
					problemReporter().typeCollidesWithEnclosingType(memberContext);
					continue nextMember;
				}
				type = type.enclosingType();
			} while (type != null);
			// check that the member type does not conflict with another sibling member type
			for (int j = 0; j < i; j++) {
				if (CharOperation.equals(this.referenceContext.memberTypes[j].name, memberContext.name)) {
					problemReporter().duplicateNestedType(memberContext);
					continue nextMember;
				}
			}

			ClassScope memberScope = new ClassScope(this, memberContext);
			memberTypeBindings[count++] = memberScope.buildType(sourceType, sourceType.fPackage, accessRestriction);
		}
		if (count != length)
			System.arraycopy(memberTypeBindings, 0, memberTypeBindings = new ReferenceBinding[count], 0, count);
	}
	sourceType.setMemberTypes(memberTypeBindings);
}
 
Example 15
Source File: BinaryType.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public boolean isClass() throws JavaModelException {
	IBinaryType info = (IBinaryType) getElementInfo();
	return TypeDeclaration.kind(info.getModifiers()) == TypeDeclaration.CLASS_DECL;

}
 
Example 16
Source File: BinaryType.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * @see IType#isEnum()
 * @since 3.0
 */
public boolean isEnum() throws JavaModelException {
	IBinaryType info = (IBinaryType) getElementInfo();
	return TypeDeclaration.kind(info.getModifiers()) == TypeDeclaration.ENUM_DECL;
}
 
Example 17
Source File: HierarchyBuilder.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Connect the supplied type to its superclass & superinterfaces.
 * The superclass & superinterfaces are the identical binary or source types as
 * supplied by the name environment.
 */
public void connect(
	IGenericType type,
	IType typeHandle,
	IType superclassHandle,
	IType[] superinterfaceHandles) {

	/*
	 * Temporary workaround for 1G2O5WK: ITPJCORE:WINNT - NullPointerException when selecting "Show in Type Hierarchy" for a inner class
	 */
	if (typeHandle == null)
		return;
	if (TypeHierarchy.DEBUG) {
		System.out.println(
			"Connecting: " + ((JavaElement) typeHandle).toStringWithAncestors()); //$NON-NLS-1$
		System.out.println(
			"  to superclass: " //$NON-NLS-1$
				+ (superclassHandle == null
					? "<None>" //$NON-NLS-1$
					: ((JavaElement) superclassHandle).toStringWithAncestors()));
		System.out.print("  and superinterfaces:"); //$NON-NLS-1$
		if (superinterfaceHandles == null || superinterfaceHandles.length == 0) {
			System.out.println(" <None>"); //$NON-NLS-1$
		} else {
			System.out.println();
			for (int i = 0, length = superinterfaceHandles.length; i < length; i++) {
				if (superinterfaceHandles[i] == null) continue;
				System.out.println(
					"    " + ((JavaElement) superinterfaceHandles[i]).toStringWithAncestors()); //$NON-NLS-1$
			}
		}
	}
	// now do the caching
	switch (TypeDeclaration.kind(type.getModifiers())) {
		case TypeDeclaration.CLASS_DECL :
		case TypeDeclaration.ENUM_DECL :
			if (superclassHandle == null) {
				this.hierarchy.addRootClass(typeHandle);
			} else {
				this.hierarchy.cacheSuperclass(typeHandle, superclassHandle);
			}
			break;
		case TypeDeclaration.INTERFACE_DECL :
		case TypeDeclaration.ANNOTATION_TYPE_DECL :
			// https://bugs.eclipse.org/bugs/show_bug.cgi?id=329663
			if (this.hierarchy.typeToSuperInterfaces.get(typeHandle) == null)
				this.hierarchy.addInterface(typeHandle);
			break;
	}
	if (superinterfaceHandles == null) {
		superinterfaceHandles = TypeHierarchy.NO_TYPE;
	}
	this.hierarchy.cacheSuperInterfaces(typeHandle, superinterfaceHandles);

	// record flags
	this.hierarchy.cacheFlags(typeHandle, type.getModifiers());
}
 
Example 18
Source File: BinaryType.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * @see IType#isAnnotation()
 * @since 3.0
 */
public boolean isAnnotation() throws JavaModelException {
	IBinaryType info = (IBinaryType) getElementInfo();
	return TypeDeclaration.kind(info.getModifiers()) == TypeDeclaration.ANNOTATION_TYPE_DECL;
}
 
Example 19
Source File: ClassScope.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private LocalTypeBinding buildLocalType(SourceTypeBinding enclosingType, PackageBinding packageBinding) {

		this.referenceContext.scope = this;
		this.referenceContext.staticInitializerScope = new MethodScope(this, this.referenceContext, true);
		this.referenceContext.initializerScope = new MethodScope(this, this.referenceContext, false);

		// build the binding or the local type
		LocalTypeBinding localType = new LocalTypeBinding(this, enclosingType, innermostSwitchCase());
		this.referenceContext.binding = localType;
		checkAndSetModifiers();
		buildTypeVariables();

		// Look at member types
		ReferenceBinding[] memberTypeBindings = Binding.NO_MEMBER_TYPES;
		if (this.referenceContext.memberTypes != null) {
			int size = this.referenceContext.memberTypes.length;
			memberTypeBindings = new ReferenceBinding[size];
			int count = 0;
			nextMember : for (int i = 0; i < size; i++) {
				TypeDeclaration memberContext = this.referenceContext.memberTypes[i];
				switch(TypeDeclaration.kind(memberContext.modifiers)) {
					case TypeDeclaration.INTERFACE_DECL :
					case TypeDeclaration.ANNOTATION_TYPE_DECL :
						problemReporter().illegalLocalTypeDeclaration(memberContext);
						continue nextMember;
				}
				ReferenceBinding type = localType;
				// check that the member does not conflict with an enclosing type
				do {
					if (CharOperation.equals(type.sourceName, memberContext.name)) {
						problemReporter().typeCollidesWithEnclosingType(memberContext);
						continue nextMember;
					}
					type = type.enclosingType();
				} while (type != null);
				// check the member type does not conflict with another sibling member type
				for (int j = 0; j < i; j++) {
					if (CharOperation.equals(this.referenceContext.memberTypes[j].name, memberContext.name)) {
						problemReporter().duplicateNestedType(memberContext);
						continue nextMember;
					}
				}
				ClassScope memberScope = new ClassScope(this, this.referenceContext.memberTypes[i]);
				LocalTypeBinding memberBinding = memberScope.buildLocalType(localType, packageBinding);
				memberBinding.setAsMemberType();
				memberTypeBindings[count++] = memberBinding;
			}
			if (count != size)
				System.arraycopy(memberTypeBindings, 0, memberTypeBindings = new ReferenceBinding[count], 0, count);
		}
		localType.setMemberTypes(memberTypeBindings);
		return localType;
	}
 
Example 20
Source File: RecoveredMethod.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public RecoveredElement add(TypeDeclaration typeDeclaration, int bracketBalanceValue) {

	/* do not consider a type starting passed the type end (if set)
		it must be belonging to an enclosing type */
	if (this.methodDeclaration.declarationSourceEnd != 0
		&& typeDeclaration.declarationSourceStart > this.methodDeclaration.declarationSourceEnd){

		if (this.parent == null) {
			return this; // ignore
		}
		return this.parent.add(typeDeclaration, bracketBalanceValue);
	}
	if ((typeDeclaration.bits & ASTNode.IsLocalType) != 0 || parser().methodRecoveryActivated || parser().statementRecoveryActivated){
		if (this.methodBody == null){
			Block block = new Block(0);
			block.sourceStart = this.methodDeclaration.bodyStart;
			this.add(block, 1);
		}
		this.methodBody.attachPendingModifiers(
				this.pendingAnnotations,
				this.pendingAnnotationCount,
				this.pendingModifiers,
				this.pendingModifersSourceStart);
		resetPendingModifiers();
		return this.methodBody.add(typeDeclaration, bracketBalanceValue, true);
	}
	switch (TypeDeclaration.kind(typeDeclaration.modifiers)) {
		case TypeDeclaration.INTERFACE_DECL :
		case TypeDeclaration.ANNOTATION_TYPE_DECL :
			resetPendingModifiers();
			this.updateSourceEndIfNecessary(previousAvailableLineEnd(typeDeclaration.declarationSourceStart - 1));
			if (this.parent == null) {
				return this; // ignore
			}
			// close the constructor
			return this.parent.add(typeDeclaration, bracketBalanceValue);
	}
	if (this.localTypes == null) {
		this.localTypes = new RecoveredType[5];
		this.localTypeCount = 0;
	} else {
		if (this.localTypeCount == this.localTypes.length) {
			System.arraycopy(
				this.localTypes,
				0,
				(this.localTypes = new RecoveredType[2 * this.localTypeCount]),
				0,
				this.localTypeCount);
		}
	}
	RecoveredType element = new RecoveredType(typeDeclaration, this, bracketBalanceValue);
	this.localTypes[this.localTypeCount++] = element;

	if(this.pendingAnnotationCount > 0) {
		element.attach(
				this.pendingAnnotations,
				this.pendingAnnotationCount,
				this.pendingModifiers,
				this.pendingModifersSourceStart);
	}
	resetPendingModifiers();

	/* consider that if the opening brace was not found, it is there */
	if (!this.foundOpeningBrace){
		this.foundOpeningBrace = true;
		this.bracketBalance++;
	}
	return element;
}