@@ -563,8 +563,10 @@ class VarDecl extends TVarDecl, VarDef, Declaration {
563563 )
564564 }
565565
566- /** If this is a field, returns the class type that declares it. */
567- ClassType getDeclaringType ( ) { result .getDeclaration ( ) .getAField ( ) = this }
566+ /** If this is declared in a field, returns the class type that declares it. */
567+ ClassType getDeclaringType ( ) {
568+ exists ( FieldDecl f | f .getVarDecl ( ) = this and result = f .getParent ( ) .( Class ) .getType ( ) )
569+ }
568570
569571 /**
570572 * Holds if this is a class field that overrides the field `other`.
@@ -580,6 +582,32 @@ class VarDecl extends TVarDecl, VarDef, Declaration {
580582 override string toString ( ) { result = this .getName ( ) }
581583}
582584
585+ /**
586+ * A field declaration;
587+ */
588+ class FieldDecl extends TFieldDecl , AstNode {
589+ QL:: Field f ;
590+
591+ FieldDecl ( ) { this = TFieldDecl ( f ) }
592+
593+ VarDecl getVarDecl ( ) { toQL ( result ) = f .getChild ( ) }
594+
595+ override AstNode getAChild ( string pred ) {
596+ result = super .getAChild ( pred )
597+ or
598+ pred = directMember ( "getVarDecl" ) and result = this .getVarDecl ( )
599+ }
600+
601+ override string getAPrimaryQlClass ( ) { result = "FieldDecl" }
602+
603+ /** Holds if this field is annotated as overriding another field. */
604+ predicate isOverride ( ) { this .hasAnnotation ( "override" ) }
605+
606+ string getName ( ) { result = getVarDecl ( ) .getName ( ) }
607+
608+ override QLDoc getQLDoc ( ) { result = any ( Class c ) .getQLDocFor ( this ) }
609+ }
610+
583611/**
584612 * A type reference, such as `DataFlow::Node`.
585613 */
@@ -716,10 +744,7 @@ class Class extends TClass, TypeDeclaration, ModuleDeclaration {
716744 */
717745 CharPred getCharPred ( ) { toQL ( result ) = cls .getChild ( _) .( QL:: ClassMember ) .getChild ( _) }
718746
719- AstNode getMember ( int i ) {
720- toQL ( result ) = cls .getChild ( i ) .( QL:: ClassMember ) .getChild ( _) or
721- toQL ( result ) = cls .getChild ( i ) .( QL:: ClassMember ) .getChild ( _) .( QL:: Field ) .getChild ( )
722- }
747+ AstNode getMember ( int i ) { toQL ( result ) = cls .getChild ( i ) .( QL:: ClassMember ) .getChild ( _) }
723748
724749 QLDoc getQLDocFor ( AstNode m ) {
725750 exists ( int i | result = this .getMember ( i ) and m = this .getMember ( i + 1 ) )
@@ -743,9 +768,7 @@ class Class extends TClass, TypeDeclaration, ModuleDeclaration {
743768 /**
744769 * Gets a field in this class.
745770 */
746- VarDecl getAField ( ) {
747- toQL ( result ) = cls .getChild ( _) .( QL:: ClassMember ) .getChild ( _) .( QL:: Field ) .getChild ( )
748- }
771+ FieldDecl getAField ( ) { result = getMember ( _) }
749772
750773 /**
751774 * Gets a super-type referenced in the `extends` part of the class declaration.
0 commit comments