From a5917514b6208d0c13cbdaa2df989c512e09735f Mon Sep 17 00:00:00 2001 From: Manindra Moharana Date: Sat, 17 Aug 2013 21:11:26 +0530 Subject: [PATCH] validate new name before refactor --- pdex/Todo, GSoC 2013.txt | 1 + .../processing/mode/experimental/ASTGenerator.java | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/pdex/Todo, GSoC 2013.txt b/pdex/Todo, GSoC 2013.txt index cd2025c60..b8583482d 100644 --- a/pdex/Todo, GSoC 2013.txt +++ b/pdex/Todo, GSoC 2013.txt @@ -71,6 +71,7 @@ Refactoring * Undo misbehaves here, handle carefully. +x New Name is validated. x Ordered list in 'Show Usage' window x Add support for word select on right click and rename, mouse co-ordinates need to obtained carefully diff --git a/pdex/src/processing/mode/experimental/ASTGenerator.java b/pdex/src/processing/mode/experimental/ASTGenerator.java index 9073a4d70..025b17a18 100644 --- a/pdex/src/processing/mode/experimental/ASTGenerator.java +++ b/pdex/src/processing/mode/experimental/ASTGenerator.java @@ -1806,7 +1806,7 @@ public class ASTGenerator { } private void refactorIt(){ - String newName = txtRenameField.getText(); + String newName = txtRenameField.getText().trim(); String selText = lastClickedWord == null ? editor.ta.getSelectedText() : lastClickedWord; DefaultMutableTreeNode defCU = findAllOccurrences(); @@ -1814,6 +1814,14 @@ public class ASTGenerator { editor.statusError("Can't locate definition of " + selText); return; } + + if(!newName.matches("([a-zA-Z][a-zA-Z0-9_]*)|([_][a-zA-Z0-9_]+)")) + { + JOptionPane.showConfirmDialog(new JFrame(), newName + " isn't a valid name.","Uh oh..", JOptionPane.PLAIN_MESSAGE); + return; + } + //else log("New name looks K."); + errorCheckerService.pauseThread(); treeRename.setModel(new DefaultTreeModel(defCU)); ((DefaultTreeModel) treeRename.getModel()).reload(); @@ -1851,7 +1859,7 @@ public class ASTGenerator { pdeoffsets[1], javaoffsets[1] + off, javaoffsets[2]); - //int k = JOptionPane.showConfirmDialog(new JFrame(), "Rename?","", JOptionPane.OK_OPTION)); + //int k = JOptionPane.showConfirmDialog(new JFrame(), "Rename?","", JOptionPane.INFORMATION_MESSAGE)); editor.ta.setSelectedText(newName); } errorCheckerService.resumeThread();