@ -26,34 +26,53 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
@@ -26,34 +26,53 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
{
}
public override void VisitTypeDeclaration ( TypeDeclaration typeD eclaration)
public override void VisitTypeDeclaration ( TypeDeclaration d eclaration)
{
var result = ctx . Resolve ( typeD eclaration) as TypeResolveResult ;
var result = ctx . Resolve ( d eclaration) as TypeResolveResult ;
var baseType = result . Type . GetNonInterfaceBaseTypes ( ) . FirstOrDefault ( t = > ! t . IsKnownType ( KnownTypeCode . Object ) & & ! object . Equals ( t , result . Type ) ) ;
if ( baseType ! = null )
{
var c onstructor = baseType . GetConstructors ( c = > c . Parameters . Count = = 0 ) . FirstOrDefault ( ) ;
var baseC onstructor = baseType . GetConstructors ( c = > c . Parameters . Count = = 0 ) . FirstOrDefault ( ) ;
if ( c onstructor = = null ) {
base . VisitTypeDeclaration ( typeDeclaration ) ;
if ( baseC onstructor = = null ) {
var constructor = result . Type . GetConstructors ( f = > ! f . IsSynthetic ) . FirstOrDefault ( ) ;
if ( ! this . initializerInvoked ) {
var identifier = typeDeclaration . GetChildByRole ( Roles . Identifier ) ;
this . AddIssue ( identifier , ctx . TranslateString ( "There is no default constructor in the base class" ) ) ;
if ( constructor = = null ) {
// If there are no constructors declared then the base constructor isn't being invoked
this . AddIssue ( declaration ) ;
} else {
base . VisitTypeDeclaration ( declaration ) ;
}
}
}
}
public override void VisitConstructorInitializer ( ConstructorInitializer constructorInitializer )
public override void VisitConstructorDeclaration ( ConstructorDeclaration declaration )
{
var result = ctx . Resolve ( constructorInitializer ) ;
this . initializerInvoked = false ;
base . VisitConstructorDeclaration ( declaration ) ;
if ( ! this . initializerInvoked ) {
this . AddIssue ( declaration ) ;
}
}
public override void VisitConstructorInitializer ( ConstructorInitializer initializer )
{
var result = ctx . Resolve ( initializer ) ;
if ( ! result . IsError ) {
this . initializerInvoked = true ;
}
}
private void AddIssue ( AstNode node )
{
var identifier = node . GetChildByRole ( Roles . Identifier ) ;
this . AddIssue ( identifier , ctx . TranslateString ( "There is no default constructor in the base class" ) ) ;
}
}
}
}