Skip to content

Commit

Permalink
Remove AbstractUnnamedTypeDeclaration
Browse files Browse the repository at this point in the history
- rework hierarchy so ImplicitTypeDeclaration depends directly on AbstractTypeDeclaration
  - use subclass of `SimpleName` "EmptyName" as the `typeName` for
    `ImplicitTypeDeclaration`,
    since `SimpleName` cannot have the empty string as the type name
- delete AbstractUnnamedTypeDeclaration
- revert AbstractTypeDeclaration to pre-ImplicitTypeDeclaration
  - reincorporate Jörg's fix in AbstractTypeDeclaration that makes `typeName` volatile

Signed-off-by: David Thompson <davthomp@redhat.com>
  • Loading branch information
datho7561 authored and iloveeclipse committed May 24, 2024
1 parent c0d823f commit 70560b9
Show file tree
Hide file tree
Showing 6 changed files with 185 additions and 126 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
*******************************************************************************/
package org.eclipse.jdt.core.dom;

import java.util.List;

/**
* Abstract subclass for type declaration, enum declaration,
* and annotation type declaration AST node types.
Expand All @@ -26,7 +28,7 @@
* @since 3.0
*/
@SuppressWarnings("rawtypes")
public abstract class AbstractTypeDeclaration extends AbstractUnnamedTypeDeclaration {
public abstract class AbstractTypeDeclaration extends BodyDeclaration {

/**
* The type name; lazily initialized; defaults to a unspecified,
Expand All @@ -35,6 +37,32 @@ public abstract class AbstractTypeDeclaration extends AbstractUnnamedTypeDeclara
*/
volatile SimpleName typeName;

/**
* The body declarations (element type: {@link BodyDeclaration}).
* Defaults to an empty list.
* @since 2.0 (originally declared on {@link TypeDeclaration})
*/
ASTNode.NodeList bodyDeclarations;

/**
* Returns structural property descriptor for the "bodyDeclarations" property
* of this node (element type: {@link BodyDeclaration}).
*
* @return the property descriptor
*/
abstract ChildListPropertyDescriptor internalBodyDeclarationsProperty();

/**
* Returns structural property descriptor for the "bodyDeclarations" property
* of this node (element type: {@link BodyDeclaration}).
*
* @return the property descriptor
* @since 3.1
*/
public final ChildListPropertyDescriptor getBodyDeclarationsProperty() {
return internalBodyDeclarationsProperty();
}

/**
* Returns structural property descriptor for the "name" property
* of this node (child type: {@link SimpleName}).
Expand All @@ -54,6 +82,16 @@ public final ChildPropertyDescriptor getNameProperty() {
return internalNameProperty();
}

/**
* Creates and returns a structural property descriptor for the
* "bodyDeclaration" property declared on the given concrete node type (element type: {@link BodyDeclaration}).
*
* @return the property descriptor
*/
static final ChildListPropertyDescriptor internalBodyDeclarationPropertyFactory(Class nodeClass) {
return new ChildListPropertyDescriptor(nodeClass, "bodyDeclarations", BodyDeclaration.class, CYCLE_RISK); //$NON-NLS-1$
}

/**
* Creates and returns a structural property descriptor for the
* "name" property declared on the given concrete node type (child type: {@link SimpleName}).
Expand All @@ -77,6 +115,7 @@ static final ChildPropertyDescriptor internalNamePropertyFactory(Class nodeClass
*/
AbstractTypeDeclaration(AST ast) {
super(ast);
this.bodyDeclarations = new ASTNode.NodeList(internalBodyDeclarationsProperty());
}

/**
Expand Down Expand Up @@ -122,6 +161,70 @@ public void setName(SimpleName typeName) {
postReplaceChild(oldChild, typeName, p);
}

/**
* Returns the live ordered list of body declarations of this type
* declaration.
*
* @return the live list of body declarations
* (element type: {@link BodyDeclaration})
* @since 2.0 (originally declared on {@link TypeDeclaration})
*/
public List bodyDeclarations() {
return this.bodyDeclarations;
}

/**
* Returns whether this type declaration is a package member (that is,
* a top-level type).
* <p>
* Note that this is a convenience method that simply checks whether
* this node's parent is a compilation unit node.
* </p>
*
* @return <code>true</code> if this type declaration is a child of
* a compilation unit node, and <code>false</code> otherwise
* @since 2.0 (originally declared on {@link TypeDeclaration})
*/
public boolean isPackageMemberTypeDeclaration() {
ASTNode parent = getParent();
return (parent instanceof CompilationUnit);
}

/**
* Returns whether this type declaration is a type member.
* <p>
* Note that this is a convenience method that simply checks whether
* this node's parent is a type declaration node or an anonymous
* class declaration.
* </p>
*
* @return <code>true</code> if this type declaration is a child of
* a type declaration node or an anonymous class declaration node,
* and <code>false</code> otherwise
* @since 2.0 (originally declared on {@link TypeDeclaration})
*/
public boolean isMemberTypeDeclaration() {
ASTNode parent = getParent();
return (parent instanceof AbstractTypeDeclaration)
|| (parent instanceof AnonymousClassDeclaration);
}

/**
* Returns whether this type declaration is a local type.
* <p>
* Note that this is a convenience method that simply checks whether
* this node's parent is a type declaration statement node.
* </p>
*
* @return <code>true</code> if this type declaration is a child of
* a type declaration statement node, and <code>false</code> otherwise
* @since 2.0 (originally declared on <code>TypeDeclaration</code>)
*/
public boolean isLocalTypeDeclaration() {
ASTNode parent = getParent();
return (parent instanceof TypeDeclarationStatement);
}

/**
* Resolves and returns the binding for the type declared in this type
* declaration.
Expand Down Expand Up @@ -149,7 +252,7 @@ public final ITypeBinding resolveBinding() {

@Override
int memSize() {
return super.memSize() + 4;
return super.memSize() + 2 * 4;
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,10 @@ ITypeBinding resolveType(TypeDeclaration type) {
return null;
}

ITypeBinding resolveType(ImplicitTypeDeclaration type) {
return null;
}

/**
* Resolves the given type parameter and returns the type binding for the
* type parameter.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,12 @@ public class CompilationUnit extends ASTNode {
private static final List PROPERTY_DESCRIPTORS_9_0;

/**
* The "types" structural property of this node type (element type: {@link AbstractUnnamedTypeDeclaration}).
* The "types" structural property of this node type (element type: {@link AbstractTypeDeclaration}).
*
* @since 3.0
*/
public static final ChildListPropertyDescriptor TYPES_PROPERTY =
new ChildListPropertyDescriptor(CompilationUnit.class, "types", AbstractUnnamedTypeDeclaration.class, CYCLE_RISK); //$NON-NLS-1$
new ChildListPropertyDescriptor(CompilationUnit.class, "types", AbstractTypeDeclaration.class, CYCLE_RISK); //$NON-NLS-1$

static {
List properyList = new ArrayList(4);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1879,6 +1879,24 @@ synchronized ITypeBinding resolveType(TypeDeclaration type) {
return null;
}

@Override
synchronized ITypeBinding resolveType(ImplicitTypeDeclaration type) {
final Object node = this.newAstToOldAst.get(type);
if (node instanceof org.eclipse.jdt.internal.compiler.ast.ImplicitTypeDeclaration implicitTypeDeclaration) {
ITypeBinding typeBinding = internalGetTypeBinding(implicitTypeDeclaration.binding, null);
if (typeBinding == null) {
return null;
}
this.bindingsToAstNodes.put(typeBinding, type);
String key = typeBinding.getKey();
if (key != null) {
this.bindingTables.bindingKeysToBindings.put(key, typeBinding);
}
return typeBinding;
}
return null;
}

@Override
synchronized ITypeBinding resolveTypeParameter(TypeParameter typeParameter) {
final Object node = this.newAstToOldAst.get(typeParameter);
Expand Down
Loading

0 comments on commit 70560b9

Please sign in to comment.