mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
cleanup
This commit is contained in:
@@ -23,11 +23,12 @@ import com.intellij.openapi.util.JDOMUtil;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
|
||||
import com.intellij.util.UniqueFileNamesProvider;
|
||||
import com.intellij.util.text.UniqueNameGenerator;
|
||||
import org.jdom.Document;
|
||||
import org.jdom.Element;
|
||||
import org.jdom.JDOMException;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.URL;
|
||||
@@ -91,9 +92,8 @@ public class MigrationMapSet {
|
||||
return ret;
|
||||
}
|
||||
|
||||
private File getMapDirectory() {
|
||||
@NonNls String directoryPath = PathManager.getConfigPath() + File.separator + "migration";
|
||||
File dir = new File(directoryPath);
|
||||
private static File getMapDirectory() {
|
||||
File dir = new File(PathManager.getConfigPath() + File.separator + "migration");
|
||||
|
||||
if (!dir.exists()){
|
||||
if (!dir.mkdir()){
|
||||
@@ -129,14 +129,15 @@ public class MigrationMapSet {
|
||||
return dir;
|
||||
}
|
||||
|
||||
private File[] getMapFiles() {
|
||||
private static File[] getMapFiles() {
|
||||
File dir = getMapDirectory();
|
||||
if (dir == null){
|
||||
return new File[0];
|
||||
}
|
||||
File[] ret = dir.listFiles(new FileFilter() {
|
||||
@Override
|
||||
@SuppressWarnings({"HardCodedStringLiteral"})
|
||||
public boolean accept(File file){
|
||||
public boolean accept(@NotNull File file){
|
||||
return !file.isDirectory() && StringUtil.endsWithIgnoreCase(file.getName(), ".xml");
|
||||
}
|
||||
});
|
||||
@@ -170,12 +171,13 @@ public class MigrationMapSet {
|
||||
}
|
||||
}
|
||||
|
||||
private MigrationMap readMap(File file) throws JDOMException, InvalidDataException, IOException {
|
||||
if (!file.exists()) return null;
|
||||
Document document = JDOMUtil.loadDocument(file);
|
||||
private static MigrationMap readMap(File file) throws JDOMException, InvalidDataException, IOException {
|
||||
if (!file.exists()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Element root = document.getRootElement();
|
||||
if (root == null || !MIGRATION_MAP.equals(root.getName())){
|
||||
Element root = JDOMUtil.load(file);
|
||||
if (!MIGRATION_MAP.equals(root.getName())){
|
||||
throw new InvalidDataException();
|
||||
}
|
||||
|
||||
@@ -237,18 +239,18 @@ public class MigrationMapSet {
|
||||
@NonNls String[] filePaths = new String[myMaps.size()];
|
||||
Document[] documents = new Document[myMaps.size()];
|
||||
|
||||
UniqueFileNamesProvider namesProvider = new UniqueFileNamesProvider();
|
||||
UniqueNameGenerator namesProvider = new UniqueNameGenerator();
|
||||
for(int i = 0; i < myMaps.size(); i++){
|
||||
MigrationMap map = myMaps.get(i);
|
||||
|
||||
filePaths[i] = dir + File.separator + namesProvider.suggestName(map.getName()) + ".xml";
|
||||
filePaths[i] = dir + File.separator + namesProvider.generateUniqueName(FileUtil.sanitizeName(map.getName())) + ".xml";
|
||||
documents[i] = saveMap(map);
|
||||
}
|
||||
|
||||
JDOMUtil.updateFileSet(files, filePaths, documents, CodeStyleSettingsManager.getSettings(null).getLineSeparator());
|
||||
}
|
||||
|
||||
private Document saveMap(MigrationMap map) {
|
||||
private static Document saveMap(MigrationMap map) {
|
||||
Element root = new Element(MIGRATION_MAP);
|
||||
|
||||
Element nameElement = new Element(NAME);
|
||||
|
||||
@@ -35,7 +35,6 @@ import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.PsiManagerImpl;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jdom.Document;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -145,10 +144,8 @@ public abstract class PsiTestCase extends ModuleTestCase {
|
||||
}
|
||||
|
||||
private PsiTestData loadData(String dataName) throws Exception {
|
||||
Document document = JDOMUtil.loadDocument(new File(myDataRoot + "/" + "data.xml"));
|
||||
|
||||
PsiTestData data = createData();
|
||||
Element documentElement = document.getRootElement();
|
||||
Element documentElement = JDOMUtil.load(new File(myDataRoot + "/" + "data.xml"));
|
||||
|
||||
final List nodes = documentElement.getChildren("data");
|
||||
|
||||
|
||||
+1
-2
@@ -174,8 +174,7 @@ public class PluginsAdvertiser implements StartupActivity {
|
||||
try {
|
||||
File file = getExtensionsFile();
|
||||
if (file.isFile()) {
|
||||
final Document document = JDOMUtil.loadDocument(file);
|
||||
knownExtensions = XmlSerializer.deserialize(document, KnownExtensions.class);
|
||||
knownExtensions = XmlSerializer.deserialize(JDOMUtil.load(file), KnownExtensions.class);
|
||||
ourKnownExtensions = new SoftReference<KnownExtensions>(knownExtensions);
|
||||
return knownExtensions;
|
||||
}
|
||||
|
||||
+1
-3
@@ -4,7 +4,6 @@ import com.intellij.openapi.util.JDOMUtil;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.testFramework.PlatformTestUtil;
|
||||
import com.intellij.util.containers.HashMap;
|
||||
import org.jdom.Document;
|
||||
import org.jdom.Element;
|
||||
import org.jdom.JDOMException;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
@@ -27,8 +26,7 @@ import java.util.Map;
|
||||
public TestBlock readTestBlock(String dataName) throws IOException, JDOMException {
|
||||
final File dataFile = new File( PlatformTestUtil.getCommunityPath().replace(File.separatorChar, '/') +
|
||||
"/platform/platform-tests/testData/newGeneralFormatter", dataName + ".xml");
|
||||
final Document document = JDOMUtil.loadDocument(dataFile);
|
||||
return readBlock(document.getRootElement());
|
||||
return readBlock(JDOMUtil.load(dataFile));
|
||||
}
|
||||
|
||||
private TestBlock readBlock(final Element rootElement) {
|
||||
|
||||
@@ -356,6 +356,11 @@ public class JDOMUtil {
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Element load(@NotNull File file) throws JDOMException, IOException {
|
||||
return load(new BufferedInputStream(new FileInputStream(file)));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Document loadDocument(@NotNull InputStream stream) throws JDOMException, IOException {
|
||||
InputStreamReader reader = new InputStreamReader(stream, CharsetToolkit.UTF8_CHARSET);
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.intellij.openapi.util.io.FileUtil;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Deprecated
|
||||
/**
|
||||
* Use {@link com.intellij.util.text.UniqueNameGenerator}
|
||||
|
||||
Reference in New Issue
Block a user