?? refactorings.java
字號:
package com.xrefactory.jedit;import org.gjt.sp.jedit.*;import javax.swing.*;import org.gjt.sp.jedit.io.*;import java.io.*;public abstract class Refactorings { String param; // abstract methods abstract int getCode(); abstract public String toString(); void perform() { if (s.debug) new Exception().printStackTrace(System.err); JOptionPane.showMessageDialog(s.view, "Not yet implemented", "Xrefactory Error", JOptionPane.ERROR_MESSAGE); } static void setMovingTarget() { s.targetFile = s.getFileName(); s.targetLine = s.getTextArea().getCaretLine()+1; } static public class No_refactoring extends Refactorings { int getCode() { return(Protocol.PPC_AVR_NO_REFACTORING); } public String toString() { return("No Refactoring"); } void perform() { } } static public class Rename_symbol extends Refactorings { int getCode() { return(Protocol.PPC_AVR_RENAME_SYMBOL); } public String toString() { return("Rename"); } void perform() { RenameDialog dd = new RenameDialog("symbol", s.getIdentifierOnCaret()); String newname = dd.getNewName(); renameSymbol(newname); } } static public class Rename_class extends Refactorings { int getCode() { return(Protocol.PPC_AVR_RENAME_CLASS); } public String toString() { return("Rename Class"); } void perform() { RenameDialog dd = new RenameDialog("class",s.getIdentifierOnCaret()); String newname = dd.getNewName(); renameClass(newname,false); } } static public class Rename_package extends Refactorings { int getCode() { return(Protocol.PPC_AVR_RENAME_PACKAGE); } public String toString() { return("Rename Package"); } void perform() { RenameDialog dd = new RenameDialog("package", s.dotifyString(param)); String newname = dd.getNewName(); if (newname!=null) { XrefStringArray xroption = new XrefStringArray(); xroption.add("-rfct-rename-package"); xroption.add("-renameto="+newname); mainRefactorerInvocation(xroption,false); } } } static public class Add_parameter extends Refactorings { int getCode() { return(Protocol.PPC_AVR_ADD_PARAMETER); } public String toString() { return("Add Parameter"); } void perform() { AddParameterDialog d = new AddParameterDialog(s.getIdentifierOnCaret()); int position = Integer.parseInt(d.getPosition()); String definition = d. getDefinition(); String usage = d.getUsage(); if (position>0 && (!definition.equals("")) && (!usage.equals(""))) { XrefStringArray xroption = new XrefStringArray(); xroption.add("-rfct-add-param"); xroption.add("-olcxparnum="+position); xroption.add("-rfct-param1="+definition); xroption.add("-rfct-param2="+usage); mainRefactorerInvocation(xroption,false); } } } static public class Del_parameter extends Refactorings { int getCode() { return(Protocol.PPC_AVR_DEL_PARAMETER); } public String toString() { return("Delete Parameter"); } void perform() { DelParameterDialog d = new DelParameterDialog(s.getIdentifierOnCaret()); int position = Integer.parseInt(d.getPosition()); if (position>0) { XrefStringArray xroption = new XrefStringArray(); xroption.add("-rfct-del-param"); xroption.add("-olcxparnum="+position); mainRefactorerInvocation(xroption,false); } } } static public class Move_parameter extends Refactorings { int getCode() { return(Protocol.PPC_AVR_MOVE_PARAMETER); } public String toString() { return("Move Parameter"); } void perform() { MoveParameterDialog d = new MoveParameterDialog(s.getIdentifierOnCaret()); int position = Integer.parseInt(d.getPosition()); int position2 = Integer.parseInt(d.getPosition2()); if (position>0 && position2>0) { XrefStringArray xroption = new XrefStringArray(); xroption.add("-rfct-move-param"); xroption.add("-olcxparnum="+position); xroption.add("-olcxparnum2="+position2); mainRefactorerInvocation(xroption,false); } } } static public class Extract_method extends Refactorings { int getCode() { return(Protocol.PPC_AVR_EXTRACT_METHOD); } public String toString() { return("Extract Method"); } void perform() { XrefStringArray xroption = new XrefStringArray(); xroption.add("-rfct-extract-method"); mainRefactorerInvocation(xroption, true); if (s.xExtractMethod!=null) { String def = s.getBuffer().getLineText(s.xExtractMethod.definitionLine-1); int offset = def.indexOf("newMethod_"); if (offset != -1) { s.moveToPosition(s.view, s.getFileName(), s.xExtractMethod.definitionLine, offset); renameSymbol(s.xExtractMethod.name.getText()); } else { offset = def.indexOf("NewClass_"); if (offset != -1) { s.moveToPosition(s.view, s.getFileName(), s.xExtractMethod.definitionLine, offset); renameClass(s.upperCaseFirstLetter(s.xExtractMethod.name.getText()), true); String lcdef = s.getBuffer().getLineText(s.xExtractMethod.invocationLine-1); offset = lcdef.indexOf("newClass_"); if (offset != -1) { s.moveToPosition(s.view, s.getFileName(), s.xExtractMethod.invocationLine, offset); renameSymbol(s.lowerCaseFirstLetter(s.xExtractMethod.name.getText())); } } } } } } static public class Extract_function extends Refactorings { int getCode() { return(Protocol.PPC_AVR_EXTRACT_FUNCTION); } public String toString() { return("Extract Function"); } void perform() { XrefStringArray xroption = new XrefStringArray(); xroption.add("-rfct-extract-method"); mainRefactorerInvocation(xroption, true); if (s.xExtractMethod!=null) { String def = s.getBuffer().getLineText(s.xExtractMethod.definitionLine-1); int offset = def.indexOf("newFunction_"); if (offset != -1) { s.moveToPosition(s.view, s.getFileName(), s.xExtractMethod.definitionLine, offset); renameSymbol(s.xExtractMethod.name.getText()); } } } } static public class Extract_macro extends Refactorings { int getCode() { return(Protocol.PPC_AVR_EXTRACT_MACRO); } public String toString() { return("Extract Macro"); } void perform() { XrefStringArray xroption = new XrefStringArray(); xroption.add("-rfct-extract-macro"); mainRefactorerInvocation(xroption, true); if (s.xExtractMethod!=null) { String def = s.getBuffer().getLineText(s.xExtractMethod.definitionLine-1); int offset = def.indexOf("NEW_MACRO_"); if (offset != -1) { s.moveToPosition(s.view, s.getFileName(), s.xExtractMethod.definitionLine, offset); renameSymbol(s.xExtractMethod.name.getText()); } } } } static public class Move_static_field extends Refactorings { MoveDialog d; int getCode() { return(Protocol.PPC_AVR_MOVE_STATIC_FIELD); } public String toString() { return("Move Static Field"); } void perform() { String name = s.getIdentifierOnCaret(); new MoveDialog("Move static field '"+name+"'", false, "-rfct-move-static-field","-olcxmmtarget"); } } static public class Move_static_method extends Refactorings { MoveDialog d; int getCode() { return(Protocol.PPC_AVR_MOVE_STATIC_METHOD); } public String toString() { return("Move Static Method"); } void perform() { String name = s.getIdentifierOnCaret(); new MoveDialog("Move static method '"+name+"'", false, "-rfct-move-static-method","-olcxmmtarget"); } } static public class Move_class extends Refactorings { int getCode() { return(Protocol.PPC_AVR_MOVE_CLASS); } public String toString() { return("Move Class"); } void perform() { String name = s.getIdentifierOnCaret(); new MoveDialog("Move class '"+name+"'", false, "-rfct-move-class","-olcxmctarget"); } } static public class Move_class_to_new_file extends Refactorings { int getCode() { return(Protocol.PPC_AVR_MOVE_CLASS); } public String toString() { return("Move Class To New File"); } void perform() { String name = s.getIdentifierOnCaret(); s.Position cpos = s.getPosition(s.view); JFileChooser chooser = new JFileChooser(); chooser.setSelectedFile(new File((new File(s.getBuffer().getPath())).getParentFile().getAbsolutePath()+s.slash+name+".java")); chooser.setDialogTitle("Select file for class moving"); int returnVal = chooser.showSaveDialog(s.view); if(returnVal == JFileChooser.APPROVE_OPTION) { File ff = chooser.getSelectedFile(); if (ff.getAbsolutePath().equals(cpos.file)) { JOptionPane.showMessageDialog( s.view, "The file contains the class to be moved. Can not clear it and then move.", "Xrefactory Error", JOptionPane.ERROR_MESSAGE); } else { s.moveToPosition(s.view, ff.getAbsolutePath(), 0); if (ff.exists()) { int confirm = JOptionPane.YES_OPTION; confirm = JOptionPane.showConfirmDialog( s.view, "File "+ff+" exists. Can I erase it first?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (confirm == JOptionPane.YES_OPTION) { s.getTextArea().setText(""); } } setMovingTarget(); s.moveToPosition(cpos); s.performMovingRefactoring("-rfct-move-class-to-new-file", null); } } } } static public class Move_field extends Refactorings { int getCode() { return(Protocol.PPC_AVR_MOVE_FIELD); } public String toString() { return("Move Field"); } void perform() { String name = s.getIdentifierOnCaret(); new MoveDialog("Move field '"+name+"'", true, "-rfct-move-field","-olcxmmtarget"); } } static public class Pull_up_field extends Refactorings { int getCode() { return(Protocol.PPC_AVR_PULL_UP_FIELD); } public String toString() { return("Pull Up Field"); } void perform() { String name = s.getIdentifierOnCaret(); new MoveDialog("Pull up field '"+name+"'", false, "-rfct-pull-up-field","-olcxmmtarget"); } } static public class Pull_up_method extends Refactorings { int getCode() { return(Protocol.PPC_AVR_PULL_UP_METHOD); } public String toString() { return("Pull Up Method"); }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -