Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2000, 2012 IBM Corporation and others. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html Contributors: IBM Corporation - initial API and implementation /
 
 
 package org.eclipse.jdt.core.dom;
 
 import java.util.List;

Type declaration AST node type. A type declaration is the union of a class declaration and an interface declaration. For JLS2:
 TypeDeclaration:
   ClassDeclaration
   InterfaceDeclaration
 ClassDeclaration:
      [ Javadoc ] { Modifier } class Identifier
   [ extends Type]
   [ implements Type { , Type } ]
   { { ClassBodyDeclaration | ; } }
 InterfaceDeclaration:
      [ Javadoc ] { Modifier } interface Identifier
   [ extends Type { , Type } ]
    { { InterfaceBodyDeclaration | ; } }
 
For JLS3, type parameters and reified modifiers (and annotations) were added, and the superclass type name and superinterface types names are generalized to type so that parameterized types can be referenced:
 TypeDeclaration:
   ClassDeclaration
   InterfaceDeclaration
 ClassDeclaration:
      [ Javadoc ] { ExtendedModifier } class Identifier
   [ < TypeParameter { , TypeParameter } > ]
   [ extends Type ]
   [ implements Type { , Type } ]
   { { ClassBodyDeclaration | ; } }
 InterfaceDeclaration:
      [ Javadoc ] { ExtendedModifier } interface Identifier
   [ < TypeParameter { , TypeParameter } > ]
   [ extends Type { , Type } ]
    { { InterfaceBodyDeclaration | ; } }
 

When a Javadoc comment is present, the source range begins with the first character of the "/**" comment delimiter. When there is no Javadoc comment, the source range begins with the first character of the first modifier or annotation (if any), or the first character of the "class" or "interface" keyword (if no modifiers or annotations). The source range extends through the last character of the "}" token following the body declarations.

Since:
2.0
Noinstantiate:
This class is not intended to be instantiated by clients.
 
 public class TypeDeclaration extends AbstractTypeDeclaration {

The "javadoc" structural property of this node type (child type: Javadoc).

Since:
3.0
 
 	public static final ChildPropertyDescriptor JAVADOC_PROPERTY =
The "modifiers" structural property of this node type (type: java.lang.Integer) (JLS2 API only).

Since:
3.0
 
 	public static final SimplePropertyDescriptor MODIFIERS_PROPERTY =
The "modifiers" structural property of this node type (element type: IExtendedModifier) (added in JLS3 API).

Since:
3.1
 
The "interface" structural property of this node type (type: java.lang.Boolean).

Since:
3.0
 
 	public static final SimplePropertyDescriptor INTERFACE_PROPERTY =
 		new SimplePropertyDescriptor(TypeDeclaration.class"interface"boolean.class); //$NON-NLS-1$
 
The "name" structural property of this node type (child type: SimpleName).

Since:
3.0
	public static final ChildPropertyDescriptor NAME_PROPERTY =
The "superclass" structural property of this node type (child type: Name) (JLS2 API only).

Since:
3.0
		new ChildPropertyDescriptor(TypeDeclaration.class"superclass"Name.class); //$NON-NLS-1$
The "superInterfaces" structural property of this node type (element type: Name) (JLS2 API only).

Since:
3.0
		new ChildListPropertyDescriptor(TypeDeclaration.class"superInterfaces"Name.class); //$NON-NLS-1$
The "superclassType" structural property of this node type (child type: Type) (added in JLS3 API).

Since:
3.1
		new ChildPropertyDescriptor(TypeDeclaration.class"superclassType"Type.class); //$NON-NLS-1$
The "superInterfaceTypes" structural property of this node type (element type: Type) (added in JLS3 API).

Since:
3.1
		new ChildListPropertyDescriptor(TypeDeclaration.class"superInterfaceTypes"Type.class); //$NON-NLS-1$
The "typeParameters" structural property of this node type (element type: TypeParameter) (added in JLS3 API).

Since:
3.1
		new ChildListPropertyDescriptor(TypeDeclaration.class"typeParameters"TypeParameter.class); //$NON-NLS-1$
The "bodyDeclarations" structural property of this node type (element type: BodyDeclaration) (added in JLS3 API).

Since:
3.0
A list of property descriptors (element type: StructuralPropertyDescriptor), or null if uninitialized.

Since:
3.0
	private static final List PROPERTY_DESCRIPTORS_2_0;

A list of property descriptors (element type: StructuralPropertyDescriptor), or null if uninitialized.

Since:
3.1
	private static final List PROPERTY_DESCRIPTORS_3_0;
	static {
		List propertyList = new ArrayList(8);
		createPropertyList(TypeDeclaration.classpropertyList);
		addProperty(propertyList);
		propertyList = new ArrayList(9);
		createPropertyList(TypeDeclaration.classpropertyList);
		addProperty(propertyList);
	}

Returns a list of structural property descriptors for this node type. Clients must not modify the result.

Parameters:
apiLevel the API level; one of the AST.JLS* constants
Returns:
a list of property descriptors (element type: StructuralPropertyDescriptor)
Since:
3.0
	public static List propertyDescriptors(int apiLevel) {
		if (apiLevel == .) {
else {
		}
	}

true for an interface, false for a class. Defaults to class.
	private boolean isInterface = false;

The type parameters (element type: TypeParameter). Null in JLS2. Added in JLS3; defaults to an empty list (see constructor).

Since:
3.1
	private ASTNode.NodeList typeParameters = null;

The optional superclass name; null if none. Defaults to none. Note that this field is not used for interface declarations. Not used in 3.0.
	private Name optionalSuperclassName = null;

The superinterface names (element type: Name). JLS2 only; defaults to an empty list. Not used in JLS3. (see constructor).
The optional superclass type; null if none. Defaults to none. Note that this field is not used for interface declarations. Null in JLS2. Added in JLS3.

Since:
3.1
	private Type optionalSuperclassType = null;

The superinterface types (element type: Type). Null in JLS2. Added in JLS3; defaults to an empty list (see constructor).

Since:
3.1
Creates a new AST node for a type declaration owned by the given AST. By default, the type declaration is for a class of an unspecified, but legal, name; no modifiers; no javadoc; no type parameters; no superclass or superinterfaces; and an empty list of body declarations.

N.B. This constructor is package-private; all subclasses must be declared in the same package; clients are unable to declare additional subclasses.

Parameters:
ast the AST that is to own this node
		super(ast);
		if (ast.apiLevel == .) {
		}
		if (ast.apiLevel >= .) {
		}
	}
	/* (omit javadoc for this method)
	 * Method declared on ASTNode.
	 * @since 3.0
	 */
	final List internalStructuralPropertiesForType(int apiLevel) {
		return propertyDescriptors(apiLevel);
	}
	/* (omit javadoc for this method)
	 * Method declared on ASTNode.
	 */
	final int internalGetSetIntProperty(SimplePropertyDescriptor propertyboolean getint value) {
		if (property == ) {
			if (get) {
				return getModifiers();
else {
				return 0;
			}
		}
		// allow default implementation to flag the error
		return super.internalGetSetIntProperty(propertygetvalue);
	}
	/* (omit javadoc for this method)
	 * Method declared on ASTNode.
	 */
	final boolean internalGetSetBooleanProperty(SimplePropertyDescriptor propertyboolean getboolean value) {
		if (property == ) {
			if (get) {
				return isInterface();
else {
				return false;
			}
		}
		// allow default implementation to flag the error
		return super.internalGetSetBooleanProperty(propertygetvalue);
	}
	/* (omit javadoc for this method)
	 * Method declared on ASTNode.
	 */
	final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor propertyboolean getASTNode child) {
		if (property == ) {
			if (get) {
				return getJavadoc();
else {
				return null;
			}
		}
		if (property == ) {
			if (get) {
				return getName();
else {
				return null;
			}
		}
		if (property == ) {
			if (get) {
				return getSuperclass();
else {
				return null;
			}
		}
		if (property == ) {
			if (get) {
else {
				return null;
			}
		}
		// allow default implementation to flag the error
		return super.internalGetSetChildProperty(propertygetchild);
	}
	/* (omit javadoc for this method)
	 * Method declared on ASTNode.
	 */
		if (property == ) {
			return modifiers();
		}
		if (property == ) {
			return typeParameters();
		}
		if (property == ) {
			return superInterfaces();
		}
		if (property == ) {
		}
		if (property == ) {
		}
		// allow default implementation to flag the error
		return super.internalGetChildListProperty(property);
	}
	/* (omit javadoc for this method)
	 * Method declared on BodyDeclaration.
	 */
	}
	/* (omit javadoc for this method)
	 * Method declared on BodyDeclaration.
	 */
	}
	/* (omit javadoc for this method)
	 * Method declared on BodyDeclaration.
	 */
	}
	/* (omit javadoc for this method)
	 * Method declared on AbstractTypeDeclaration.
	 */
	}
	/* (omit javadoc for this method)
	 * Method declared on AbstractTypeDeclaration.
	 */
	}
	/* (omit javadoc for this method)
	 * Method declared on ASTNode.
	 */
	final int getNodeType0() {
	}
	/* (omit javadoc for this method)
	 * Method declared on ASTNode.
	 */
	ASTNode clone0(AST target) {
		TypeDeclaration result = new TypeDeclaration(target);
		result.setJavadoc(
			(Javadoc) ASTNode.copySubtree(targetgetJavadoc()));
		if (this.. == .) {
					(Name) ASTNode.copySubtree(targetgetSuperclass()));
					ASTNode.copySubtrees(targetsuperInterfaces()));
		}
		result.setName((SimpleNamegetName().clone(target));
		if (this.. >= .) {
			result.modifiers().addAll(ASTNode.copySubtrees(targetmodifiers()));
					ASTNode.copySubtrees(targettypeParameters()));
					(Type) ASTNode.copySubtree(targetgetSuperclassType()));
					ASTNode.copySubtrees(targetsuperInterfaceTypes()));
		}
			ASTNode.copySubtrees(targetbodyDeclarations()));
		return result;
	}
	/* (omit javadoc for this method)
	 * Method declared on ASTNode.
	 */
	final boolean subtreeMatch0(ASTMatcher matcherObject other) {
		// dispatch to correct overloaded match method
		return matcher.match(thisother);
	}
	/* (omit javadoc for this method)
	 * Method declared on ASTNode.
	 */
	void accept0(ASTVisitor visitor) {
		boolean visitChildren = visitor.visit(this);
		if (visitChildren) {
			// visit children in normal left to right reading order
			if (this.. == .) {
				acceptChild(visitorgetJavadoc());
				acceptChild(visitorgetName());
			}
			if (this.. >= .) {
				acceptChild(visitorgetJavadoc());
				acceptChildren(visitorthis.);
				acceptChild(visitorgetName());
			}
		}
		visitor.endVisit(this);
	}

Returns whether this type declaration declares a class or an interface.

Returns:
true if this is an interface declaration, and false if this is a class declaration
	public boolean isInterface() {
		return this.;
	}

Sets whether this type declaration declares a class or an interface.

Parameters:
isInterface true if this is an interface declaration, and false if this is a class declaration
	public void setInterface(boolean isInterface) {
		this. = isInterface;
	}

Returns the live ordered list of type parameters of this type declaration (added in JLS3 API). This list is non-empty for parameterized types.

Returns:
the live list of type parameters (element type: TypeParameter)
Throws:
java.lang.UnsupportedOperationException if this operation is used in a JLS2 AST
Since:
3.1
	public List typeParameters() {
		// more efficient than just calling unsupportedIn2() to check
		if (this. == null) {
		}
		return this.;
	}

Returns the name of the superclass declared in this type declaration, or null if there is none (JLS2 API only).

Note that this child is not relevant for interface declarations (although it does still figure in subtree equality comparisons).

Deprecated:
In the JLS3 API, this method is replaced by getSuperclassType(), which returns a Type instead of a Name.
Returns:
the superclass name node, or null if there is none
Throws:
java.lang.UnsupportedOperationException if this operation is used in an AST later than JLS2
	public Name getSuperclass() {
	}

Internal synonym for deprecated method. Used to avoid deprecation warnings.

Since:
3.1
	/*package*/ final Name internalGetSuperclass() {
	}

Returns the superclass declared in this type declaration, or null if there is none (added in JLS3 API).

Note that this child is not relevant for interface declarations (although it does still figure in subtree equality comparisons).

Returns:
the superclass type node, or null if there is none
Throws:
java.lang.UnsupportedOperationException if this operation is used in a JLS2 AST
Since:
3.1
	public Type getSuperclassType() {
	    unsupportedIn2();
	}

Sets or clears the name of the superclass declared in this type declaration (JLS2 API only).

Note that this child is not relevant for interface declarations (although it does still figure in subtree equality comparisons).

Deprecated:
In the JLS3 API, this method is replaced by setSuperclassType(org.eclipse.jdt.core.dom.Type), which expects a Type instead of a Name.
Parameters:
superclassName the superclass name node, or null if there is none
Throws:
java.lang.IllegalArgumentException if:
  • the node belongs to a different AST
  • the node already has a parent
java.lang.UnsupportedOperationException if this operation is used in an AST later than JLS2
	public void setSuperclass(Name superclassName) {
		internalSetSuperclass(superclassName);
	}

Internal synonym for deprecated method. Used to avoid deprecation warnings.

Since:
3.1
	/*package*/ final void internalSetSuperclass(Name superclassName) {
		ASTNode oldChild = this.;
		preReplaceChild(oldChildsuperclassName);
		this. = superclassName;
		postReplaceChild(oldChildsuperclassName);
	}

Sets or clears the superclass declared in this type declaration (added in JLS3 API).

Note that this child is not relevant for interface declarations (although it does still figure in subtree equality comparisons).

Parameters:
superclassType the superclass type node, or null if there is none
Throws:
java.lang.IllegalArgumentException if:
  • the node belongs to a different AST
  • the node already has a parent
java.lang.UnsupportedOperationException if this operation is used in a JLS2 AST
Since:
3.1
	public void setSuperclassType(Type superclassType) {
	    unsupportedIn2();
		ASTNode oldChild = this.;
		preReplaceChild(oldChildsuperclassType);
		this. = superclassType;
		postReplaceChild(oldChildsuperclassType);
 	}

Returns the live ordered list of names of superinterfaces of this type declaration (JLS2 API only). For a class declaration, these are the names of the interfaces that this class implements; for an interface declaration, these are the names of the interfaces that this interface extends.

Deprecated:
In the JLS3 API, this method is replaced by superInterfaceTypes().
Returns:
the live list of interface names (element type: Name)
Throws:
java.lang.UnsupportedOperationException if this operation is used in an AST later than JLS2
	public List superInterfaces() {
	}

Internal synonym for deprecated method. Used to avoid deprecation warnings.

Since:
3.1
	/*package*/ final List internalSuperInterfaces() {
		// more efficient than just calling supportedOnlyIn2() to check
		if (this. == null) {
		}
		return this.;
	}

Returns the live ordered list of superinterfaces of this type declaration (added in JLS3 API). For a class declaration, these are the interfaces that this class implements; for an interface declaration, these are the interfaces that this interface extends.

Returns:
the live list of interface types (element type: Type)
Throws:
java.lang.UnsupportedOperationException if this operation is used in a JLS2 AST
Since:
3.1
		// more efficient than just calling unsupportedIn2() to check
		if (this. == null) {
		}
		return this.;
	}

Returns the ordered list of field declarations of this type declaration. For a class declaration, these are the field declarations; for an interface declaration, these are the constant declarations.

This convenience method returns this node's body declarations with non-fields filtered out. Unlike bodyDeclarations, this method does not return a live result.

Returns:
the (possibly empty) list of field declarations
		int fieldCount = 0;
		for (Iterator it = bd.listIterator(); it.hasNext(); ) {
			if (it.next() instanceof FieldDeclaration) {
				fieldCount++;
			}
		}
		FieldDeclaration[] fields = new FieldDeclaration[fieldCount];
		int next = 0;
		for (Iterator it = bd.listIterator(); it.hasNext(); ) {
			Object decl = it.next();
			if (decl instanceof FieldDeclaration) {
				fields[next++] = (FieldDeclarationdecl;
			}
		}
		return fields;
	}

Returns the ordered list of method declarations of this type declaration.

This convenience method returns this node's body declarations with non-methods filtered out. Unlike bodyDeclarations, this method does not return a live result.

Returns:
the (possibly empty) list of method (and constructor) declarations
		int methodCount = 0;
		for (Iterator it = bd.listIterator(); it.hasNext(); ) {
			if (it.next() instanceof MethodDeclaration) {
				methodCount++;
			}
		}
		MethodDeclaration[] methods = new MethodDeclaration[methodCount];
		int next = 0;
		for (Iterator it = bd.listIterator(); it.hasNext(); ) {
			Object decl = it.next();
			if (decl instanceof MethodDeclaration) {
				methods[next++] = (MethodDeclarationdecl;
			}
		}
		return methods;
	}

Returns the ordered list of member type declarations of this type declaration.

This convenience method returns this node's body declarations with non-types filtered out. Unlike bodyDeclarations, this method does not return a live result.

Returns:
the (possibly empty) list of member type declarations
	public TypeDeclaration[] getTypes() {
		int typeCount = 0;
		for (Iterator it = bd.listIterator(); it.hasNext(); ) {
			if (it.next() instanceof TypeDeclaration) {
				typeCount++;
			}
		}
		TypeDeclaration[] memberTypes = new TypeDeclaration[typeCount];
		int next = 0;
		for (Iterator it = bd.listIterator(); it.hasNext(); ) {
			Object decl = it.next();
			if (decl instanceof TypeDeclaration) {
				memberTypes[next++] = (TypeDeclarationdecl;
			}
		}
		return memberTypes;
	}
	/* (omit javadoc for this method)
	 * Method declared on AsbtractTypeDeclaration.
	 */
		return this..getBindingResolver().resolveType(this);
	}
	/* (omit javadoc for this method)
	 * Method declared on ASTNode.
	 */
	int memSize() {
		return super.memSize() + 6 * 4;
	}
	/* (omit javadoc for this method)
	 * Method declared on ASTNode.
	 */
	int treeSize() {
		return memSize()
			+ (this. == null ? 0 : getJavadoc().treeSize())
			+ (this. == null ? 0 : this..listSize())
			+ (this. == null ? 0 : getName().treeSize())
			+ (this. == null ? 0 : this..listSize())
			+ (this. == null ? 0 : getSuperclass().treeSize())
			+ (this. == null ? 0 : getSuperclassType().treeSize())
			+ (this. == null ? 0 : this..listSize())
			+ (this. == null ? 0 : this..listSize())
	}
New to GrepCode? Check out our FAQ X