<commit_before>/*
 * Copyright 2004-2011 the original author or authors.
 * 
 * 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.codehaus.griffon.runtime.core;

import griffon.core.GriffonApplication;
import griffon.core.GriffonClass;
import griffon.util.GriffonNameUtils;
import griffon.util.GriffonClassUtils;
import griffon.exceptions.NewInstanceCreationException;
import groovy.lang.Closure;
import groovy.lang.GroovyObject;
import groovy.lang.GroovySystem;
import groovy.lang.MetaClass;
import groovy.lang.MetaMethod;
import groovy.lang.MetaProperty;
import groovy.lang.MetaBeanProperty;
import groovy.lang.ClosureInvokingMethod;

import java.beans.PropertyDescriptor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Modifier;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import java.lang.reflect.Method;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.codehaus.griffon.runtime.util.GriffonApplicationHelper;

/**
 * Abstract base class for Griffon types that provides common functionality for
 * evaluating conventions within classes
 * 
 * @author <NAME> (Grails 0.1)
 * @author <NAME> (Grails 0.1)
 * @author <NAME>
 *
 * @since 0.9.1
 */
public abstract class AbstractGriffonClass implements GriffonClass {
    private final Class<?> clazz;
    private final String type;
    private final GriffonApplication app;
    private final String fullName;
    private final String name;
    private final String packageName;
    private final String naturalName;
    private final String shortName;
    private final String propertyName;
    private final String logicalPropertyName;
    private final ClassPropertyFetcher classPropertyFetcher;
    
    protected final Set<String> eventsCache = new TreeSet<String>();
    protected final Logger log;

    /**
     * <p>Contructor to be used by all child classes to create a
     * new instance and get the name right.
     *
     * @param app
     * @param clazz
     * @param type
     * @param trailingName
     */
    public AbstractGriffonClass(GriffonApplication app, Class<?> clazz, String type, String trailingName) {
        this.app = app;
        this.clazz = clazz;
        this.type = type;
        fullName = clazz.getName();
        log = LoggerFactory.getLogger(getClass().getSimpleName() +"["+ fullName +"]");
        packageName = GriffonClassUtils.getPackageName(clazz);
        naturalName = GriffonNameUtils.getNaturalName(clazz.getName());
        shortName = GriffonClassUtils.getShortClassName(clazz);        
        name = GriffonNameUtils.getLogicalName(clazz, trailingName);
        propertyName = GriffonNameUtils.getPropertyNameRepresentation(shortName);
        if(GriffonNameUtils.isBlank(name)) {
            logicalPropertyName = propertyName;
        } else {
            logicalPropertyName = GriffonNameUtils.getPropertyNameRepresentation(name);
        }
        classPropertyFetcher = ClassPropertyFetcher.forClass(clazz);
    }

    public String getShortName() {
        return shortName;
    }

    public Class<?> getClazz() {
        return clazz;
    }

    public String getArtifactType() {
        return type;
    }

    public GriffonApplication getApp() {
        return app;
    }

    public Object newInstance() {
        try {
            Object instance = GriffonApplicationHelper.newInstance(app, clazz, type);
            if(instance instanceof AbstractGriffonArtifact) {
                ((AbstractGriffonArtifact) instance).setApp(app);
            }
            return instance;
        } catch (Exception e) {
            Throwable targetException = null;
            if (e instanceof InvocationTargetException) {
                targetException = ((InvocationTargetException)e).getTargetException();
            } else {
                targetException = e;
            }
            throw new NewInstanceCreationException("Could not create a new instance of class [" + clazz.getName() + "]!", targetException);
        }
    }

    public String getName() {
        return name;
    }

    public String getNaturalName() {
        return naturalName;
    }

    public String getFullName() {
        return fullName;
    }

    public String getPropertyName() {
        return propertyName;<commit_msg>Minor tewak to exception trace when a bean cannot be instantiated form within a GriffonClass<commit_after>/*
 * Copyright 2004-2011 the original author or authors.
 * 
 * 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.codehaus.griffon.runtime.core;

import griffon.core.GriffonApplication;
import griffon.core.GriffonClass;
import griffon.util.GriffonNameUtils;
import griffon.util.GriffonClassUtils;
import griffon.util.GriffonExceptionHandler;
import griffon.exceptions.NewInstanceCreationException;
import groovy.lang.Closure;
import groovy.lang.GroovyObject;
import groovy.lang.GroovySystem;
import groovy.lang.MetaClass;
import groovy.lang.MetaMethod;
import groovy.lang.MetaProperty;
import groovy.lang.MetaBeanProperty;
import groovy.lang.ClosureInvokingMethod;

import java.beans.PropertyDescriptor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Modifier;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import java.lang.reflect.Method;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.codehaus.griffon.runtime.util.GriffonApplicationHelper;

/**
 * Abstract base class for Griffon types that provides common functionality for
 * evaluating conventions within classes
 * 
 * @author <NAME> (Grails 0.1)
 * @author <NAME> (Grails 0.1)
 * @author <NAME>
 *
 * @since 0.9.1
 */
public abstract class AbstractGriffonClass implements GriffonClass {
    private final Class<?> clazz;
    private final String type;
    private final GriffonApplication app;
    private final String fullName;
    private final String name;
    private final String packageName;
    private final String naturalName;
    private final String shortName;
    private final String propertyName;
    private final String logicalPropertyName;
    private final ClassPropertyFetcher classPropertyFetcher;
    
    protected final Set<String> eventsCache = new TreeSet<String>();
    protected final Logger log;

    /**
     * <p>Contructor to be used by all child classes to create a
     * new instance and get the name right.
     *
     * @param app
     * @param clazz
     * @param type
     * @param trailingName
     */
    public AbstractGriffonClass(GriffonApplication app, Class<?> clazz, String type, String trailingName) {
        this.app = app;
        this.clazz = clazz;
        this.type = type;
        fullName = clazz.getName();
        log = LoggerFactory.getLogger(getClass().getSimpleName() +"["+ fullName +"]");
        packageName = GriffonClassUtils.getPackageName(clazz);
        naturalName = GriffonNameUtils.getNaturalName(clazz.getName());
        shortName = GriffonClassUtils.getShortClassName(clazz);        
        name = GriffonNameUtils.getLogicalName(clazz, trailingName);
        propertyName = GriffonNameUtils.getPropertyNameRepresentation(shortName);
        if(GriffonNameUtils.isBlank(name)) {
            logicalPropertyName = propertyName;
        } else {
            logicalPropertyName = GriffonNameUtils.getPropertyNameRepresentation(name);
        }
        classPropertyFetcher = ClassPropertyFetcher.forClass(clazz);
    }

    public String getShortName() {
        return shortName;
    }

    public Class<?> getClazz() {
        return clazz;
    }

    public String getArtifactType() {
        return type;
    }

    public GriffonApplication getApp() {
        return app;
    }

    public Object newInstance() {
        try {
            Object instance = GriffonApplicationHelper.newInstance(app, clazz, type);
            if(instance instanceof AbstractGriffonArtifact) {
                ((AbstractGriffonArtifact) instance).setApp(app);
            }
            return instance;
        } catch (Exception e) {
            Throwable targetException = null;
            if (e instanceof InvocationTargetException) {
                targetException = ((InvocationTargetException)e).getTargetException();
            } else {
                targetException = e;
            }
            throw new NewInstanceCreationException("Could not create a new instance of class " + clazz.getName(), GriffonExceptionHandler.sanitize(targetException));
        }
    }

    public String getName() {
        return name;
    }

    public String getNaturalName() {
        return naturalName;
    }

    public String getFullName() {
        return fullName;
    }

    public String getPropertyName() {
        return propertyName;
{'fraction_non_alphanumeric': 0.08191056910569106, 'fraction_numerical': 0.00426829268292683, 'mean_word_length': 3.1488195615514334, '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': '5630301', 'n_tokens_mistral': 2711, 'n_tokens_neox': 2633, 'n_words': 758}