CObject(CLibrary library, String name, boolean isProtocol) { super(name); this.library = library; this.isProtocol = isProtocol; genericsCount = Advisor.genericsSupport(name); this.cClassName = library.getPackagename().replace(".", "_") + "_" + name; }
public void finalizeObject() { /* * Fix Constructors */ CConstructor base, running; String basesig; Set<CConstructor> doubles = new HashSet<CConstructor>(); for (int i = 0; i < constructors.size() - 1; i++) { base = constructors.get(i); basesig = base.getSignature(name); for (int j = i + 1; j < constructors.size(); j++) { running = constructors.get(j); if (!doubles.contains(running) && running.getSignature(name).equals(basesig)) { base.updateEnum( basesig); // The enumaration definition happens HERE, because we want to finish with // typedefs first and be sure that an override REALLY exists if (base.isOverloaded()) { if (base.getEnum() != null) // Might be overloaded but we don't support this in Java hasConstructorEnums = true; for (String def : running.getDefinitions()) base.addDefinition(def); doubles.add(running); } else Reporter.UNKNOWN_OVERRIDE.report( "constructor " + basesig, base.getDefinitions().iterator().next() + " ## " + running.getDefinitions().iterator().next()); } } } for (CConstructor obs : doubles) constructors.remove(obs); /* * Fix Methods */ // Search if this is a delegate, so that the selector name aggregator will be more aggressive boolean isDelegate = false; for (String pattern : Advisor.getDelegatePatterns()) isDelegate |= name.matches(pattern); Map<String, List<CMethod>> maps = new HashMap<String, List<CMethod>>(); List<CMethod> toRemove = new ArrayList<CMethod>(); // Put methods in order for (CMethod m : methods) { String givenName = Advisor.getMethodCanonical((m.isStatic() ? "+" : "-") + m.getSignature(name)); if (givenName != null) if (givenName.equals("")) toRemove.add(m); else m.setCanonicalName(givenName); else { String key = isDelegate ? m.getNameParts().get(0) : m.getSignature( ""); // if it is a delegate, group by first type, to minimize namespace // pollution List<CMethod> list = maps.get(key); if (list == null) { list = new ArrayList<CMethod>(); maps.put(key, list); } list.add(m); } m.setMandatory(AdvisorMediator.methodIsMandatoryForObject(m.getSelectorName(), this.name)); } // find conflicting methods for (List<CMethod> conflict : maps.values()) // get a list of all methods in categorized format if (conflict.size() > 1) { // only affect methods with conflict List<List<String>> parts = new ArrayList<List<String>>(); // aggregate parameter names List<Boolean> statics = new ArrayList<Boolean>(); for (CMethod meth : conflict) { parts.add(meth.getNameParts()); statics.add(meth.isStatic()); } List<String> newnames = Oracle.findUniqueNames(parts, statics, isDelegate); // find new names String cname; for (int i = 0; i < conflict.size(); i++) { cname = newnames.get(i); if (cname == null) methods.remove(conflict.get(i)); else conflict.get(i).setCanonicalName(newnames.get(i)); } } // Remove methods which are not valid for (CMethod m : toRemove) methods.remove(m); if (AdvisorMediator.objectHasMandatoryMethods(this.name)) hasMandatoryMethods = true; }