001/*
002 *  Copyright 2013 Christopher Pheby
003 *
004 *  Licensed under the Apache License, Version 2.0 (the "License");
005 *  you may not use this file except in compliance with the License.
006 *  You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 *  Unless required by applicable law or agreed to in writing, software
011 *  distributed under the License is distributed on an "AS IS" BASIS,
012 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 *  See the License for the specific language governing permissions and
014 *  limitations under the License.
015 */
016package org.jadira.reflection.access.api;
017
018import java.lang.reflect.Field;
019import java.lang.reflect.Method;
020
021import org.jadira.reflection.access.model.ClassModel;
022
023/**
024 * Defines a mechanism for accessing the capabilities of a class
025 * @param <C> The class to be access
026 */
027public interface ClassAccess<C> {
028
029        /**
030         * Create a new, uninitialised instance of the given class (if supported). Depending on
031         * strategy, this may or may not initialise instance fields, and may or may not invoke
032         * constructors.
033         * @return The new instance of the type, C.
034         */
035        C newInstance();
036
037        /**
038         * Get the Class being accessed
039         * @return The class
040         */
041        Class<C> getType();
042        
043        /**
044         * Gets a field accessor for each field in the class
045         * @return Array of FieldAccess
046         */
047        FieldAccess<C>[] getDeclaredFieldAccessors();
048        
049        /**
050         * Get a field accessor for the given field
051         * @param f The Field to be accessed
052         * @return The matching FieldAccess
053         */
054        FieldAccess<C> getDeclaredFieldAccess(Field f);
055        
056        /**
057         * Gets a method accessor for each method in the class
058         * @return Array of MethodAccess
059         */
060        MethodAccess<C>[] getDeclaredMethodAccessors();
061        
062        /**
063         * Get a method accessor for the given method
064         * @param m The Method to be accessed
065         * @return The matching MethodAccess
066         */
067        MethodAccess<C> getDeclaredMethodAccess(Method m);
068        
069        /**
070         * Return the ClassModel used by this ClassAccess instance
071         * @return The associated ClassModel
072         */
073        ClassModel<C> getClassModel();
074        
075        /**
076         * Get the Class being accessed
077         * @return The class
078         */
079        ClassAccess<? super C> getSuperClassAccess();
080
081        /**
082         * True if the hashCode method is overridden by this class
083         * @return True if hashCode provided
084         */
085        boolean providesHashCode();
086
087        /**
088         * True if the equals method is overridden by this class
089         * @return True if equals provided
090         */
091        boolean providesEquals();
092}