@ -133,6 +133,12 @@ public class NewExprent extends Exprent {
List < Exprent > lst = new ArrayList < Exprent > ( ) ;
List < Exprent > lst = new ArrayList < Exprent > ( ) ;
if ( newtype . arraydim = = 0 ) {
if ( newtype . arraydim = = 0 ) {
if ( constructor ! = null ) {
if ( constructor ! = null ) {
Exprent constructor_instance = constructor . getInstance ( ) ;
if ( constructor_instance ! = null ) { // should be true only for a lambda expression with a virtual content method
lst . add ( constructor_instance ) ;
}
lst . addAll ( constructor . getLstParameters ( ) ) ;
lst . addAll ( constructor . getLstParameters ( ) ) ;
}
}
} else {
} else {
@ -165,21 +171,21 @@ public class NewExprent extends Exprent {
public String toJava ( int indent ) {
public String toJava ( int indent ) {
StringBuilder buf = new StringBuilder ( ) ;
StringBuilder buf = new StringBuilder ( ) ;
if ( anonymous ) {
if ( anonymous ) {
ClassNode child = DecompilerContext . getClassprocessor ( ) . getMapRootClasses ( ) . get ( newtype . value ) ;
ClassNode child = DecompilerContext . getClassprocessor ( ) . getMapRootClasses ( ) . get ( newtype . value ) ;
buf . append ( "(" ) ;
buf . append ( "(" ) ;
if ( ! lambda & & constructor ! = null ) {
if ( ! lambda & & constructor ! = null ) {
InvocationExprent invsuper = child . superInvocation ;
InvocationExprent invsuper = child . superInvocation ;
ClassNode newnode = DecompilerContext . getClassprocessor ( ) . getMapRootClasses ( ) . get ( invsuper . getClassname ( ) ) ;
ClassNode newnode = DecompilerContext . getClassprocessor ( ) . getMapRootClasses ( ) . get ( invsuper . getClassname ( ) ) ;
List < VarVersionPaar > sigFields = null ;
List < VarVersionPaar > sigFields = null ;
if ( newnode ! = null ) { // own class
if ( newnode ! = null ) { // own class
if ( newnode . wrapper ! = null ) {
if ( newnode . wrapper ! = null ) {
sigFields = newnode . wrapper . getMethodWrapper ( "<init>" , invsuper . getStringDescriptor ( ) ) . signatureFields ;
sigFields = newnode . wrapper . getMethodWrapper ( "<init>" , invsuper . getStringDescriptor ( ) ) . signatureFields ;
} else {
} else {
if ( newnode . type = = ClassNode . CLASS_MEMBER & & ( newnode . access & CodeConstants . ACC_STATIC ) = = 0 & &
if ( newnode . type = = ClassNode . CLASS_MEMBER & & ( newnode . access & CodeConstants . ACC_STATIC ) = = 0 & &
@ -191,21 +197,22 @@ public class NewExprent extends Exprent {
}
}
boolean firstpar = true ;
boolean firstpar = true ;
int start = 0 , end = invsuper . getLstParameters ( ) . size ( ) ;
int start = 0 , end = invsuper . getLstParameters ( ) . size ( ) ;
if ( enumconst ) {
if ( enumconst ) {
start + = 2 ; end - = 1 ;
start + = 2 ;
}
end - = 1 ;
for ( int i = start ; i < end ; i + + ) {
}
if ( sigFields = = null | | sigFields . get ( i ) = = null ) {
for ( int i = start ; i < end ; i + + ) {
if ( ! firstpar ) {
if ( sigFields = = null | | sigFields . get ( i ) = = null ) {
if ( ! firstpar ) {
buf . append ( ", " ) ;
buf . append ( ", " ) ;
}
}
Exprent param = invsuper . getLstParameters ( ) . get ( i ) ;
Exprent param = invsuper . getLstParameters ( ) . get ( i ) ;
if ( param . type = = Exprent . EXPRENT_VAR ) {
if ( param . type = = Exprent . EXPRENT_VAR ) {
int varindex = ( ( VarExprent ) param ) . getIndex ( ) ;
int varindex = ( ( VarExprent ) param ) . getIndex ( ) ;
if ( varindex > 0 & & varindex < = constructor . getLstParameters ( ) . size ( ) ) {
if ( varindex > 0 & & varindex < = constructor . getLstParameters ( ) . size ( ) ) {
param = constructor . getLstParameters ( ) . get ( varindex - 1 ) ;
param = constructor . getLstParameters ( ) . get ( varindex - 1 ) ;
}
}
}
}
@ -219,63 +226,64 @@ public class NewExprent extends Exprent {
}
}
if ( ! enumconst ) {
if ( ! enumconst ) {
String enclosing = null ;
String enclosing = null ;
if ( ! lambda & & constructor ! = null ) {
if ( ! lambda & & constructor ! = null ) {
enclosing = getQualifiedNewInstance ( child . anonimousClassType . value , constructor . getLstParameters ( ) , indent ) ;
enclosing = getQualifiedNewInstance ( child . anonimousClassType . value , constructor . getLstParameters ( ) , indent ) ;
}
}
String typename = ExprProcessor . getCastTypeName ( child . anonimousClassType ) ;
String typename = ExprProcessor . getCastTypeName ( child . anonimousClassType ) ;
if ( enclosing ! = null ) {
if ( enclosing ! = null ) {
ClassNode anonimousNode = DecompilerContext . getClassprocessor ( ) . getMapRootClasses ( ) . get ( child . anonimousClassType . value ) ;
ClassNode anonimousNode = DecompilerContext . getClassprocessor ( ) . getMapRootClasses ( ) . get ( child . anonimousClassType . value ) ;
if ( anonimousNode ! = null ) {
if ( anonimousNode ! = null ) {
typename = anonimousNode . simpleName ;
typename = anonimousNode . simpleName ;
} else {
} else {
typename = typename . substring ( typename . lastIndexOf ( '.' ) + 1 ) ;
typename = typename . substring ( typename . lastIndexOf ( '.' ) + 1 ) ;
}
}
}
}
buf . insert ( 0 , "new " + typename ) ;
buf . insert ( 0 , "new " + typename ) ;
if ( enclosing ! = null ) {
if ( enclosing ! = null ) {
buf . insert ( 0 , enclosing + "." ) ;
buf . insert ( 0 , enclosing + "." ) ;
}
}
}
}
buf . append ( ")" ) ;
buf . append ( ")" ) ;
if ( enumconst & & buf . length ( ) = = 2 ) {
if ( enumconst & & buf . length ( ) = = 2 ) {
buf . setLength ( 0 ) ;
buf . setLength ( 0 ) ;
}
}
StringWriter strwriter = new StringWriter ( ) ;
StringWriter strwriter = new StringWriter ( ) ;
BufferedWriter bufstrwriter = new BufferedWriter ( strwriter ) ;
BufferedWriter bufstrwriter = new BufferedWriter ( strwriter ) ;
ClassWriter clwriter = new ClassWriter ( ) ;
ClassWriter clwriter = new ClassWriter ( ) ;
try {
try {
if ( lambda ) {
if ( lambda ) {
clwriter . classLambdaToJava ( child , bufstrwriter , indent ) ;
clwriter . classLambdaToJava ( child , bufstrwriter , ( constructor = = null ? null : constructor . getInstance ( ) ) , indent ) ;
} else {
} else {
clwriter . classToJava ( child , bufstrwriter , indent ) ;
clwriter . classToJava ( child , bufstrwriter , indent ) ;
}
}
bufstrwriter . flush ( ) ;
bufstrwriter . flush ( ) ;
} catch ( IOException ex ) {
} catch ( IOException ex ) {
throw new RuntimeException ( ex ) ;
throw new RuntimeException ( ex ) ;
}
}
if ( lambda & & ! DecompilerContext . getOption ( IFernflowerPreferences . LAMBDA_TO_ANONYMOUS_CLASS ) ) {
if ( lambda & & ! DecompilerContext . getOption ( IFernflowerPreferences . LAMBDA_TO_ANONYMOUS_CLASS ) ) {
buf . setLength ( 0 ) ; // remove the usual 'new <class>()', it will be replaced with lambda style '() ->'
buf . setLength ( 0 ) ; // remove the usual 'new <class>()', it will
// be replaced with lambda style '() ->'
}
}
buf . append ( strwriter . toString ( ) ) ;
buf . append ( strwriter . toString ( ) ) ;
} else if ( directArrayInit ) {
} else if ( directArrayInit ) {
VarType leftType = newtype . copy ( ) ;
VarType leftType = newtype . copy ( ) ;
leftType . decArrayDim ( ) ;
leftType . decArrayDim ( ) ;
buf . append ( "{" ) ;
buf . append ( "{" ) ;
for ( int i = 0 ; i < lstArrayElements . size ( ) ; i + + ) {
for ( int i = 0 ; i < lstArrayElements . size ( ) ; i + + ) {
if ( i > 0 ) {
if ( i > 0 ) {
buf . append ( ", " ) ;
buf . append ( ", " ) ;
}
}
StringBuilder buff = new StringBuilder ( ) ;
StringBuilder buff = new StringBuilder ( ) ;
@ -285,90 +293,90 @@ public class NewExprent extends Exprent {
}
}
buf . append ( "}" ) ;
buf . append ( "}" ) ;
} else {
} else {
if ( newtype . arraydim = = 0 ) {
if ( newtype . arraydim = = 0 ) {
if ( constructor ! = null ) {
if ( constructor ! = null ) {
List < Exprent > lstParameters = constructor . getLstParameters ( ) ;
List < Exprent > lstParameters = constructor . getLstParameters ( ) ;
ClassNode newnode = DecompilerContext . getClassprocessor ( ) . getMapRootClasses ( ) . get ( constructor . getClassname ( ) ) ;
ClassNode newnode = DecompilerContext . getClassprocessor ( ) . getMapRootClasses ( ) . get ( constructor . getClassname ( ) ) ;
List < VarVersionPaar > sigFields = null ;
List < VarVersionPaar > sigFields = null ;
if ( newnode ! = null ) { // own class
if ( newnode ! = null ) { // own class
if ( newnode . wrapper ! = null ) {
if ( newnode . wrapper ! = null ) {
sigFields = newnode . wrapper . getMethodWrapper ( "<init>" , constructor . getStringDescriptor ( ) ) . signatureFields ;
sigFields = newnode . wrapper . getMethodWrapper ( "<init>" , constructor . getStringDescriptor ( ) ) . signatureFields ;
} else {
} else {
if ( newnode . type = = ClassNode . CLASS_MEMBER & & ( newnode . access & CodeConstants . ACC_STATIC ) = = 0 & &
if ( newnode . type = = ClassNode . CLASS_MEMBER & & ( newnode . access & CodeConstants . ACC_STATIC ) = = 0 & &
! constructor . getLstParameters ( ) . isEmpty ( ) ) { // member non-static class invoked with enclosing class instance
! constructor . getLstParameters ( ) . isEmpty ( ) ) { // member non-static class invoked with enclosing class instance
sigFields = new ArrayList < VarVersionPaar > ( Collections . nCopies ( lstParameters . size ( ) , ( VarVersionPaar ) null ) ) ;
sigFields = new ArrayList < VarVersionPaar > ( Collections . nCopies ( lstParameters . size ( ) , ( VarVersionPaar ) null ) ) ;
sigFields . set ( 0 , new VarVersionPaar ( - 1 , 0 ) ) ;
sigFields . set ( 0 , new VarVersionPaar ( - 1 , 0 ) ) ;
}
}
}
}
}
}
int start = enumconst ? 2 : 0 ;
int start = enumconst ? 2 : 0 ;
if ( ! enumconst | | start < lstParameters . size ( ) ) {
if ( ! enumconst | | start < lstParameters . size ( ) ) {
buf . append ( "(" ) ;
buf . append ( "(" ) ;
boolean firstpar = true ;
boolean firstpar = true ;
for ( int i = start ; i < lstParameters . size ( ) ; i + + ) {
for ( int i = start ; i < lstParameters . size ( ) ; i + + ) {
if ( sigFields = = null | | sigFields . get ( i ) = = null ) {
if ( sigFields = = null | | sigFields . get ( i ) = = null ) {
if ( ! firstpar ) {
if ( ! firstpar ) {
buf . append ( ", " ) ;
buf . append ( ", " ) ;
}
}
StringBuilder buff = new StringBuilder ( ) ;
StringBuilder buff = new StringBuilder ( ) ;
ExprProcessor . getCastedExprent ( lstParameters . get ( i ) , constructor . getDescriptor ( ) . params [ i ] , buff , indent , true ) ;
ExprProcessor . getCastedExprent ( lstParameters . get ( i ) , constructor . getDescriptor ( ) . params [ i ] , buff , indent , true ) ;
buf . append ( buff ) ;
buf . append ( buff ) ;
firstpar = false ;
firstpar = false ;
}
}
}
}
buf . append ( ")" ) ;
buf . append ( ")" ) ;
}
}
}
}
if ( ! enumconst ) {
if ( ! enumconst ) {
String enclosing = null ;
String enclosing = null ;
if ( constructor ! = null ) {
if ( constructor ! = null ) {
enclosing = getQualifiedNewInstance ( newtype . value , constructor . getLstParameters ( ) , indent ) ;
enclosing = getQualifiedNewInstance ( newtype . value , constructor . getLstParameters ( ) , indent ) ;
}
}
String typename = ExprProcessor . getTypeName ( newtype ) ;
String typename = ExprProcessor . getTypeName ( newtype ) ;
if ( enclosing ! = null ) {
if ( enclosing ! = null ) {
ClassNode newNode = DecompilerContext . getClassprocessor ( ) . getMapRootClasses ( ) . get ( newtype . value ) ;
ClassNode newNode = DecompilerContext . getClassprocessor ( ) . getMapRootClasses ( ) . get ( newtype . value ) ;
if ( newNode ! = null ) {
if ( newNode ! = null ) {
typename = newNode . simpleName ;
typename = newNode . simpleName ;
} else {
} else {
typename = typename . substring ( typename . lastIndexOf ( '.' ) + 1 ) ;
typename = typename . substring ( typename . lastIndexOf ( '.' ) + 1 ) ;
}
}
}
}
buf . insert ( 0 , "new " + typename ) ;
buf . insert ( 0 , "new " + typename ) ;
if ( enclosing ! = null ) {
if ( enclosing ! = null ) {
buf . insert ( 0 , enclosing + "." ) ;
buf . insert ( 0 , enclosing + "." ) ;
}
}
}
}
} else {
} else {
buf . append ( "new " ) . append ( ExprProcessor . getTypeName ( newtype ) ) ;
buf . append ( "new " ) . append ( ExprProcessor . getTypeName ( newtype ) ) ;
if ( lstArrayElements . isEmpty ( ) ) {
if ( lstArrayElements . isEmpty ( ) ) {
for ( int i = 0 ; i < newtype . arraydim ; i + + ) {
for ( int i = 0 ; i < newtype . arraydim ; i + + ) {
buf . append ( "[" ) . append ( i < lstDims . size ( ) ? lstDims . get ( i ) . toJava ( indent ) : "" ) . append ( "]" ) ;
buf . append ( "[" ) . append ( i < lstDims . size ( ) ? lstDims . get ( i ) . toJava ( indent ) : "" ) . append ( "]" ) ;
}
}
} else {
} else {
for ( int i = 0 ; i < newtype . arraydim ; i + + ) {
for ( int i = 0 ; i < newtype . arraydim ; i + + ) {
buf . append ( "[]" ) ;
buf . append ( "[]" ) ;
}
}
VarType leftType = newtype . copy ( ) ;
VarType leftType = newtype . copy ( ) ;
leftType . decArrayDim ( ) ;
leftType . decArrayDim ( ) ;
buf . append ( "{" ) ;
buf . append ( "{" ) ;
for ( int i = 0 ; i < lstArrayElements . size ( ) ; i + + ) {
for ( int i = 0 ; i < lstArrayElements . size ( ) ; i + + ) {
if ( i > 0 ) {
if ( i > 0 ) {
buf . append ( ", " ) ;
buf . append ( ", " ) ;
}
}
StringBuilder buff = new StringBuilder ( ) ;
StringBuilder buff = new StringBuilder ( ) ;