From d989b7d1d3f88652478978b10124e50013917384 Mon Sep 17 00:00:00 2001 From: Kay-Uwe Janssen Date: Wed, 1 Jun 2016 20:06:12 +0200 Subject: [PATCH 1/2] cast view if necessary before calling setter --- .../internal/core/handler/AbstractViewListenerHandler.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/AndroidAnnotations/androidannotations-core/androidannotations/src/main/java/org/androidannotations/internal/core/handler/AbstractViewListenerHandler.java b/AndroidAnnotations/androidannotations-core/androidannotations/src/main/java/org/androidannotations/internal/core/handler/AbstractViewListenerHandler.java index 73ec9cae94..5e7d904a0b 100644 --- a/AndroidAnnotations/androidannotations-core/androidannotations/src/main/java/org/androidannotations/internal/core/handler/AbstractViewListenerHandler.java +++ b/AndroidAnnotations/androidannotations-core/androidannotations/src/main/java/org/androidannotations/internal/core/handler/AbstractViewListenerHandler.java @@ -50,8 +50,9 @@ public void validate(Element element, ElementValidation valid) { @Override protected final void assignListeners(EComponentWithViewSupportHolder holder, List idsRefs, JDefinedClass listenerAnonymousClass) { for (JFieldRef idRef : idsRefs) { - FoundViewHolder foundViewHolder = holder.getFoundViewHolder(idRef, getListenerTargetClass(holder)); - foundViewHolder.getIfNotNullBlock().invoke(foundViewHolder.getRef(), getSetterName()).arg(_new(listenerAnonymousClass)); + AbstractJClass listenerTargetClass = getListenerTargetClass(holder); + FoundViewHolder foundViewHolder = holder.getFoundViewHolder(idRef, listenerTargetClass); + foundViewHolder.getIfNotNullBlock().invoke(foundViewHolder.getOrCastRef(listenerTargetClass), getSetterName()).arg(_new(listenerAnonymousClass)); } } From 492820b6147c5e85f15259404686a01613a27232 Mon Sep 17 00:00:00 2001 From: Kay-Uwe Janssen Date: Wed, 1 Jun 2016 20:06:22 +0200 Subject: [PATCH 2/2] add compilation test for view casting of view listener annotations --- .../AbstractViewListenerActivity.java | 45 +++++++++++++++++ .../AdapterViewListenerActivity.java | 38 +++++++++++++++ .../CompoundButtonListenerActivity.java | 28 +++++++++++ .../TextViewListenerActivity.java | 29 +++++++++++ .../ViewListenerCompilationTest.java | 48 +++++++++++++++++++ .../viewlistener/AndroidManifest.xml | 30 ++++++++++++ 6 files changed, 218 insertions(+) create mode 100644 AndroidAnnotations/androidannotations-core/androidannotations/src/test/java/org/androidannotations/viewlistener/AbstractViewListenerActivity.java create mode 100644 AndroidAnnotations/androidannotations-core/androidannotations/src/test/java/org/androidannotations/viewlistener/AdapterViewListenerActivity.java create mode 100644 AndroidAnnotations/androidannotations-core/androidannotations/src/test/java/org/androidannotations/viewlistener/CompoundButtonListenerActivity.java create mode 100644 AndroidAnnotations/androidannotations-core/androidannotations/src/test/java/org/androidannotations/viewlistener/TextViewListenerActivity.java create mode 100644 AndroidAnnotations/androidannotations-core/androidannotations/src/test/java/org/androidannotations/viewlistener/ViewListenerCompilationTest.java create mode 100644 AndroidAnnotations/androidannotations-core/androidannotations/src/test/resources/org/androidannotations/viewlistener/AndroidManifest.xml diff --git a/AndroidAnnotations/androidannotations-core/androidannotations/src/test/java/org/androidannotations/viewlistener/AbstractViewListenerActivity.java b/AndroidAnnotations/androidannotations-core/androidannotations/src/test/java/org/androidannotations/viewlistener/AbstractViewListenerActivity.java new file mode 100644 index 0000000000..9abfe43bd5 --- /dev/null +++ b/AndroidAnnotations/androidannotations-core/androidannotations/src/test/java/org/androidannotations/viewlistener/AbstractViewListenerActivity.java @@ -0,0 +1,45 @@ +/** + * Copyright (C) 2010-2016 eBusiness Information, Excilys Group + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed To in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.androidannotations.viewlistener; + +import org.androidannotations.annotations.Click; +import org.androidannotations.annotations.EActivity; +import org.androidannotations.annotations.FocusChange; +import org.androidannotations.annotations.LongClick; +import org.androidannotations.annotations.Touch; +import org.androidannotations.viewbyid.R; + +import android.app.Activity; + +@EActivity +public abstract class AbstractViewListenerActivity extends Activity { + + @FocusChange(R.id.view) + protected void onFocusChange() { + } + + @Click(R.id.view) + protected void onClick() { + } + + @LongClick(R.id.view) + protected void onLongClick() { + } + + @Touch(R.id.view) + protected void onTouch() { + } +} diff --git a/AndroidAnnotations/androidannotations-core/androidannotations/src/test/java/org/androidannotations/viewlistener/AdapterViewListenerActivity.java b/AndroidAnnotations/androidannotations-core/androidannotations/src/test/java/org/androidannotations/viewlistener/AdapterViewListenerActivity.java new file mode 100644 index 0000000000..329eb0e7a4 --- /dev/null +++ b/AndroidAnnotations/androidannotations-core/androidannotations/src/test/java/org/androidannotations/viewlistener/AdapterViewListenerActivity.java @@ -0,0 +1,38 @@ +/** + * Copyright (C) 2010-2016 eBusiness Information, Excilys Group + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed To in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.androidannotations.viewlistener; + +import org.androidannotations.annotations.EActivity; +import org.androidannotations.annotations.ItemClick; +import org.androidannotations.annotations.ItemLongClick; +import org.androidannotations.annotations.ItemSelect; +import org.androidannotations.viewbyid.R; + +@EActivity +public class AdapterViewListenerActivity extends AbstractViewListenerActivity { + + @ItemClick(R.id.view) + protected void onItemClick() { + } + + @ItemLongClick(R.id.view) + protected void onItemLongClick() { + } + + @ItemSelect(R.id.view) + protected void onItemSelect(boolean selected) { + } +} diff --git a/AndroidAnnotations/androidannotations-core/androidannotations/src/test/java/org/androidannotations/viewlistener/CompoundButtonListenerActivity.java b/AndroidAnnotations/androidannotations-core/androidannotations/src/test/java/org/androidannotations/viewlistener/CompoundButtonListenerActivity.java new file mode 100644 index 0000000000..77594572df --- /dev/null +++ b/AndroidAnnotations/androidannotations-core/androidannotations/src/test/java/org/androidannotations/viewlistener/CompoundButtonListenerActivity.java @@ -0,0 +1,28 @@ +/** + * Copyright (C) 2010-2016 eBusiness Information, Excilys Group + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed To in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.androidannotations.viewlistener; + +import org.androidannotations.annotations.CheckedChange; +import org.androidannotations.annotations.EActivity; +import org.androidannotations.viewbyid.R; + +@EActivity +public class CompoundButtonListenerActivity extends AbstractViewListenerActivity { + + @CheckedChange(R.id.view) + protected void onCheckedChange() { + } +} diff --git a/AndroidAnnotations/androidannotations-core/androidannotations/src/test/java/org/androidannotations/viewlistener/TextViewListenerActivity.java b/AndroidAnnotations/androidannotations-core/androidannotations/src/test/java/org/androidannotations/viewlistener/TextViewListenerActivity.java new file mode 100644 index 0000000000..e6a9780a7d --- /dev/null +++ b/AndroidAnnotations/androidannotations-core/androidannotations/src/test/java/org/androidannotations/viewlistener/TextViewListenerActivity.java @@ -0,0 +1,29 @@ +/** + * Copyright (C) 2010-2016 eBusiness Information, Excilys Group + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed To in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.androidannotations.viewlistener; + +import org.androidannotations.annotations.EActivity; +import org.androidannotations.annotations.EditorAction; +import org.androidannotations.viewbyid.R; + +@EActivity +public class TextViewListenerActivity extends AbstractViewListenerActivity { + + @EditorAction(R.id.view) + protected void onEditorAction() { + } + +} diff --git a/AndroidAnnotations/androidannotations-core/androidannotations/src/test/java/org/androidannotations/viewlistener/ViewListenerCompilationTest.java b/AndroidAnnotations/androidannotations-core/androidannotations/src/test/java/org/androidannotations/viewlistener/ViewListenerCompilationTest.java new file mode 100644 index 0000000000..1c4b1891a2 --- /dev/null +++ b/AndroidAnnotations/androidannotations-core/androidannotations/src/test/java/org/androidannotations/viewlistener/ViewListenerCompilationTest.java @@ -0,0 +1,48 @@ +/** + * Copyright (C) 2010-2016 eBusiness Information, Excilys Group + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed To in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.androidannotations.viewlistener; + +import java.io.IOException; + +import org.androidannotations.internal.AndroidAnnotationProcessor; +import org.androidannotations.testutils.AAProcessorTestHelper; +import org.junit.Before; +import org.junit.Test; + +public class ViewListenerCompilationTest extends AAProcessorTestHelper { + + @Before + public void setUp() { + addManifestProcessorParameter(AbstractViewListenerActivity.class); + addProcessor(AndroidAnnotationProcessor.class); + ensureOutputDirectoryIsEmpty(); + } + + @Test + public void ensureAdapterViewListenerCompilationSuccessful() throws IOException { + assertCompilationSuccessful(compileFiles(AdapterViewListenerActivity.class)); + } + + @Test + public void ensureTextViewListenerCompilationSuccessful() throws IOException { + assertCompilationSuccessful(compileFiles(TextViewListenerActivity.class)); + } + + @Test + public void ensureCompundButtonListenerCompilationSuccessful() throws IOException { + assertCompilationSuccessful(compileFiles(CompoundButtonListenerActivity.class)); + } +} diff --git a/AndroidAnnotations/androidannotations-core/androidannotations/src/test/resources/org/androidannotations/viewlistener/AndroidManifest.xml b/AndroidAnnotations/androidannotations-core/androidannotations/src/test/resources/org/androidannotations/viewlistener/AndroidManifest.xml new file mode 100644 index 0000000000..e373827a9f --- /dev/null +++ b/AndroidAnnotations/androidannotations-core/androidannotations/src/test/resources/org/androidannotations/viewlistener/AndroidManifest.xml @@ -0,0 +1,30 @@ + + + + + + + + + + +