From 654a730e13137a089c18ce54a3bb9bd002b8d212 Mon Sep 17 00:00:00 2001 From: Jim Chen Date: Thu, 22 Oct 2015 17:45:45 -0400 Subject: [PATCH] Bug 1210585 - Avoid fields with same name in class and superclass; r=snorp Java allows a class field to have the same name as a superclass field, but when we generate bindings for them, they'll end up with the same C++ name and cause an error. This patch makes the SDK processor filter out any superclass fields that are hidden by a subclass field with the same name. --- build/annotationProcessors/SDKProcessor.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/build/annotationProcessors/SDKProcessor.java b/build/annotationProcessors/SDKProcessor.java index ea9edc4c7bd7..8b045fa1d676 100644 --- a/build/annotationProcessors/SDKProcessor.java +++ b/build/annotationProcessors/SDKProcessor.java @@ -162,6 +162,20 @@ public class SDKProcessor { continue; } + // Sometimes (e.g. KeyEvent) a field can appear in both a class and a superclass. In + // that case we want to filter out the version that appears in the superclass, or + // we'll have bindings with duplicate names. + try { + if (m instanceof Field && !m.equals(cls.getField(m.getName()))) { + // m is a field in a superclass that has been hidden by + // a field with the same name in a subclass. + System.out.println("Skipping " + m.getName() + + " from " + m.getDeclaringClass()); + continue; + } + } catch (final NoSuchFieldException e) { + } + list.add(m); }