Class AbstractTypeDeclaration

    • Constructor Detail

      • AbstractTypeDeclaration

        public AbstractTypeDeclaration()
    • Method Detail

      • isFunctionalInterface

        public final boolean isFunctionalInterface()
        Description copied from interface: ResolvedReferenceTypeDeclaration
        This means that the type has a functional method. Conceptually, a functional interface has exactly one abstract method. Typically these classes has the FunctionInterface annotation but this is not mandatory.
        Specified by:
        isFunctionalInterface in interface ResolvedReferenceTypeDeclaration
      • isRecordType

        public static boolean isRecordType​(java.lang.Class<?> clazz)
        With the introduction of records in Java 14 (Preview), the Class.isRecord method was added to check whether a class is a record or not (similar to isEnum etc.). This method cannot be used directly in JavaParser, however, since it will not compile on Java versions 8-13 (or 15 if preview features aren't enabled) which are supported by the project. This workaround calls the isRecord method via reflection which compiles while still giving the expected answer. There are 2 cases to consider when this method is called: 1) JavaParser is invoked using a Java runtime which supports records In this case, the isRecord method exists, so invoking it will give the answer as usual. 2) JavaParser is invoked using an older Java runtime without record support In this case, the isRecord method does not exist, so attempting to invoke it will throw a NoSuchMethodException. This is not a problem since the classloader cannot load classes compiled by Java versions greater than that used to invoke JavaParser. This means that if JavaParser is invoked with a Java 8 runtime, for example, then no classes compiled with Java versions greater than 8 are supported, so no class loaded by the classloader could possibly be a record class since it could not be compiled in the first place. There may be an edge case here for classes compiled with Java 14/15 preview, but most likely these won't load either. In the case of an NoSuchMethodException, simply return false as the type could not be a record for the reason explained above.