Skip to content

Commit d056e87

Browse files
committed
Added MethodContext
1 parent 3802d79 commit d056e87

6 files changed

Lines changed: 154 additions & 12 deletions

File tree

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/*
22
* Copyright 2011 <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
3-
*
3+
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
7-
*
7+
*
88
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
9+
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -15,13 +15,25 @@
1515
*/
1616
package org.ocpsoft.rewrite.annotation.api;
1717

18+
import org.ocpsoft.rewrite.annotation.spi.AnnotationHandler;
1819
import org.ocpsoft.rewrite.config.ConfigurationBuilder;
1920
import org.ocpsoft.rewrite.config.RuleBuilder;
2021
import org.ocpsoft.rewrite.context.Context;
2122

23+
/**
24+
* Context storing information for all {@link AnnotationHandler} implementations working on a given class visit.
25+
*
26+
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
27+
*/
2228
public interface ClassContext extends Context
2329
{
30+
/**
31+
* Get the {@link ConfigurationBuilder} shared by all class visits for the entire annotation configuration.
32+
*/
2433
ConfigurationBuilder getConfigurationBuilder();
2534

35+
/**
36+
* Get the {@link RuleBuilder} for the current class visit.
37+
*/
2638
RuleBuilder getRuleBuilder();
2739
}

‎config-annotations-api/src/main/java/org/ocpsoft/rewrite/annotation/api/FieldContext.java‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/*
22
* Copyright 2011 <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
3-
*
3+
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
7-
*
7+
*
88
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
9+
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -19,7 +19,7 @@
1919

2020
/**
2121
* Context for scanning a single field of a class
22-
*
22+
*
2323
* @author Christian Kaltepoth
2424
*/
2525
@SuppressWarnings("rawtypes")
@@ -38,4 +38,8 @@ public interface FieldContext extends ClassContext
3838
*/
3939
public BindingBuilder getBindingBuilder();
4040

41+
/**
42+
* Return the parent {@link ClassContext} to which this context is a descendant.
43+
*/
44+
ClassContext getClassContext();
4145
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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.annotation.api;
17+
18+
import org.ocpsoft.rewrite.bind.BindingBuilder;
19+
20+
/**
21+
* Context for scanning a single field of a class
22+
*
23+
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
24+
*/
25+
@SuppressWarnings("rawtypes")
26+
public interface MethodContext extends ClassContext
27+
{
28+
29+
/**
30+
* Sets the {@link BindingBuilder} for the current method. Should be called by annotation handlers after they created
31+
* a binding for the method.
32+
*/
33+
public void setBindingBuilder(BindingBuilder bindingBuilder);
34+
35+
/**
36+
* Returns the {@link BindingBuilder} for the current method. May return <code>null</code> if no binding has yet been
37+
* created for the method.
38+
*/
39+
public BindingBuilder getBindingBuilder();
40+
41+
/**
42+
* Return the parent {@link ClassContext} to which this context is a descendant.
43+
*/
44+
ClassContext getClassContext();
45+
46+
}

‎config-annotations-impl/src/main/java/org/ocpsoft/rewrite/annotation/ClassVisitorImpl.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.ocpsoft.rewrite.annotation.api.ClassVisitor;
1515
import org.ocpsoft.rewrite.annotation.scan.ClassContextImpl;
1616
import org.ocpsoft.rewrite.annotation.scan.FieldContextImpl;
17+
import org.ocpsoft.rewrite.annotation.scan.MethodContextImpl;
1718
import org.ocpsoft.rewrite.annotation.spi.AnnotationHandler;
1819
import org.ocpsoft.rewrite.config.Configuration;
1920
import org.ocpsoft.rewrite.config.ConfigurationBuilder;
@@ -83,7 +84,7 @@ public void visit(Class<?> clazz)
8384

8485
// finally the methods
8586
for (Method method : clazz.getDeclaredMethods()) {
86-
visit(method, context);
87+
visit(method, new MethodContextImpl(context));
8788
}
8889

8990
}

‎config-annotations-impl/src/main/java/org/ocpsoft/rewrite/annotation/scan/FieldContextImpl.java‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/*
22
* Copyright 2011 <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
3-
*
3+
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
7-
*
7+
*
88
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
9+
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -24,7 +24,7 @@
2424

2525
/**
2626
* Default implementation of {@link FieldContext}
27-
*
27+
*
2828
* @author Christian Kaltepoth
2929
*/
3030
@SuppressWarnings("rawtypes")
@@ -40,6 +40,12 @@ public FieldContextImpl(ClassContext classContext)
4040
this.classContext = classContext;
4141
}
4242

43+
@Override
44+
public ClassContext getClassContext()
45+
{
46+
return classContext;
47+
}
48+
4349
@Override
4450
public ConfigurationBuilder getConfigurationBuilder()
4551
{
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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.annotation.scan;
17+
18+
import org.ocpsoft.rewrite.annotation.api.ClassContext;
19+
import org.ocpsoft.rewrite.annotation.api.MethodContext;
20+
import org.ocpsoft.rewrite.bind.BindingBuilder;
21+
import org.ocpsoft.rewrite.config.ConfigurationBuilder;
22+
import org.ocpsoft.rewrite.config.RuleBuilder;
23+
import org.ocpsoft.rewrite.context.ContextBase;
24+
25+
/**
26+
* Default implementation of {@link MethodContext}
27+
*
28+
* @author Christian Kaltepoth
29+
*/
30+
@SuppressWarnings("rawtypes")
31+
public class MethodContextImpl extends ContextBase implements MethodContext
32+
{
33+
34+
private final ClassContext classContext;
35+
36+
private BindingBuilder bindingBuilder;
37+
38+
public MethodContextImpl(ClassContext classContext)
39+
{
40+
this.classContext = classContext;
41+
}
42+
43+
@Override
44+
public ClassContext getClassContext()
45+
{
46+
return classContext;
47+
}
48+
49+
@Override
50+
public ConfigurationBuilder getConfigurationBuilder()
51+
{
52+
return classContext.getConfigurationBuilder();
53+
}
54+
55+
@Override
56+
public RuleBuilder getRuleBuilder()
57+
{
58+
return classContext.getRuleBuilder();
59+
}
60+
61+
@Override
62+
public void setBindingBuilder(BindingBuilder bindingBuilder)
63+
{
64+
this.bindingBuilder = bindingBuilder;
65+
}
66+
67+
@Override
68+
public BindingBuilder getBindingBuilder()
69+
{
70+
return bindingBuilder;
71+
}
72+
73+
}

0 commit comments

Comments
 (0)