@@ -77,6 +77,63 @@ class ClassType extends Type, TClass {
7777 or
7878 result = super .getAnInternalSuperType ( )
7979 }
80+
81+ ClassPredicate getClassPredicate ( string name , int arity ) {
82+ result = classPredCandidate ( this , name , arity ) and
83+ not exists ( ClassPredicate other | other = classPredCandidate ( this , name , arity ) |
84+ other .getDeclaringType ( ) .getASuperType + ( ) = result .getDeclaringType ( )
85+ )
86+ }
87+
88+ VarDecl getField ( string name ) {
89+ result = fieldCandidate ( this , name ) and
90+ not exists ( VarDecl other | other = fieldCandidate ( this , name ) |
91+ other .getDeclaringType ( ) .getASuperType + ( ) = result .getDeclaringType ( )
92+ )
93+ }
94+ }
95+
96+ private ClassPredicate declaredPred ( ClassType ty , string name , int arity ) {
97+ result = ty .getDeclaration ( ) .getAClassPredicate ( ) and
98+ result .getName ( ) = name and
99+ result .getArity ( ) = arity
100+ }
101+
102+ private ClassPredicate classPredCandidate ( ClassType ty , string name , int arity ) {
103+ result = declaredPred ( ty , name , arity )
104+ or
105+ not exists ( declaredPred ( ty , name , arity ) ) and
106+ result = inherClassPredCandidate ( ty , name , arity )
107+ }
108+
109+ private ClassPredicate inherClassPredCandidate ( ClassType ty , string name , int arity ) {
110+ result = classPredCandidate ( ty .getASuperType ( ) , name , arity ) and
111+ not result .isPrivate ( )
112+ }
113+
114+ predicate predOverrides ( ClassPredicate sub , ClassPredicate sup ) {
115+ sup = inherClassPredCandidate ( sub .getDeclaringType ( ) , sub .getName ( ) , sub .getArity ( ) )
116+ }
117+
118+ private VarDecl declaredField ( ClassType ty , string name ) {
119+ result = ty .getDeclaration ( ) .getAField ( ) and
120+ result .getName ( ) = name
121+ }
122+
123+ private VarDecl fieldCandidate ( ClassType ty , string name ) {
124+ result = declaredField ( ty , name )
125+ or
126+ not exists ( declaredField ( ty , name ) ) and
127+ result = inherFieldCandidate ( ty , name )
128+ }
129+
130+ private VarDecl inherFieldCandidate ( ClassType ty , string name ) {
131+ result = fieldCandidate ( ty .getASuperType ( ) , name ) and
132+ not result .isPrivate ( )
133+ }
134+
135+ predicate fieldOverrides ( VarDecl sub , VarDecl sup ) {
136+ sup = inherFieldCandidate ( sub .getDeclaringType ( ) , sub .getName ( ) )
80137}
81138
82139class ClassCharType extends Type , TClassChar {
0 commit comments