File tree Expand file tree Collapse file tree 2 files changed +38
-31
lines changed
java/ql/lib/semmle/code/java Expand file tree Collapse file tree 2 files changed +38
-31
lines changed Original file line number Diff line number Diff line change @@ -874,6 +874,44 @@ class ClassOrInterface extends RefType, @classorinterface {
874
874
}
875
875
}
876
876
877
+ private string getAPublicObjectMethodSignature ( ) {
878
+ exists ( Method m |
879
+ m .getDeclaringType ( ) instanceof TypeObject and
880
+ m .isPublic ( ) and
881
+ result = m .getSignature ( )
882
+ )
883
+ }
884
+
885
+ private Method getAnAbstractMethod ( Interface interface ) {
886
+ interface .inherits ( result ) and
887
+ result .isAbstract ( ) and
888
+ // JLS 9.8, ignore Object methods
889
+ not result .getSignature ( ) = getAPublicObjectMethodSignature ( ) and
890
+ // Make sure that there is no other non-abstract method
891
+ // (e.g. `default`) which overrides the abstract one
892
+ not exists ( Method m |
893
+ interface .inherits ( m ) and
894
+ not m .isAbstract ( ) and
895
+ m .overrides ( result )
896
+ )
897
+ }
898
+
899
+ /**
900
+ * A functional interface is an interface that has just one abstract method
901
+ * (aside from the methods of Object), and thus represents a single function
902
+ * contract.
903
+ *
904
+ * See JLS 9.8, Functional Interfaces.
905
+ */
906
+ class FunctionalInterface extends Interface {
907
+ Method run ;
908
+
909
+ FunctionalInterface ( ) { run = unique( Method r | r = getAnAbstractMethod ( this ) ) }
910
+
911
+ /** Gets the single abstract method of this interface. */
912
+ Method getRunMethod ( ) { result = run }
913
+ }
914
+
877
915
/**
878
916
* A primitive type.
879
917
*
Original file line number Diff line number Diff line change 6
6
import java
7
7
import VirtualDispatch
8
8
9
- private string getAPublicObjectMethodSignature ( ) {
10
- exists ( Method m |
11
- m .getDeclaringType ( ) instanceof TypeObject and
12
- m .isPublic ( ) and
13
- result = m .getSignature ( )
14
- )
15
- }
16
-
17
- private Method getAPotentialRunMethod ( Interface i ) {
18
- i .inherits ( result ) and
19
- result .isPublic ( ) and
20
- not result .getSignature ( ) = getAPublicObjectMethodSignature ( )
21
- }
22
-
23
- /**
24
- * A functional interface is an interface that has just one abstract method
25
- * (aside from the methods of Object), and thus represents a single function
26
- * contract.
27
- *
28
- * See JLS 9.8, Functional Interfaces.
29
- */
30
- class FunctionalInterface extends Interface {
31
- FunctionalInterface ( ) {
32
- 1 = strictcount ( getAPotentialRunMethod ( this ) ) and
33
- not exists ( Method m | this .inherits ( m ) and m .isDefault ( ) )
34
- }
35
-
36
- /** Gets the single method of this interface. */
37
- Method getRunMethod ( ) { getAPotentialRunMethod ( this ) .getSourceDeclaration ( ) = result }
38
- }
39
-
40
9
/**
41
10
* Holds if `m` might invoke `runmethod` through a functional interface on the
42
11
* `n`th parameter.
You can’t perform that action at this time.
0 commit comments