diff --git a/AndroidAnnotations/androidannotations-core/androidannotations/src/main/java/org/androidannotations/internal/process/ModelProcessor.java b/AndroidAnnotations/androidannotations-core/androidannotations/src/main/java/org/androidannotations/internal/process/ModelProcessor.java index a6a0d0c9cd..6c32c6af14 100644 --- a/AndroidAnnotations/androidannotations-core/androidannotations/src/main/java/org/androidannotations/internal/process/ModelProcessor.java +++ b/AndroidAnnotations/androidannotations-core/androidannotations/src/main/java/org/androidannotations/internal/process/ModelProcessor.java @@ -1,5 +1,6 @@ /** * Copyright (C) 2010-2016 eBusiness Information, Excilys Group + * Copyright (C) 2016-2018 the AndroidAnnotations project * * 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 @@ -169,6 +170,7 @@ private boolean isAbstractClass(Element annotatedElement) { @SuppressWarnings({ "unchecked", "rawtypes" }) private boolean generateElements(AnnotationElements validatedModel, ProcessHolder processHolder) throws Exception { boolean isElementRemaining = false; + Set validatedElements = validatedModel.getAllElements(); for (GeneratingAnnotationHandler generatingAnnotationHandler : environment.getGeneratingHandlers()) { if (!generatingAnnotationHandler.isEnabled()) { continue; @@ -192,7 +194,11 @@ private boolean generateElements(AnnotationElements validatedModel, ProcessHolde Element enclosingElement = annotatedElement.getEnclosingElement(); if (typeElement.getNestingKind() == NestingKind.MEMBER && processHolder.getGeneratedClassHolder(enclosingElement) == null) { - isElementRemaining = true; + if (validatedElements.contains(enclosingElement)) { + isElementRemaining = true; + } else { + LOGGER.error("Enclosing element {} has not been successfully validated", annotatedElement, enclosingElement); + } } else { GeneratedClassHolder generatedClassHolder = generatingAnnotationHandler.createGeneratedClassHolder(environment, typeElement); processHolder.put(annotatedElement, generatedClassHolder); diff --git a/AndroidAnnotations/androidannotations-core/androidannotations/src/test/java/org/androidannotations/generation/InvalidFragmentWithValidBean.java b/AndroidAnnotations/androidannotations-core/androidannotations/src/test/java/org/androidannotations/generation/InvalidFragmentWithValidBean.java new file mode 100644 index 0000000000..cdfd074751 --- /dev/null +++ b/AndroidAnnotations/androidannotations-core/androidannotations/src/test/java/org/androidannotations/generation/InvalidFragmentWithValidBean.java @@ -0,0 +1,29 @@ +/** + * Copyright (C) 2010-2016 eBusiness Information, Excilys Group + * Copyright (C) 2016-2018 the AndroidAnnotations project + * + * 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.generation; + +import org.androidannotations.annotations.EBean; +import org.androidannotations.annotations.EFragment; + +@EFragment +public class InvalidFragmentWithValidBean { + + @EBean + public static class ValidBean { + } + +} diff --git a/AndroidAnnotations/androidannotations-core/androidannotations/src/test/java/org/androidannotations/generation/NestedEnhancedClassGenerationTest.java b/AndroidAnnotations/androidannotations-core/androidannotations/src/test/java/org/androidannotations/generation/NestedEnhancedClassGenerationTest.java new file mode 100644 index 0000000000..2c367965d0 --- /dev/null +++ b/AndroidAnnotations/androidannotations-core/androidannotations/src/test/java/org/androidannotations/generation/NestedEnhancedClassGenerationTest.java @@ -0,0 +1,44 @@ +/** + * Copyright (C) 2010-2016 eBusiness Information, Excilys Group + * Copyright (C) 2016-2018 the AndroidAnnotations project + * + * 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.generation; + +import java.io.IOException; + +import org.androidannotations.internal.AndroidAnnotationProcessor; +import org.androidannotations.testutils.AAProcessorTestHelper; +import org.junit.Before; +import org.junit.Test; + +public class NestedEnhancedClassGenerationTest extends AAProcessorTestHelper { + + @Before + public void setUp() { + addManifestProcessorParameter(ActivityInManifest.class); + addProcessor(AndroidAnnotationProcessor.class); + ensureOutputDirectoryIsEmpty(); + } + + @Test(timeout = 10_000) + public void shouldNotLoop() throws IOException { + CompileResult result = compileFiles(InvalidFragmentWithValidBean.class); + + assertCompilationErrorCount(2, result); + + assertCompilationErrorOn(InvalidFragmentWithValidBean.class, "@EFragment", result); + assertCompilationErrorOn(InvalidFragmentWithValidBean.class, "@EBean", result); + } +}