Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Criteria. Rename Criteria to Matcher (all classes except generated ones)
- Loading branch information
1 parent
3bc0e14
commit 0f64e8a
Showing
12 changed files
with
90 additions
and
82 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
2 changes: 1 addition & 1 deletion
2
...criteria/constraints/CriteriaContext.java → ...les/criteria/matcher/CriteriaContext.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
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
2 changes: 1 addition & 1 deletion
2
...les/criteria/constraints/Disjunction.java → ...utables/criteria/matcher/Disjunction.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
35 changes: 35 additions & 0 deletions
35
criteria/common/src/org/immutables/criteria/matcher/Matchers.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,35 @@ | |||
package org.immutables.criteria.matcher; | |||
|
|||
import org.immutables.criteria.expression.Expression; | |||
|
|||
import java.lang.reflect.Field; | |||
import java.util.Arrays; | |||
import java.util.Objects; | |||
|
|||
public class Matchers { | |||
|
|||
|
|||
/** | |||
* Hacky (and temporary) reflection until we define proper sub-classes for criterias | |||
* (to hide Expressional implementation). | |||
*/ | |||
static Expression extract(Object object) { | |||
Objects.requireNonNull(object, "object"); | |||
try { | |||
Class<?> current = object.getClass(); | |||
while(current.getSuperclass() != null){ | |||
if (Arrays.stream(current.getDeclaredFields()).anyMatch(f -> f.getName().equals("context"))) { | |||
Field field = current.getDeclaredField("context"); | |||
field.setAccessible(true); | |||
CriteriaContext<?> context = (CriteriaContext<?>) field.get(object); | |||
return context.expression(); | |||
} | |||
current = current.getSuperclass(); | |||
} | |||
} catch (NoSuchFieldException|IllegalAccessException e) { | |||
throw new RuntimeException("No field in " + object.getClass().getName(), e); | |||
} | |||
|
|||
throw new UnsupportedOperationException("No field context found in " + object.getClass().getName()); | |||
} | |||
} |
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