@ -34,8 +34,9 @@ import java.security.NoSuchAlgorithmException;
///#def COLLECTIONS java.util
///#def COLLECTIONS java.util
import java.util.Arrays ;
import java.util.Arrays ;
import java.util.Iterator ;
import java.util.Iterator ;
import java.util.LinkedList ;
import java.util.ListIterator ;
import java.util.ListIterator ;
import java.util.List ;
import java.util.ArrayList ;
///#enddef
///#enddef
///#def COLLECTIONEXTRA java.lang
///#def COLLECTIONEXTRA java.lang
import java.lang.Comparable ;
import java.lang.Comparable ;
@ -239,10 +240,10 @@ public final class ClassInfo extends BinaryInfo implements Comparable {
private ClassInfo outerClass ;
private ClassInfo outerClass ;
private ClassInfo [ ] interfaces ;
private ClassInfo [ ] interfaces ;
private ClassInfo [ ] innerClasses ;
private ClassInfo [ ] innerClasses ;
private ClassInfo [ ] extraClasses ;
private FieldInfo [ ] fields ;
private FieldInfo [ ] fields ;
private MethodInfo [ ] methods ;
private MethodInfo [ ] methods ;
private String sourceFile ;
private String sourceFile ;
private boolean hasInnerClassesAttr ;
/ * *
/ * *
* This constant can be used as parameter to drop . It specifies
* This constant can be used as parameter to drop . It specifies
@ -469,6 +470,8 @@ public final class ClassInfo extends BinaryInfo implements Comparable {
* < / pre >
* < / pre >
* doesn ' t work .
* doesn ' t work .
* /
* /
hasInnerClassesAttr = true ;
int count = input . readUnsignedShort ( ) ;
int count = input . readUnsignedShort ( ) ;
if ( length ! = 2 + 8 * count )
if ( length ! = 2 + 8 * count )
@ -559,12 +562,21 @@ public final class ClassInfo extends BinaryInfo implements Comparable {
} else
} else
innerClasses = null ;
innerClasses = null ;
if ( extraCount > 0 ) {
/ * All remaining classes that are mentioned in the constant
extraClasses = new ClassInfo [ extraCount ] ;
* pool must have an empty outer class info . This is
for ( int i = 0 ; i < extraCount ; i + + )
* specified in the 2nd edition of the JVM specification .
extraClasses [ i ] = innerExtra [ count - i - 1 ] ;
* /
} else
for ( int i = 1 ; i < cp . size ( ) ; i + + ) {
extraClasses = null ;
if ( cp . tags [ i ] = = cp . CLASS ) {
String clName = cp . getUTF8 ( cp . indices1 [ i ] ) ;
if ( clName . charAt ( 0 ) ! = '[' ) {
ClassInfo ci = classpath . getClassInfo
( clName . replace ( '/' , '.' ) ) ;
if ( ci . status < OUTERCLASS )
ci . mergeOuterInfo ( null , null , - 1 , false ) ;
}
}
}
}
}
void readAttribute ( String name , int length ,
void readAttribute ( String name , int length ,
@ -810,9 +822,9 @@ public final class ClassInfo extends BinaryInfo implements Comparable {
private void prepareWriting ( GrowableConstantPool gcp ) {
private void prepareWriting ( GrowableConstantPool gcp ) {
gcp . putClassName ( name ) ;
gcp . putClassName ( name ) ;
gcp . putClassName ( superclass . getName ( ) ) ;
gcp . putClassName ( superclass . name ) ;
for ( int i = 0 ; i < interfaces . length ; i + + )
for ( int i = 0 ; i < interfaces . length ; i + + )
gcp . putClassName ( interfaces [ i ] . getName ( ) ) ;
gcp . putClassName ( interfaces [ i ] . name ) ;
for ( int i = 0 ; i < fields . length ; i + + )
for ( int i = 0 ; i < fields . length ; i + + )
fields [ i ] . prepareWriting ( gcp ) ;
fields [ i ] . prepareWriting ( gcp ) ;
@ -820,52 +832,46 @@ public final class ClassInfo extends BinaryInfo implements Comparable {
for ( int i = 0 ; i < methods . length ; i + + )
for ( int i = 0 ; i < methods . length ; i + + )
methods [ i ] . prepareWriting ( gcp ) ;
methods [ i ] . prepareWriting ( gcp ) ;
for ( int i = 0 ; i < innerClasses . length ; i + + )
gcp . putClassName ( innerClasses [ i ] . name ) ;
if ( sourceFile ! = null ) {
if ( sourceFile ! = null ) {
gcp . putUTF8 ( "SourceFile" ) ;
gcp . putUTF8 ( "SourceFile" ) ;
gcp . putUTF8 ( sourceFile ) ;
gcp . putUTF8 ( sourceFile ) ;
}
}
if ( outerClass ! = null | | methodScoped
| | innerClasses ! = null | | extraClasses ! = null ) {
/ * All classes mentioned in the constant pool must have an
gcp . putUTF8 ( "InnerClasses" ) ;
* outer class info . This is clearly specified in the 2nd
* edition of the JVM specification .
ClassInfo outer = this ;
* /
while ( outer . outerClass ! = null | | outer . methodScoped ) {
hasInnerClassesAttr = false ;
if ( outer . status < = OUTERCLASS )
for ( int i = 1 ; i < gcp . size ( ) ; i + + ) {
throw new IllegalStateException
if ( gcp . tags [ i ] = = gcp . CLASS ) {
( outer . name + "'s state is " + outer . status ) ;
String clName ;
if ( outer . className ! = null )
try {
gcp . putClassName ( outer . className ) ;
clName = gcp . getUTF8 ( gcp . indices1 [ i ] ) ;
if ( outer . outerClass = = null )
} catch ( ClassFormatException ex ) {
break ;
throw new InternalError ( ex . getMessage ( ) ) ;
gcp . putClassName ( outer . outerClass . name ) ;
}
outer = outer . outerClass ;
if ( clName . charAt ( 0 ) ! = '[' ) {
}
ClassInfo ci = classpath . getClassInfo
int innerCount = innerClasses ! = null ? innerClasses . length : 0 ;
( clName . replace ( '/' , '.' ) ) ;
for ( int i = innerCount ; i - - > 0 ; i + + ) {
if ( ci . status < OUTERCLASS ) {
if ( innerClasses [ i ] . status < = OUTERCLASS )
GlobalOptions . err . println
throw new IllegalStateException
( "WARNING: " + ci . name
( innerClasses [ i ] . name + "'s state is "
+ "'s outer class isn't known." ) ;
+ innerClasses [ i ] . status ) ;
} else {
if ( innerClasses [ i ] . outerClass ! = this )
if ( ( ci . outerClass ! = null | | ci . methodScoped )
throw new IllegalStateException
& & ! hasInnerClassesAttr ) {
( innerClasses [ i ] . name + "'s outer is " +
gcp . putUTF8 ( "innerClasses" ) ;
innerClasses [ i ] . outerClass . name ) ;
hasInnerClassesAttr = true ;
}
gcp . putClassName ( innerClasses [ i ] . name ) ;
if ( ci . outerClass ! = null )
if ( innerClasses [ i ] . className ! = null )
gcp . putClassName ( ci . outerClass . name ) ;
gcp . putUTF8 ( innerClasses [ i ] . className ) ;
if ( ci . className ! = null )
}
gcp . putUTF8 ( ci . className ) ;
int extraCount = extraClasses ! = null ? extraClasses . length : 0 ;
}
for ( int i = extraCount ; i - - > = 0 ; ) {
}
if ( extraClasses [ i ] . status < = OUTERCLASS )
throw new IllegalStateException
( extraClasses [ i ] . name + "'s state is "
+ extraClasses [ i ] . status ) ;
gcp . putClassName ( extraClasses [ i ] . name ) ;
if ( extraClasses [ i ] . outerClass ! = null )
gcp . putClassName ( extraClasses [ i ] . outerClass . name ) ;
if ( extraClasses [ i ] . className ! = null )
gcp . putUTF8 ( extraClasses [ i ] . className ) ;
}
}
}
}
prepareAttributes ( gcp ) ;
prepareAttributes ( gcp ) ;
@ -875,8 +881,7 @@ public final class ClassInfo extends BinaryInfo implements Comparable {
int count = 0 ;
int count = 0 ;
if ( sourceFile ! = null )
if ( sourceFile ! = null )
count + + ;
count + + ;
if ( outerClass ! = null | | methodScoped
if ( hasInnerClassesAttr )
| | innerClasses ! = null | | extraClasses ! = null )
count + + ;
count + + ;
return count ;
return count ;
}
}
@ -889,71 +894,48 @@ public final class ClassInfo extends BinaryInfo implements Comparable {
output . writeInt ( 2 ) ;
output . writeInt ( 2 ) ;
output . writeShort ( gcp . putUTF8 ( sourceFile ) ) ;
output . writeShort ( gcp . putUTF8 ( sourceFile ) ) ;
}
}
if ( outerClass ! = null | | methodScoped
| | innerClasses ! = null | | extraClasses ! = null ) {
List outers = new ArrayList ( ) ;
// XXX TODO: Closeness of extra outer information.
for ( int i = 0 ; i < gcp . size ( ) ; i + + ) {
gcp . putUTF8 ( "InnerClasses" ) ;
if ( gcp . tags [ i ] = = gcp . CLASS ) {
String clName ;
ClassInfo outer ;
try {
LinkedList outerExtraClasses = new LinkedList ( ) ;
clName = gcp . getUTF8 ( gcp . indices1 [ i ] ) ;
} catch ( ClassFormatException ex ) {
outer = this ;
throw new InternalError ( ex . getMessage ( ) ) ;
while ( outer . outerClass ! = null | | outer . methodScoped ) {
}
/ * Outers must be written in backward order , so we
if ( clName . charAt ( 0 ) ! = '[' ) {
* add them to the beginning of the list .
ClassInfo ci = classpath . getClassInfo
* /
( clName . replace ( '/' , '.' ) ) ;
outerExtraClasses . add ( 0 , outer ) ;
while ( ci . status > = OUTERCLASS
if ( outer . outerClass = = null )
& & ci . outerClass ! = null | | ci . methodScoped ) {
break ;
/ * Order is important so remove ci if it
outer = outer . outerClass ;
* already exists and add it to the end . This
}
* way the outermost classes go to the end .
if ( extraClasses ! = null ) {
int extraCount = extraClasses . length ;
for ( int i = 0 ; i < extraCount ; i + + ) {
outer = extraClasses [ i ] ;
ListIterator insertIter
= outerExtraClasses . listIterator
( outerExtraClasses . size ( ) ) ;
int insertPos = outerExtraClasses . size ( ) ;
while ( outer . outerClass ! = null | | outer . methodScoped ) {
if ( outerExtraClasses . contains ( outer ) )
break ;
/ * We have to add outers in reverse order to the
* end of the list . We use the insertIter to do
* this trick .
* /
* /
insertIter . add ( outer ) ;
outers . remove ( ci ) ;
insertIter . previous ( ) ;
outers . add ( ci ) ;
if ( outer . outerClass = = null )
ci = ci . outerClass ;
break ;
outer = outer . outerClass ;
}
}
}
}
}
}
}
int innerCount = ( innerClasses ! = null ) ? innerClasses . length : 0 ;
if ( hasInnerClassesAttr ) {
int count = outerExtraClasses . size ( ) + innerCount ;
int count = outers . size ( ) ;
output . writeShort ( gcp . putUTF8 ( "InnerClasses" ) ) ;
output . writeInt ( 2 + count * 8 ) ;
output . writeInt ( 2 + count * 8 ) ;
output . writeShort ( count ) ;
output . writeShort ( count ) ;
for ( Iterator i = outerExtraClasses . iterator ( ) ; i . hasNext ( ) ; ) {
ListIterator iter = outers . listIterator ( count ) ;
outer = ( ClassInfo ) i . next ( ) ;
while ( iter . hasPrevious ( ) ) {
ClassInfo ci = ( ClassInfo ) iter . previous ( ) ;
output . writeShort ( gcp . putClassName ( outer . name ) ) ;
output . writeShort ( gcp . putClassName ( ci . name ) ) ;
output . writeShort ( outer . outerClass = = null ? 0 :
output . writeShort ( ci . outerClass = = null ? 0 :
gcp . putClassName ( outer . outerClass . name ) ) ;
gcp . putClassName ( ci . outerClass . name ) ) ;
output . writeShort ( outer . className = = null ? 0 :
output . writeShort ( ci . className = = null ? 0 :
gcp . putUTF8 ( outer . className ) ) ;
gcp . putUTF8 ( ci . className ) ) ;
output . writeShort ( outer . modifiers ) ;
output . writeShort ( ci . modifiers ) ;
}
for ( int i = innerCount ; i - - > 0 ; i + + ) {
output . writeShort ( gcp . putClassName ( innerClasses [ i ] . name ) ) ;
output . writeShort ( innerClasses [ i ] . outerClass ! = null ?
gcp . putClassName ( innerClasses [ i ]
. outerClass . name ) : 0 ) ;
output . writeShort ( innerClasses [ i ] . className ! = null ?
gcp . putUTF8 ( innerClasses [ i ] . className ) : 0 ) ;
output . writeShort ( innerClasses [ i ] . modifiers ) ;
}
}
}
}
}
}
@ -1122,7 +1104,6 @@ public final class ClassInfo extends BinaryInfo implements Comparable {
methodScoped = false ;
methodScoped = false ;
outerClass = null ;
outerClass = null ;
innerClasses = null ;
innerClasses = null ;
extraClasses = null ;
}
}
if ( keep < PUBLICDECLARATIONS ) {
if ( keep < PUBLICDECLARATIONS ) {
@ -1285,12 +1266,6 @@ public final class ClassInfo extends BinaryInfo implements Comparable {
return innerClasses ;
return innerClasses ;
}
}
public ClassInfo [ ] getExtraClasses ( ) {
if ( status < OUTERCLASS )
throw new IllegalStateException ( "status is " + status ) ;
return extraClasses ;
}
public String getSourceFile ( ) {
public String getSourceFile ( ) {
return sourceFile ;
return sourceFile ;
}
}
@ -1340,11 +1315,6 @@ public final class ClassInfo extends BinaryInfo implements Comparable {
modified = true ;
modified = true ;
}
}
public void setExtraClasses ( ClassInfo [ ] ec ) {
extraClasses = ec ;
modified = true ;
}
public void setSourceFile ( String newSource ) {
public void setSourceFile ( String newSource ) {
sourceFile = newSource ;
sourceFile = newSource ;
modified = true ;
modified = true ;