<commit_before>/*
   Copyright 2009-2012 <NAME>

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 */

package org.dynalang.dynalink.beans;

import java.io.Serializable;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;

import org.dynalang.dynalink.support.Lookup;

/**
 * Object that represents the static facet of a class (its static methods, properties, and fields). Objects of this
 * class are recognized by the {@link BeansLinker} as being special, and operations on them will be linked against the
 * represented class' static facet. The "class" synthetic property is additionally recognized and returns the Java Class
 * object, as per {@link #getRepresentedClass()} method. Conversely, {@link Class} objects exposed through
 * {@link BeansLinker} expose the "statics" synthetic property which returns an instance of this class. The linker also
 * interprets the "dyn:new" operation on these objects just as if they were executed on the Class they represent.
 */
public class ClassStatics implements Serializable {
    private static final ClassValue<ClassStatics> statics = new ClassValue<ClassStatics>() {
        @Override
        protected ClassStatics computeValue(Class<?> type) {
            return new ClassStatics(type);
        }
    };

    private static final long serialVersionUID = 1L;

    private final Class<?> clazz;

    private ClassStatics(Class<?> clazz) {
        clazz.getClass(); // NPE check
        this.clazz = clazz;
    }

    /**
     * Retrieves the {@link ClassStatics} instance for the specified class.
     * @param clazz the class for which the statics instance is requested.
     * @return the {@link ClassStatics} instance representing the specified class.
     */
    public static ClassStatics forClass(Class<?> clazz) {
        return statics.get(clazz);
    }

    /**
     * Returns the represented Java class.
     * @return the represented Java class.
     */
    public Class<?> getRepresentedClass() {
        return clazz;
    }

    @Override
    public String toString() {
        return "ClassStatics[" + clazz.getName() + "]";
    }

    static final MethodHandle FOR_CLASS = new Lookup(MethodHandles.lookup()).findStatic(ClassLinker.class,
            "forClass", MethodType.methodType(ClassStatics.class, Class.class));

    static final MethodHandle IS_CLASS = new Lookup(MethodHandles.lookup()).findStatic(ClassStatics.class,
            "isClass", MethodType.methodType(Boolean.TYPE, Class.class, Object.class));

    static final MethodHandle GET_CLASS = new Lookup(MethodHandles.lookup()).findSpecial(ClassStatics.class,
            "getRepresentedClass", MethodType.methodType(Class.class));

    static MethodHandle getIsClass(Class<?> clazz) {
        return IS_CLASS.bindTo(clazz);
    }

    @SuppressWarnings("unused")<commit_msg>Bugfix<commit_after>/*
   Copyright 2009-2012 <NAME>

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 */

package org.dynalang.dynalink.beans;

import java.io.Serializable;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;

import org.dynalang.dynalink.support.Lookup;

/**
 * Object that represents the static facet of a class (its static methods, properties, and fields). Objects of this
 * class are recognized by the {@link BeansLinker} as being special, and operations on them will be linked against the
 * represented class' static facet. The "class" synthetic property is additionally recognized and returns the Java Class
 * object, as per {@link #getRepresentedClass()} method. Conversely, {@link Class} objects exposed through
 * {@link BeansLinker} expose the "statics" synthetic property which returns an instance of this class. The linker also
 * interprets the "dyn:new" operation on these objects just as if they were executed on the Class they represent.
 */
public class ClassStatics implements Serializable {
    private static final ClassValue<ClassStatics> statics = new ClassValue<ClassStatics>() {
        @Override
        protected ClassStatics computeValue(Class<?> type) {
            return new ClassStatics(type);
        }
    };

    private static final long serialVersionUID = 1L;

    private final Class<?> clazz;

    private ClassStatics(Class<?> clazz) {
        clazz.getClass(); // NPE check
        this.clazz = clazz;
    }

    /**
     * Retrieves the {@link ClassStatics} instance for the specified class.
     * @param clazz the class for which the statics instance is requested.
     * @return the {@link ClassStatics} instance representing the specified class.
     */
    public static ClassStatics forClass(Class<?> clazz) {
        return statics.get(clazz);
    }

    /**
     * Returns the represented Java class.
     * @return the represented Java class.
     */
    public Class<?> getRepresentedClass() {
        return clazz;
    }

    @Override
    public String toString() {
        return "ClassStatics[" + clazz.getName() + "]";
    }

    static final MethodHandle FOR_CLASS = new Lookup(MethodHandles.lookup()).findStatic(ClassStatics.class,
            "forClass", MethodType.methodType(ClassStatics.class, Class.class));

    static final MethodHandle IS_CLASS = new Lookup(MethodHandles.lookup()).findStatic(ClassStatics.class,
            "isClass", MethodType.methodType(Boolean.TYPE, Class.class, Object.class));

    static final MethodHandle GET_CLASS = new Lookup(MethodHandles.lookup()).findSpecial(ClassStatics.class,
            "getRepresentedClass", MethodType.methodType(Class.class));

    static MethodHandle getIsClass(Class<?> clazz) {
        return IS_CLASS.bindTo(clazz);
    }

    @SuppressWarnings("unused")
{'fraction_non_alphanumeric': 0.08672408672408673, 'fraction_numerical': 0.003861003861003861, 'mean_word_length': 3.5537525354969572, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4439471', 'n_tokens_mistral': 1793, 'n_tokens_neox': 1755, 'n_words': 647}