Skip to content

Commit

Permalink
works with field annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
verhas committed Jun 24, 2019
1 parent ad3cf4a commit 6605a22
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 12 deletions.
Expand Up @@ -17,6 +17,7 @@
public class AbstractAccessor extends AbstractFilteredFieldsGenerator {

protected static class Config {
protected String mnemonic = "";
protected String access = "public";
protected String filter = "true";
protected String getter = null;
Expand Down Expand Up @@ -110,6 +111,7 @@ public static AbstractAccessor.Builder builder() {
"access",
"filter",
"getter",
"mnemonic",
"only",
"setter",
"id"
Expand Down Expand Up @@ -145,6 +147,11 @@ public Builder getterReturnValueDecorator(java.util.function.Function<String,Str
return this;
}

public Builder mnemonic(String mnemonic) {
config.mnemonic = mnemonic;
return this;
}

public Builder only(String only) {
config.only = only;
return this;
Expand Down Expand Up @@ -176,6 +183,7 @@ private Config localConfig(CompoundParams params){
local.getter = params.get("getter",config.getter);
local.getterNameGenerator = config.getterNameGenerator;
local.getterReturnValueDecorator = config.getterReturnValueDecorator;
local.mnemonic = params.get("mnemonic",config.mnemonic);
local.only = params.get("only",config.only);
local.processAllClasses = config.processAllClasses;
local.setter = params.get("setter",config.setter);
Expand Down
Expand Up @@ -6,6 +6,10 @@

public class Accessor extends AbstractAccessor {

public Accessor(){
config.mnemonic = "accessor";
}


@Override
protected void writeSetter(Field field, String name, String setterName,
Expand All @@ -20,7 +24,7 @@ protected void writeSetter(Field field, String name, String setterName,

@Override
public String mnemonic() {
return "accessor";
return config.mnemonic;
}


Expand Down
Expand Up @@ -15,6 +15,7 @@ public class ChainedAccessor extends AbstractAccessor {

public ChainedAccessor(){
config.setterNameGenerator = name -> "with" + ucase(name);
config.mnemonic = "caccessor";
}

@Override
Expand All @@ -35,6 +36,6 @@ public static AbstractAccessor.Builder builder() {
}
@Override
public String mnemonic() {
return "caccessor";
return config.mnemonic;
}
}
@@ -0,0 +1,8 @@
package javax0.geci.tests.accessors;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

@Retention(RetentionPolicy.RUNTIME)
public @interface Getter {
}
@@ -1,12 +1,6 @@
package javax0.geci.tests.accessors;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

public class NeedAccessorFieldAnnotatedOnly {
@Retention(RetentionPolicy.RUNTIME)
public @interface Getter {
}

@Getter
private final String apple = "";
Expand All @@ -16,9 +10,7 @@ public class NeedAccessorFieldAnnotatedOnly {

protected boolean truth;
protected int not_this;


//<editor-fold id="accessor">
//<editor-fold id="SettersGetters">
public String getApple(){
return apple;
}
Expand Down
Expand Up @@ -27,7 +27,7 @@ public void testAllSourcesAccessor() throws Exception {
Assertions.assertFalse(
(geci = new Geci()).source(
maven().module("javageci-examples").mainSource()
).register(Accessor.builder().filter("annotation ~ /Getter|Setter/").processAllClasses(true).build()).generate(),
).register(Accessor.builder().mnemonic("SettersGetters").filter("annotation ~ /Getter|Setter/").processAllClasses(true).build()).generate(),
geci.failed());
}

Expand Down

0 comments on commit 6605a22

Please sign in to comment.