Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

RF-12261: fixed NPE when element is not provided

  • Loading branch information...
commit 58f5d0cfc6c7071148a6e142caba2038eeb755be 1 parent 16634d8
@lfryc lfryc authored
View
47 generator/src/main/java/org/richfaces/cdk/apt/processors/ProcessorBase.java
@@ -21,6 +21,7 @@
import org.richfaces.cdk.model.ViewElement;
import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
import com.google.inject.Inject;
import com.google.inject.Provider;
@@ -101,25 +102,55 @@ protected void setDescription(DescriptionGroup model, AnnotationMirror annotatio
protected void processAttributes(Element element, ModelElementBase component, AnnotationMirror annotation) {
AttributesProcessor attributesProcessor = getAttributeProcessor();
- SourceUtils sourceUtils = getSourceUtils();
- // interfaces can be in annotation or they can be directly implemented
- final Iterable<? extends TypeMirror> attributeInterfaces = sourceUtils.getAnnotationValues(annotation, "interfaces",
- TypeMirror.class);
- final Iterable<? extends TypeMirror> implementedInterfaces = sourceUtils.asTypeElement(element.asType())
- .getInterfaces();
+ final Iterable<String> attributesFragments = getAttributesFragment(annotation);
+ final Iterable<? extends TypeMirror> interfaces = getAllInterfaces(element, annotation);
- for (String atributesFragment : sourceUtils.getAnnotationValues(annotation, "attributes", String.class)) {
+ for (String atributesFragment : attributesFragments) {
attributesProcessor.processXmlFragment(component, atributesFragment);
}
- for (TypeMirror atributesInterface : Iterables.concat(implementedInterfaces, attributeInterfaces)) {
+ for (TypeMirror atributesInterface : interfaces) {
processInterface(component, attributesProcessor, atributesInterface);
}
+
if (element != null && ElementKind.CLASS.equals(element.getKind())) {
attributesProcessor.processType(component, (TypeElement) element);
}
}
+ /**
+ * Get fragments from 'attributes' attribute of annotation
+ */
+ private Iterable<String> getAttributesFragment(AnnotationMirror annotation) {
+ final SourceUtils sourceUtils = getSourceUtils();
+ return sourceUtils.getAnnotationValues(annotation, "attributes", String.class);
+ }
+
+ /**
+ * Get interfaces from 'interfaces' attribute of annotation
+ */
+ private Iterable<? extends TypeMirror> getAttributeInterfaces(AnnotationMirror annotation) {
+ final SourceUtils sourceUtils = getSourceUtils();
+ return sourceUtils.getAnnotationValues(annotation, "interfaces", TypeMirror.class);
+ }
+
+ /**
+ * Get interfaces list from the given class element
+ */
+ private Iterable<? extends TypeMirror> getImplementedInterfaces(Element element) {
+ final SourceUtils sourceUtils = getSourceUtils();
+
+ if (element == null) {
+ return Lists.newLinkedList();
+ }
+
+ return sourceUtils.asTypeElement(element.asType()).getInterfaces();
+ }
+
+ private Iterable<? extends TypeMirror> getAllInterfaces(Element element, AnnotationMirror annotation) {
+ return Iterables.concat(getImplementedInterfaces(element), getAttributeInterfaces(annotation));
+ }
+
private void processInterface(ModelElementBase component, AttributesProcessor attributesProcessor, TypeMirror mirror) {
component.getInterfaces().add(ClassName.parseName(mirror.toString()));
if (TypeKind.DECLARED.equals(mirror.getKind())) {
Please sign in to comment.
Something went wrong with that request. Please try again.