All Projects → Genymobile → Mirror

Genymobile / Mirror

Licence: apache-2.0
Easy reflection for Java and Android

Programming Languages

java
68154 projects - #9 most used programming language
reflection
70 projects

Projects that are alternatives of or similar to Mirror

Cosmonaut
🌐 A supercharged Azure CosmosDB .NET SDK with ORM support
Stars: ✭ 309 (-4.63%)
Mutual labels:  library
Consistency
The Hoa\Consistency library.
Stars: ✭ 317 (-2.16%)
Mutual labels:  library
Jackrabbit Oak
Mirror of Apache Jackrabbit Oak
Stars: ✭ 321 (-0.93%)
Mutual labels:  library
Grabana
User-friendly Go library for building Grafana dashboards
Stars: ✭ 313 (-3.4%)
Mutual labels:  library
Gokv
Simple key-value store abstraction and implementations for Go (Redis, Consul, etcd, bbolt, BadgerDB, LevelDB, Memcached, DynamoDB, S3, PostgreSQL, MongoDB, CockroachDB and many more)
Stars: ✭ 314 (-3.09%)
Mutual labels:  library
Circle Menu
⭕️ CircleMenu is a simple, elegant UI menu with a circular layout and material design animations. Swift UI library made by @Ramotion
Stars: ✭ 3,306 (+920.37%)
Mutual labels:  library
Protocol
The Hoa\Protocol library.
Stars: ✭ 308 (-4.94%)
Mutual labels:  library
Tensorflow Windows Wheel
Tensorflow prebuilt binary for Windows
Stars: ✭ 3,428 (+958.02%)
Mutual labels:  library
Exception
The Hoa\Exception library.
Stars: ✭ 316 (-2.47%)
Mutual labels:  library
Event
The Hoa\Event library
Stars: ✭ 319 (-1.54%)
Mutual labels:  library
Android Permissions
Library for easy handling of android run-time permissions.
Stars: ✭ 311 (-4.01%)
Mutual labels:  library
Pulseview
Widget that generates pulsation relative to your icons. Tinder search like.
Stars: ✭ 315 (-2.78%)
Mutual labels:  library
Bem Components
Set of components for sites development
Stars: ✭ 318 (-1.85%)
Mutual labels:  library
Gerador Validador Cpf
Biblioteca JS open-source para gerar e validar CPF.
Stars: ✭ 312 (-3.7%)
Mutual labels:  library
React Component Library
A project skeleton to get your very own React Component Library up and running using Rollup, Typescript, SASS + Storybook
Stars: ✭ 313 (-3.4%)
Mutual labels:  library
Regex
The Hoa\Regex library.
Stars: ✭ 308 (-4.94%)
Mutual labels:  library
Klib
A standalone and lightweight C library
Stars: ✭ 3,442 (+962.35%)
Mutual labels:  library
File
The Hoa\File library.
Stars: ✭ 322 (-0.62%)
Mutual labels:  library
Tintlayout
This library help you to achieve popular drop shadow effect from view.
Stars: ✭ 322 (-0.62%)
Mutual labels:  library
Fcharts
📊 [wip] Create beautiful, responsive, animated charts using a simple and intuitive API.
Stars: ✭ 318 (-1.85%)
Mutual labels:  library

MirrorMirror

Easy reflection for Java and Android

Introduction

Mirror turns a private class you want to use reflection on into a Java interface.

@Class("com.framework.PrivateCoolClass")
public interface CoolClass {
    @Constructor
    void callConstructor(String aString);

    // A cool method, we want to call
    String doCoolStuff(int value);
}

The Mirror class generates an implementation of the CoolClass interface.

CoolClass coolClass = Mirror.create(CoolClass.class)

You'll need to set up the wrapper with an instance first, for example by calling a constructor.

coolClass.callConstructor("Super"); // this call the PrivateCoolClass(String) constructor;

Each call on the generated CoolClass wrapper makes a call on the instance of PrivateCoolClass.

// This will call the method doCoolStuff(int) on the PrivateCoolClass Object
String cool = coolClass.doCoolStuff(42);

Refection annotations

Use Mirror's annotations to describe your object wrapper and how you want to interact with it.

Declaring the private Class

Use the Class annotation to setup the class you want to use reflection on.

@Class("com.framework.private.PrivateClass")
public interface NotSoPrivateClass {
  ...
}

Instance management

Each wrapper needs to be fed with an instance before any other call.

@Constructor
void callConstructor(String aString);
// or
@SetInstance
void setInstance(Object object);

There are two way for setting an instance into a wrapper:

  • Calling a Constructor annotated method that will create the instance using the constructor matching the exact same parameters.
  • Calling a SetInstance annotated method that will use this object as the instance.

If you need to retrieve the instance, simply add a method annotated with GetInstance returning an object.

@GetInstance
Object getInstance();

Calling methods

If not annotated, a method will be directly called on the instance using the exact same signature.

Playing with fields

SetField and GetField can be used to set and get fields from the instance. Both annotation needs the name of the field to work.

@GetField("aField")
Object getField();

@SetField("aField")
void setField(String aString);

Download

Gradle:

compile 'com.genymobile:mirror:1.0.0'

Mirror requires at minimum Java 7.

Cool but wait... Warning!

This is super slow. Everything is done at runtime (internal reflexion, wrapping...) so don't use this for intensive work. The main goal of this library is to give a tool to quickly play with reflexion and private APIs, classes... and software prototyping.

What next?

There is still some refactoring to do, plenty of bugs to fix, safety checks to implements. Maybe a v2 with code generation to get rid of the performance issue. Anyway, do not hesitate to file bugs or contribute.

License

Copyright 2016 Genymobile

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.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].