<s> package org . eclipse . jdt . internal . eval ; import org . eclipse . jdt . core . compiler . CategorizedProblem ; import org . eclipse . jdt . internal . compiler . ClassFile ; import org . eclipse . jdt . internal . compiler . CompilationResult ; import org . eclipse . jdt . internal . compiler . ast . AbstractMethodDeclaration ; import org . eclipse . jdt . internal . compiler . ast . TypeDeclaration ; import org . eclipse . jdt . internal . compiler . classfmt . ClassFileConstants ; import org . eclipse . jdt . internal . compiler . codegen . CodeStream ; import org . eclipse . jdt . internal . compiler . codegen . ConstantPool ; import org . eclipse . jdt . internal . compiler . codegen . StackMapFrameCodeStream ; import org . eclipse . jdt . internal . compiler . lookup . Binding ; import org . eclipse . jdt . internal . compiler . lookup . FieldBinding ; import org . eclipse . jdt . internal . compiler . lookup . MethodBinding ; import org . eclipse . jdt . internal . compiler . lookup . ReferenceBinding ; import org . eclipse . jdt . internal . compiler . lookup . SourceTypeBinding ; import org . eclipse . jdt . internal . compiler . lookup . TagBits ; import org . eclipse . jdt . internal . compiler . lookup . TypeVariableBinding ; import org . eclipse . jdt . internal . compiler . util . Util ; public class CodeSnippetClassFile extends ClassFile { public CodeSnippetClassFile ( org . eclipse . jdt . internal . compiler . lookup . SourceTypeBinding aType , org . eclipse . jdt . internal . compiler . ClassFile enclosingClassFile , boolean creatingProblemType ) { this . referenceBinding = aType ; initByteArrays ( ) ; this . header [ this . headerOffset ++ ] = ( byte ) ( 0xCAFEBABEL >> 24 ) ; this . header [ this . headerOffset ++ ] = ( byte ) ( 0xCAFEBABEL >> 16 ) ; this . header [ this . headerOffset ++ ] = ( byte ) ( 0xCAFEBABEL >> 8 ) ; this . header [ this . headerOffset ++ ] = ( byte ) ( 0xCAFEBABEL >> 0 ) ; long targetVersion = this . targetJDK = this . referenceBinding . scope . compilerOptions ( ) . targetJDK ; this . header [ this . headerOffset ++ ] = ( byte ) ( targetVersion >> 8 ) ; this . header [ this . headerOffset ++ ] = ( byte ) ( targetVersion >> 0 ) ; this . header [ this . headerOffset ++ ] = ( byte ) ( targetVersion >> 24 ) ; this . header [ this . headerOffset ++ ] = ( byte ) ( targetVersion >> 16 ) ; this . constantPoolOffset = this . headerOffset ; this . headerOffset += 2 ; this . constantPool = new ConstantPool ( this ) ; int accessFlags = aType . getAccessFlags ( ) ; if ( ! aType . isInterface ( ) ) { accessFlags |= ClassFileConstants . AccSuper ; } if ( aType . isNestedType ( ) ) { if ( aType . isStatic ( ) ) { accessFlags &= ~ ClassFileConstants . AccStatic ; } if ( aType . isPrivate ( ) ) { accessFlags &= ~ ( ClassFileConstants . AccPrivate | ClassFileConstants . AccPublic ) ; } if ( aType . isProtected ( ) ) { accessFlags &= ~ ClassFileConstants . AccProtected ; accessFlags |= ClassFileConstants . AccPublic ; } } accessFlags &= ~ ClassFileConstants . AccStrictfp ; this . enclosingClassFile = enclosingClassFile ; this . contents [ this . contentsOffset ++ ] = ( byte ) ( accessFlags >> 8 ) ; this . contents [ this . contentsOffset ++ ] = ( byte ) accessFlags ; int classNameIndex = this . constantPool . literalIndexForType ( aType ) ; this . contents [ this . contentsOffset ++ ] = ( byte ) ( classNameIndex >> 8 ) ; this . contents [ this . contentsOffset ++ ] = ( byte ) classNameIndex ; int superclassNameIndex ; if ( aType . isInterface ( ) ) { superclassNameIndex = this . constantPool . literalIndexForType ( ConstantPool . JavaLangObjectConstantPoolName ) ; } else { superclassNameIndex = ( aType . superclass == null ? 0 : this . constantPool . literalIndexForType ( aType . superclass ) ) ; } this . contents [ this . contentsOffset ++ ] = ( byte ) ( superclassNameIndex >> 8 ) ; this . contents [ this . contentsOffset ++ ] = ( byte ) superclassNameIndex ; ReferenceBinding [ ] superInterfacesBinding = aType . superInterfaces ( ) ; int interfacesCount = superInterfacesBinding . length ; this . contents [ this . contentsOffset ++ ] = ( byte ) ( interfacesCount >> 8 ) ; this . contents [ this . contentsOffset ++ ] = ( byte ) interfacesCount ; for ( int i = 0 ; i < interfacesCount ; i ++ ) { int interfaceIndex = this . constantPool . literalIndexForType ( superInterfacesBinding [ i ] ) ; this . contents [ this . contentsOffset ++ ] = ( byte ) ( interfaceIndex >> 8 ) ; this . contents [ this . contentsOffset ++ ] = ( byte ) interfaceIndex ; } this . produceAttributes = this . referenceBinding . scope . compilerOptions ( ) . produceDebugAttributes ; this . creatingProblemType = creatingProblemType ; if ( this . targetJDK >= ClassFileConstants . JDK1_6 ) { this . codeStream = new StackMapFrameCodeStream ( this ) ; this . produceAttributes |= ClassFileConstants . ATTR_STACK_MAP_TABLE ; } else if ( this . targetJDK == ClassFileConstants . CLDC_1_1 ) { this . targetJDK = ClassFileConstants . JDK1_1 ; this . produceAttributes |= ClassFileConstants . ATTR_STACK_MAP ; this . codeStream = new StackMapFrameCodeStream ( this ) ; } else { this . codeStream = new CodeStream ( this ) ; } this . codeStream . maxFieldCount = aType . scope . outerMostClassScope ( ) . referenceType ( ) . maxFieldCount ; } public static void createProblemType ( TypeDeclaration typeDeclaration , CompilationResult unitResult ) { SourceTypeBinding typeBinding = typeDeclaration . binding ; ClassFile classFile = new CodeSnippetClassFile ( typeBinding , null , true ) ; if ( typeBinding . hasMemberTypes ( ) ) { ReferenceBinding [ ] members = typeBinding . memberTypes ; for ( int i = 0 , l = members . length ; i < l ; i ++ ) classFile . recordInnerClasses ( members [ i ] ) ; } 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 ) ; } } FieldBinding [ ] fields = typeBinding . fields ( ) ; if ( ( fields != null ) && ( fields != Binding . NO_FIELDS ) ) { classFile . addFieldInfos ( ) ; } else { classFile . contents [ classFile . contentsOffset ++ ] = 0 ; classFile . contents [ classFile . contentsOffset ++ ] = 0 ; } classFile . setForMethodInfos ( ) ; 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 ( ) ) { 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 ) ; } } } classFile . addDefaultAbstractMethods ( ) ; } 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 ) ; } } </s>