Skip to content

Commit 2089432

Browse files
committed
Merge pull request androidannotations#519 from excilys/331_View_Scopes
view scopes. Fixes androidannotations#331
2 parents 66d5331 + b3c3efb commit 2089432

60 files changed

Lines changed: 761 additions & 213 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎AndroidAnnotations/androidannotations-api/.settings/org.eclipse.jdt.core.prefs‎

Lines changed: 280 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
eclipse.preferences.version=1
2+
editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
3+
formatter_profile=_custom
4+
formatter_settings_version=12
5+
sp_cleanup.add_default_serial_version_id=true
6+
sp_cleanup.add_generated_serial_version_id=false
7+
sp_cleanup.add_missing_annotations=true
8+
sp_cleanup.add_missing_deprecated_annotations=true
9+
sp_cleanup.add_missing_methods=false
10+
sp_cleanup.add_missing_nls_tags=false
11+
sp_cleanup.add_missing_override_annotations=true
12+
sp_cleanup.add_missing_override_annotations_interface_methods=true
13+
sp_cleanup.add_serial_version_id=false
14+
sp_cleanup.always_use_blocks=true
15+
sp_cleanup.always_use_parentheses_in_expressions=false
16+
sp_cleanup.always_use_this_for_non_static_field_access=false
17+
sp_cleanup.always_use_this_for_non_static_method_access=false
18+
sp_cleanup.convert_to_enhanced_for_loop=false
19+
sp_cleanup.correct_indentation=false
20+
sp_cleanup.format_source_code=true
21+
sp_cleanup.format_source_code_changes_only=false
22+
sp_cleanup.make_local_variable_final=false
23+
sp_cleanup.make_parameters_final=false
24+
sp_cleanup.make_private_fields_final=true
25+
sp_cleanup.make_type_abstract_if_missing_method=false
26+
sp_cleanup.make_variable_declarations_final=true
27+
sp_cleanup.never_use_blocks=false
28+
sp_cleanup.never_use_parentheses_in_expressions=true
29+
sp_cleanup.on_save_use_additional_actions=false
30+
sp_cleanup.organize_imports=true
31+
sp_cleanup.qualify_static_field_accesses_with_declaring_class=false
32+
sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
33+
sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
34+
sp_cleanup.qualify_static_member_accesses_with_declaring_class=false
35+
sp_cleanup.qualify_static_method_accesses_with_declaring_class=false
36+
sp_cleanup.remove_private_constructors=true
37+
sp_cleanup.remove_trailing_whitespaces=false
38+
sp_cleanup.remove_trailing_whitespaces_all=true
39+
sp_cleanup.remove_trailing_whitespaces_ignore_empty=false
40+
sp_cleanup.remove_unnecessary_casts=true
41+
sp_cleanup.remove_unnecessary_nls_tags=false
42+
sp_cleanup.remove_unused_imports=false
43+
sp_cleanup.remove_unused_local_variables=false
44+
sp_cleanup.remove_unused_private_fields=true
45+
sp_cleanup.remove_unused_private_members=false
46+
sp_cleanup.remove_unused_private_methods=true
47+
sp_cleanup.remove_unused_private_types=true
48+
sp_cleanup.sort_members=false
49+
sp_cleanup.sort_members_all=false
50+
sp_cleanup.use_blocks=false
51+
sp_cleanup.use_blocks_only_for_return_and_throw=false
52+
sp_cleanup.use_parentheses_in_expressions=false
53+
sp_cleanup.use_this_for_non_static_field_access=false
54+
sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true
55+
sp_cleanup.use_this_for_non_static_method_access=false
56+
sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true

‎AndroidAnnotations/androidannotations-api/META-INF/MANIFEST.MF‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ Export-Package: org.androidannotations.annotations,
77
org.androidannotations.annotations.res,
88
org.androidannotations.annotations.rest,
99
org.androidannotations.annotations.sharedpreferences,
10-
org.androidannotations.api.rest
10+
org.androidannotations.api.rest,
11+
org.androidannotations.api.view
1112
Bundle-Vendor: androidannotations
1213
Bundle-Activator: org.androidannotations.api.Activator
1314
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package org.androidannotations.api.view;
2+
3+
import android.view.View;
4+
5+
public interface HasViews {
6+
View findViewById(int id);
7+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package org.androidannotations.api.view;
2+
3+
public interface OnViewChangedListener {
4+
void onViewChanged(HasViews hasViews);
5+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package org.androidannotations.api.view;
2+
3+
import java.util.LinkedList;
4+
import java.util.List;
5+
6+
public class OnViewChangedNotifier {
7+
8+
private static OnViewChangedNotifier currentNotifier;
9+
10+
public static OnViewChangedNotifier replaceNotifier(OnViewChangedNotifier notifier) {
11+
OnViewChangedNotifier previousNotifier = currentNotifier;
12+
currentNotifier = notifier;
13+
return previousNotifier;
14+
}
15+
16+
public static void registerOnViewChangedListener(OnViewChangedListener listener) {
17+
if (currentNotifier != null) {
18+
currentNotifier.listeners.add(listener);
19+
}
20+
}
21+
22+
private final List<OnViewChangedListener> listeners = new LinkedList<OnViewChangedListener>();
23+
24+
public void notifyViewChanged(HasViews hasViews) {
25+
for (OnViewChangedListener listener : listeners) {
26+
listener.onViewChanged(hasViews);
27+
}
28+
}
29+
30+
}

‎AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/helper/APTCodeModelHelper.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ public JBlock ifContextInstanceOfActivity(EBeanHolder holder, JBlock methodBody)
268268
return methodBody._if(holder.contextRef._instanceof(holder.classes().ACTIVITY))._then();
269269
}
270270

271-
public void copyConstructorsAndAddStaticEViewBuilders(Element element, JCodeModel codeModel, JClass eBeanClass, EBeanHolder holder, JMethod setContentViewMethod) {
271+
public void copyConstructorsAndAddStaticEViewBuilders(Element element, JCodeModel codeModel, JClass eBeanClass, EBeanHolder holder, JMethod setContentViewMethod, JMethod init) {
272272
List<ExecutableElement> constructors = new ArrayList<ExecutableElement>();
273273
for (Element e : element.getEnclosedElements()) {
274274
if (e.getKind() == CONSTRUCTOR) {
@@ -294,7 +294,7 @@ public void copyConstructorsAndAddStaticEViewBuilders(Element element, JCodeMode
294294
JVar newCall = staticHelper.body().decl(holder.generatedClass, "instance", newInvocation);
295295
staticHelper.body().invoke(newCall, "onFinishInflate");
296296
staticHelper.body()._return(newCall);
297-
body.invoke(holder.init);
297+
body.invoke(init);
298298
}
299299
}
300300

‎AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/helper/OnSeekBarChangeListenerHelper.java‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
package org.androidannotations.helper;
1717

18+
import static com.sun.codemodel.JExpr.cast;
19+
1820
import java.lang.annotation.Annotation;
1921

2022
import javax.annotation.processing.ProcessingEnvironment;
@@ -23,6 +25,7 @@
2325
import org.androidannotations.processing.EBeanHolder;
2426
import org.androidannotations.processing.OnSeekBarChangeListenerHolder;
2527
import org.androidannotations.rclass.IRClass;
28+
2629
import com.sun.codemodel.JBlock;
2730
import com.sun.codemodel.JClass;
2831
import com.sun.codemodel.JCodeModel;
@@ -74,14 +77,14 @@ public OnSeekBarChangeListenerHolder getOrCreateListener(JCodeModel codeModel, E
7477
onStopTrackingTouchMethod.param(seekBarClass, "seekBar");
7578
onStopTrackingTouchMethod.annotate(Override.class);
7679

77-
JBlock block = holder.afterSetContentView.body().block();
80+
JBlock block = holder.onViewChanged().body().block();
7881

7982
TypeMirror viewParameterType = typeElementFromQualifiedName(CanonicalNameConstants.SEEKBAR).asType();
8083

8184
String viewParameterTypeString = viewParameterType.toString();
8285
JClass viewClass = holder.refClass(viewParameterTypeString);
8386

84-
JExpression findViewById = JExpr.cast(viewClass, JExpr.invoke("findViewById").arg(idRef));
87+
JExpression findViewById = cast(viewClass, holder.onViewChanged().findViewById(idRef));
8588

8689
JVar viewVariable = block.decl(JMod.FINAL, viewClass, "view", findViewById);
8790
block._if(viewVariable.ne(JExpr._null()))._then().invoke(viewVariable, "setOnSeekBarChangeListener").arg(JExpr._new(onSeekbarChangeListenerClass));

‎AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/helper/TextWatcherHelper.java‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
*/
1616
package org.androidannotations.helper;
1717

18+
import static com.sun.codemodel.JExpr._new;
19+
import static com.sun.codemodel.JExpr.cast;
20+
import static com.sun.codemodel.JMod.FINAL;
21+
1822
import java.lang.annotation.Annotation;
1923

2024
import javax.annotation.processing.ProcessingEnvironment;
@@ -23,6 +27,7 @@
2327
import org.androidannotations.processing.EBeanHolder;
2428
import org.androidannotations.processing.TextWatcherHolder;
2529
import org.androidannotations.rclass.IRClass;
30+
2631
import com.sun.codemodel.JBlock;
2732
import com.sun.codemodel.JClass;
2833
import com.sun.codemodel.JCodeModel;
@@ -78,7 +83,7 @@ public TextWatcherHolder getOrCreateListener(JCodeModel codeModel, EBeanHolder h
7883
beforeTextChangedMethod.param(codeModel.INT, "after");
7984
beforeTextChangedMethod.annotate(Override.class);
8085

81-
JBlock block = holder.afterSetContentView.body().block();
86+
JBlock block = holder.onViewChanged().body().block();
8287

8388
JClass viewClass;
8489
if (viewParameterType != null) {
@@ -87,10 +92,10 @@ public TextWatcherHolder getOrCreateListener(JCodeModel codeModel, EBeanHolder h
8792
} else {
8893
viewClass = holder.classes().TEXT_VIEW;
8994
}
90-
JExpression findViewById = JExpr.cast(viewClass, JExpr.invoke("findViewById").arg(idRef));
95+
JExpression findViewById = cast(viewClass, holder.onViewChanged().findViewById(idRef));
9196

92-
JVar viewVariable = block.decl(JMod.FINAL, viewClass, "view", findViewById);
93-
block._if(viewVariable.ne(JExpr._null()))._then().invoke(viewVariable, "addTextChangedListener").arg(JExpr._new(onTextChangeListenerClass));
97+
JVar viewVariable = block.decl(FINAL, viewClass, "view", findViewById);
98+
block._if(viewVariable.ne(JExpr._null()))._then().invoke(viewVariable, "addTextChangedListener").arg(_new(onTextChangeListenerClass));
9499

95100
textWatcherHolder = new TextWatcherHolder(//
96101
afterTextChangedMethod, //

‎AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/processing/AfterInjectProcessor.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public Class<? extends Annotation> getTarget() {
3333
public void process(Element element, JCodeModel codeModel, EBeanHolder holder) {
3434
String methodName = element.getSimpleName().toString();
3535

36-
holder.init.body().invoke(methodName);
36+
holder.initBody.invoke(methodName);
3737
}
3838

3939
}

0 commit comments

Comments
 (0)