diff --git a/src/main/java/org/jetbrains/research/refactorinsight/services/RefactoringsBundle.java b/src/main/java/org/jetbrains/research/refactorinsight/RefactorInsightBundle.java similarity index 78% rename from src/main/java/org/jetbrains/research/refactorinsight/services/RefactoringsBundle.java rename to src/main/java/org/jetbrains/research/refactorinsight/RefactorInsightBundle.java index 5ed76dbf..ce8038a3 100644 --- a/src/main/java/org/jetbrains/research/refactorinsight/services/RefactoringsBundle.java +++ b/src/main/java/org/jetbrains/research/refactorinsight/RefactorInsightBundle.java @@ -1,4 +1,4 @@ -package org.jetbrains.research.refactorinsight.services; +package org.jetbrains.research.refactorinsight; import com.intellij.AbstractBundle; import com.intellij.reference.SoftReference; @@ -6,11 +6,11 @@ import java.util.ResourceBundle; import org.jetbrains.annotations.PropertyKey; -public final class RefactoringsBundle { - private static final String BUNDLE = "RefactoringsBundle"; +public final class RefactorInsightBundle { + private static final String BUNDLE = "RefactorInsightBundle"; private static Reference INSTANCE; - private RefactoringsBundle() { + private RefactorInsightBundle() { } public static String message(@PropertyKey(resourceBundle = BUNDLE) String key, Object... params) { diff --git a/src/main/java/org/jetbrains/research/refactorinsight/actions/RefactoringAction.java b/src/main/java/org/jetbrains/research/refactorinsight/actions/RefactoringAction.java index 8c29cc94..3b70bfd0 100644 --- a/src/main/java/org/jetbrains/research/refactorinsight/actions/RefactoringAction.java +++ b/src/main/java/org/jetbrains/research/refactorinsight/actions/RefactoringAction.java @@ -8,7 +8,7 @@ import java.util.List; import org.jetbrains.annotations.NotNull; import org.jetbrains.research.refactorinsight.services.MiningService; -import org.jetbrains.research.refactorinsight.services.RefactoringsBundle; +import org.jetbrains.research.refactorinsight.RefactorInsightBundle; /** @@ -25,8 +25,8 @@ public void actionPerformed(@NotNull AnActionEvent e) { final List repositories = GitRepositoryManager .getInstance(e.getProject()).getRepositories(); if (repositories.isEmpty()) { - Messages.showErrorDialog(RefactoringsBundle.message("no.repo"), - RefactoringsBundle.message("name")); + Messages.showErrorDialog(RefactorInsightBundle.message("no.repo"), + RefactorInsightBundle.message("name")); return; } GitRepository repository = repositories.get(0); diff --git a/src/main/java/org/jetbrains/research/refactorinsight/processors/CommitMiner.java b/src/main/java/org/jetbrains/research/refactorinsight/processors/CommitMiner.java index af0e8a0d..d95ea7c1 100644 --- a/src/main/java/org/jetbrains/research/refactorinsight/processors/CommitMiner.java +++ b/src/main/java/org/jetbrains/research/refactorinsight/processors/CommitMiner.java @@ -1,5 +1,6 @@ package org.jetbrains.research.refactorinsight.processors; +import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.progress.ProcessCanceledException; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.project.Project; @@ -10,7 +11,6 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; -import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; @@ -19,7 +19,8 @@ import java.util.concurrent.atomic.AtomicInteger; import org.eclipse.jgit.lib.Repository; import org.jetbrains.research.refactorinsight.data.RefactoringEntry; -import org.jetbrains.research.refactorinsight.services.RefactoringsBundle; +import org.jetbrains.research.refactorinsight.RefactorInsightBundle; +import org.jetbrains.research.refactorinsight.services.MiningService; import org.refactoringminer.api.GitHistoryRefactoringMiner; import org.refactoringminer.api.GitService; import org.refactoringminer.api.Refactoring; @@ -33,7 +34,7 @@ * Consumes a git commit, calls RefactoringMiner and detects the refactorings for a commit. */ public class CommitMiner implements Consumer { - private static final String progress = RefactoringsBundle.message("progress"); + private static final String progress = RefactorInsightBundle.message("progress"); private final ExecutorService pool; private final Map map; private final Project myProject; @@ -52,40 +53,29 @@ public class CommitMiner implements Consumer { public CommitMiner(ExecutorService pool, Map map, GitRepository repository, AtomicInteger commitsDone, ProgressIndicator progressIndicator, int limit) { - this.pool = pool; this.map = map; myProject = repository.getProject(); //NB: nullable, check if initialized correctly - myRepository = openRepository(myProject.getBasePath()); + myRepository = ServiceManager.getService(myProject, MiningService.class).getRepository(); this.commitsDone = commitsDone; this.progressIndicator = progressIndicator; this.limit = limit; } - private static Repository openRepository(final String path) { - try { - return new GitServiceImpl().openRepository(path); - } catch (Exception e) { - e.printStackTrace(); - return null; - } - } - /** * Method that mines only one commit. * * @param commit commit metadata * @param map the inner map that should be updated * @param project the current project + * @param repository Git Repository */ public static void mineAtCommit(VcsCommitMetadata commit, Map map, - Project project) { - GitService gitService = new GitServiceImpl(); + Project project, Repository repository) { GitHistoryRefactoringMiner miner = new GitHistoryRefactoringMinerImpl(); try { - miner.detectAtCommit(gitService.openRepository(project.getBasePath()), - commit.getId().asString(), + miner.detectAtCommit(repository, commit.getId().asString(), new RefactoringHandler() { @Override public void handle(String commitId, List refactorings) { @@ -98,55 +88,6 @@ public void handle(String commitId, List refactorings) { } } - /** - * Mines a single commit if the mining process does not take longer than - * 60 seconds. - * - * @param commit to be mined - * @param map refactorings map - * @param project the current project - */ - public static void mineAtCommitTimeout(VcsCommitMetadata commit, - Map map, - Project project) { - GitService gitService = new GitServiceImpl(); - GitHistoryRefactoringMiner miner = new GitHistoryRefactoringMinerImpl(); - ExecutorService service = Executors.newSingleThreadExecutor(); - Future f = null; - final Repository repository; - try { - repository = gitService.openRepository(project.getBasePath()); - } catch (Exception e) { - return; - } - try { - Runnable r = () -> { - miner.detectAtCommit(repository, - commit.getId().asString(), new RefactoringHandler() { - @Override - public void handle(String commitId, List refactorings) { - map.put(commitId, - RefactoringEntry - .convert(refactorings, commit, project)); - } - }); - }; - f = service.submit(r); - f.get(60, TimeUnit.SECONDS); - } catch (TimeoutException e) { - if (f.cancel(true)) { - RefactoringEntry refactoringEntry = RefactoringEntry - .convert(new ArrayList<>(), commit, project); - refactoringEntry.setTimeout(true); - map.put(commit.getId().asString(), refactoringEntry); - } - } catch (Exception e) { - e.printStackTrace(); - } finally { - service.shutdown(); - } - } - /** * Mines a gitCommit. * Method that calls RefactoringMiner and updates the refactoring map. diff --git a/src/main/java/org/jetbrains/research/refactorinsight/processors/SingleCommitRefactoringTask.java b/src/main/java/org/jetbrains/research/refactorinsight/processors/SingleCommitRefactoringTask.java new file mode 100644 index 00000000..cfbbeaf0 --- /dev/null +++ b/src/main/java/org/jetbrains/research/refactorinsight/processors/SingleCommitRefactoringTask.java @@ -0,0 +1,145 @@ +package org.jetbrains.research.refactorinsight.processors; + +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.components.ServiceManager; +import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.progress.ProcessCanceledException; +import com.intellij.openapi.progress.ProgressIndicator; +import com.intellij.openapi.progress.ProgressManager; +import com.intellij.openapi.progress.Task; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.Ref; +import com.intellij.util.ExceptionUtil; +import com.intellij.vcs.log.VcsCommitMetadata; +import java.util.ArrayList; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; +import org.eclipse.jgit.lib.Repository; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.research.refactorinsight.RefactorInsightBundle; +import org.jetbrains.research.refactorinsight.data.RefactoringEntry; +import org.jetbrains.research.refactorinsight.services.MiningService; +import org.jetbrains.research.refactorinsight.ui.windows.GitWindow; + +public class SingleCommitRefactoringTask extends Task.Backgroundable { + + private final Project project; + private final VcsCommitMetadata commit; + private final GitWindow window; + private final MiningService service; + private final Repository myRepository; + private boolean canceled = false; + private final Logger logger = Logger.getInstance(SingleCommitRefactoringTask.class); + + /** + * Cancelable mining task for mining a single commit. + * + * @param project Current IDEA project + * @param commit Commit meta data + * @param window Git Window for callback + */ + public SingleCommitRefactoringTask( + @Nullable Project project, + VcsCommitMetadata commit, + GitWindow window) { + super(project, + String.format(RefactorInsightBundle.message("mining.at"), commit.getId().toShortString())); + this.project = project; + this.commit = commit; + this.window = window; + this.service = ServiceManager.getService(project, MiningService.class); + this.myRepository = service.getRepository(); + } + + @Override + public void onCancel() { + super.onCancel(); + } + + @Override + public void onFinished() { + super.onFinished(); + if (service.containsCommit(commit.getId().asString())) { + System.out.println(RefactorInsightBundle.message("finished")); + ApplicationManager.getApplication() + .invokeLater(() -> window.refresh(commit.getId().asString())); + } + } + + @Override + public void run(@NotNull ProgressIndicator progressIndicator) { + try { + runWithCheckCanceled( + () -> CommitMiner.mineAtCommit(commit, service.getState().refactoringsMap.map, project, myRepository), + progressIndicator, commit, project + ); + } catch (Exception e) { + logger.info(String.format("The mining of refactorings at the commit %s was canceled", commit.getId())); + } + } + + public void cancel() { + canceled = true; + } + + /** + * Allows to interrupt a process which does not performs checkCancelled() calls by itself. + */ + public void runWithCheckCanceled(@NotNull final Runnable runnable, + @NotNull final ProgressIndicator indicator, + VcsCommitMetadata commit, Project project) throws Exception { + final Ref error = Ref.create(); + Future future = ApplicationManager.getApplication().executeOnPooledThread( + () -> ProgressManager.getInstance().executeProcessUnderProgress(() -> { + try { + runnable.run(); + } catch (Throwable t) { + error.set(t); + } + }, indicator) + ); + try { + runWithCheckCanceled(future, indicator, commit, project); + ExceptionUtil.rethrowAll(error.get()); + } catch (ProcessCanceledException e) { + future.cancel(true); + throw e; + } + } + + /** + * Waits for {@code future} to be complete or reach the maximum allowed mining time of 60 sec, + * or the current thread's indicator to be canceled. + */ + private void runWithCheckCanceled(@NotNull Future future, + @NotNull final ProgressIndicator indicator, + VcsCommitMetadata commit, Project project) throws + ExecutionException { + int timeout = 6000; + while (timeout > 0) { + if (canceled) { + indicator.cancel(); + } + indicator.checkCanceled(); + try { + future.get(10, TimeUnit.MILLISECONDS); + return; + } catch (InterruptedException e) { + throw new ProcessCanceledException(e); + } catch (TimeoutException ignored) { + logger.info("The timeout has been exceeded while checking task cancellation"); + } + timeout -= 1; + } + if (timeout == 0) { + RefactoringEntry refactoringEntry = RefactoringEntry + .convert(new ArrayList<>(), commit, project); + refactoringEntry.setTimeout(true); + MiningService.getInstance(project).getState().refactoringsMap.map.put(commit.getId().asString(), + refactoringEntry); + } + } +} \ No newline at end of file diff --git a/src/main/java/org/jetbrains/research/refactorinsight/services/MiningService.java b/src/main/java/org/jetbrains/research/refactorinsight/services/MiningService.java index 5f40cdd1..b34a3f0c 100644 --- a/src/main/java/org/jetbrains/research/refactorinsight/services/MiningService.java +++ b/src/main/java/org/jetbrains/research/refactorinsight/services/MiningService.java @@ -1,6 +1,5 @@ package org.jetbrains.research.refactorinsight.services; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.components.PersistentStateComponent; import com.intellij.openapi.components.Service; import com.intellij.openapi.components.ServiceManager; @@ -14,6 +13,7 @@ import com.intellij.vcs.log.VcsCommitMetadata; import git4idea.history.GitHistoryUtils; import git4idea.repo.GitRepository; + import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -24,17 +24,22 @@ import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; + +import org.eclipse.jgit.lib.Repository; import org.jetbrains.annotations.NotNull; +import org.jetbrains.research.refactorinsight.RefactorInsightBundle; import org.jetbrains.research.refactorinsight.data.RefactoringEntry; import org.jetbrains.research.refactorinsight.data.RefactoringInfo; import org.jetbrains.research.refactorinsight.processors.CommitMiner; +import org.jetbrains.research.refactorinsight.processors.SingleCommitRefactoringTask; import org.jetbrains.research.refactorinsight.ui.windows.GitWindow; import org.jetbrains.research.refactorinsight.utils.Utils; +import org.refactoringminer.util.GitServiceImpl; /** * This is the MiningService. * It computes, process and stores the data retrieved from RefactoringMiner. - * It can mine 1 specific commit, a fixed number of commits, or all commits in the repository. + * It can mine one specific commit, a fixed number of commits, or all commits in the repository. * it stores and persists the detected refactoring data in .idea/refactorings.xml file. */ @State(name = "MiningRefactoringsState", @@ -43,9 +48,11 @@ public class MiningService implements PersistentStateComponent { public static ConcurrentHashMap> methodHistory - = new ConcurrentHashMap>(); + = new ConcurrentHashMap<>(); private boolean mining = false; private MyState innerState = new MyState(); + private SingleCommitRefactoringTask task = null; + private Repository myRepository = null; public MiningService() { } @@ -73,6 +80,19 @@ public void loadState(MyState state) { } } + public Repository getRepository() { + return myRepository; + } + + private static Repository openRepository(final String path) { + try { + return new GitServiceImpl().openRepository(path); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + /** * Mine complete git repo for refactorings. * @@ -112,8 +132,11 @@ public void mineRepo(GitRepository repository) { * @param limit int */ public void mineRepo(GitRepository repository, int limit) { + if (myRepository == null) { + myRepository = openRepository(repository.getProject().getBasePath()); + } ProgressManager.getInstance() - .run(new Task.Backgroundable(repository.getProject(), "Mining refactorings", true) { + .run(new Task.Backgroundable(repository.getProject(), RefactorInsightBundle.message("mining"), true) { @Override public void onCancel() { @@ -122,7 +145,7 @@ public void onCancel() { public void run(@NotNull ProgressIndicator progressIndicator) { mining = true; - progressIndicator.setText(RefactoringsBundle.message("mining")); + progressIndicator.setText(RefactorInsightBundle.message("mining")); progressIndicator.setIndeterminate(false); int cores = SettingsState .getInstance(repository.getProject()).threads; @@ -154,7 +177,7 @@ public void run(@NotNull ProgressIndicator progressIndicator) { if (repository.getCurrentRevision() != null) { computeRefactoringHistory(repository.getCurrentRevision(), repository.getProject()); } - progressIndicator.setText(RefactoringsBundle.message("finished")); + progressIndicator.setText(RefactorInsightBundle.message("finished")); } }); } @@ -178,38 +201,24 @@ public void mineAndWait(GitRepository repository) { } /** - * Method for mining a single commit. + * Mine refactorings in the specific commit. * * @param commit to be mined. * @param project current project. - * @param info to be updated. + * @param window to be updated. */ - public void mineAtCommit(VcsCommitMetadata commit, Project project, GitWindow info) { - ProgressManager.getInstance() - .run(new Task.Backgroundable(project, String.format( - RefactoringsBundle.message("mining.at"), commit.getId().asString())) { - - @Override - public void onCancel() { - super.onCancel(); - } - - public void onFinished() { - super.onFinished(); - if (containsCommit(commit.getId().asString())) { - System.out.println(RefactoringsBundle.message("finished")); - ApplicationManager.getApplication() - .invokeLater(() -> info.refresh(commit.getId().asString())); - } - } + public void mineAtCommit(VcsCommitMetadata commit, Project project, GitWindow window) { + if (task != null) { + task.cancel(); + } + if (myRepository == null) { + myRepository = openRepository(project.getBasePath()); + } - public void run(@NotNull ProgressIndicator progressIndicator) { - CommitMiner.mineAtCommitTimeout(commit, innerState.refactoringsMap.map, project); - } - }); + task = new SingleCommitRefactoringTask(project, commit, window); + ProgressManager.getInstance().run(task); } - public Map> getRefactoringHistory() { return methodHistory; } diff --git a/src/main/java/org/jetbrains/research/refactorinsight/services/SettingsConfigurable.java b/src/main/java/org/jetbrains/research/refactorinsight/services/SettingsConfigurable.java index 6370b9dd..2f8bd00d 100644 --- a/src/main/java/org/jetbrains/research/refactorinsight/services/SettingsConfigurable.java +++ b/src/main/java/org/jetbrains/research/refactorinsight/services/SettingsConfigurable.java @@ -2,13 +2,13 @@ import com.intellij.openapi.options.Configurable; import com.intellij.openapi.project.Project; -import com.intellij.openapi.ui.Messages; import git4idea.repo.GitRepository; import git4idea.repo.GitRepositoryManager; import java.util.List; import javax.swing.JComponent; import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.Nullable; +import org.jetbrains.research.refactorinsight.RefactorInsightBundle; import org.jetbrains.research.refactorinsight.ui.windows.SettingsComponent; /** @@ -25,7 +25,7 @@ public SettingsConfigurable(Project project) { @Nls(capitalization = Nls.Capitalization.Title) @Override public String getDisplayName() { - return RefactoringsBundle.message("setting"); + return RefactorInsightBundle.message("setting"); } @Override diff --git a/src/main/java/org/jetbrains/research/refactorinsight/ui/windows/GitWindow.java b/src/main/java/org/jetbrains/research/refactorinsight/ui/windows/GitWindow.java index 6376c053..86dc2ec7 100644 --- a/src/main/java/org/jetbrains/research/refactorinsight/ui/windows/GitWindow.java +++ b/src/main/java/org/jetbrains/research/refactorinsight/ui/windows/GitWindow.java @@ -15,7 +15,7 @@ import com.intellij.vcs.log.ui.MainVcsLogUi; import com.intellij.vcs.log.ui.table.VcsLogColumn; import com.intellij.vcs.log.ui.table.VcsLogGraphTable; -import icons.RefactorInsightIcons; + import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.util.Objects; @@ -23,11 +23,13 @@ import javax.swing.SwingConstants; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.TreePath; + +import icons.RefactorInsightIcons; import org.jetbrains.annotations.NotNull; import org.jetbrains.research.refactorinsight.data.RefactoringEntry; import org.jetbrains.research.refactorinsight.data.RefactoringInfo; import org.jetbrains.research.refactorinsight.services.MiningService; -import org.jetbrains.research.refactorinsight.services.RefactoringsBundle; +import org.jetbrains.research.refactorinsight.RefactorInsightBundle; import org.jetbrains.research.refactorinsight.ui.tree.TreeUtils; import org.jetbrains.research.refactorinsight.ui.tree.renderers.MainCellRenderer; @@ -129,7 +131,7 @@ private void buildComponent() { if (entry.timeout || entry.getRefactorings().isEmpty()) { final JBLabel component = - new JBLabel(RefactoringsBundle.message("no.ref"), SwingConstants.CENTER); + new JBLabel(RefactorInsightBundle.message("no.ref"), SwingConstants.CENTER); component.setForeground(Gray._105); viewport.setView(component); return; diff --git a/src/main/java/org/jetbrains/research/refactorinsight/ui/windows/RefactoringHistoryToolbar.java b/src/main/java/org/jetbrains/research/refactorinsight/ui/windows/RefactoringHistoryToolbar.java index aba1204e..b895c330 100644 --- a/src/main/java/org/jetbrains/research/refactorinsight/ui/windows/RefactoringHistoryToolbar.java +++ b/src/main/java/org/jetbrains/research/refactorinsight/ui/windows/RefactoringHistoryToolbar.java @@ -43,7 +43,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.research.refactorinsight.data.RefactoringInfo; -import org.jetbrains.research.refactorinsight.services.RefactoringsBundle; +import org.jetbrains.research.refactorinsight.RefactorInsightBundle; import org.jetbrains.research.refactorinsight.ui.tree.TreeUtils; import org.jetbrains.research.refactorinsight.ui.tree.renderers.HistoryToolbarRenderer; import org.jetbrains.research.refactorinsight.utils.Utils; @@ -74,7 +74,7 @@ public RefactoringHistoryToolbar(Project project) { factory = VcsProjectLog.getInstance(project).getLogManager() .getMainLogUiFactory("method history", VcsLogFilterObject.collection()); toolWindow = - toolWindowManager.registerToolWindow(RefactoringsBundle.message("history"), + toolWindowManager.registerToolWindow(RefactorInsightBundle.message("history"), true, ToolWindowAnchor.BOTTOM); } @@ -112,7 +112,7 @@ public void showToolbar(Set refactorings, private void setSecondComponent(JBSplitter splitter) { final JBLabel component = - new JBLabel(RefactoringsBundle.message("click.to.jump"), SwingConstants.CENTER); + new JBLabel(RefactorInsightBundle.message("click.to.jump"), SwingConstants.CENTER); component.setForeground(Gray._105); splitter.setSecondComponent(component); } @@ -120,7 +120,7 @@ private void setSecondComponent(JBSplitter splitter) { private void setFirstComponent(int size, JBSplitter splitter, Tree tree) { JBScrollPane pane = new JBScrollPane(tree); JBLabel label = - new JBLabel(String.format(RefactoringsBundle.message("how.many.detected"), + new JBLabel(String.format(RefactorInsightBundle.message("how.many.detected"), size, size > 1 ? "s" : "", type.toString().toLowerCase())); label.setForeground(Gray._105); pane.setColumnHeaderView(label); @@ -192,7 +192,7 @@ private Tree createTree(List refactorings, if (methods != null && !methods.isEmpty()) { DefaultMutableTreeNode child = new DefaultMutableTreeNode( - RefactoringsBundle.message("check.methods")); + RefactorInsightBundle.message("check.methods")); addObjectsToTree(methods, child, true); if (child.getChildCount() > 0) { root.add(child); @@ -201,7 +201,7 @@ private Tree createTree(List refactorings, if (attributes != null && !attributes.isEmpty()) { DefaultMutableTreeNode child = new DefaultMutableTreeNode( - RefactoringsBundle.message("check.fields")); + RefactorInsightBundle.message("check.fields")); addObjectsToTree(attributes, child, false); if (child.getChildCount() > 0) { root.add(child); @@ -264,7 +264,7 @@ private void showContent(String methodName, JComponent tree) { private void showPopup(DataContext datacontext) { JBPanel panel = new JBPanel(new GridLayout(0, 1)); - panel.add(new JBLabel(RefactoringsBundle.message("no.ref.history"))); + panel.add(new JBLabel(RefactorInsightBundle.message("no.ref.history"))); JBPopup popup = JBPopupFactory.getInstance() .createComponentPopupBuilder(panel, null).createPopup(); popup.showInBestPositionFor(datacontext); diff --git a/src/main/java/org/jetbrains/research/refactorinsight/ui/windows/SettingsComponent.java b/src/main/java/org/jetbrains/research/refactorinsight/ui/windows/SettingsComponent.java index 936db74b..e61bf102 100644 --- a/src/main/java/org/jetbrains/research/refactorinsight/ui/windows/SettingsComponent.java +++ b/src/main/java/org/jetbrains/research/refactorinsight/ui/windows/SettingsComponent.java @@ -15,7 +15,7 @@ import javax.swing.JComponent; import javax.swing.JPanel; import org.jetbrains.research.refactorinsight.services.MiningService; -import org.jetbrains.research.refactorinsight.services.RefactoringsBundle; +import org.jetbrains.research.refactorinsight.RefactorInsightBundle; import org.jetbrains.research.refactorinsight.services.RefactoringsMapConverter; /** @@ -36,14 +36,14 @@ public class SettingsComponent { public SettingsComponent(Project project) { - JButton clear = new JButton(RefactoringsBundle.message("button.clear")); + JButton clear = new JButton(RefactorInsightBundle.message("button.clear")); clear.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { MiningService.getInstance(project).clear(); } }); - JButton all = new JButton(RefactoringsBundle.message("button.mine")); + JButton all = new JButton(RefactorInsightBundle.message("button.mine")); all.setPreferredSize(clear.getPreferredSize()); all.addMouseListener(new MouseAdapter() { @Override @@ -53,7 +53,7 @@ public void mouseClicked(MouseEvent e) { MiningService.getInstance(project).mineAll(repository); } }); - JButton choose = new JButton(RefactoringsBundle.message("button.import")); + JButton choose = new JButton(RefactorInsightBundle.message("button.import")); choose.setPreferredSize(clear.getPreferredSize()); choose.addMouseListener(new MouseAdapter() { @Override @@ -70,8 +70,8 @@ public void mouseClicked(MouseEvent e) { MiningService.getInstance(project).getState().refactoringsMap = new RefactoringsMapConverter().fromString(content); } catch (Exception ex) { - Messages.showErrorDialog(RefactoringsBundle.message("bad.file"), - RefactoringsBundle.message("name")); + Messages.showErrorDialog(RefactorInsightBundle.message("bad.file"), + RefactorInsightBundle.message("name")); } } ); @@ -79,10 +79,10 @@ public void mouseClicked(MouseEvent e) { }); myMainPanel = FormBuilder.createFormBuilder() - .addLabeledComponent(RefactoringsBundle.message("label.max.commits"), commitLimit, 1, false) - .addLabeledComponent(RefactoringsBundle.message("label.max.history"), historyLimit, 1, + .addLabeledComponent(RefactorInsightBundle.message("label.max.commits"), commitLimit, 1, false) + .addLabeledComponent(RefactorInsightBundle.message("label.max.history"), historyLimit, 1, false) - .addLabeledComponent(RefactoringsBundle.message("label.threads"), threads, 1, false) + .addLabeledComponent(RefactorInsightBundle.message("label.threads"), threads, 1, false) .addComponent(clear) .addComponent(all) .addComponent(choose) diff --git a/src/main/java/org/jetbrains/research/refactorinsight/utils/IdeUtils.java b/src/main/java/org/jetbrains/research/refactorinsight/utils/IdeUtils.java new file mode 100644 index 00000000..e69de29b diff --git a/src/main/java/org/jetbrains/research/refactorinsight/utils/Utils.java b/src/main/java/org/jetbrains/research/refactorinsight/utils/Utils.java index 21d36a79..b39098ad 100644 --- a/src/main/java/org/jetbrains/research/refactorinsight/utils/Utils.java +++ b/src/main/java/org/jetbrains/research/refactorinsight/utils/Utils.java @@ -33,7 +33,7 @@ import org.jetbrains.research.refactorinsight.data.RefactoringEntry; import org.jetbrains.research.refactorinsight.data.RefactoringInfo; import org.jetbrains.research.refactorinsight.data.RefactoringLine; -import org.jetbrains.research.refactorinsight.services.RefactoringsBundle; +import org.jetbrains.research.refactorinsight.RefactorInsightBundle; import org.refactoringminer.api.RefactoringType; public class Utils { @@ -179,20 +179,20 @@ public static RefactoringInfo getMainRefactoringInfo(List infos if (infos.stream().anyMatch(ofType(RENAME_ATTRIBUTE)) && infos.stream().anyMatch(ofType(CHANGE_ATTRIBUTE_TYPE))) { info = infos.stream().filter(ofType(RENAME_ATTRIBUTE)).findFirst().get(); - info.setName(RefactoringsBundle.message("change.rename.attribute")); + info.setName(RefactorInsightBundle.message("change.rename.attribute")); } else if (infos.stream().anyMatch(ofType(RENAME_ATTRIBUTE))) { info = infos.stream().filter(ofType(RENAME_ATTRIBUTE)).findFirst().get(); - info.setName(RefactoringsBundle.message("rename.attribute")); + info.setName(RefactorInsightBundle.message("rename.attribute")); } else if (infos.stream().anyMatch(ofType(CHANGE_ATTRIBUTE_TYPE))) { info = infos.stream().filter(ofType(CHANGE_ATTRIBUTE_TYPE)).findFirst().get(); - info.setName(RefactoringsBundle.message("change.attribute")); + info.setName(RefactorInsightBundle.message("change.attribute")); } else if (infos.stream().anyMatch(ofType(CHANGE_VARIABLE_TYPE))) { info = infos.stream().filter(ofType(CHANGE_VARIABLE_TYPE)).findFirst().get(); - info.setName(RefactoringsBundle.message("change.rename.var")); + info.setName(RefactorInsightBundle.message("change.rename.var")); } else if (infos.stream().anyMatch(ofType(RENAME_PARAMETER)) && infos.stream().anyMatch(ofType(CHANGE_PARAMETER_TYPE))) { info = infos.stream().filter(ofType(RENAME_PARAMETER)).findFirst().get(); - info.setName(RefactoringsBundle.message("change.rename.param")); + info.setName(RefactorInsightBundle.message("change.rename.param")); } return info; } @@ -296,7 +296,7 @@ public static int getCommitCount(GitRepository repository) throws IOException { * @return the current version. */ public static String version() { - return RefactoringsBundle.message("version") + String.valueOf(Stream.of( + return RefactorInsightBundle.message("version") + String.valueOf(Stream.of( //all classes that can change RefactoringEntry.class, RefactoringInfo.class, diff --git a/src/main/resources/RefactoringsBundle.properties b/src/main/resources/RefactorInsightBundle.properties similarity index 100% rename from src/main/resources/RefactoringsBundle.properties rename to src/main/resources/RefactorInsightBundle.properties