All Downloads are FREE. Search and download functionalities are using the official Maven repository.

metamodel.access.ObjectAccessor Maven / Gradle / Ivy

The newest version!
/*
 * The MIT License (MIT)
 *
 * Copyright (c) 2014 Michael Kroll
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
package metamodel.access;

import metamodel.access.field.FieldAccessor;
import metamodel.access.method.Callable0;
import metamodel.access.method.Callable1;
import metamodel.access.method.Callable10;
import metamodel.access.method.Callable11;
import metamodel.access.method.Callable12;
import metamodel.access.method.Callable13;
import metamodel.access.method.Callable14;
import metamodel.access.method.Callable15;
import metamodel.access.method.Callable16;
import metamodel.access.method.Callable2;
import metamodel.access.method.Callable3;
import metamodel.access.method.Callable4;
import metamodel.access.method.Callable5;
import metamodel.access.method.Callable6;
import metamodel.access.method.Callable7;
import metamodel.access.method.Callable8;
import metamodel.access.method.Callable9;
import metamodel.field.AbstractField;
import metamodel.method.Method0;
import metamodel.method.Method1;
import metamodel.method.Method10;
import metamodel.method.Method11;
import metamodel.method.Method12;
import metamodel.method.Method13;
import metamodel.method.Method14;
import metamodel.method.Method15;
import metamodel.method.Method16;
import metamodel.method.Method2;
import metamodel.method.Method3;
import metamodel.method.Method4;
import metamodel.method.Method5;
import metamodel.method.Method6;
import metamodel.method.Method7;
import metamodel.method.Method8;
import metamodel.method.Method9;

/**
 * Allows access of fields and methods of object instances, even if they are private. Use it as follows:
 *
 * 
 * // field manipulation
 * ObjectAccessor.on(targetObject).field(TargetObject_.field).set(42);
 * int fortyTwo = ObjectAccessor.on(targetObject).field(TargetObject_.field).get();
 * 
 * // method invocation
 * ObjectAccessor.on(targetObject).method(TargetObject_.aVoidMethod).invoke("Hello World!");
 * int fortyTwo = ObjectAccessor.on(targetObject).method(TargetObject_.getField).invoke();
 * 
 * // this is an example class that the above ObjectAccessor example uses
 * class TargetObject {
 * 	private int field;
 * 
 * 	private int getField() {
 * 		return field;
 * 	}
 * }
 * 
* * @author Michael Kroll * @param type of object to be accessed */ public class ObjectAccessor { /** object to be accessed. */ private final BASE object; protected ObjectAccessor(final BASE object) { this.object = object; } public FieldAccessor field(final AbstractField fieldDefinition) { return new FieldAccessor<>(object, fieldDefinition); } public Callable0 method(final Method0 methodDefinition) { return new Callable0<>(object, methodDefinition); } public Callable1 method(final Method1 methodDefinition) { return new Callable1<>(object, methodDefinition); } public Callable2 method(final Method2 methodDefinition) { return new Callable2<>(object, methodDefinition); } public Callable3 method( final Method3 methodDefinition) { return new Callable3<>(object, methodDefinition); } public Callable4 method( final Method4 methodDefinition) { return new Callable4<>(object, methodDefinition); } public Callable5 method( final Method5 methodDefinition) { return new Callable5<>(object, methodDefinition); } public Callable6 method( final Method6 methodDefinition) { return new Callable6<>(object, methodDefinition); } public Callable7 method( final Method7 methodDefinition) { return new Callable7<>(object, methodDefinition); } public Callable8 method( final Method8 methodDefinition) { return new Callable8<>(object, methodDefinition); } public Callable9 method( final Method9 methodDefinition) { return new Callable9<>(object, methodDefinition); } public Callable10 method( final Method10 methodDefinition) { return new Callable10<>(object, methodDefinition); } public Callable11 method( final Method11 methodDefinition) { return new Callable11<>(object, methodDefinition); } public Callable12 method( final Method12 methodDefinition) { return new Callable12<>(object, methodDefinition); } public Callable13 method( final Method13 methodDefinition) { return new Callable13<>(object, methodDefinition); } public Callable14 method( final Method14 methodDefinition) { return new Callable14<>(object, methodDefinition); } public Callable15 method( final Method15 methodDefinition) { return new Callable15<>(object, methodDefinition); } public Callable16 method( final Method16 methodDefinition) { return new Callable16<>(object, methodDefinition); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy