<commit_before>package annotations.el;

import checkers.nullness.quals.Nullable;
import checkers.javari.quals.ReadOnly;

import java.io.File;
import java.util.*;
import java.lang.annotation.RetentionPolicy;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

import annotations.el.AElement;
import annotations.AnnotationBuilder;
import annotations.field.*;
import annotations.util.coll.*;
import annotations.Annotation;
import annotations.Annotations;

/**
 * An annotation type definition, consisting of the annotation name,
 * its meta-annotations, and its field names and
 * types. <code>AnnotationDef</code>s are immutable.  An AnnotationDef with
 * a non-null retention policy is called a "top-level annotation definition".
 */
public final /*@ReadOnly*/ class AnnotationDef extends AElement {

    /**
     * The fully qualified name of the annotation type, such as
     * "foo.Bar$Baz".
     */
    public final String name;

    /**
     * A map of the names of this annotation type's fields to their types. Since
     * {@link AnnotationDef}s are immutable, attempting to modify this
     * map will result in an exception.
     */
    public /*@ReadOnly*/ Map<String, AnnotationFieldType> fieldTypes;

    /**
     * Constructs an annotation definition with the given name.
     * You MUST call setFieldTypes afterward, even if with an empty map.  (Yuck.)
     */
    public AnnotationDef(String name) {
        super("annotation: " + name);
        assert name != null;
        this.name = name;
    }

    // Problem:  I am not sure how to handle circularities (annotations meta-annotated with themselves
    /**
     * Look up an AnnotationDefs in adefs.
     * If not found, read from a class and insert in adefs.
     */
    public static AnnotationDef fromClass(Class<? extends java.lang.annotation.Annotation> annoType, Map<String,AnnotationDef> adefs) {
        String name = annoType.getCanonicalName();
        assert name != null;

        if (adefs.containsKey(name)) {
            return adefs.get(name);
        }

        Map<String,AnnotationFieldType> fieldTypes = new LinkedHashMap<String,AnnotationFieldType>();
        for (Method m : annoType.getDeclaredMethods()) {
            AnnotationFieldType aft = AnnotationFieldType.fromClass(m.getReturnType(), adefs);
            fieldTypes.put(m.getName(), aft);
        }

        AnnotationDef result = new AnnotationDef(name, Annotations.noAnnotations, fieldTypes);
        adefs.put(name, result);

        // An annotation can be meta-annotated with itself, so add
        // meta-annotations after putting the annotation in the map.
        java.lang.annotation.Annotation[] jannos;
        try {<commit_msg>Trivial grammar fix in comment<commit_after>package annotations.el;

import checkers.nullness.quals.Nullable;
import checkers.javari.quals.ReadOnly;

import java.io.File;
import java.util.*;
import java.lang.annotation.RetentionPolicy;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

import annotations.el.AElement;
import annotations.AnnotationBuilder;
import annotations.field.*;
import annotations.util.coll.*;
import annotations.Annotation;
import annotations.Annotations;

/**
 * An annotation type definition, consisting of the annotation name,
 * its meta-annotations, and its field names and
 * types. <code>AnnotationDef</code>s are immutable.  An AnnotationDef with
 * a non-null retention policy is called a "top-level annotation definition".
 */
public final /*@ReadOnly*/ class AnnotationDef extends AElement {

    /**
     * The fully qualified name of the annotation type, such as
     * "foo.Bar$Baz".
     */
    public final String name;

    /**
     * A map of the names of this annotation type's fields to their types. Since
     * {@link AnnotationDef}s are immutable, attempting to modify this
     * map will result in an exception.
     */
    public /*@ReadOnly*/ Map<String, AnnotationFieldType> fieldTypes;

    /**
     * Constructs an annotation definition with the given name.
     * You MUST call setFieldTypes afterward, even if with an empty map.  (Yuck.)
     */
    public AnnotationDef(String name) {
        super("annotation: " + name);
        assert name != null;
        this.name = name;
    }

    // Problem:  I am not sure how to handle circularities (annotations meta-annotated with themselves)
    /**
     * Look up an AnnotationDefs in adefs.
     * If not found, read from a class and insert in adefs.
     */
    public static AnnotationDef fromClass(Class<? extends java.lang.annotation.Annotation> annoType, Map<String,AnnotationDef> adefs) {
        String name = annoType.getCanonicalName();
        assert name != null;

        if (adefs.containsKey(name)) {
            return adefs.get(name);
        }

        Map<String,AnnotationFieldType> fieldTypes = new LinkedHashMap<String,AnnotationFieldType>();
        for (Method m : annoType.getDeclaredMethods()) {
            AnnotationFieldType aft = AnnotationFieldType.fromClass(m.getReturnType(), adefs);
            fieldTypes.put(m.getName(), aft);
        }

        AnnotationDef result = new AnnotationDef(name, Annotations.noAnnotations, fieldTypes);
        adefs.put(name, result);

        // An annotation can be meta-annotated with itself, so add
        // meta-annotations after putting the annotation in the map.
        java.lang.annotation.Annotation[] jannos;
        try {
{'fraction_non_alphanumeric': 0.09528197567268706, 'fraction_numerical': 0.0, 'mean_word_length': 3.1144806671721, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2882765', 'n_tokens_mistral': 1506, 'n_tokens_neox': 1444, 'n_words': 478}