public void saveMaps() throws IOException{ File dir = getMapDirectory(); if (dir == null) { return; } File[] files = getMapFiles(); @NonNls String[] filePaths = new String[myMaps.size()]; Document[] documents = new Document[myMaps.size()]; UniqueNameGenerator namesProvider = new UniqueNameGenerator(); for(int i = 0; i < myMaps.size(); i++){ MigrationMap map = myMaps.get(i); filePaths[i] = dir + File.separator + namesProvider.generateUniqueName(FileUtil.sanitizeFileName(map.getName(), false)) + ".xml"; documents[i] = saveMap(map); } JDOMUtil.updateFileSet(files, filePaths, documents, CodeStyleSettingsManager.getSettings(null).getLineSeparator()); }
@Override public void actionPerformed(AnActionEvent e) { String name = UniqueNameGenerator.generateUniqueName(myServerType.getPresentableName(), new Condition<String>() { @Override public boolean value(String s) { for (NamedConfigurable<RemoteServer<?>> configurable : getConfiguredServers()) { if (configurable.getDisplayName().equals(s)) { return false; } } return true; } }); MyNode node = addServerNode(myServersManager.createServer(myServerType, name), true); selectNodeInTree(node); }
protected void doSetup(ModifiableModelsProvider modifiableModelsProvider, final Module module) { final ModifiableFacetModel model = modifiableModelsProvider.getFacetModifiableModel(module); final String name = UniqueNameGenerator.generateUniqueName(myFacetType.getDefaultFacetName(), new Condition<String>() { @Override public boolean value(String s) { return FacetManager.getInstance(module).findFacet(myFacetType.getId(), s) == null; } }); final F facet = FacetManager.getInstance(module).createFacet(myFacetType, name, myConfiguration, findUnderlyingFacet(module)); model.addFacet(facet); modifiableModelsProvider.commitFacetModifiableModel(module, model); final ModifiableRootModel rootModel = modifiableModelsProvider.getModuleModifiableModel(module); myDetector.setupFacet(facet, rootModel); modifiableModelsProvider.commitModuleModifiableModel(rootModel); }
@Nonnull private String checkFileNameIsFree(@Nonnull String subPath, @Nonnull String schemeName) { for (Named scheme : mySchemes) { if (scheme instanceof ExternalizableScheme) { String name = ((ExternalizableScheme)scheme).getExternalInfo().getCurrentFileName(); if (name != null && !schemeName.equals(scheme.getName()) && subPath.length() == (name.length() + mySchemeExtension.length()) && subPath.startsWith(name) && subPath.endsWith(mySchemeExtension)) { return UniqueNameGenerator.generateUniqueName(FileUtil.sanitizeName(schemeName), collectAllFileNames()); } } } return subPath; }
@Override public void addNewScheme(@Nonnull T scheme, boolean replaceExisting) { int toReplace = -1; for (int i = 0; i < mySchemes.size(); i++) { T existingScheme = mySchemes.get(i); if (existingScheme.getName().equals(scheme.getName())) { toReplace = i; break; } } if (toReplace == -1) { mySchemes.add(scheme); } else if (replaceExisting || !(scheme instanceof ExternalizableScheme)) { mySchemes.set(toReplace, scheme); } else { //noinspection unchecked renameScheme((ExternalizableScheme)scheme, UniqueNameGenerator.generateUniqueName(scheme.getName(), collectExistingNames(mySchemes))); mySchemes.add(scheme); } schemeAdded(scheme); checkCurrentScheme(scheme); }
public static PsiParameter[] overriddenParameters(PsiParameter[] parameters, @NotNull JVMElementFactory factory, @NotNull JavaCodeStyleManager codeStyleManager, @NotNull PsiSubstitutor substitutor, PsiElement target) { PsiParameter[] result = new PsiParameter[parameters.length]; UniqueNameGenerator generator = new UniqueNameGenerator(); for (int i = 0; i < parameters.length; i++) { PsiParameter parameter = parameters[i]; final PsiType parameterType = parameter.getType(); final PsiType substituted = substituteType(substitutor, parameterType, (PsiMethod)parameter.getDeclarationScope()); String paramName = parameter.getName(); boolean isBaseNameGenerated = true; final boolean isSubstituted = substituted.equals(parameterType); if (!isSubstituted && isBaseNameGenerated(codeStyleManager, TypeConversionUtil.erasure(parameterType), paramName)) { isBaseNameGenerated = false; } if (paramName == null || isBaseNameGenerated && !isSubstituted && isBaseNameGenerated(codeStyleManager, parameterType, paramName) || !factory.isValidParameterName(paramName)) { String[] names = codeStyleManager.suggestVariableName(VariableKind.PARAMETER, null, null, substituted).names; if (names.length > 0) { paramName = generator.generateUniqueName(names[0]); } else { paramName = generator.generateUniqueName("p"); } } else if (!generator.value(paramName)) { paramName = generator.generateUniqueName(paramName); } generator.addExistingName(paramName); result[i] = factory.createParameter(paramName, substituted, target); } return result; }
private static String getUniqueLibraryName(final String baseName, final LibraryTable.ModifiableModel model) { return UniqueNameGenerator.generateUniqueName(baseName, "", "", " (", ")", new Condition<String>() { @Override public boolean value(String s) { return model.getLibraryByName(s) == null; } }); }
@Override public final List<Pair<Element, String>> splitState(@NotNull Element state) { UniqueNameGenerator generator = new UniqueNameGenerator(); List<Pair<Element, String>> result = new SmartList<Pair<Element, String>>(); for (Iterator<Element> iterator = state.getChildren(getSubStateTagName()).iterator(); iterator.hasNext(); ) { Element element = iterator.next(); iterator.remove(); result.add(createItem(getSubStateFileName(element), generator, element)); } if (!JDOMUtil.isEmpty(state)) { result.add(createItem(getComponentStateFileName(), generator, state)); } return result; }
@NotNull protected static List<Pair<Element, String>> splitState(@NotNull Element state, @NotNull String attributeName) { UniqueNameGenerator generator = new UniqueNameGenerator(); List<Pair<Element, String>> result = new SmartList<Pair<Element, String>>(); for (Element subState : state.getChildren()) { result.add(createItem(generator, subState, attributeName)); } return result; }
private String generateServerName() { return UniqueNameGenerator.generateUniqueName(myCloudType.getPresentableName(), new Condition<String>() { @Override public boolean value(String s) { for (RemoteServer<?> server : RemoteServersManager.getInstance().getServers()) { if (server.getName().equals(s)) { return false; } } return true; } }); }
private static String generateServerName(ServerType<?> cloudType) { return UniqueNameGenerator.generateUniqueName(cloudType.getPresentableName(), new Condition<String>() { @Override public boolean value(String s) { for (RemoteServer<?> server : RemoteServersManager.getInstance().getServers()) { if (server.getName().equals(s)) { return false; } } return true; } }); }
public SaveSchemeDialog(@NotNull Component parent, String title, @NotNull List<String> existingNames, @NotNull String selectedName) { super(parent, false); myExistingNames = existingNames; setTitle(title); mySchemeName.setText(UniqueNameGenerator.generateUniqueName(selectedName + " copy", existingNames)); init(); }
@NotNull private File generateUniqueSchemePatchDir(@NotNull final String defaultName, boolean createResourceDirectory) { ignoreShelfDirectoryIfFirstShelf(); String uniqueName = UniqueNameGenerator .generateUniqueName(shortenAndSanitize(defaultName), mySchemeManager.getAllSchemeNames()); File dir = new File(myFileProcessor.getBaseDir(), uniqueName); if (createResourceDirectory && !dir.exists()) { //noinspection ResultOfMethodCallIgnored dir.mkdirs(); } return dir; }
ExportRunConfigurationTableModel(List<RunConfiguration> configurations) { enabled = new Boolean[configurations.size()]; names = new String[configurations.size()]; paths = new String[configurations.size()]; UniqueNameGenerator nameGenerator = new UniqueNameGenerator(); for (int i = 0; i < configurations.size(); i++) { RunConfiguration config = configurations.get(i); enabled[i] = false; names[i] = config.getName(); paths[i] = nameGenerator.generateUniqueName(FileUtil.sanitizeFileName(config.getName()), "", ".xml"); } }
@Override public List<Pair<Element, String>> splitState(Element e) { final UniqueNameGenerator generator = new UniqueNameGenerator(); final List<Pair<Element, String>> result = new ArrayList<Pair<Element, String>>(); result.add(new Pair<Element, String>(e, generator.generateUniqueName("template_variable_settings") + ".xml")); return result; }
private static void substituteParameters(@NotNull JVMElementFactory factory, @NotNull JavaCodeStyleManager codeStyleManager, @NotNull PsiParameterList sourceParameterList, @NotNull PsiParameterList targetParameterList, @NotNull PsiSubstitutor substitutor, PsiElement target) { PsiParameter[] parameters = sourceParameterList.getParameters(); UniqueNameGenerator generator = new UniqueNameGenerator(); for (PsiParameter parameter : parameters) { final PsiType parameterType = parameter.getType(); final PsiType substituted = substituteType(substitutor, parameterType, (PsiMethod)parameter.getDeclarationScope()); @NonNls String paramName = parameter.getName(); boolean isBaseNameGenerated = true; final boolean isSubstituted = substituted.equals(parameterType); if (!isSubstituted && isBaseNameGenerated(codeStyleManager, TypeConversionUtil.erasure(parameterType), paramName)) { isBaseNameGenerated = false; } if (paramName == null || isBaseNameGenerated && !isSubstituted && isBaseNameGenerated(codeStyleManager, parameterType, paramName) || !factory.isValidParameterName(paramName)) { String[] names = codeStyleManager.suggestVariableName(VariableKind.PARAMETER, null, null, substituted).names; if (names.length > 0) { paramName = generator.generateUniqueName(names[0]); } else { paramName = generator.generateUniqueName("p"); } } else if (!generator.value(paramName)) { paramName = generator.generateUniqueName(paramName); } generator.addExistingName(paramName); final PsiParameter newParameter = factory.createParameter(paramName, substituted, target); copyOrReplaceModifierList(parameter, newParameter); targetParameterList.add(newParameter); } }
public List<Pair<Element, String>> splitState(Element e) { final UniqueNameGenerator generator = new UniqueNameGenerator(); List<Pair<Element, String>> result = new ArrayList<Pair<Element, String>>(); for (Element element : JDOMUtil.getElements(e)) { final String name = generator.generateUniqueName(FileUtil.sanitizeFileName(element.getAttributeValue(ArtifactState.NAME_ATTRIBUTE))) + ".xml"; result.add(new Pair<Element, String>(element, name)); } return result; }
public List<Pair<Element, String>> splitState(Element e) { final UniqueNameGenerator generator = new UniqueNameGenerator(); List<Pair<Element, String>> result = new ArrayList<Pair<Element, String>>(); for (Element element : JDOMUtil.getElements(e)) { final String name = generator.generateUniqueName(FileUtil.sanitizeFileName(element.getAttributeValue(DictionaryState.NAME_ATTRIBUTE))) + ".xml"; result.add(new Pair<Element, String>(element, name)); } return result; }
@Override public List<Pair<Element, String>> splitState(Element e) { final UniqueNameGenerator generator = new UniqueNameGenerator(); List<Pair<Element, String>> result = new ArrayList<Pair<Element, String>>(); final List list = e.getChildren(); for (final Object o : list) { Element library = (Element)o; @NonNls final String name = generator.generateUniqueName(FileUtil.sanitizeFileName(library.getAttributeValue(LibraryImpl.LIBRARY_NAME_ATTR))) + ".xml"; result.add(new Pair<Element, String>(library, name)); } return result; }
@Override public List<Pair<Element, String>> splitState(Element e) { final UniqueNameGenerator generator = new UniqueNameGenerator(); List<Pair<Element, String>> result = new ArrayList<Pair<Element, String>>(); final List list = e.getChildren(); for (final Object o : list) { Element library = (Element)o; final String name = generator.generateUniqueName(FileUtil.sanitizeFileName(library.getAttributeValue(RunManagerImpl.NAME_ATTR))) + ".xml"; result.add(new Pair<Element, String>(library, name)); } return result; }
@Override public final List<Pair<Element, String>> splitState(@Nonnull Element state) { UniqueNameGenerator generator = new UniqueNameGenerator(); List<Pair<Element, String>> result = new SmartList<Pair<Element, String>>(); for (Iterator<Element> iterator = state.getChildren(getSubStateTagName()).iterator(); iterator.hasNext(); ) { Element element = iterator.next(); iterator.remove(); result.add(createItem(getSubStateFileName(element), generator, element)); } if (!JDOMUtil.isEmpty(state)) { result.add(createItem(getComponentStateFileName(), generator, state)); } return result; }
@Nonnull protected static List<Pair<Element, String>> splitState(@Nonnull Element state, @Nonnull String attributeName) { UniqueNameGenerator generator = new UniqueNameGenerator(); List<Pair<Element, String>> result = new SmartList<Pair<Element, String>>(); for (Element subState : state.getChildren()) { result.add(createItem(generator, subState, attributeName)); } return result; }
public SaveSchemeDialog(@Nonnull Component parent, String title, @Nonnull List<String> existingNames, @Nonnull String selectedName) { super(parent, false); myExistingNames = existingNames; setTitle(title); mySchemeName.setText(UniqueNameGenerator.generateUniqueName(selectedName + " copy", existingNames)); init(); }
@Nonnull private File generateUniqueSchemePatchDir(@Nonnull final String defaultName, boolean createResourceDirectory) { ignoreShelfDirectoryIfFirstShelf(); String uniqueName = UniqueNameGenerator.generateUniqueName(shortenAndSanitize(defaultName), mySchemeManager.getAllSchemeNames()); File dir = new File(myFileProcessor.getBaseDir(), uniqueName); if (createResourceDirectory && !dir.exists()) { //noinspection ResultOfMethodCallIgnored dir.mkdirs(); } return dir; }
public void saveMaps() throws IOException { File dir = getMapDirectory(); if(dir == null) { return; } File[] files = getMapFiles(dir); @NonNls String[] filePaths = new String[myMaps.size()]; Document[] documents = new Document[myMaps.size()]; UniqueNameGenerator namesProvider = new UniqueNameGenerator(); for(int i = 0; i < myMaps.size(); i++) { MigrationMap map = myMaps.get(i); filePaths[i] = dir + File.separator + namesProvider.generateUniqueName(map.getFileName()) + ".xml"; documents[i] = saveMap(map); } JDOMUtil.updateFileSet(files, filePaths, documents, CodeStyleSettingsManager.getSettings(null).getLineSeparator()); if(!myDeletedMaps.isEmpty()) { FileUtil.writeToFile(new File(dir, "deleted.txt"), StringUtil.join(myDeletedMaps, "\n")); } }
public JpsArtifact addArtifact(LayoutElementTestUtil.LayoutElementCreator root) { Set<String> usedNames = getArtifactNames(); final String name = UniqueNameGenerator.generateUniqueName("a", usedNames); return addArtifact(name, root); }
@NotNull protected static Pair<Element, String> createItem(@NotNull UniqueNameGenerator generator, @NotNull Element element, @NotNull String attributeName) { return createItem(element.getAttributeValue(attributeName), generator, element); }
@NotNull protected static Pair<Element, String> createItem(@NotNull String fileName, @NotNull UniqueNameGenerator generator, @NotNull Element element) { return Pair.create(element, generator.generateUniqueName(FileUtil.sanitizeFileName(fileName)) + ".xml"); }
@NotNull @Override public String generateFileName(@NotNull Condition<String> validator) { return UniqueNameGenerator.generateUniqueName("", myFileName, myFileExtension, "_", "", validator); }
private static String createUniqueFileName(final Collection<String> strings, final String schemeName) { return UniqueNameGenerator.generateUniqueName(schemeName, strings); }
@NotNull public Collection<SharedScheme<E>> loadSharedSchemes(Collection<T> currentSchemeList) { Collection<String> names = new HashSet<String>(getAllSchemeNames(currentSchemeList)); final StreamProvider[] providers = ((ApplicationImpl)ApplicationManager.getApplication()).getStateStore().getStateStorageManager() .getStreamProviders(RoamingType.GLOBAL); final HashMap<String, SharedScheme<E>> result = new HashMap<String, SharedScheme<E>>(); if (providers != null) { for (StreamProvider provider : providers) { if (provider.isEnabled()) { String[] paths = provider.listSubFiles(myFileSpec); for (String subpath : paths) { try { final Document subDocument = StorageUtil.loadDocument(provider.loadContent(getFileFullPath(subpath), RoamingType.GLOBAL)); if (subDocument != null) { SharedSchemeData original = unwrap(subDocument); final E scheme = myProcessor.readScheme(original.original); if (!alreadyShared(subpath, currentSchemeList)) { String schemeName = original.name; String uniqueName = UniqueNameGenerator.generateUniqueName("[shared] " + schemeName, names); renameScheme(scheme, uniqueName); schemeName = uniqueName; scheme.getExternalInfo().setOriginalPath(getFileFullPath(subpath)); scheme.getExternalInfo().setIsImported(true); result.put(schemeName, new SharedScheme<E>(original.user == null ? "unknown" : original.user, original.description, scheme)); } } } catch (Exception e) { LOG.debug("Cannot load data from IDEAServer: " + e.getLocalizedMessage()); } } } } } for (SharedScheme<E> t : result.values()) { myProcessor.initScheme(t.getScheme()); } return result.values(); }
private String generateUniqueName(final T scheme) { return UniqueNameGenerator.generateUniqueName(UniqueFileNamesProvider.convertName(scheme.getName()), collectExistingNames(mySchemes)); }
@Nonnull protected static Pair<Element, String> createItem(@Nonnull UniqueNameGenerator generator, @Nonnull Element element, @Nonnull String attributeName) { return createItem(element.getAttributeValue(attributeName), generator, element); }