66 * (`Interface`).
77 *
88 * Reference types can be at the top level (`TopLevelType`) or nested (`NestedType`).
9- * Classes can also be local (`LocalClass`) or anonymous (`AnonymousClass`).
10- * Enumerated types (`EnumType`) are a special kind of class .
9+ * Classes and interfaces can also be local (`LocalClassOrInterface`, `LocalClass`) or anonymous (`AnonymousClass`).
10+ * Enumerated types (`EnumType`) and records (`Record`) are special kinds of classes .
1111 */
1212
1313import Member
@@ -269,7 +269,7 @@ predicate declaresMember(Type t, @member m) {
269269 // Since the type `@member` in the dbscheme includes all `@reftype`s,
270270 // anonymous and local classes need to be excluded here.
271271 not m instanceof AnonymousClass and
272- not m instanceof LocalClass
272+ not m instanceof LocalClassOrInterface
273273}
274274
275275/**
@@ -608,20 +608,10 @@ class SrcRefType extends RefType {
608608}
609609
610610/** A class declaration. */
611- class Class extends RefType , @class {
611+ class Class extends ClassOrInterface , @class {
612612 /** Holds if this class is an anonymous class. */
613613 predicate isAnonymous ( ) { isAnonymClass ( this , _) }
614614
615- /** Holds if this class is a local class. */
616- predicate isLocal ( ) { isLocalClass ( this , _) }
617-
618- /** Holds if this class is package protected, that is, neither public nor private nor protected. */
619- predicate isPackageProtected ( ) {
620- not isPrivate ( ) and
621- not isProtected ( ) and
622- not isPublic ( )
623- }
624-
625615 override RefType getSourceDeclaration ( ) { classes ( this , _, _, result ) }
626616
627617 /**
@@ -630,11 +620,13 @@ class Class extends RefType, @class {
630620 * Note that a class may inherit annotations from super-classes.
631621 */
632622 override Annotation getAnAnnotation ( ) {
633- result = RefType .super .getAnAnnotation ( )
623+ result = ClassOrInterface .super .getAnAnnotation ( )
634624 or
635625 exists ( AnnotationType tp | tp = result .getType ( ) |
636626 tp .isInherited ( ) and
637- not exists ( Annotation ann | ann = RefType .super .getAnAnnotation ( ) | ann .getType ( ) = tp ) and
627+ not exists ( Annotation ann | ann = ClassOrInterface .super .getAnAnnotation ( ) |
628+ ann .getType ( ) = tp
629+ ) and
638630 result = this .getASupertype ( ) .( Class ) .getAnAnnotation ( )
639631 )
640632 }
@@ -643,8 +635,6 @@ class Class extends RefType, @class {
643635}
644636
645637/**
646- * PREVIEW FEATURE in Java 14. Subject to removal in a future release.
647- *
648638 * A record declaration.
649639 */
650640class Record extends Class {
@@ -727,12 +717,25 @@ class AnonymousClass extends NestedClass {
727717 override string getAPrimaryQlClass ( ) { result = "AnonymousClass" }
728718}
729719
730- /** A local class. */
731- class LocalClass extends NestedClass {
732- LocalClass ( ) { this .isLocal ( ) }
720+ /** A local class or interface . */
721+ class LocalClassOrInterface extends NestedType , ClassOrInterface {
722+ LocalClassOrInterface ( ) { this .isLocal ( ) }
733723
734724 /** Gets the statement that declares this local class. */
735- LocalClassDeclStmt getLocalClassDeclStmt ( ) { isLocalClass ( this , result ) }
725+ LocalTypeDeclStmt getLocalTypeDeclStmt ( ) { isLocalClassOrInterface ( this , result ) }
726+
727+ /**
728+ * DEPRECATED: renamed `getLocalTypeDeclStmt` to reflect the fact that
729+ * as of Java 16 interfaces can also be declared locally.
730+ */
731+ deprecated LocalTypeDeclStmt getLocalClassDeclStmt ( ) { result = this .getLocalTypeDeclStmt ( ) }
732+
733+ override string getAPrimaryQlClass ( ) { result = "LocalClassOrInterface" }
734+ }
735+
736+ /** A local class. */
737+ class LocalClass extends LocalClassOrInterface , NestedClass {
738+ LocalClass ( ) { this .isLocal ( ) }
736739
737740 override string getAPrimaryQlClass ( ) { result = "LocalClass" }
738741}
@@ -842,34 +845,32 @@ class InnerClass extends NestedClass {
842845 predicate hasEnclosingInstance ( ) {
843846 // JLS 15.9.2. Determining Enclosing Instances
844847 not this .( AnonymousClass ) .getClassInstanceExpr ( ) .isInStaticContext ( ) and
845- not this .( LocalClass ) .getLocalClassDeclStmt ( ) .getEnclosingCallable ( ) .isStatic ( )
848+ not this .( LocalClass ) .getLocalTypeDeclStmt ( ) .getEnclosingCallable ( ) .isStatic ( )
846849 }
847850}
848851
849852/** An interface. */
850- class Interface extends RefType , @interface {
853+ class Interface extends ClassOrInterface , @interface {
851854 override RefType getSourceDeclaration ( ) { interfaces ( this , _, _, result ) }
852855
853856 override predicate isAbstract ( ) {
854857 // JLS 9.1.1.1: "Every interface is implicitly abstract"
855858 any ( )
856859 }
857860
858- /** Holds if this interface is package protected, that is, neither public nor private nor protected. */
859- predicate isPackageProtected ( ) {
860- not isPrivate ( ) and
861- not isProtected ( ) and
862- not isPublic ( )
863- }
864-
865861 override string getAPrimaryQlClass ( ) { result = "Interface" }
866862}
867863
868864/** A class or interface. */
869- class ClassOrInterface extends RefType {
870- ClassOrInterface ( ) {
871- this instanceof Class or
872- this instanceof Interface
865+ class ClassOrInterface extends RefType , @classorinterface {
866+ /** Holds if this class or interface is local. */
867+ predicate isLocal ( ) { isLocalClassOrInterface ( this , _) }
868+
869+ /** Holds if this class or interface is package protected, that is, neither public nor private nor protected. */
870+ predicate isPackageProtected ( ) {
871+ not isPrivate ( ) and
872+ not isProtected ( ) and
873+ not isPublic ( )
873874 }
874875}
875876
0 commit comments