Java Eclipse插件开发-添加自己的QuickAssist->;提取局部变量
我想为eclipse添加自己的快速帮助。我发现我需要扩展iquickassist处理器来实现这个目标。因为条目和逻辑与“extract to local variable”(提取到局部变量)快速辅助非常相似,所以我想找到相应的代码,看看它是如何工作的。有人能告诉我该快速修复的相应实现吗?这是我在Eclipse4.2中找到的唯一实现iquickassist处理器的代码。它位于org.eclipse.ui.workbench.textdeditor.source jar中 也许你需要用iquickassistant来代替Java Eclipse插件开发-添加自己的QuickAssist->;提取局部变量,java,eclipse,eclipse-plugin,Java,Eclipse,Eclipse Plugin,我想为eclipse添加自己的快速帮助。我发现我需要扩展iquickassist处理器来实现这个目标。因为条目和逻辑与“extract to local variable”(提取到局部变量)快速辅助非常相似,所以我想找到相应的代码,看看它是如何工作的。有人能告诉我该快速修复的相应实现吗?这是我在Eclipse4.2中找到的唯一实现iquickassist处理器的代码。它位于org.eclipse.ui.workbench.textdeditor.source jar中 也许你需要用iquicka
/*******************************************************************************
* Copyright (c) 2006, 2009 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.ui.texteditor.spelling;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import org.eclipse.jface.text.Position;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.jface.text.quickassist.IQuickAssistInvocationContext;
import org.eclipse.jface.text.quickassist.IQuickAssistProcessor;
import org.eclipse.jface.text.source.Annotation;
import org.eclipse.jface.text.source.IAnnotationModel;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.text.source.TextInvocationContext;
import org.eclipse.ui.internal.texteditor.spelling.NoCompletionsProposal;
/**
* Spelling correction processor used to show quick
* fixes for spelling problems.
*
* @since 3.3
*/
public final class SpellingCorrectionProcessor implements IQuickAssistProcessor {
private static final ICompletionProposal[] fgNoSuggestionsProposal= new ICompletionProposal[] { new NoCompletionsProposal() };
/*
* @see IContentAssistProcessor#computeCompletionProposals(ITextViewer, int)
*/
public ICompletionProposal[] computeQuickAssistProposals(IQuickAssistInvocationContext quickAssistContext) {
ISourceViewer viewer= quickAssistContext.getSourceViewer();
int documentOffset= quickAssistContext.getOffset();
int length= viewer != null ? viewer.getSelectedRange().y : -1;
TextInvocationContext context= new TextInvocationContext(viewer, documentOffset, length);
IAnnotationModel model= viewer.getAnnotationModel();
if (model == null)
return fgNoSuggestionsProposal;
List proposals= computeProposals(context, model);
if (proposals.isEmpty())
return fgNoSuggestionsProposal;
return (ICompletionProposal[]) proposals.toArray(new ICompletionProposal[proposals.size()]);
}
private boolean isAtPosition(int offset, Position pos) {
return (pos != null) && (offset >= pos.getOffset() && offset <= (pos.getOffset() + pos.getLength()));
}
private List computeProposals(IQuickAssistInvocationContext context, IAnnotationModel model) {
int offset= context.getOffset();
ArrayList annotationList= new ArrayList();
Iterator iter= model.getAnnotationIterator();
while (iter.hasNext()) {
Annotation annotation= (Annotation)iter.next();
if (canFix(annotation)) {
Position pos= model.getPosition(annotation);
if (isAtPosition(offset, pos)) {
collectSpellingProblems(annotation, annotationList);
}
}
}
SpellingProblem[] spellingProblems= (SpellingProblem[]) annotationList.toArray(new SpellingProblem[annotationList.size()]);
return computeProposals(context, spellingProblems);
}
private void collectSpellingProblems(Annotation annotation, List problems) {
if (annotation instanceof SpellingAnnotation)
problems.add(((SpellingAnnotation)annotation).getSpellingProblem());
}
private List computeProposals(IQuickAssistInvocationContext context, SpellingProblem[] spellingProblems) {
List proposals= new ArrayList();
for (int i= 0; i < spellingProblems.length; i++)
proposals.addAll(Arrays.asList(spellingProblems[i].getProposals(context)));
return proposals;
}
/*
* @see IContentAssistProcessor#getErrorMessage()
*/
public String getErrorMessage() {
return null;
}
/*
* @see org.eclipse.jface.text.quickassist.IQuickAssistProcessor#canFix(org.eclipse.jface.text.source.Annotation)
*/
public boolean canFix(Annotation annotation) {
return annotation instanceof SpellingAnnotation && !annotation.isMarkedDeleted();
}
/*
* @see org.eclipse.jface.text.quickassist.IQuickAssistProcessor#canAssist(org.eclipse.jface.text.quickassist.IQuickAssistInvocationContext)
*/
public boolean canAssist(IQuickAssistInvocationContext invocationContext) {
return false;
}
}
/*******************************************************************************
*版权所有(c)2006、2009 IBM公司和其他公司。
*版权所有。本计划及随附材料
*根据Eclipse公共许可证v1.0的条款提供
*随本发行版发行,可在
* http://www.eclipse.org/legal/epl-v10.html
*
*贡献者:
*IBM公司-初始API和实现
*******************************************************************************/
包org.eclipse.ui.texteditor.spelling;
导入java.util.ArrayList;
导入java.util.array;
导入java.util.Iterator;
导入java.util.List;
导入org.eclipse.jface.text.Position;
导入org.eclipse.jface.text.contentassist.ICompletionProposal;
导入org.eclipse.jface.text.quickassist.iquickassist上下文;
导入org.eclipse.jface.text.quickassist.IQuickAssistProcessor;
导入org.eclipse.jface.text.source.Annotation;
导入org.eclipse.jface.text.source.IAnnotationModel;
导入org.eclipse.jface.text.source.isoourceviewer;
导入org.eclipse.jface.text.source.TextInvocationContext;
导入org.eclipse.ui.internal.texteditor.spelling.NoCompletionsProposal;
/**
*拼写更正处理器用于显示快速
*修复拼写问题。
*
*@自3.3
*/
公共最终类SpellingCorrectionProcessor实现iquickAsistProcessor{
私有静态最终ICompletionProposal[]fgNoSuggestionsProposal=新ICompletionProposal[]{new NoCompletionsProposal()};
/*
*@see IContentasistProcessor#ComputeCompletionPropositions(ITextViewer,int)
*/
公共IComplementProposal[]计算快速助手建议(IQuickAssistInvocationContext快速助手上下文){
ISourceViewer=quickAssistContext.getSourceViewer();
int documentOffset=quickAssistContext.getOffset();
int length=viewer!=null?viewer.getSelectedRange().y:-1;
TextInvocationContext=新的TextInvocationContext(查看器、文档偏移量、长度);
IANotationModel=viewer.getAnnotationModel();
if(model==null)
返回建议建议书;
列表提案=计算提案(上下文、模型);
if(propositions.isEmpty())
返回建议建议书;
返回(ICompletionProposal[])提案。toArray(新ICompletionProposal[Propositions.size()]);
}
专用布尔isAtPosition(整数偏移量,位置位置){
返回(pos!=null)&&(offset>=pos.getOffset()&&offset