private static String getLoggerFieldName()

in dubbo-error-code-inspector/src/main/java/org/apache/dubbo/errorcode/extractor/JdtBasedInvalidLoggerInvocationLocator.java [182:229]


    private static String getLoggerFieldName(String classFile) {
        ClassFile clsF = JavassistUtils.openClassFile(classFile);
        List<FieldInfo> fields = clsF.getFields();

        Predicate<FieldInfo> etaLogger = x -> x.getDescriptor().equals("Lorg/apache/dubbo/common/logger/ErrorTypeAwareLogger;");
        Predicate<FieldInfo> legacyLogger = x -> x.getDescriptor().equals("Lorg/apache/dubbo/common/logger/Logger;");
        Predicate<FieldInfo> loggerType = etaLogger.or(legacyLogger);

        List<FieldDefinition> fieldNameCollection = fields.stream()
            .filter(loggerType)
            .map(x -> {
                FieldDefinition def = new FieldDefinition();

                def.setContainerClass(clsF.getName());
                def.setFieldName(x.getName());
                def.setFieldType(x.getDescriptor());

                return def;
            }).collect(Collectors.toList());

        if (fieldNameCollection.isEmpty()) {
            // Logger field is in the super class.

            String superClass = clsF.getSuperclass();

            if (Objects.equals(superClass, Object.class.getName())) {
                return "logger";
            }

            String superClassSimpleName = superClass.substring(superClass.lastIndexOf('.') + 1);

            String classFileFolderPath = Paths.get(classFile).getParent().toString();
            String superClassClassFile = classFileFolderPath + File.separator + superClassSimpleName + ".class";

            if (!Files.exists(Paths.get(superClassClassFile))) {
                // The field is in the different module or package.

                // Since walking over the project has a really poor performance,
                // just return the most frequently used field name...

                return "logger";
            }

            return getLoggerFieldName(superClassClassFile);
        }

        return fieldNameCollection.get(0).getFieldName();
    }