package com.azure.tools.apiview.processor.diagnostics.rules;

import com.azure.tools.apiview.processor.diagnostics.DiagnosticRule;
import com.azure.tools.apiview.processor.model.APIListing;
import com.azure.tools.apiview.processor.model.Diagnostic;
import com.github.javaparser.ast.CompilationUnit;

import java.util.regex.Pattern;

import static com.azure.tools.apiview.processor.analysers.util.ASTUtils.*;

public class PackageNameDiagnosticRule implements DiagnosticRule {
    final static Pattern regex = Pattern.compile("^com.azure.[a-z0-9]*(\\.[a-z0-9]+)+[0-9a-z]$");

    @Override
    public void scan(final CompilationUnit cu, final APIListing listing) {
        getPackageName(cu).ifPresent(packageName -> {
            // we need to map the issue to the class id, because package text isn't printed in the APIView output
            getClassName(cu).map(listing.getKnownTypes()::get).ifPresent(typeId -> {
                if (!regex.matcher(packageName).matches()) {
                    listing.addDiagnostic(new Diagnostic(typeId,
                            "Package name must start with 'com.azure', and it must be lower-case, with no underscores or hyphens."));
                }
            });
        });
    }
}

@@ -533,18 +533,8 @@
 zure
-.%5Ba-z0-9%5D*
 (%5C%5C.
@@ -548,16 +548,8 @@
 %5D+)+
-%5B0-9a-z%5D
 $%22);

Fix regex for package naming diagnostic