本文整理汇总了Java中com.intellij.refactoring.IntroduceTargetChooser类的典型用法代码示例。如果您正苦于以下问题:Java IntroduceTargetChooser类的具体用法?Java IntroduceTargetChooser怎么用?Java IntroduceTargetChooser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IntroduceTargetChooser类属于com.intellij.refactoring包,在下文中一共展示了IntroduceTargetChooser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: invoke
import com.intellij.refactoring.IntroduceTargetChooser; //导入依赖的package包/类
@Override
public void invoke(@NotNull final Project project, final Editor editor, final PsiFile file, @Nullable DataContext dataContext) {
editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
final SelectionModel model = editor.getSelectionModel();
if (model.hasSelection()) {
invokeImpl(project, editor, file, model.getSelectionStart(), model.getSelectionEnd());
}
else {
final List<GrExpression> expressions = GrIntroduceHandlerBase.collectExpressions(file, editor, editor.getCaretModel().getOffset(), true);
final Pass<GrExpression> callback = new Callback(project, editor, file);
if (expressions.size() == 1) {
callback.pass(expressions.get(0));
}
else if (expressions.isEmpty()) {
model.selectLineAtCaret();
invokeImpl(project, editor, file, model.getSelectionStart(), model.getSelectionEnd());
}
else {
IntroduceTargetChooser.showChooser(editor, expressions, callback, GrIntroduceHandlerBase.GR_EXPRESSION_RENDERER);
}
}
}
示例2: invoke
import com.intellij.refactoring.IntroduceTargetChooser; //导入依赖的package包/类
@Override
public void invoke(@NotNull final Project project, final Editor editor, final PsiFile file, @Nullable final DataContext dataContext) {
final SelectionModel selectionModel = editor.getSelectionModel();
if (!selectionModel.hasSelection()) {
final int offset = editor.getCaretModel().getOffset();
final List<GrExpression> expressions = collectExpressions(file, editor, offset, false);
if (expressions.isEmpty()) {
updateSelectionForVariable(editor, file, selectionModel, offset);
}
else if (expressions.size() == 1) {
final TextRange textRange = expressions.get(0).getTextRange();
selectionModel.setSelection(textRange.getStartOffset(), textRange.getEndOffset());
}
else {
IntroduceTargetChooser.showChooser(editor, expressions, new Pass<GrExpression>() {
@Override
public void pass(final GrExpression selectedValue) {
invoke(project, editor, file, selectedValue.getTextRange().getStartOffset(), selectedValue.getTextRange().getEndOffset());
}
}, GR_EXPRESSION_RENDERER);
return;
}
}
invoke(project, editor, file, selectionModel.getSelectionStart(), selectionModel.getSelectionEnd());
}
示例3: invoke
import com.intellij.refactoring.IntroduceTargetChooser; //导入依赖的package包/类
public void invoke(@NotNull final Project project, final Editor editor, final PsiFile file, @Nullable DataContext dataContext) {
editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
final SelectionModel model = editor.getSelectionModel();
if (model.hasSelection()) {
invokeImpl(project, editor, file, model.getSelectionStart(), model.getSelectionEnd());
}
else {
final List<GrExpression> expressions = GrIntroduceHandlerBase.collectExpressions(file, editor, editor.getCaretModel().getOffset(), true);
final Pass<GrExpression> callback = new Callback(project, editor, file);
if (expressions.size() == 1) {
callback.pass(expressions.get(0));
}
else if (expressions.isEmpty()) {
model.selectLineAtCaret();
invokeImpl(project, editor, file, model.getSelectionStart(), model.getSelectionEnd());
}
else {
IntroduceTargetChooser.showChooser(editor, expressions, callback, GrIntroduceHandlerBase.GR_EXPRESSION_RENDERER);
}
}
}
示例4: selectAndPass
import com.intellij.refactoring.IntroduceTargetChooser; //导入依赖的package包/类
public static void selectAndPass(@NotNull final Project project, @NotNull final Editor editor, @NotNull final PsiFile file, @NotNull final Pass<PsiElement[]> callback) {
editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
if (!editor.getSelectionModel().hasSelection()) {
final int offset = editor.getCaretModel().getOffset();
final List<PsiExpression> expressions = IntroduceVariableBase.collectExpressions(file, editor, offset, true);
if (expressions.isEmpty()) {
editor.getSelectionModel().selectLineAtCaret();
}
else if (expressions.size() == 1) {
callback.pass(new PsiElement[]{expressions.get(0)});
return;
}
else {
IntroduceTargetChooser.showChooser(editor, expressions, new Pass<PsiExpression>() {
@Override
public void pass(PsiExpression psiExpression) {
callback.pass(new PsiElement[]{psiExpression});
}
}, new PsiExpressionTrimRenderer.RenderFunction());
return;
}
}
PsiDocumentManager.getInstance(project).commitAllDocuments();
callback.pass(getElements(project, editor, file));
}
示例5: actionPerformed
import com.intellij.refactoring.IntroduceTargetChooser; //导入依赖的package包/类
@Override
public void actionPerformed(AnActionEvent e) {
final Editor editor = CommonDataKeys.EDITOR.getData(e.getDataContext());
if (editor == null) return;
final PsiFile psiFile = HandlerUtils.getPsiFile(editor, e.getDataContext());
if (!(psiFile instanceof GroovyFile)) return;
int offset = editor.getCaretModel().getOffset();
final List<GrControlFlowOwner> controlFlowOwners = collectControlFlowOwners(psiFile, editor, offset);
if (controlFlowOwners.isEmpty()) return;
if (controlFlowOwners.size() == 1) {
passInner(controlFlowOwners.get(0));
}
else {
IntroduceTargetChooser.showChooser(editor, controlFlowOwners, new Pass<GrControlFlowOwner>() {
@Override
public void pass(GrControlFlowOwner grExpression) {
passInner(grExpression);
}
}, new Function<GrControlFlowOwner, String>() {
@Override
public String fun(GrControlFlowOwner flowOwner) {
return flowOwner.getText();
}
}
);
}
}
示例6: processIntention
import com.intellij.refactoring.IntroduceTargetChooser; //导入依赖的package包/类
@Override
protected void processIntention(@NotNull PsiElement element, Project project, Editor editor) throws IncorrectOperationException {
final PsiFile file = element.getContainingFile();
final int offset = editor.getCaretModel().getOffset();
final AccessToken accessToken = ReadAction.start();
final List<GrExpression> expressions;
try {
expressions = collectExpressions(file, offset);
}
finally {
accessToken.finish();
}
final Document document = editor.getDocument();
if (expressions.size() == 1) {
invokeImpl(expressions.get(0), document);
}
else if (!expressions.isEmpty()) {
if (ApplicationManager.getApplication().isUnitTestMode()) {
invokeImpl(expressions.get(expressions.size() - 1), document);
return;
}
IntroduceTargetChooser.showChooser(editor, expressions,
new Pass<GrExpression>() {
@Override
public void pass(final GrExpression selectedValue) {
invokeImpl(selectedValue, document);
}
},
new Function<GrExpression, String>() {
@Override
public String fun(GrExpression grExpression) {
return grExpression.getText();
}
}
);
}
}
示例7: processIntention
import com.intellij.refactoring.IntroduceTargetChooser; //导入依赖的package包/类
@Override
protected void processIntention(@NotNull PsiElement element, final Project project, final Editor editor) throws IncorrectOperationException {
final List<GrExpression> expressions;
if (editor.getSelectionModel().hasSelection()) {
expressions = Collections.singletonList(((GrExpression)element));
}
else {
final AccessToken accessToken = ReadAction.start();
try {
expressions = collectExpressions(element);
}
finally {
accessToken.finish();
}
}
if (expressions.size() == 1) {
invokeImpl(expressions.get(0), project, editor);
}
else if (ApplicationManager.getApplication().isUnitTestMode()) {
invokeImpl(expressions.get(expressions.size() - 1), project, editor);
}
else {
final Pass<GrExpression> callback = new Pass<GrExpression>() {
@Override
public void pass(@NotNull final GrExpression selectedValue) {
invokeImpl(selectedValue, project, editor);
}
};
final Function<GrExpression, String> renderer = new Function<GrExpression, String>() {
@Override
public String fun(@NotNull GrExpression grExpression) {
return grExpression.getText();
}
};
IntroduceTargetChooser.showChooser(editor, expressions, callback, renderer);
}
}
示例8: invoke
import com.intellij.refactoring.IntroduceTargetChooser; //导入依赖的package包/类
@Override
public void invoke(@NotNull final Project project, @NotNull final Editor editor, @NotNull final PsiFile file, @Nullable final DataContext dataContext) {
final SelectionModel selectionModel = editor.getSelectionModel();
if (!selectionModel.hasSelection()) {
final int offset = editor.getCaretModel().getOffset();
final List<GrExpression> expressions = GrIntroduceHandlerBase.collectExpressions(file, editor, offset, false);
if (expressions.isEmpty()) {
GrIntroduceHandlerBase.updateSelectionForVariable(editor, file, selectionModel, offset);
}
else if (expressions.size() == 1 || ApplicationManager.getApplication().isUnitTestMode()) {
final TextRange textRange = expressions.get(0).getTextRange();
selectionModel.setSelection(textRange.getStartOffset(), textRange.getEndOffset());
}
else {
IntroduceTargetChooser.showChooser(editor, expressions, new Pass<GrExpression>() {
@Override
public void pass(final GrExpression selectedValue) {
invoke(project, editor, file, selectedValue.getTextRange().getStartOffset(), selectedValue.getTextRange().getEndOffset());
}
}, new Function<GrExpression, String>() {
@Override
public String fun(GrExpression grExpression) {
return grExpression.getText();
}
}
);
return;
}
}
invoke(project, editor, file, selectionModel.getSelectionStart(), selectionModel.getSelectionEnd());
}
示例9: actionPerformed
import com.intellij.refactoring.IntroduceTargetChooser; //导入依赖的package包/类
@Override
public void actionPerformed(AnActionEvent e) {
final Editor editor = PlatformDataKeys.EDITOR.getData(e.getDataContext());
if (editor == null) return;
final PsiFile psiFile = HandlerUtils.getPsiFile(editor, e.getDataContext());
if (!(psiFile instanceof GroovyFile)) return;
int offset = editor.getCaretModel().getOffset();
final List<GrControlFlowOwner> controlFlowOwners = collectControlFlowOwners(psiFile, editor, offset);
if (controlFlowOwners.size() == 0) return;
if (controlFlowOwners.size() == 1) {
passInner(controlFlowOwners.get(0));
}
else {
IntroduceTargetChooser.showChooser(editor, controlFlowOwners, new Pass<GrControlFlowOwner>() {
@Override
public void pass(GrControlFlowOwner grExpression) {
passInner(grExpression);
}
}, new Function<GrControlFlowOwner, String>() {
@Override
public String fun(GrControlFlowOwner flowOwner) {
return flowOwner.getText();
}
}
);
}
}
示例10: processIntention
import com.intellij.refactoring.IntroduceTargetChooser; //导入依赖的package包/类
@Override
protected void processIntention(@NotNull PsiElement element, Project project, Editor editor) throws IncorrectOperationException {
final PsiFile file = element.getContainingFile();
final int offset = editor.getCaretModel().getOffset();
final AccessToken accessToken = ReadAction.start();
final List<GrExpression> expressions;
try {
expressions = collectExpressions(file, offset);
}
finally {
accessToken.finish();
}
final Document document = editor.getDocument();
if (expressions.size() == 1) {
invokeImpl(expressions.get(0), document);
}
else if (expressions.size() > 0) {
if (ApplicationManager.getApplication().isUnitTestMode()) {
invokeImpl(expressions.get(expressions.size() - 1), document);
return;
}
IntroduceTargetChooser.showChooser(editor, expressions,
new Pass<GrExpression>() {
public void pass(final GrExpression selectedValue) {
invokeImpl(selectedValue, document);
}
},
new Function<GrExpression, String>() {
@Override
public String fun(GrExpression grExpression) {
return grExpression.getText();
}
}
);
}
}
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:37,代码来源:ConvertConcatenationToGstringIntention.java
示例11: processIntention
import com.intellij.refactoring.IntroduceTargetChooser; //导入依赖的package包/类
@Override
protected void processIntention(@NotNull PsiElement element, final Project project, final Editor editor) throws IncorrectOperationException {
final List<GrExpression> expressions;
if (editor.getSelectionModel().hasSelection()) {
expressions = Collections.singletonList(((GrExpression)element));
}
else {
final AccessToken accessToken = ReadAction.start();
try {
expressions = collectExpressions(element);
}
finally {
accessToken.finish();
}
}
if (expressions.size() == 1) {
invokeImpl(expressions.get(0), project, editor);
}
else if (ApplicationManager.getApplication().isUnitTestMode()) {
invokeImpl(expressions.get(expressions.size() - 1), project, editor);
}
else {
final Pass<GrExpression> callback = new Pass<GrExpression>() {
public void pass(@NotNull final GrExpression selectedValue) {
invokeImpl(selectedValue, project, editor);
}
};
final Function<GrExpression, String> renderer = new Function<GrExpression, String>() {
@Override
public String fun(@NotNull GrExpression grExpression) {
return grExpression.getText();
}
};
IntroduceTargetChooser.showChooser(editor, expressions, callback, renderer);
}
}
示例12: expand
import com.intellij.refactoring.IntroduceTargetChooser; //导入依赖的package包/类
@Override
public void expand(@NotNull PsiElement context, @NotNull final Editor editor) {
List<PsiExpression> expressions = getExpressions(context, editor.getDocument(), editor.getCaretModel().getOffset());
if (expressions.isEmpty()) {
PostfixTemplatesUtils.showErrorHint(context.getProject(), editor);
}
else if (expressions.size() == 1) {
doIt(editor, expressions.get(0));
}
else {
IntroduceTargetChooser.showChooser(
editor, expressions,
new Pass<PsiExpression>() {
public void pass(@NotNull final PsiExpression e) {
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
CommandProcessor.getInstance().executeCommand(e.getProject(), new Runnable() {
public void run() {
doIt(editor, e);
}
}, "Expand postfix template", PostfixLiveTemplate.POSTFIX_TEMPLATE_ID);
}
});
}
},
new PsiExpressionTrimRenderer.RenderFunction(),
"Expressions", 0, ScopeHighlighter.NATURAL_RANGER
);
}
}
示例13: processElementToWorkOn
import com.intellij.refactoring.IntroduceTargetChooser; //导入依赖的package包/类
public static void processElementToWorkOn(final Editor editor, final PsiFile file, final String refactoringName, final String helpId, final Project project, final ElementsProcessor<ElementToWorkOn> processor) {
PsiLocalVariable localVar = null;
PsiExpression expr = null;
if (!editor.getSelectionModel().hasSelection()) {
PsiElement element = TargetElementUtil.findTargetElement(editor, TargetElementUtil
.ELEMENT_NAME_ACCEPTED | TargetElementUtil
.REFERENCED_ELEMENT_ACCEPTED | TargetElementUtil
.LOOKUP_ITEM_ACCEPTED);
if (element instanceof PsiLocalVariable) {
localVar = (PsiLocalVariable) element;
PsiElement elementAt = file.findElementAt(editor.getCaretModel().getOffset());
if (elementAt instanceof PsiIdentifier && elementAt.getParent() instanceof PsiReferenceExpression) {
expr = (PsiExpression) elementAt.getParent();
} else {
final PsiReference reference = TargetElementUtil.findReference(editor);
if (reference != null) {
final PsiElement refElement = reference.getElement();
if (refElement instanceof PsiReferenceExpression) {
expr = (PsiReferenceExpression)refElement;
}
}
}
} else {
final PsiLocalVariable variable = PsiTreeUtil.getParentOfType(file.findElementAt(editor.getCaretModel().getOffset()), PsiLocalVariable.class);
final int offset = editor.getCaretModel().getOffset();
final PsiElement[] statementsInRange = IntroduceVariableBase.findStatementsAtOffset(editor, file, offset);
if (statementsInRange.length == 1 && IntroduceVariableBase.selectLineAtCaret(offset, statementsInRange)) {
editor.getSelectionModel().selectLineAtCaret();
final ElementToWorkOn elementToWorkOn = getElementToWorkOn(editor, file, refactoringName, helpId, project, localVar, expr);
if (elementToWorkOn == null || elementToWorkOn.getLocalVariable() == null && elementToWorkOn.getExpression() == null || !processor.accept(elementToWorkOn)) {
editor.getSelectionModel().removeSelection();
}
}
if (!editor.getSelectionModel().hasSelection()){
final List<PsiExpression> expressions = IntroduceVariableBase.collectExpressions(file, editor, offset);
for (Iterator<PsiExpression> iterator = expressions.iterator(); iterator.hasNext(); ) {
PsiExpression expression = iterator.next();
if (!processor.accept(new ElementToWorkOn(null, expression))) {
iterator.remove();
}
}
if (expressions.isEmpty()) {
editor.getSelectionModel().selectLineAtCaret();
}
else if (!IntroduceVariableBase.isChooserNeeded(expressions)) {
expr = expressions.get(0);
}
else {
final int selection = IntroduceVariableBase.preferredSelection(statementsInRange, expressions);
IntroduceTargetChooser.showChooser(editor, expressions, new Pass<PsiExpression>() {
@Override
public void pass(final PsiExpression selectedValue) {
PsiLocalVariable var = null; //replace var if selected expression == var initializer
if (variable != null && variable.getInitializer() == selectedValue) {
var = variable;
}
processor.pass(getElementToWorkOn(editor, file, refactoringName, helpId, project, var, selectedValue));
}
}, new PsiExpressionTrimRenderer.RenderFunction(), "Expressions", selection, ScopeHighlighter.NATURAL_RANGER);
return;
}
}
}
}
processor.pass(getElementToWorkOn(editor, file, refactoringName, helpId, project, localVar, expr));
}
示例14: selectAndPass
import com.intellij.refactoring.IntroduceTargetChooser; //导入依赖的package包/类
public static void selectAndPass(@NotNull final Project project, @NotNull final Editor editor, @NotNull final PsiFile file, @NotNull final Pass<PsiElement[]> callback) {
editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
if (!editor.getSelectionModel().hasSelection()) {
final int offset = editor.getCaretModel().getOffset();
final List<PsiExpression> expressions = IntroduceVariableBase.collectExpressions(file, editor, offset, true);
if (expressions.isEmpty()) {
editor.getSelectionModel().selectLineAtCaret();
}
else if (expressions.size() == 1) {
callback.pass(new PsiElement[]{expressions.get(0)});
return;
}
else {
IntroduceTargetChooser.showChooser(editor, expressions, new Pass<PsiExpression>() {
@Override
public void pass(PsiExpression psiExpression) {
callback.pass(new PsiElement[]{psiExpression});
}
}, new PsiExpressionTrimRenderer.RenderFunction());
return;
}
}
int startOffset = editor.getSelectionModel().getSelectionStart();
int endOffset = editor.getSelectionModel().getSelectionEnd();
PsiDocumentManager.getInstance(project).commitAllDocuments();
PsiElement[] elements;
PsiExpression expr = CodeInsightUtil.findExpressionInRange(file, startOffset, endOffset);
if (expr != null) {
elements = new PsiElement[]{expr};
}
else {
elements = CodeInsightUtil.findStatementsInRange(file, startOffset, endOffset);
if (elements.length == 0) {
final PsiExpression expression = IntroduceVariableBase.getSelectedExpression(project, file, startOffset, endOffset);
if (expression != null && IntroduceVariableBase.getErrorMessage(expression) == null) {
final PsiType originalType = RefactoringUtil.getTypeByExpressionWithExpectedType(expression);
if (originalType != null) {
elements = new PsiElement[]{expression};
}
}
}
}
callback.pass(elements);
}
示例15: processElementToWorkOn
import com.intellij.refactoring.IntroduceTargetChooser; //导入依赖的package包/类
public static void processElementToWorkOn(final Editor editor, final PsiFile file, final String refactoringName, final String helpId, final Project project, final ElementsProcessor<ElementToWorkOn> processor) {
PsiLocalVariable localVar = null;
PsiExpression expr = null;
if (!editor.getSelectionModel().hasSelection()) {
PsiElement element = TargetElementUtilBase.findTargetElement(editor, TargetElementUtilBase
.ELEMENT_NAME_ACCEPTED | TargetElementUtilBase
.REFERENCED_ELEMENT_ACCEPTED | TargetElementUtilBase
.LOOKUP_ITEM_ACCEPTED);
if (element instanceof PsiLocalVariable) {
localVar = (PsiLocalVariable) element;
PsiElement elementAt = file.findElementAt(editor.getCaretModel().getOffset());
if (elementAt instanceof PsiIdentifier && elementAt.getParent() instanceof PsiReferenceExpression) {
expr = (PsiExpression) elementAt.getParent();
} else {
final PsiReference reference = TargetElementUtilBase.findReference(editor);
if (reference != null) {
final PsiElement refElement = reference.getElement();
if (refElement instanceof PsiReferenceExpression) {
expr = (PsiReferenceExpression)refElement;
}
}
}
} else {
final PsiLocalVariable variable = PsiTreeUtil.getParentOfType(file.findElementAt(editor.getCaretModel().getOffset()), PsiLocalVariable.class);
final int offset = editor.getCaretModel().getOffset();
final PsiElement[] statementsInRange = IntroduceVariableBase.findStatementsAtOffset(editor, file, offset);
if (statementsInRange.length == 1 && (PsiUtilCore.hasErrorElementChild(statementsInRange[0]) || !PsiUtil.isStatement(statementsInRange[0]))) {
editor.getSelectionModel().selectLineAtCaret();
final ElementToWorkOn elementToWorkOn = getElementToWorkOn(editor, file, refactoringName, helpId, project, localVar, expr);
if (elementToWorkOn == null || elementToWorkOn.getLocalVariable() == null && elementToWorkOn.getExpression() == null || !processor.accept(elementToWorkOn)) {
editor.getSelectionModel().removeSelection();
}
}
if (!editor.getSelectionModel().hasSelection()){
final List<PsiExpression> expressions = IntroduceVariableBase.collectExpressions(file, editor, offset);
for (Iterator<PsiExpression> iterator = expressions.iterator(); iterator.hasNext(); ) {
PsiExpression expression = iterator.next();
if (!processor.accept(new ElementToWorkOn(null, expression))) {
iterator.remove();
}
}
if (expressions.isEmpty()) {
editor.getSelectionModel().selectLineAtCaret();
}
else if (expressions.size() == 1) {
expr = expressions.get(0);
}
else {
IntroduceTargetChooser.showChooser(editor, expressions, new Pass<PsiExpression>() {
@Override
public void pass(final PsiExpression selectedValue) {
PsiLocalVariable var = null; //replace var if selected expression == var initializer
if (variable != null && variable.getInitializer() == selectedValue) {
var = variable;
}
processor.pass(getElementToWorkOn(editor, file, refactoringName, helpId, project, var, selectedValue));
}
}, new PsiExpressionTrimRenderer.RenderFunction());
return;
}
}
}
}
processor.pass(getElementToWorkOn(editor, file, refactoringName, helpId, project, localVar, expr));
}