<s> package org . eclipse . jdt . internal . core ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jdt . core . IJavaElement ; import org . eclipse . jdt . core . IJavaModelStatus ; import org . eclipse . jdt . core . IJavaModelStatusConstants ; import org . eclipse . jdt . core . IType ; import org . eclipse . jdt . core . JavaModelException ; import org . eclipse . jdt . core . dom . ASTNode ; import org . eclipse . jdt . core . dom . AbstractTypeDeclaration ; import org . eclipse . jdt . core . dom . SimpleName ; import org . eclipse . jdt . core . dom . rewrite . ASTRewrite ; import org . eclipse . jdt . internal . core . util . Messages ; public class CreateTypeOperation extends CreateTypeMemberOperation { public CreateTypeOperation ( IJavaElement parentElement , String source , boolean force ) { super ( parentElement , source , force ) ; } protected ASTNode generateElementAST ( ASTRewrite rewriter , ICompilationUnit cu ) throws JavaModelException { ASTNode node = super . generateElementAST ( rewriter , cu ) ; if ( ! ( node instanceof AbstractTypeDeclaration ) ) throw new JavaModelException ( new JavaModelStatus ( IJavaModelStatusConstants . INVALID_CONTENTS ) ) ; return node ; } protected IJavaElement generateResultHandle ( ) { IJavaElement parent = getParentElement ( ) ; switch ( parent . getElementType ( ) ) { case IJavaElement . COMPILATION_UNIT : return ( ( ICompilationUnit ) parent ) . getType ( getASTNodeName ( ) ) ; case IJavaElement . TYPE : return ( ( IType ) parent ) . getType ( getASTNodeName ( ) ) ; } return null ; } public String getMainTaskName ( ) { return Messages . operation_createTypeProgress ; } protected IType getType ( ) { IJavaElement parent = getParentElement ( ) ; if ( parent . getElementType ( ) == IJavaElement . TYPE ) { return ( IType ) parent ; } return null ; } protected IJavaModelStatus verifyNameCollision ( ) { IJavaElement parent = getParentElement ( ) ; switch ( parent . getElementType ( ) ) { case IJavaElement . COMPILATION_UNIT : String typeName = getASTNodeName ( ) ; if ( ( ( ICompilationUnit ) parent ) . getType ( typeName ) . exists ( ) ) { return new JavaModelStatus ( IJavaModelStatusConstants . NAME_COLLISION , Messages . bind ( Messages . status_nameCollision , typeName ) ) ; } break ; case IJavaElement . TYPE : typeName = getASTNodeName ( ) ; if ( ( ( IType ) parent ) . getType ( typeName ) . exists ( ) ) { return new JavaModelStatus ( IJavaModelStatusConstants . NAME_COLLISION , Messages . bind ( Messages . status_nameCollision , typeName ) ) ; } break ; } return JavaModelStatus . VERIFIED_OK ; } public IJavaModelStatus verify ( ) { IJavaModelStatus status = super . verify ( ) ; if ( ! status . isOK ( ) ) return status ; try { IJavaElement parent = getParentElement ( ) ; if ( this . anchorElement != null && this . anchorElement . getElementType ( ) == IJavaElement . FIELD && parent . getElementType ( ) == IJavaElement . TYPE && ( ( IType ) parent ) . isEnum ( ) ) return new JavaModelStatus ( IJavaModelStatusConstants . INVALID_SIBLING , this . anchorElement ) ; } catch ( JavaModelException e ) { return e . getJavaModelStatus ( ) ; } return JavaModelStatus . VERIFIED_OK ; } private String getASTNodeName ( ) { return ( ( AbstractTypeDeclaration ) this . createdNode ) . getName ( ) . getIdentifier ( ) ; } protected SimpleName rename ( ASTNode node , SimpleName newName ) { AbstractTypeDeclaration type = ( AbstractTypeDeclaration ) node ; SimpleName oldName = type . getName ( ) ; type . setName ( newName ) ; return oldName ; } } </s>