Skip to content

Commit 8bc1c3a

Browse files
committed
Invalidate non-abstract inner classes with abstract outer
We only generat code for non-abstract classes, so if the outer class is abstract, we cannot put the inner class anywhere. This resulted in an infinite code thus break processing. Now we invalidate this case.
1 parent 0273cd3 commit 8bc1c3a

6 files changed

Lines changed: 137 additions & 0 deletions

File tree

‎AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/handler/BaseGeneratingAnnotationHandler.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ protected void validate(Element element, AnnotationElements validatedElements, I
4545

4646
validatorHelper.enclosingElementHasAndroidAnnotation(element, validatedElements, valid);
4747

48+
validatorHelper.enclosingElementIsNotAbstractIfNotAbstract(element, valid);
4849
}
4950
}
5051

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,13 @@ public void isStatic(Element element, IsValid valid) {
201201
}
202202
}
203203

204+
public void enclosingElementIsNotAbstractIfNotAbstract(Element element, IsValid valid) {
205+
if (!annotationHelper.isAbstract(element) && annotationHelper.isAbstract(element.getEnclosingElement())) {
206+
valid.invalidate();
207+
annotationHelper.printAnnotationError(element, "%s cannot be used on a non-abstract inner element whose outer element is abstract");
208+
}
209+
}
210+
204211
public void enclosingElementHasEBeanAnnotation(Element element, AnnotationElements validatedElements, IsValid valid) {
205212
Element enclosingElement = element.getEnclosingElement();
206213
hasClassAnnotation(element, enclosingElement, validatedElements, EBean.class, valid);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Copyright (C) 2010-2015 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.innerclasses;
17+
18+
import org.androidannotations.annotations.EActivity;
19+
import org.androidannotations.annotations.EBean;
20+
21+
import android.app.Activity;
22+
23+
@EActivity
24+
public abstract class AbstractActivityWithAbstractInnerClass extends Activity {
25+
26+
@EBean
27+
static abstract class InnerClass {
28+
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* Copyright (C) 2010-2015 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.innerclasses;
17+
18+
import org.androidannotations.annotations.EActivity;
19+
import org.androidannotations.annotations.EBean;
20+
21+
import android.app.Activity;
22+
23+
@EActivity
24+
public abstract class AbstractActivityWithNonAbstractInnerClass extends Activity {
25+
26+
@EBean
27+
public static class InnerClass {
28+
29+
}
30+
31+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* Copyright (C) 2010-2015 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.innerclasses;
17+
18+
import org.androidannotations.AndroidAnnotationProcessor;
19+
import org.androidannotations.utils.AAProcessorTestHelper;
20+
import org.junit.Before;
21+
import org.junit.Test;
22+
23+
public class InnerClassTest extends AAProcessorTestHelper {
24+
25+
@Before
26+
public void setUp() {
27+
addManifestProcessorParameter(InnerClassTest.class);
28+
addProcessor(AndroidAnnotationProcessor.class);
29+
}
30+
31+
@Test
32+
public void testNonAbstractInnerClassWithAbstractOuterClassDoesNotCompile() {
33+
assertCompilationError(compileFiles(AbstractActivityWithNonAbstractInnerClass.class));
34+
}
35+
36+
@Test
37+
public void testAbstractInnerClassWithAbstractOuterClassDoesCompile() {
38+
assertCompilationSuccessful(compileFiles(AbstractActivityWithAbstractInnerClass.class));
39+
}
40+
41+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
4+
Copyright (C) 2010-2015 eBusiness Information, Excilys Group
5+
6+
Licensed under the Apache License, Version 2.0 (the "License"); you may not
7+
use this file except in compliance with the License. You may obtain a copy of
8+
the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed To in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14+
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15+
License for the specific language governing permissions and limitations under
16+
the License.
17+
18+
-->
19+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
20+
package="org.androidannotations.testprocessor"
21+
android:versionCode="1"
22+
android:versionName="1.0" >
23+
24+
<application>
25+
</application>
26+
27+
</manifest>

0 commit comments

Comments
 (0)