diff --git a/epoxy-processor/src/main/java/com/airbnb/epoxy/EpoxyProcessor.java b/epoxy-processor/src/main/java/com/airbnb/epoxy/EpoxyProcessor.java index 05afe9dd6c..057708a118 100755 --- a/epoxy-processor/src/main/java/com/airbnb/epoxy/EpoxyProcessor.java +++ b/epoxy-processor/src/main/java/com/airbnb/epoxy/EpoxyProcessor.java @@ -129,7 +129,7 @@ public boolean process(Set annotations, RoundEnvironment for (Element attribute : roundEnv.getElementsAnnotatedWith(EpoxyAttribute.class)) { try { - processAttribute(attribute, modelClassMap); + addAttributeToGeneratedClass(attribute, modelClassMap); } catch (Exception e) { logError(e); } @@ -197,21 +197,19 @@ private void validateAttributesImplementHashCode( } } - private void processAttribute(Element attribute, + private void addAttributeToGeneratedClass(Element attribute, Map modelClassMap) { - - validateAccessibleViaGeneratedCode(attribute); - TypeElement classElement = (TypeElement) attribute.getEnclosingElement(); ClassToGenerateInfo helperClass = getOrCreateTargetClass(modelClassMap, classElement); + helperClass.addAttribute(buildAttributeInfo(attribute)); + } - AttributeInfo attributeInfo = new AttributeInfo(attribute, typeUtils); - - helperClass.addAttribute(attributeInfo); + private AttributeInfo buildAttributeInfo(Element attribute) { + validateAccessibleViaGeneratedCode(attribute); + return new AttributeInfo(attribute, typeUtils); } private void validateAccessibleViaGeneratedCode(Element attribute) { - TypeElement enclosingElement = (TypeElement) attribute.getEnclosingElement(); // Verify method modifiers. @@ -290,20 +288,33 @@ private void addAttributesFromOtherModules(Map new HashSet<>(modelClassMap.entrySet()); for (Entry entry : originalEntries) { - TypeMirror superclassType = entry.getKey().getSuperclass(); + TypeElement currentEpoxyModel = entry.getKey(); + TypeMirror superclassType = currentEpoxyModel.getSuperclass(); + ClassToGenerateInfo classToGenerateInfo = entry.getValue(); while (isEpoxyModel(superclassType)) { - TypeElement superclassElement = (TypeElement) typeUtils.asElement(superclassType); + TypeElement superclassEpoxyModel = (TypeElement) typeUtils.asElement(superclassType); - if (!modelClassMap.keySet().contains(superclassElement)) { - for (Element element : superclassElement.getEnclosedElements()) { + if (!modelClassMap.keySet().contains(superclassEpoxyModel)) { + for (Element element : superclassEpoxyModel.getEnclosedElements()) { if (element.getAnnotation(EpoxyAttribute.class) != null) { - processAttribute(element, modelClassMap); + AttributeInfo attributeInfo = buildAttributeInfo(element); + if (!belongToTheSamePackage(currentEpoxyModel, superclassEpoxyModel) + && attributeInfo.isPackagePrivate()) { + // We can't inherit a package private attribute if we're not in the same package + continue; + } + + // We add just the attribute info to the class in our module. We do NOT want to + // generate a class for the super class EpoxyModel in the other module since one + // will be created when that module is processed. If we make one as well there will + // be a duplicate (causes proguard errors and is just wrong). + classToGenerateInfo.addAttribute(attributeInfo); } } } - superclassType = superclassElement.getSuperclass(); + superclassType = superclassEpoxyModel.getSuperclass(); } } }