public static PropertyValue createFromSuggested( DesignComponent component, String suggestedMainName, Collection<String> additionalReservedNames) { assert component.getDocument().getTransactionManager().isAccess(); Collection<? extends CodeNamePresenter> presenters = component.getPresenters(CodeNamePresenter.class); if (presenters.isEmpty()) Debug.warning("CodeNamePresenter is missing for", component); // NOI18N HashSet<String> names = new HashSet<String>(); gatherNames(component.getDocument().getRootComponent(), component, names); if (additionalReservedNames != null) names.addAll(additionalReservedNames); suggestedMainName = checkForJavaIdentifierCompliant(suggestedMainName); if (checkIfNameAlreadyReserved(presenters, suggestedMainName, names)) { int index = suggestedMainName.length(); while (index >= 1 && Character.isDigit(suggestedMainName.charAt(index - 1))) index--; int number = index < suggestedMainName.length() ? Integer.parseInt(suggestedMainName.substring(index)) : 1; suggestedMainName = suggestedMainName.substring(0, index); suggestedMainName = findNumberedInstanceName(presenters, suggestedMainName, number, names); } return MidpTypes.createStringValue(suggestedMainName); }
private static void gatherNames( DesignComponent component, DesignComponent excludeComponent, HashSet<String> names) { assert component.getDocument().getTransactionManager().isAccess(); if (component == excludeComponent) return; Collection<? extends CodeNamePresenter> presenters = component.getPresenters(CodeNamePresenter.class); for (CodeNamePresenter presenter : presenters) { List<String> reservedNames = presenter.getReservedNames(); if (reservedNames != null) names.addAll(reservedNames); } for (DesignComponent child : component.getComponents()) gatherNames(child, excludeComponent, names); }