Skip to content

Commit 4e4b461

Browse files
committed
Prototype Annotation API
1 parent c9d801c commit 4e4b461

31 files changed

Lines changed: 1634 additions & 22 deletions

File tree

‎api/src/main/java/org/ocpsoft/rewrite/config/And.java‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
*
2828
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
2929
*/
30-
public class And extends ConditionBuilder
30+
public class And extends ConditionBuilder implements CompositeCondition
3131
{
3232
private final List<Condition> conditions;
3333

@@ -59,4 +59,10 @@ public boolean evaluate(final Rewrite event, final EvaluationContext context)
5959
}
6060
return result;
6161
}
62+
63+
@Override
64+
public List<Condition> getConditions()
65+
{
66+
return conditions;
67+
}
6268
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright 2011 <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.ocpsoft.rewrite.config;
17+
18+
import java.util.List;
19+
20+
/**
21+
* A {@link Condition} that aggregates one or more conditions.
22+
*
23+
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
24+
*
25+
*/
26+
public interface CompositeCondition extends Condition
27+
{
28+
/**
29+
* Return all {@link Condition} objects contained within this {@link CompositeCondition}.
30+
*/
31+
public List<Condition> getConditions();
32+
}

‎api/src/main/java/org/ocpsoft/rewrite/config/Condition.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*
2626
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
2727
*/
28-
public interface Condition
28+
public interface Condition extends ConfigurationElement
2929
{
3030
/**
3131
* Evaluate this condition against the given {@link org.ocpsoft.rewrite.event.Rewrite} event. If this condition does not apply to the given

‎api/src/main/java/org/ocpsoft/rewrite/config/ConditionBuilder.java‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
*/
1616
package org.ocpsoft.rewrite.config;
1717

18+
import org.ocpsoft.rewrite.context.EvaluationContext;
19+
import org.ocpsoft.rewrite.event.Rewrite;
20+
1821
/**
1922
* Used as a base class to create fluent relationships between {@link Condition} objects; this class adds logical
2023
* operators to any class extending it.
@@ -23,6 +26,24 @@
2326
*/
2427
public abstract class ConditionBuilder implements Condition
2528
{
29+
30+
/**
31+
* Return a new {@link ConditionBuilder} that evaluates to {@link True} when
32+
* {@link #evaluate(Rewrite, EvaluationContext)} is invoked.
33+
*/
34+
public static Condition create()
35+
{
36+
return new True();
37+
}
38+
39+
/**
40+
* Wrap a given {@link Condition} as a new {@link ConditionBuilder} that evaluates the the original {@link Condition}
41+
* when {@link #evaluate(Rewrite, EvaluationContext)} is invoked.
42+
*/
43+
public static Condition wrap(Condition condition)
44+
{
45+
return And.all(condition);
46+
}
2647
/**
2748
* Append a new {@link Condition} to this builder, which must evaluate to true in order for this composite
2849
* {@link Condition} to evaluate to true.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright 2011 <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.ocpsoft.rewrite.config;
17+
18+
/**
19+
* Marker interface for types used to build {@link Configuration} sets.
20+
*
21+
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
22+
*
23+
*/
24+
public interface ConfigurationElement
25+
{
26+
}

‎api/src/main/java/org/ocpsoft/rewrite/config/Not.java‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
*/
1616
package org.ocpsoft.rewrite.config;
1717

18+
import java.util.Arrays;
19+
import java.util.List;
20+
1821
import org.ocpsoft.rewrite.context.EvaluationContext;
1922
import org.ocpsoft.rewrite.event.Rewrite;
2023

@@ -24,7 +27,7 @@
2427
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
2528
*
2629
*/
27-
public class Not extends ConditionBuilder
30+
public class Not extends ConditionBuilder implements CompositeCondition
2831
{
2932
private final Condition condition;
3033

@@ -46,4 +49,10 @@ public boolean evaluate(final Rewrite event, final EvaluationContext context)
4649
{
4750
return condition.evaluate(event, context) != true;
4851
}
52+
53+
@Override
54+
public List<Condition> getConditions()
55+
{
56+
return Arrays.asList(condition);
57+
}
4958
}

‎api/src/main/java/org/ocpsoft/rewrite/config/Operation.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
2525
*
2626
*/
27-
public interface Operation
27+
public interface Operation extends ConfigurationElement
2828
{
2929
/**
3030
* Perform the operation.

‎api/src/main/java/org/ocpsoft/rewrite/config/OperationBuilder.java‎

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,39 @@
2525
*/
2626
public abstract class OperationBuilder implements Operation
2727
{
28-
private class CompositeOperation extends OperationBuilder
28+
29+
/**
30+
* Return a new {@link OperationBuilder} that takes no action when {@link #perform(Rewrite, EvaluationContext)} is
31+
* invoked.
32+
*/
33+
public static OperationBuilder create()
34+
{
35+
return new OperationBuilder() {
36+
@Override
37+
public void perform(Rewrite event, EvaluationContext context)
38+
{}
39+
};
40+
}
41+
42+
/**
43+
* Wrap a given {@link Operation} as a new {@link OperationBuilder} that performs the action of the original
44+
* {@link Operation} when {@link #perform(Rewrite, EvaluationContext)} is invoked.
45+
*/
46+
public static OperationBuilder wrap(Operation operation)
47+
{
48+
return new CompositeOperation(OperationBuilder.create(), operation);
49+
}
50+
51+
/**
52+
* Join this instance with another {@link Operation} to be performed. All joined operations are guaranteed to be
53+
* evaluated. Operations are evaluated in the order in which they are added.
54+
*/
55+
public OperationBuilder and(final Operation other)
56+
{
57+
return new CompositeOperation(this, other);
58+
}
59+
60+
private static class CompositeOperation extends OperationBuilder
2961
{
3062
private final Operation left;
3163
private final Operation right;
@@ -44,13 +76,4 @@ public void perform(final Rewrite event, final EvaluationContext context)
4476
}
4577

4678
}
47-
48-
/**
49-
* Join this instance with another {@link Operation} to be performed.
50-
*/
51-
public OperationBuilder and(final Operation other)
52-
{
53-
return new CompositeOperation(this, other);
54-
}
55-
5679
}

‎api/src/main/java/org/ocpsoft/rewrite/config/Or.java‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*
2727
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
2828
*/
29-
public class Or extends ConditionBuilder
29+
public class Or extends ConditionBuilder implements CompositeCondition
3030
{
3131
private final List<Condition> conditions;
3232

@@ -57,4 +57,10 @@ public boolean evaluate(final Rewrite event, final EvaluationContext context)
5757
}
5858
return result;
5959
}
60+
61+
@Override
62+
public List<Condition> getConditions()
63+
{
64+
return conditions;
65+
}
6066
}

‎api/src/main/java/org/ocpsoft/rewrite/config/Rule.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
*
2424
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
2525
*/
26-
public interface Rule
26+
public interface Rule extends ConfigurationElement
2727
{
2828
/**
2929
* Get the ID for this {@link Rule}

0 commit comments

Comments
 (0)