private void visitObjModel(IObject objModel) { // A reference to a design model is used to check whether a potential // decorator extends or implements one of its constructor parameter // types. if (designModel == null) return; // Build up a set of components that the object may decorate. HashSet<String> possibleComponents = new HashSet<String>(); // The object may decorate one of its constructor parameter types. for (IMethod m : objModel.getAllMethodModels()) { if (m.isConstructor() && (m.getAccessLevel() == AccessLevel.Public) || (m.getAccessLevel() == AccessLevel.Protected)) { Collection<String> paramTypes = Arrays.asList(m.getParamTypeNames()); possibleComponents.addAll(paramTypes); } } // The object may decorate a type if the object extends or implements // the type. (This assumes that a class cannot decorate itself. This may // not be correct.) possibleComponents.remove(objModel.getName()); List<String> possibleComponentsList = new ArrayList<String>(possibleComponents); for (String possibleComp : possibleComponentsList) { if (!designModel.isSubType(objModel.getName(), possibleComp)) { possibleComponents.remove(possibleComp); } } // The object may decorate a type if it also has a field of that type. Set<String> fieldTypes = new HashSet<String>(); for (IField field : objModel.getAllFieldModels()) { fieldTypes.add(field.getTypeName()); } possibleComponents.retainAll(fieldTypes); // Record the components that this object decorates. if (!possibleComponents.isEmpty()) { decoratorToComponents.put(objModel.getName(), possibleComponents); } }