From 347cb62f7c0b38c78d1d82126d4f2a509675c6c3 Mon Sep 17 00:00:00 2001 From: dodgex Date: Sun, 22 Sep 2013 20:09:16 +0200 Subject: [PATCH 1/3] Implemented Changes for https://github.com/excilys/androidannotations/issues/728 --- .../helper/ValidatorParameterHelper.java | 15 +++++++++------ .../processing/TouchProcessor.java | 17 +++++++++++++++-- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/helper/ValidatorParameterHelper.java b/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/helper/ValidatorParameterHelper.java index eadfe16e80..a6f071f0cc 100644 --- a/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/helper/ValidatorParameterHelper.java +++ b/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/helper/ValidatorParameterHelper.java @@ -166,16 +166,19 @@ public void hasOneMotionEventOrTwoMotionEventViewParameters(ExecutableElement ex } else { VariableElement firstParameter = parameters.get(0); String firstParameterType = firstParameter.asType().toString(); - if (!firstParameterType.equals(CanonicalNameConstants.MOTION_EVENT)) { + if (parameters.size() == 1 && !firstParameterType.equals(CanonicalNameConstants.MOTION_EVENT)) { valid.invalidate(); - annotationHelper.printAnnotationError(executableElement, "the first parameter must be a " + CanonicalNameConstants.MOTION_EVENT + ", not a " + firstParameterType); - } - if (parameters.size() == 2) { + annotationHelper.printAnnotationError(executableElement, "the parameter must be a " + CanonicalNameConstants.MOTION_EVENT + ", not a " + firstParameterType); + } else { // if (parameters.size() == 2) VariableElement secondParameter = parameters.get(1); String secondParameterType = secondParameter.asType().toString(); - if (!secondParameterType.equals(CanonicalNameConstants.VIEW)) { + + boolean isViewAndMotion = firstParameterType.equals(CanonicalNameConstants.VIEW) && secondParameterType.equals(CanonicalNameConstants.MOTION_EVENT); + boolean isMotionAndView = firstParameterType.equals(CanonicalNameConstants.MOTION_EVENT) && secondParameterType.equals(CanonicalNameConstants.VIEW); + + if (!isViewAndMotion && !isMotionAndView) { valid.invalidate(); - annotationHelper.printAnnotationError(executableElement, "the second parameter must be a " + CanonicalNameConstants.VIEW + ", not a " + secondParameterType); + annotationHelper.printAnnotationError(executableElement, "the parameters must be a " + CanonicalNameConstants.VIEW + " and a " + CanonicalNameConstants.MOTION_EVENT + ", not a " + firstParameterType + " and a " + secondParameterType); } } } diff --git a/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/processing/TouchProcessor.java b/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/processing/TouchProcessor.java index 338944342d..1ee8a5cda9 100644 --- a/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/processing/TouchProcessor.java +++ b/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/processing/TouchProcessor.java @@ -23,6 +23,7 @@ import javax.lang.model.type.TypeMirror; import org.androidannotations.annotations.Touch; +import org.androidannotations.helper.CanonicalNameConstants; import org.androidannotations.rclass.IRClass; import com.sun.codemodel.JBlock; @@ -65,10 +66,22 @@ protected void processParameters(JMethod listenerMethod, JInvocation call, List< JVar eventParam = listenerMethod.param(classes.MOTION_EVENT, "event"); boolean hasItemParameter = parameters.size() == 2; - call.arg(eventParam); - if (hasItemParameter) { + VariableElement first = parameters.get(0); + String firstType = first.asType().toString(); + if (firstType.equals(CanonicalNameConstants.MOTION_EVENT)) { + call.arg(eventParam); + } else { // if (first.equals(CanonicalNameConstants.VIEW)) call.arg(viewParam); } + if (hasItemParameter) { + VariableElement second = parameters.get(1); + String secondType = second.asType().toString(); + if (secondType.equals(CanonicalNameConstants.MOTION_EVENT)) { + call.arg(eventParam); + } else { // if (first.equals(CanonicalNameConstants.MOTION_EVENT)) + call.arg(viewParam); + } + } } @Override From 4b5f3c4a5950f076991e70c9f9d8fc6e4da101ba Mon Sep 17 00:00:00 2001 From: dodgex Date: Wed, 25 Sep 2013 15:44:24 +0200 Subject: [PATCH 2/3] removed comments --- .../org/androidannotations/processing/TouchProcessor.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/processing/TouchProcessor.java b/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/processing/TouchProcessor.java index 1ee8a5cda9..b20921d891 100644 --- a/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/processing/TouchProcessor.java +++ b/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/processing/TouchProcessor.java @@ -70,7 +70,7 @@ protected void processParameters(JMethod listenerMethod, JInvocation call, List< String firstType = first.asType().toString(); if (firstType.equals(CanonicalNameConstants.MOTION_EVENT)) { call.arg(eventParam); - } else { // if (first.equals(CanonicalNameConstants.VIEW)) + } else { call.arg(viewParam); } if (hasItemParameter) { @@ -78,7 +78,7 @@ protected void processParameters(JMethod listenerMethod, JInvocation call, List< String secondType = second.asType().toString(); if (secondType.equals(CanonicalNameConstants.MOTION_EVENT)) { call.arg(eventParam); - } else { // if (first.equals(CanonicalNameConstants.MOTION_EVENT)) + } else { call.arg(viewParam); } } From ff3436ce789b4b424f0c54835bf56f9c502afa58 Mon Sep 17 00:00:00 2001 From: dodgex Date: Wed, 25 Sep 2013 15:45:53 +0200 Subject: [PATCH 3/3] fix possible OutOfBoundException if there is only one parameter of type MotionEvent --- .../androidannotations/helper/ValidatorParameterHelper.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/helper/ValidatorParameterHelper.java b/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/helper/ValidatorParameterHelper.java index a6f071f0cc..e0fddb6265 100644 --- a/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/helper/ValidatorParameterHelper.java +++ b/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/helper/ValidatorParameterHelper.java @@ -169,7 +169,8 @@ public void hasOneMotionEventOrTwoMotionEventViewParameters(ExecutableElement ex if (parameters.size() == 1 && !firstParameterType.equals(CanonicalNameConstants.MOTION_EVENT)) { valid.invalidate(); annotationHelper.printAnnotationError(executableElement, "the parameter must be a " + CanonicalNameConstants.MOTION_EVENT + ", not a " + firstParameterType); - } else { // if (parameters.size() == 2) + } + if (parameters.size() == 2) { VariableElement secondParameter = parameters.get(1); String secondParameterType = secondParameter.asType().toString();