Skip to content

Commit 61f56b8

Browse files
committed
Merge branch 'develop' into 739_logs
Conflicts: AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/AndroidAnnotationProcessor.java AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/generation/ApiCodeGenerator.java AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/generation/SourceCodewriter.java AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/helper/AnnotationHelper.java AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/process/ModelProcessor.java AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/process/ModelValidator.java
2 parents ccdb2d5 + 7e0c079 commit 61f56b8

314 files changed

Lines changed: 10319 additions & 12961 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/src/main/java/org/androidannotations/AndroidAnnotationProcessor.java‎

Lines changed: 21 additions & 510 deletions
Large diffs are not rendered by default.

‎AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/generation/ApiCodeGenerator.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
import org.androidannotations.logger.Logger;
2929
import org.androidannotations.logger.LoggerFactory;
30-
import org.androidannotations.processing.OriginatingElements;
30+
import org.androidannotations.process.OriginatingElements;
3131

3232
public class ApiCodeGenerator {
3333

‎AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/generation/CodeModelGenerator.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
import javax.annotation.processing.Filer;
2121

22-
import org.androidannotations.processing.ModelProcessor.ProcessResult;
22+
import org.androidannotations.process.ModelProcessor;
2323

2424
import com.sun.codemodel.writer.PrologCodeWriter;
2525

@@ -33,7 +33,7 @@ public CodeModelGenerator(Filer filer, String aaVersion) {
3333
this.aaVersion = aaVersion;
3434
}
3535

36-
public void generate(ProcessResult processResult) throws IOException {
36+
public void generate(ModelProcessor.ProcessResult processResult) throws IOException {
3737

3838
ApiCodeGenerator apiCodeGenerator = new ApiCodeGenerator(filer);
3939
apiCodeGenerator.writeApiClasses(processResult.apiClassesToGenerate, processResult.originatingElements);

‎AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/generation/SourceCodewriter.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
import org.androidannotations.logger.Logger;
2727
import org.androidannotations.logger.LoggerFactory;
28-
import org.androidannotations.processing.OriginatingElements;
28+
import org.androidannotations.process.OriginatingElements;
2929

3030
import com.sun.codemodel.CodeWriter;
3131
import com.sun.codemodel.JPackage;
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
/**
2+
* Copyright (C) 2010-2013 eBusiness Information, Excilys Group
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* 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, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
package org.androidannotations.handler;
17+
18+
import com.sun.codemodel.*;
19+
import org.androidannotations.helper.AndroidManifest;
20+
import org.androidannotations.helper.IdAnnotationHelper;
21+
import org.androidannotations.helper.IdValidatorHelper;
22+
import org.androidannotations.holder.EComponentWithViewSupportHolder;
23+
import org.androidannotations.model.AndroidSystemServices;
24+
import org.androidannotations.model.AnnotationElements;
25+
import org.androidannotations.process.IsValid;
26+
import org.androidannotations.rclass.IRClass;
27+
28+
import javax.annotation.processing.ProcessingEnvironment;
29+
import javax.lang.model.element.Element;
30+
import javax.lang.model.element.ExecutableElement;
31+
import javax.lang.model.element.VariableElement;
32+
import javax.lang.model.type.TypeMirror;
33+
import java.util.List;
34+
35+
import static com.sun.codemodel.JExpr.*;
36+
37+
public abstract class AbstractListenerHandler extends BaseAnnotationHandler<EComponentWithViewSupportHolder> {
38+
39+
private IdAnnotationHelper helper;
40+
private EComponentWithViewSupportHolder holder;
41+
private String methodName;
42+
43+
public AbstractListenerHandler(Class<?> targetClass, ProcessingEnvironment processingEnvironment) {
44+
super(targetClass, processingEnvironment);
45+
}
46+
47+
public AbstractListenerHandler(String target, ProcessingEnvironment processingEnvironment) {
48+
super(target, processingEnvironment);
49+
}
50+
51+
@Override
52+
public void setAndroidEnvironment(IRClass rClass, AndroidSystemServices androidSystemServices, AndroidManifest androidManifest) {
53+
super.setAndroidEnvironment(rClass, androidSystemServices, androidManifest);
54+
helper = new IdAnnotationHelper(processingEnv, getTarget(), rClass);
55+
}
56+
57+
@Override
58+
public void validate(Element element, AnnotationElements validatedElements, IsValid valid) {
59+
validatorHelper.enclosingElementHasEnhancedViewSupportAnnotation(element, validatedElements, valid);
60+
61+
validatorHelper.resIdsExist(element, IRClass.Res.ID, IdValidatorHelper.FallbackStrategy.USE_ELEMENT_NAME, valid);
62+
63+
validatorHelper.isNotPrivate(element, valid);
64+
65+
validatorHelper.doesntThrowException(element, valid);
66+
67+
validatorHelper.uniqueId(element, validatedElements, valid);
68+
}
69+
70+
@Override
71+
public void process(Element element, EComponentWithViewSupportHolder holder) {
72+
this.holder = holder;
73+
this.methodName = element.getSimpleName().toString();
74+
75+
ExecutableElement executableElement = (ExecutableElement) element;
76+
List<? extends VariableElement> parameters = executableElement.getParameters();
77+
TypeMirror returnType = executableElement.getReturnType();
78+
79+
List<JFieldRef> idsRefs = helper.extractAnnotationFieldRefs(processHolder, element, IRClass.Res.ID, true);
80+
81+
JDefinedClass listenerAnonymousClass = codeModel().anonymousClass(getListenerClass());
82+
JMethod listenerMethod = createListenerMethod(listenerAnonymousClass);
83+
listenerMethod.annotate(Override.class);
84+
85+
JBlock listenerMethodBody = listenerMethod.body();
86+
87+
JExpression activityRef = holder.getGeneratedClass().staticRef("this");
88+
JInvocation call = invoke(activityRef, methodName);
89+
90+
makeCall(listenerMethodBody, call, returnType);
91+
92+
processParameters(listenerMethod, call, parameters);
93+
94+
for (JFieldRef idRef : idsRefs) {
95+
if (idRef != null) {
96+
JBlock block = holder.getOnViewChangedBody().block();
97+
98+
JExpression findViewExpression = holder.findViewById(idRef);
99+
if (!getViewClass().equals(classes().VIEW)) {
100+
findViewExpression = cast(getViewClass(), findViewExpression);
101+
}
102+
103+
JVar view = block.decl(getViewClass(), "view", findViewExpression);
104+
block._if(view.ne(_null()))._then().invoke(view, getSetterName()).arg(_new(listenerAnonymousClass));
105+
}
106+
}
107+
}
108+
109+
protected abstract void makeCall(JBlock listenerMethodBody, JInvocation call, TypeMirror returnType);
110+
111+
protected abstract void processParameters(JMethod listenerMethod, JInvocation call, List<? extends VariableElement> userParameters);
112+
113+
protected abstract JMethod createListenerMethod(JDefinedClass listenerAnonymousClass);
114+
115+
protected abstract String getSetterName();
116+
117+
protected abstract JClass getListenerClass();
118+
119+
protected JType getViewClass() {
120+
return classes().VIEW;
121+
}
122+
123+
protected String getMethodName() {
124+
return methodName;
125+
}
126+
127+
protected final EComponentWithViewSupportHolder getHolder() {
128+
return holder;
129+
}
130+
}

AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/validation/RunnableValidator.java renamed to AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/handler/AbstractRunnableHandler.java

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,37 +13,24 @@
1313
* License for the specific language governing permissions and limitations under
1414
* the License.
1515
*/
16-
package org.androidannotations.validation;
16+
package org.androidannotations.handler;
1717

1818
import javax.annotation.processing.ProcessingEnvironment;
1919
import javax.lang.model.element.Element;
2020
import javax.lang.model.element.ExecutableElement;
2121

22-
import org.androidannotations.helper.TargetAnnotationHelper;
23-
import org.androidannotations.helper.ValidatorHelper;
22+
import org.androidannotations.holder.EComponentHolder;
2423
import org.androidannotations.model.AnnotationElements;
24+
import org.androidannotations.process.IsValid;
2525

26-
public class RunnableValidator implements ElementValidator {
26+
public abstract class AbstractRunnableHandler extends BaseAnnotationHandler<EComponentHolder> {
2727

28-
private final String annotationName;
29-
private ValidatorHelper validatorHelper;
30-
31-
public RunnableValidator(String annotationName, ProcessingEnvironment processingEnv) {
32-
this.annotationName = annotationName;
33-
TargetAnnotationHelper annotationHelper = new TargetAnnotationHelper(processingEnv, getTarget());
34-
validatorHelper = new ValidatorHelper(annotationHelper);
35-
}
36-
37-
@Override
38-
public String getTarget() {
39-
return annotationName;
28+
public AbstractRunnableHandler(Class<?> targetClass, ProcessingEnvironment processingEnvironment) {
29+
super(targetClass, processingEnvironment);
4030
}
4131

4232
@Override
43-
public boolean validate(Element element, AnnotationElements validatedElements) {
44-
45-
IsValid valid = new IsValid();
46-
33+
public void validate(Element element, AnnotationElements validatedElements, IsValid valid) {
4734
validatorHelper.enclosingElementHasEnhancedComponentAnnotation(element, validatedElements, valid);
4835

4936
ExecutableElement executableElement = (ExecutableElement) element;
@@ -57,8 +44,5 @@ public boolean validate(Element element, AnnotationElements validatedElements) {
5744
validatorHelper.isNotFinal(element, valid);
5845

5946
validatorHelper.isNotSynchronized(element, valid);
60-
61-
return valid.isValid();
6247
}
63-
6448
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/**
2+
* Copyright (C) 2010-2013 eBusiness Information, Excilys Group
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* 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, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
package org.androidannotations.handler;
17+
18+
import java.util.List;
19+
20+
import javax.annotation.processing.ProcessingEnvironment;
21+
import javax.lang.model.element.Element;
22+
import javax.lang.model.element.ExecutableElement;
23+
import javax.lang.model.element.VariableElement;
24+
25+
import org.androidannotations.helper.AndroidManifest;
26+
import org.androidannotations.helper.IdAnnotationHelper;
27+
import org.androidannotations.helper.IdValidatorHelper;
28+
import org.androidannotations.holder.EComponentWithViewSupportHolder;
29+
import org.androidannotations.holder.OnSeekBarChangeListenerHolder;
30+
import org.androidannotations.model.AndroidSystemServices;
31+
import org.androidannotations.model.AnnotationElements;
32+
import org.androidannotations.process.IsValid;
33+
import org.androidannotations.rclass.IRClass;
34+
35+
import com.sun.codemodel.JBlock;
36+
import com.sun.codemodel.JExpression;
37+
import com.sun.codemodel.JFieldRef;
38+
import com.sun.codemodel.JInvocation;
39+
import com.sun.codemodel.JVar;
40+
41+
public abstract class AbstractSeekBarTouchHandler extends BaseAnnotationHandler<EComponentWithViewSupportHolder> {
42+
43+
private IdAnnotationHelper annotationHelper;
44+
45+
public AbstractSeekBarTouchHandler(Class<?> targetClass, ProcessingEnvironment processingEnvironment) {
46+
super(targetClass, processingEnvironment);
47+
}
48+
49+
@Override
50+
public void setAndroidEnvironment(IRClass rClass, AndroidSystemServices androidSystemServices, AndroidManifest androidManifest) {
51+
super.setAndroidEnvironment(rClass, androidSystemServices, androidManifest);
52+
annotationHelper = new IdAnnotationHelper(processingEnv, getTarget(), rClass);
53+
}
54+
55+
@Override
56+
public void validate(Element element, AnnotationElements validatedElements, IsValid valid) {
57+
validatorHelper.enclosingElementHasEnhancedViewSupportAnnotation(element, validatedElements, valid);
58+
59+
validatorHelper.resIdsExist(element, IRClass.Res.ID, IdValidatorHelper.FallbackStrategy.USE_ELEMENT_NAME, valid);
60+
61+
validatorHelper.isNotPrivate(element, valid);
62+
63+
validatorHelper.doesntThrowException(element, valid);
64+
65+
validatorHelper.returnTypeIsVoid((ExecutableElement) element, valid);
66+
67+
validatorHelper.hasSeekBarTouchTrackingMethodParameters((ExecutableElement) element, valid);
68+
}
69+
70+
@Override
71+
public void process(Element element, EComponentWithViewSupportHolder holder) throws Exception {
72+
String methodName = element.getSimpleName().toString();
73+
74+
List<JFieldRef> idsRefs = annotationHelper.extractAnnotationFieldRefs(processHolder, element, IRClass.Res.ID, true);
75+
76+
for (JFieldRef idRef : idsRefs) {
77+
OnSeekBarChangeListenerHolder onSeekBarChangeListenerHolder = holder.getOnSeekBarChangeListenerHolder(idRef);
78+
JBlock methodBody = getMethodBodyToCall(onSeekBarChangeListenerHolder);
79+
80+
JExpression activityRef = holder.getGeneratedClass().staticRef("this");
81+
JInvocation textChangeCall = methodBody.invoke(activityRef, methodName);
82+
83+
ExecutableElement executableElement = (ExecutableElement) element;
84+
List<? extends VariableElement> parameters = executableElement.getParameters();
85+
86+
if (parameters.size() == 1) {
87+
JVar progressParameter = getMethodParamToPass(onSeekBarChangeListenerHolder);
88+
textChangeCall.arg(progressParameter);
89+
}
90+
}
91+
}
92+
93+
protected abstract JBlock getMethodBodyToCall(OnSeekBarChangeListenerHolder onSeekBarChangeListenerHolder);
94+
95+
protected abstract JVar getMethodParamToPass(OnSeekBarChangeListenerHolder onSeekBarChangeListenerHolder);
96+
}

AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/validation/AfterInjectValidator.java renamed to AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/handler/AfterInjectHandler.java

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,36 +13,25 @@
1313
* License for the specific language governing permissions and limitations under
1414
* the License.
1515
*/
16-
package org.androidannotations.validation;
16+
package org.androidannotations.handler;
1717

1818
import javax.annotation.processing.ProcessingEnvironment;
1919
import javax.lang.model.element.Element;
2020
import javax.lang.model.element.ExecutableElement;
2121

2222
import org.androidannotations.annotations.AfterInject;
23-
import org.androidannotations.helper.TargetAnnotationHelper;
24-
import org.androidannotations.helper.ValidatorHelper;
23+
import org.androidannotations.holder.EComponentHolder;
2524
import org.androidannotations.model.AnnotationElements;
25+
import org.androidannotations.process.IsValid;
2626

27-
public class AfterInjectValidator implements ElementValidator {
27+
public class AfterInjectHandler extends BaseAnnotationHandler<EComponentHolder> {
2828

29-
private ValidatorHelper validatorHelper;
30-
31-
public AfterInjectValidator(ProcessingEnvironment processingEnv) {
32-
TargetAnnotationHelper annotationHelper = new TargetAnnotationHelper(processingEnv, getTarget());
33-
validatorHelper = new ValidatorHelper(annotationHelper);
29+
public AfterInjectHandler(ProcessingEnvironment processingEnvironment) {
30+
super(AfterInject.class, processingEnvironment);
3431
}
3532

3633
@Override
37-
public String getTarget() {
38-
return AfterInject.class.getName();
39-
}
40-
41-
@Override
42-
public boolean validate(Element element, AnnotationElements validatedElements) {
43-
44-
IsValid valid = new IsValid();
45-
34+
public void validate(Element element, AnnotationElements validatedElements, IsValid valid) {
4635
validatorHelper.enclosingElementHasEnhancedComponentAnnotation(element, validatedElements, valid);
4736

4837
ExecutableElement executableElement = (ExecutableElement) element;
@@ -54,8 +43,11 @@ public boolean validate(Element element, AnnotationElements validatedElements) {
5443
validatorHelper.doesntThrowException(executableElement, valid);
5544

5645
validatorHelper.param.zeroParameter(executableElement, valid);
57-
58-
return valid.isValid();
5946
}
6047

48+
@Override
49+
public void process(Element element, EComponentHolder holder) {
50+
String methodName = element.getSimpleName().toString();
51+
holder.getInitBody().invoke(methodName);
52+
}
6153
}

0 commit comments

Comments
 (0)