Eclipse Extract Method 方法实现(二)

Eclipse Extract Method 方法实现(二)

摘要:
    前面的一篇文章本是抱着“分析Eclipse Extract Method的实现,为我所用。”的目的去看的。然后发现的Invoke部分好像是没戏了。看看代码分析的部分是否可以借鉴。                
        上一次我找到了实现Extract Method这个Function的是一个 ExtractMethodAction类。构造函数就不想多看了。直接跳到他的run函数里面看看。这个Action到底是如何工作的。    
 

if (!ActionUtil.isProcessable(getShell(), fEditor))

                     return;

              try{

                     ExtractMethodRefactoring refactoring= ExtractMethodRefactoring.create(SelectionConverter.getInputAsCompilationUnit(fEditor), selection.getOffset(), selection.getLength());

                     if (refactoring == null)

                            return;

                     new RefactoringStarter().activate(refactoring, new ExtractMethodWizard(refactoring), getShell(), DIALOG_MESSAGE_TITLE, false);

              } catch (CoreException e){

                     ExceptionHandler.handle(e, DIALOG_MESSAGE_TITLE, RefactoringMessages.NewTextRefactoringAction_exception);

              }

new RefactoringStarter().activate(refactoring, new ExtractMethodWizard(refactoring), getShell(), DIALOG_MESSAGE_TITLE, false);

 
通过                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            

可见整个ExtractMethodAction的核心在于两个类(就目前来看)。

1.         ExtractMethodRefactoring

看到他的构造函数包括如下参数:

SelectionConverter.getInputAsCompilationUnit(fEditor), selection.getOffset(), selection.getLength()

小瞄一下可以发现他的构造产生里包含了ICompilationUnit(整个Java Class),选中的起始位置和长度。有了这些信息以后就可以对代码进行分析了。猜测代码分析的动作在这里完成。打开一看:

 

private ICompilationUnit fCUnit;

       private CompilationUnit fRoot;

       private ImportRewrite fImportRewriter;

       private int fSelectionStart;

       private int fSelectionLength;

       private AST fAST;

       private ASTRewrite fRewriter;

       private IDocument fDocument;

       private ExtractMethodAnalyzer fAnalyzer;

       private int fVisibility;

       private String fMethodName;

       private boolean fThrowRuntimeExceptions;

       private List fParameterInfos;

       private Set fUsedNames;

       private boolean fGenerateJavadoc;

看到了这些你还敢怀疑吗?就是他了,肯定是他干的了。还有ExtractMethodAnalyzer这个最得力的帮手。好了我们下面就来看看他们几个是怎么合谋完成获得外部变量(可参考Eclipse 插件开发 ——我的计划一文)。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值