Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasstamann committed Oct 9, 2023
2 parents 709599f + ce3ad83 commit 7a85b36
Show file tree
Hide file tree
Showing 12 changed files with 345 additions and 8 deletions.
95 changes: 94 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ All you have to do is to define a bunch of interfaces and to configure its "plum

# Restrictions
- fluent interfaces must not contain any cycles and must be strongly hierarchically
- fluent interfaces doesn't support parent interfaces at the moment, a solution to support this is currently in work.

# How does it work?

Expand Down Expand Up @@ -367,6 +366,100 @@ Default methods will be ignored during processing of fluent api and backing bean
- They can provide alternative ways to set a parameter by providing conversions of input parameters and internally calling fluent api methods.
- They can also be very helpful to provide methods for accessing/filtering/aggregate backing bean attributes.

### Using parent interfaces to share method declarations and backing bean fields declarations
It's possible to use parent interfaces to share fluent api method declarations in multiple interfaces:

```java
@FluentApiBackingBean
interface MyRootLevelBackingBean {

@FluentApiBackingBeanField("1st")
FirstInheritedBackingBean get1st();

@FluentApiBackingBeanField("2nd")
SecondInheritedBackingBean get2nd();

}


// Parent backing bean interface must not be annotated with FluentApiBackingBean annotation
interface MyReusedBackingBeanFields {

@FluentApiBackingBeanField("name")
String getName();

}


@FluentApiBackingBean
interface FirstInheritedBackingBean extends MyReusedBackingBeanFields {

@FluentApiBackingBeanField("1st")
String get1st();

}

@FluentApiBackingBean
interface SecondInheritedBackingBean extends MyReusedBackingBeanFields {

@FluentApiBackingBeanField("2nd")
String get2nd();

}


// Fluent Api interfaces
@FluentApiInterface(MyRootLevelBackingBean.class)
@FluentApiRoot
public interface MyRootInterface {

My1stInterface goto1st();

My2ndInterface goto2nd();

@FluentApiCommand(MyCommand.class)
void myCommand();


}

// Parent fluent api interface must not be annotated with FluentApiInterface
// There must be a related backing bean interface for related attributes
// Type Parameters must be used to pass in the followup fluent api interfaces
public interface SharedInterface<FLUENT_INTERFACE> {

// Fluebt followup interface must be returned as type variable
FLUENT_INTERFACE setName(@FluentApiBackingBeanMapping(value = "name") String name);

}


@FluentApiInterface(FirstInheritedBackingBean.class)
public interface My1stInterface extends SharedInterface<My1stInterface> {

@FluentApiParentBackingBeanMapping("1st")
MyRootInterface set1st(@FluentApiBackingBeanMapping(value = "1st") String first);

}

@FluentApiInterface(SecondInheritedBackingBean.class)
public interface My2ndInterface extends SharedInterface<My2ndInterface> {

@FluentApiParentBackingBeanMapping("2nd")
MyRootInterface set1st(@FluentApiBackingBeanMapping(value = "2nd") String second);

}

// Commands
@FluentApiCommand
static class MyCommand {
static void myCommand(MyRootLevelBackingBean backingBean) {
System.out.println("CHECK");
}
}
```


# Contributing

We welcome any kind of suggestions and pull requests.
Expand Down
2 changes: 1 addition & 1 deletion fluapigen-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>io.toolisticon.fluapigen</groupId>
<artifactId>fluapigen</artifactId>
<version>0.6.0</version>
<version>0.7.0</version>
</parent>

<name>fluapigen-api</name>
Expand Down
2 changes: 1 addition & 1 deletion fluapigen-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>io.toolisticon.fluapigen</groupId>
<artifactId>fluapigen</artifactId>
<version>0.6.0</version>
<version>0.7.0</version>
</parent>

<name>fluapigen-example</name>
Expand Down
2 changes: 1 addition & 1 deletion fluapigen-integrationTest/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>io.toolisticon.fluapigen</groupId>
<artifactId>fluapigen</artifactId>
<version>0.6.0</version>
<version>0.7.0</version>
</parent>

<name>fluapigen-integrationTest</name>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package io.toolisticon.fluapigen.integrationtest;

import io.toolisticon.fluapigen.api.FluentApi;
import io.toolisticon.fluapigen.api.FluentApiBackingBean;
import io.toolisticon.fluapigen.api.FluentApiBackingBeanField;
import io.toolisticon.fluapigen.api.FluentApiBackingBeanMapping;
import io.toolisticon.fluapigen.api.FluentApiCommand;
import io.toolisticon.fluapigen.api.FluentApiInterface;
import io.toolisticon.fluapigen.api.FluentApiParentBackingBeanMapping;
import io.toolisticon.fluapigen.api.FluentApiRoot;

import java.io.Serializable;

@FluentApi("InheritanceIntegrationTestStarter")
public class IntegrationTest_Inheritance_reusingInterfaces {

// Backing Bean Interface
@FluentApiBackingBean
interface MyRootLevelBackingBean {

@FluentApiBackingBeanField("1st")
FirstInheritedBackingBean get1st();

@FluentApiBackingBeanField("2nd")
SecondInheritedBackingBean get2nd();

}


interface MyReusedBackingBeanFields {

@FluentApiBackingBeanField("name")
String getName();

}


@FluentApiBackingBean
interface FirstInheritedBackingBean extends MyReusedBackingBeanFields {

@FluentApiBackingBeanField("1st")
String get1st();

}

@FluentApiBackingBean
interface SecondInheritedBackingBean extends MyReusedBackingBeanFields {

@FluentApiBackingBeanField("2nd")
String get2nd();

}


// Fluent Api interfaces
@FluentApiInterface(MyRootLevelBackingBean.class)
@FluentApiRoot
public interface MyRootInterface {

My1stInterface goto1st();

My2ndInterface goto2nd();

@FluentApiCommand(MyCommand.class)
MyRootLevelBackingBean myCommand();


}


public interface SharedInterface<FLUENT_INTERFACE> {

FLUENT_INTERFACE setName(@FluentApiBackingBeanMapping(value = "name") String name);

}


@FluentApiInterface(FirstInheritedBackingBean.class)
public interface My1stInterface extends SharedInterface<My1stInterface> {

@FluentApiParentBackingBeanMapping("1st")
MyRootInterface set1st(@FluentApiBackingBeanMapping(value = "1st") String first);

}

@FluentApiInterface(SecondInheritedBackingBean.class)
public interface My2ndInterface extends SharedInterface<My2ndInterface> {

@FluentApiParentBackingBeanMapping("2nd")
MyRootInterface set1st(@FluentApiBackingBeanMapping(value = "2nd") String second);

}

// Commands
@FluentApiCommand
static class MyCommand {
static MyRootLevelBackingBean myCommand(MyRootLevelBackingBean backingBean) {
System.out.println("CHECK");
return backingBean;
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -353,4 +353,10 @@ public void test_fluentApi_test_toParentTraversal() {

}

@Test
public void testInheritance() {
IntegrationTest_Inheritance_reusingInterfaces.MyRootLevelBackingBean bb = InheritanceIntegrationTestStarter.goto1st().setName("1stName").set1st("1").goto2nd().setName("2ndName").set1st("2").myCommand();
MatcherAssert.assertThat(bb, Matchers.notNullValue());
}

}
2 changes: 1 addition & 1 deletion fluapigen-processor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>io.toolisticon.fluapigen</groupId>
<artifactId>fluapigen</artifactId>
<version>0.6.0</version>
<version>0.7.0</version>
</parent>

<name>fluapigen-processor</name>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package io.toolisticon.fluapigen.processor;

import io.toolisticon.aptk.compilermessage.api.DeclareCompilerMessage;
import io.toolisticon.aptk.tools.InterfaceUtils;
import io.toolisticon.aptk.tools.corematcher.AptkCoreMatchers;
import io.toolisticon.aptk.tools.wrapper.ElementWrapper;
import io.toolisticon.aptk.tools.wrapper.ExecutableElementWrapper;
import io.toolisticon.aptk.tools.wrapper.TypeElementWrapper;

import javax.lang.model.element.Modifier;
import javax.lang.model.element.TypeElement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
Expand All @@ -25,6 +28,12 @@ public class ModelBackingBean implements FetchImports, Validatable{
ModelBackingBean(FluentApiBackingBeanWrapper wrapper) {
this.wrapper = wrapper;

fields = InterfaceUtils.getMethodsToImplement(TypeElementWrapper.wrap((TypeElement) wrapper._annotatedElement()))
.stream().filter(e -> !e.isDefault())
.map(ModelBackingBeanField::new)
.collect(Collectors.toList());

/*-
fields = ElementWrapper.wrap(wrapper._annotatedElement())
.filterEnclosedElements().applyFilter(AptkCoreMatchers.IS_METHOD)
.applyFilter(AptkCoreMatchers.BY_MODIFIER).filterByNoneOf(Modifier.DEFAULT).getResult()
Expand All @@ -33,6 +42,8 @@ public class ModelBackingBean implements FetchImports, Validatable{
.map(ModelBackingBeanField::new)
.collect(Collectors.toList());
*/

// init render state helper
RenderStateHelper.addBackingBeanModel(this);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.toolisticon.fluapigen.processor;

import io.toolisticon.aptk.compilermessage.api.DeclareCompilerMessage;
import io.toolisticon.aptk.tools.InterfaceUtils;
import io.toolisticon.aptk.tools.TypeMirrorWrapper;
import io.toolisticon.aptk.tools.TypeUtils;
import io.toolisticon.aptk.tools.corematcher.AptkCoreMatchers;
Expand Down Expand Up @@ -35,8 +36,16 @@ public class ModelInterface implements FetchImports, Validatable {
this.wrapper = wrapper;
this.backingBeanModel = backingBeanModel;


for (ExecutableElementWrapper executableElement : InterfaceUtils.getMethodsToImplement(TypeElementWrapper.wrap((TypeElement) this.wrapper._annotatedElement())) ){

if (executableElement.isDefault()) {
// ignore default methods
continue;
}
//}
// get Methods
for (ExecutableElementWrapper executableElement : FluentElementFilter.createFluentElementFilter(this.wrapper._annotatedElement().getEnclosedElements()).applyFilter(AptkCoreMatchers.IS_METHOD).applyFilter(AptkCoreMatchers.BY_MODIFIER).filterByNoneOf(Modifier.DEFAULT).getResult().stream().map(ExecutableElementWrapper::wrap).collect(Collectors.toList())) {
//for (ExecutableElementWrapper executableElement : FluentElementFilter.createFluentElementFilter(this.wrapper._annotatedElement().getEnclosedElements()).applyFilter(AptkCoreMatchers.IS_METHOD).applyFilter(AptkCoreMatchers.BY_MODIFIER).filterByNoneOf(Modifier.DEFAULT).getResult().stream().map(ExecutableElementWrapper::wrap).collect(Collectors.toList())) {
methods.add(new ModelInterfaceMethod(executableElement, backingBeanModel));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,4 +395,15 @@ public void test_invalid_BackingBeanMappingConverter_wrongCollectionValueTarget(

}

@Test
public void test_Inheritance_reusingInterfaces() {

compileTestBuilder
.addSources(JavaFileObjectUtils.readFromResource("testcases/IntegrationTest_Inheritance_reusingInterfaces.java"))
.compilationShouldSucceed()
.executeTest();


}

}
Loading

0 comments on commit 7a85b36

Please sign in to comment.