
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 super BASE, TYPE> fieldDefinition) {
return new FieldAccessor<>(object, fieldDefinition);
}
public
© 2015 - 2025 Weber Informatics LLC | Privacy Policy