-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
615 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
...egrationTest/src/main/java/io/toolisticon/fluapigen/integrationtest/ValidatorExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
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.FluentApiRoot; | ||
import io.toolisticon.fluapigen.validation.api.Matches; | ||
import io.toolisticon.fluapigen.validation.api.MaxLength; | ||
import io.toolisticon.fluapigen.validation.api.NotNull; | ||
|
||
@FluentApi("ValidatorExampleStarter") | ||
public class ValidatorExample { | ||
|
||
// Backing Bean Interface | ||
@FluentApiBackingBean | ||
interface MyBackingBean { | ||
|
||
@FluentApiBackingBeanField("name") | ||
String getName(); | ||
|
||
} | ||
|
||
// Fluent Api interfaces | ||
@FluentApiInterface(MyBackingBean.class) | ||
@FluentApiRoot | ||
public interface MyRootInterface { | ||
|
||
MyRootInterface setName(@NotNull @MaxLength(8) @Matches("aaa.*") @FluentApiBackingBeanMapping("name") String name); | ||
|
||
@FluentApiCommand(MyCommand.class) | ||
void myCommand(); | ||
|
||
} | ||
|
||
// Commands | ||
@FluentApiCommand | ||
static class MyCommand { | ||
static void myCommand(MyBackingBean backingBean) { | ||
System.out.println(backingBean.getName()); | ||
} | ||
} | ||
|
||
|
||
} |
21 changes: 21 additions & 0 deletions
21
...tionTest/src/test/java/io/toolisticon/fluapigen/integrationtest/ValidatorExampleTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package io.toolisticon.fluapigen.integrationtest; | ||
|
||
import org.junit.Test; | ||
|
||
public class ValidatorExampleTest { | ||
|
||
@Test(expected = RuntimeException.class) | ||
public void testValidator_failingValidation() { | ||
|
||
ValidatorExampleStarter.setName("bbbadadadsd").myCommand(); | ||
|
||
} | ||
|
||
@Test() | ||
public void testValidator() { | ||
|
||
ValidatorExampleStarter.setName("aaaBDSXS").myCommand(); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
fluapigen-processor/src/main/java/io/toolisticon/fluapigen/processor/ModelValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package io.toolisticon.fluapigen.processor; | ||
|
||
import io.toolisticon.aptk.common.ToolingProvider; | ||
import io.toolisticon.aptk.tools.TypeMirrorWrapper; | ||
import io.toolisticon.aptk.tools.corematcher.AptkCoreMatchers; | ||
import io.toolisticon.aptk.tools.wrapper.AnnotationMirrorWrapper; | ||
import io.toolisticon.aptk.tools.wrapper.AnnotationValueWrapper; | ||
import io.toolisticon.aptk.tools.wrapper.TypeElementWrapper; | ||
|
||
import javax.lang.model.element.ExecutableElement; | ||
import java.util.List; | ||
|
||
public class ModelValidator { | ||
|
||
|
||
private final AnnotationMirrorWrapper validatorAnnotation; | ||
|
||
public ModelValidator(AnnotationMirrorWrapper validatorAnnotation) { | ||
this.validatorAnnotation = validatorAnnotation; | ||
} | ||
|
||
FluentApiValidatorWrapper getValidatorAnnotation() { | ||
return FluentApiValidatorWrapper.wrap(this.validatorAnnotation.asElement().unwrap()); | ||
} | ||
|
||
// TODO NOT USED YET, MUST BE IMPLEMENTED | ||
public boolean validate() { | ||
// must check if parameter types are assignable | ||
FluentApiValidatorWrapper validatorMetaAnnotation = getValidatorAnnotation(); | ||
TypeMirrorWrapper validatorImplType = validatorMetaAnnotation.valueAsTypeMirrorWrapper(); | ||
String[] parameterNames = validatorMetaAnnotation.parameterNames(); | ||
|
||
if (parameterNames.length > 0) { | ||
|
||
} else if (!validatorImplType.getTypeElement().isPresent()) { | ||
// couldn't get type element | ||
} else { | ||
// must have a noarg constructor or just the default | ||
TypeElementWrapper validatorImplTypeElement = validatorImplType.getTypeElement().get(); | ||
boolean hasNoargConstructor = validatorImplTypeElement.filterEnclosedElements().applyFilter(AptkCoreMatchers.IS_CONSTRUCTOR).applyFilter(AptkCoreMatchers.HAS_NO_PARAMETERS).getResult().size() == 1; | ||
boolean hasJustDefaultConstructor = validatorImplTypeElement.filterEnclosedElements().applyFilter(AptkCoreMatchers.IS_CONSTRUCTOR).hasSize(0); | ||
|
||
if (! ( hasNoargConstructor || hasJustDefaultConstructor)) { | ||
//ToolingProvider.getTooling().getMessager(). | ||
//this.validatorAnnotation. | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
|
||
public String validatorExpression() { | ||
StringBuilder stringBuilder = new StringBuilder(); | ||
stringBuilder.append("new ").append(getValidatorAnnotation().valueAsFqn()).append("("); | ||
|
||
boolean isFirst = true; | ||
for (String parameterName : getValidatorAnnotation().parameterNames()) { | ||
|
||
// add separator | ||
if (!isFirst) { | ||
stringBuilder.append(", "); | ||
} else { | ||
isFirst = false; | ||
} | ||
|
||
AnnotationValueWrapper attribute = validatorAnnotation.getAttributeWithDefault(parameterName); | ||
|
||
if (attribute.isString()) { | ||
stringBuilder.append("\"").append(attribute.getStringValue()).append("\""); | ||
} else if (attribute.isClass()) { | ||
stringBuilder.append(attribute.getClassValue().getQualifiedName()).append(".class"); | ||
} else if (attribute.isInteger()) { | ||
stringBuilder.append(attribute.getIntegerValue()); | ||
} else if (attribute.isLong()) { | ||
stringBuilder.append(attribute.getLongValue()).append("L"); | ||
} else if (attribute.isBoolean()) { | ||
stringBuilder.append(attribute.getBooleanValue()); | ||
} else if (attribute.isFloat()) { | ||
stringBuilder.append(attribute.getFloatValue()).append("f"); | ||
} else if (attribute.isDouble()) { | ||
stringBuilder.append(attribute.getFloatValue()); | ||
} else if (attribute.isEnum()) { | ||
stringBuilder.append(TypeElementWrapper.toTypeElement(attribute.getEnumValue().getEnclosingElement().get()).getQualifiedName()); | ||
stringBuilder.append("."); | ||
stringBuilder.append(attribute.getEnumValue().getSimpleName()); | ||
} | ||
|
||
} | ||
|
||
stringBuilder.append(")"); | ||
return stringBuilder.toString(); | ||
} | ||
|
||
public String getValidatorSummary() { | ||
return validatorAnnotation.getStringRepresentation(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.