All Projects → skydoves → MethodScope

skydoves / MethodScope

Licence: Apache-2.0 license
Reduce repetitive inheritance works in OOP world using @MethodScope.

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to MethodScope

simple-annotation-processor
Simple annotation processor example. Inspired by the idea of "How ButterKnife works?"
Stars: ✭ 54 (+63.64%)
Mutual labels:  annotation, annotation-processor, annotation-processing
AnnotationProcessing
✔️ㅤ[ARTICLE] Writing your own Annotation Processors in Android
Stars: ✭ 47 (+42.42%)
Mutual labels:  annotation, annotation-processor, annotation-processing
AnnotationProcessorStarter
Project to set up basics of a Java annotation processor
Stars: ✭ 19 (-42.42%)
Mutual labels:  annotation, annotation-processor, annotation-processing
RapidORM
Quick solutions for Android ORM
Stars: ✭ 24 (-27.27%)
Mutual labels:  annotation-processor, annotation-processing
piri
Piri is a lightweight annotation processing library that generates static factory methods for your Activities and Fragments.
Stars: ✭ 53 (+60.61%)
Mutual labels:  annotation-processor, annotation-processing
generate-kotlin-multiple-rounds
Android sample project demonstrating how to generate Kotlin code through annotation processing, and then feeding it into a second round of annotation processing.
Stars: ✭ 25 (-24.24%)
Mutual labels:  annotation-processor, annotation-processing
Placeholderview
This library provides advance views for lists and stacks. Some of the views are build on top of RecyclerView and others are written in their own. Annotations are compiled by annotation processor to generate bind classes. DOCS -->
Stars: ✭ 2,104 (+6275.76%)
Mutual labels:  annotation-processor, annotation-processing
dagger2-ktx
Kotlin extension bridge library for Dagger2 (proof-of-concept)
Stars: ✭ 41 (+24.24%)
Mutual labels:  annotation-processor, annotation-processing
aptk
A toolkit project to enable you to build annotation processors more easily
Stars: ✭ 28 (-15.15%)
Mutual labels:  annotation, annotation-processor
shade
Automatic code generation for the SharedPreferences operation.
Stars: ✭ 26 (-21.21%)
Mutual labels:  annotation, annotation-processing
annotation-processor-sample
An annotation processor which implements "Builder pattern" for your java classes.
Stars: ✭ 22 (-33.33%)
Mutual labels:  annotation, annotation-processor
Kotlin-Annotation-Processor
Annotation Processor Sample in Kotlin
Stars: ✭ 19 (-42.42%)
Mutual labels:  annotation-processor, annotation-processing
annotate
Create 3D labelled bounding boxes in RViz
Stars: ✭ 104 (+215.15%)
Mutual labels:  annotation
copydynamic
Prototype of generating `copyDynamic` extension functions for kotlin data classes
Stars: ✭ 57 (+72.73%)
Mutual labels:  annotation-processing
green-annotations
An Android Annotations plugin to support Green Robot.
Stars: ✭ 21 (-36.36%)
Mutual labels:  annotation-processor
piaf
Question Answering annotation platform - Plateforme d'annotation
Stars: ✭ 62 (+87.88%)
Mutual labels:  annotation
fit
easy storage Object on SharedPreferences
Stars: ✭ 53 (+60.61%)
Mutual labels:  annotation
BACTpipe
BACTpipe: An assembly and annotation pipeline for bacterial genomics
Stars: ✭ 19 (-42.42%)
Mutual labels:  annotation
MS-CleanR
No description or website provided.
Stars: ✭ 21 (-36.36%)
Mutual labels:  annotation
ensembldb
This is the ensembldb development repository.
Stars: ✭ 31 (-6.06%)
Mutual labels:  annotation

MethodScope

License API Build Status

Methodscope automatically generates classes that perform similar function tasks on a per-scope basis for a class.
When similar and repetitive classes need to be created, the work what repetitive inheritance can be decreased.

methodscope

Including in your project

Download

Gradle

And add below two dependencies code on your module's build.gradle file.

dependencies {
    implementation "com.github.skydoves:methodscope:1.0.1"
    annotationProcessor "com.github.skydoves:methodscope-processor:1.0.1"
}

Usage

@MethodScope

Create a custom scope annotation using @MethodScope annotation.

@MethodScope
public @interface MyScope {
}

Here is the kotlin code example.

@MethodScope
annotation class MyScope

Attach the custom scope annotation on top of a class.
All of the public methods are the base method for the scoped like the init() method.
And designate scoping method using @Scoped annotation with the naming rule what startWith the base method's name.

@MyScope
public class MyClass {
  private String scope;

  public void init() { // this is the base method of the scoped methods.
    this.scope = "initialized";
  }

  @Scoped(MyScope.class)
  public void initMyScope() { // this is a scoped method for @MyScope.
    this.scope = "initialized by @MyScope";
  }
}

After build the project, MyClass_MyScope class will be auto-generated.

MyClass_MyScope myClass_myScope = new MyClass_MyScope();
myClass_myScope.init(); // calls init() and initMyScope() methods.
myClass_myScope.initMyScope(); // calls only initMyScope() method.

Multiple Scoping

Here is how to create multiple scoped class.

@MyScope
@HisScope
@YourScope
public class MyClass {
  private String scope;

  public void init() { // this is the base method of the scoped methods.
    this.scope = "initialized";
  }

  @Scoped(MyScope.class)
  public void initMyScope() { // this is a scoped method for @MyScope.
    this.scope = "initialized by @MyScope";
  }

  @Scoped(YourScope.class)
  public void initMineScopeNotYours() { // this is a scoped method for @YourScope.
    this.scope = "initialized by @YourScope";
  }
}

After build the project, MyClass_MyScope, MyClass_HisScope, MyClass_YourScope classes will be auto-generated.

Scoping with a return type and parameters

Methods that have a return type and parameters can be scoped method.
The base method's return type and parameters are must be the same as the scoped method's one.

@MyScope
abstract public class MyClass {
  private String scope;

  public String init(String text) { // this is the base method of the scoped methods.
    this.scope += text;
    return this.scope;
  }

  @Scoped(MyScope.class)
  public String initMyScope(String text) { // this is a scoped method for @MyScope.
    this.scope += text;
    return this.scope;
  }

Abstract class Scoping

MethodScope supports scopping for the abstract class.
This is more clear because the base method of the scoped methods is being explicitly abstract.

@MyScope
@YourScope
abstract public class MyClass {
  private String scope;

  abstract void init();

  @Scoped(MyScope.class)
  public void initMyScope() { // this is a scoped method for @MyScope.
    this.scope = "initialized by @MyScope";
  }

  @Scoped(YourScope.class)
  public void initMineScopeNotYours() { // this is a scoped method for @YourScope.
    this.scope = "initialized by @YourScope";
  }

Android Project Usage

MethodScope is useful to the Android project for creating similar screens.

methodscope_android

Basic example

@MyScope
@TestScope(deeplink = DeepLink("https://github.com/skydoves"))
abstract class MainActivity : AppCompatActivity() {

    private lateinit var hello: String

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        init() // calls the base method. this will call each scoped method in the scoped class.
    }

    open fun init() {
        hello = "hello, "
    }

    @Scoped(MyScope::class)
    fun initMyScope() {
        setContentView(R.layout.activity_main_myscope) // setContentView for MyScope.
        text_message_myscope.text = hello + "MyScope" // changes text of the textView.
    }

    @Scoped(TestScope::class)
    fun initTestScope() {
        setContentView(R.layout.activity_main_testscope) // setContentView for TestScope.
        text_message_testscope.text = hello + "TestScope" // changes text of the textView.
    }
}

And on the AndroidManifest.xml, we should declare new generated activities.

<activity android:name=".MainActivity_MyScope" />
<activity android:name=".MainActivity_TestScope" />

And then we can use the new activities.

val intent = Intent(this, MainActivity_MyScope::class.java)
startActivity(intent)

License

Copyright 2019 skydoves

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].