forked from apache/incubator-kie-drools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Type protocols/"specs" as hints to compilation stage (#15)
* 2 step fwd 1 step back * Hard-coded, but working. * Less hard-coding, working. * Should no longer have hard-coding, and working. * Draft of working version. * Refactorings. * Basic support for Maps. * Refactoring to use FEEL Type for hierarchical type definition * WIP hierarchical. * Removing unnecessary changes. * Removing scratchpad tests. * Moving determineTypeFromClass from Type interface to ParserHelper class. * Was static class in interface "Field", now "Property" interface+impl. * Was "FEELAccessor", now "FEELProperty".
- Loading branch information
Showing
16 changed files
with
472 additions
and
10 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/CustomType.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,9 @@ | ||
package org.kie.dmn.feel.lang; | ||
|
||
import java.util.Map; | ||
|
||
public interface CustomType extends Type { | ||
|
||
Map<String, Property> getProperties(); | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/FEELProperty.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,15 @@ | ||
package org.kie.dmn.feel.lang; | ||
|
||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
|
||
@Retention(RUNTIME) | ||
@Target(ElementType.METHOD) | ||
public @interface FEELProperty { | ||
|
||
String value(); | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/Property.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,10 @@ | ||
package org.kie.dmn.feel.lang; | ||
|
||
|
||
public interface Property { | ||
|
||
String getName(); | ||
|
||
Type getType(); | ||
|
||
} |
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
49 changes: 49 additions & 0 deletions
49
kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/impl/JavaBackedType.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,49 @@ | ||
package org.kie.dmn.feel.lang.impl; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Stream; | ||
|
||
import org.kie.dmn.feel.lang.CustomType; | ||
import org.kie.dmn.feel.lang.FEELProperty; | ||
import org.kie.dmn.feel.lang.Property; | ||
import org.kie.dmn.feel.parser.feel11.ParserHelper; | ||
|
||
public class JavaBackedType implements CustomType { | ||
private Class<?> wrapped; | ||
private Map<String, Property> properties = new HashMap<>(); | ||
|
||
public JavaBackedType(Class<?> class1) { | ||
this.wrapped = class1; | ||
Stream.of( class1.getMethods() ) | ||
.filter( m -> m.getAnnotation(FEELProperty.class) != null ) | ||
.forEach( m -> properties.put( m.getAnnotation(FEELProperty.class).value() , new PropertyImpl( m.getAnnotation(FEELProperty.class).value() , ParserHelper.determineTypeFromClass(m.getReturnType()) ) ) ); | ||
; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return wrapped.getName(); | ||
} | ||
|
||
@Override | ||
public Object fromString(String value) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public String toString(Object value) { | ||
return null; | ||
} | ||
|
||
public Class<?> getWrapped() { | ||
return wrapped; | ||
} | ||
|
||
@Override | ||
public Map<String, Property> getProperties() { | ||
return this.properties; | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/impl/MapBackedType.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,58 @@ | ||
package org.kie.dmn.feel.lang.impl; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.kie.dmn.feel.lang.CustomType; | ||
import org.kie.dmn.feel.lang.Property; | ||
import org.kie.dmn.feel.lang.Type; | ||
import org.kie.dmn.feel.parser.feel11.ParserHelper; | ||
|
||
public class MapBackedType implements CustomType { | ||
|
||
private Map<String, Property> properties = new HashMap<>(); | ||
|
||
public MapBackedType() { | ||
} | ||
|
||
/** | ||
* Utility constructor by reflection over key-value pairs. | ||
* @param fields | ||
*/ | ||
public MapBackedType(Map<String, ?> map) { | ||
map.entrySet().stream() | ||
.map( kv -> new PropertyImpl( kv.getKey(), ParserHelper.determineTypeFromClass( kv.getValue().getClass()) ) ) | ||
.forEach( f -> properties.put( f.getName(), f ) ); | ||
} | ||
|
||
public MapBackedType(List<Property> properties) { | ||
properties.stream().forEach(p -> this.properties.put(p.getName(), p) ); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public Object fromString(String value) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public String toString(Object value) { | ||
return null; | ||
} | ||
|
||
public MapBackedType addField(String name, Type type) { | ||
properties.put( name, new PropertyImpl(name, type) ); | ||
return this; | ||
} | ||
|
||
@Override | ||
public Map<String, Property> getProperties() { | ||
return properties; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/impl/PropertyImpl.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,26 @@ | ||
package org.kie.dmn.feel.lang.impl; | ||
|
||
import org.kie.dmn.feel.lang.Property; | ||
import org.kie.dmn.feel.lang.Type; | ||
|
||
|
||
public class PropertyImpl implements Property { | ||
private final String name; | ||
private final Type type; | ||
|
||
public PropertyImpl(String name, Type type) { | ||
super(); | ||
this.name = name; | ||
this.type = type; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
@Override | ||
public Type getType() { | ||
return type; | ||
} | ||
} |
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
Oops, something went wrong.