Collection<JMethod> extractMethods( TreeLogger logger, SourceBuilder<ModelMagic> sb, GeneratorContext ctx, JClassType type) throws UnableToCompleteException { assert type.isInterface() != null; ModelMagic models = sb.getPayload(); Map<String, JMethod> uniqueMethods = new LinkedHashMap<String, JMethod>(); JMethod[] existing = type.getInheritableMethods(); Set<? extends JClassType> hierarchy = type.getFlattenedSupertypeHierarchy(); if (ModelGeneratorGwt.allAbstract(existing)) { // still an interface; grab our root type. existing = models.getRootType(logger, ctx).getInheritableMethods(); } for (JMethod method : existing) { if (!method.isAbstract()) uniqueMethods.put(xapi.dev.model.ModelGeneratorGwt.toSignature(method), method); } boolean debug = logger.isLoggable(Type.DEBUG); for (JClassType next : hierarchy) { if (next.isInterface() != null) { sb.getClassBuffer().addInterfaces(next.getQualifiedSourceName()); for (JMethod method : next.getMethods()) { String sig = ModelGeneratorGwt.toSignature(method); if (!uniqueMethods.containsKey(sig)) uniqueMethods.put(sig, method); } } else { for (JMethod method : next.getMethods()) { String sig = ModelGeneratorGwt.toSignature(method); if (uniqueMethods.containsKey(sig)) { if (debug) logger.log( Type.WARN, "Found multiple model methods for " + type.getName() + "::" + sig + "; preferring method from " + uniqueMethods.get(sig).getEnclosingType().getName()); } else { uniqueMethods.put(sig, method); } } } } return uniqueMethods.values(); }
void implementMethod(TreeLogger logger, JMethod ifaceMethod, GeneratorContext ctx) { logger.log(Type.INFO, "Implementing model method " + ifaceMethod.getJsniSignature()); toGenerate.add(xapi.dev.model.ModelGeneratorGwt.toSignature(ifaceMethod)); applyAnnotations(logger, ifaceMethod, ifaceMethod.getAnnotations(), ctx); }