本文整理汇总了Java中com.intellij.refactoring.introduce.inplace.OccurrencesChooser类的典型用法代码示例。如果您正苦于以下问题:Java OccurrencesChooser类的具体用法?Java OccurrencesChooser怎么用?Java OccurrencesChooser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
OccurrencesChooser类属于com.intellij.refactoring.introduce.inplace包,在下文中一共展示了OccurrencesChooser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testNameSuggestion
import com.intellij.refactoring.introduce.inplace.OccurrencesChooser; //导入依赖的package包/类
public void testNameSuggestion() {
final String expectedTypeName = "Path";
doTest(new MockIntroduceVariableHandler("path", true, false, false, expectedTypeName) {
@Override
public IntroduceVariableSettings getSettings(Project project, Editor editor,
PsiExpression expr, PsiExpression[] occurrences,
TypeSelectorManagerImpl typeSelectorManager,
boolean declareFinalIfAll,
boolean anyAssignmentLHS,
InputValidator validator,
PsiElement anchor, final OccurrencesChooser.ReplaceChoice replaceChoice) {
final PsiType type = typeSelectorManager.getDefaultType();
assertTrue(type.getPresentableText(), type.getPresentableText().equals(expectedTypeName));
assertEquals("path", IntroduceVariableBase.getSuggestedName(type, expr).names[0]);
return super.getSettings(project, editor, expr, occurrences, typeSelectorManager, declareFinalIfAll, anyAssignmentLHS,
validator, anchor, replaceChoice);
}
});
}
示例2: testSiblingInnerClassType
import com.intellij.refactoring.introduce.inplace.OccurrencesChooser; //导入依赖的package包/类
public void testSiblingInnerClassType() {
doTest(new MockIntroduceVariableHandler("vari", true, false, false, "A.B") {
@Override
public IntroduceVariableSettings getSettings(Project project, Editor editor,
PsiExpression expr, PsiExpression[] occurrences,
TypeSelectorManagerImpl typeSelectorManager,
boolean declareFinalIfAll,
boolean anyAssignmentLHS,
InputValidator validator,
PsiElement anchor, final OccurrencesChooser.ReplaceChoice replaceChoice) {
final PsiType type = typeSelectorManager.getDefaultType();
assertTrue(type.getPresentableText(), type.getPresentableText().equals("B"));
return super.getSettings(project, editor, expr, occurrences, typeSelectorManager, declareFinalIfAll, anyAssignmentLHS,
validator, anchor, replaceChoice);
}
});
}
示例3: doTestReplaceChoice
import com.intellij.refactoring.introduce.inplace.OccurrencesChooser; //导入依赖的package包/类
private void doTestReplaceChoice(OccurrencesChooser.ReplaceChoice choice, Pass<AbstractInplaceIntroducer> pass) {
String name = getTestName(true);
configureByFile(getBasePath() + name + getExtension());
final boolean enabled = getEditor().getSettings().isVariableInplaceRenameEnabled();
try {
TemplateManagerImpl.setTemplateTesting(getProject(), getTestRootDisposable());
getEditor().getSettings().setVariableInplaceRenameEnabled(true);
MyIntroduceHandler handler = createIntroduceHandler();
((MyIntroduceVariableHandler)handler).setChoice(choice);
final AbstractInplaceIntroducer introducer = invokeRefactoring(handler);
if (pass != null) {
pass.pass(introducer);
}
TemplateState state = TemplateManagerImpl.getTemplateState(getEditor());
assert state != null;
state.gotoEnd(false);
checkResultByFile(getBasePath() + name + "_after" + getExtension());
}
finally {
getEditor().getSettings().setVariableInplaceRenameEnabled(enabled);
}
}
示例4: performActionOnElementOccurrences
import com.intellij.refactoring.introduce.inplace.OccurrencesChooser; //导入依赖的package包/类
protected void performActionOnElementOccurrences(final IntroduceOperation operation) {
final Editor editor = operation.getEditor();
if (editor.getSettings().isVariableInplaceRenameEnabled()) {
ensureName(operation);
if (operation.isReplaceAll() != null) {
performInplaceIntroduce(operation);
}
else {
OccurrencesChooser.simpleChooser(editor).showChooser(operation.getElement(), operation.getOccurrences(), new Pass<OccurrencesChooser.ReplaceChoice>() {
@Override
public void pass(OccurrencesChooser.ReplaceChoice replaceChoice) {
operation.setReplaceAll(replaceChoice == OccurrencesChooser.ReplaceChoice.ALL);
performInplaceIntroduce(operation);
}
});
}
}
else {
performIntroduceWithDialog(operation);
}
}
示例5: GrInplaceConstantIntroducer
import com.intellij.refactoring.introduce.inplace.OccurrencesChooser; //导入依赖的package包/类
public GrInplaceConstantIntroducer(GrIntroduceContext context, OccurrencesChooser.ReplaceChoice choice) {
super(IntroduceConstantHandler.REFACTORING_NAME, choice, context);
myContext = context;
myPanel = new GrInplaceIntroduceConstantPanel();
GrVariable localVar = GrIntroduceHandlerBase.resolveLocalVar(context);
if (localVar != null) {
ArrayList<String> result = ContainerUtil.newArrayList(localVar.getName());
GrExpression initializer = localVar.getInitializerGroovy();
if (initializer != null) {
ContainerUtil.addAll(result, GroovyNameSuggestionUtil.suggestVariableNames(initializer, new GroovyInplaceFieldValidator(context), true));
}
mySuggestedNames = ArrayUtil.toStringArray(result);
}
else {
GrExpression expression = context.getExpression();
assert expression != null;
mySuggestedNames = GroovyNameSuggestionUtil.suggestVariableNames(expression, new GroovyInplaceFieldValidator(context), true);
}
}
示例6: getOccurrenceOptions
import com.intellij.refactoring.introduce.inplace.OccurrencesChooser; //导入依赖的package包/类
@NotNull
@Override
protected Map<OccurrencesChooser.ReplaceChoice, List<Object>> getOccurrenceOptions(@NotNull GrIntroduceContext context) {
HashMap<OccurrencesChooser.ReplaceChoice, List<Object>> map = ContainerUtil.newLinkedHashMap();
GrVariable localVar = resolveLocalVar(context);
if (localVar != null) {
map.put(OccurrencesChooser.ReplaceChoice.ALL, Arrays.<Object>asList(context.getOccurrences()));
return map;
}
if (context.getExpression() != null) {
map.put(OccurrencesChooser.ReplaceChoice.NO, Collections.<Object>singletonList(context.getExpression()));
}
else if (context.getStringPart() != null) {
map.put(OccurrencesChooser.ReplaceChoice.NO, Collections.<Object>singletonList(context.getStringPart()));
}
PsiElement[] occurrences = context.getOccurrences();
if (occurrences.length > 1) {
map.put(OccurrencesChooser.ReplaceChoice.ALL, Arrays.<Object>asList(occurrences));
}
return map;
}
示例7: getInitialSettingsForInplace
import com.intellij.refactoring.introduce.inplace.OccurrencesChooser; //导入依赖的package包/类
@Nullable
@Override
protected GrIntroduceParameterSettings getInitialSettingsForInplace(@NotNull GrIntroduceContext context,
@NotNull OccurrencesChooser.ReplaceChoice choice,
String[] names) {
GrExpression expression = context.getExpression();
GrVariable var = context.getVar();
PsiType type = var != null ? var.getDeclaredType() :
expression != null ? expression.getType() :
null;
return new GrIntroduceExpressionSettingsImpl(myInfo, names[0], false, new TIntArrayList(), false,
IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, expression,
var, type, false, false, false);
}
示例8: GrInplaceFieldIntroducer
import com.intellij.refactoring.introduce.inplace.OccurrencesChooser; //导入依赖的package包/类
public GrInplaceFieldIntroducer(GrIntroduceContext context, OccurrencesChooser.ReplaceChoice choice) {
super(IntroduceFieldHandler.REFACTORING_NAME, choice, context);
finalListener = new GrFinalListener(myEditor);
myLocalVar = GrIntroduceHandlerBase.resolveLocalVar(context);
if (myLocalVar != null) {
//myLocalVariable = myLocalVar;
ArrayList<String> result = ContainerUtil.newArrayList(myLocalVar.getName());
GrExpression initializer = myLocalVar.getInitializerGroovy();
if (initializer != null) {
ContainerUtil.addAll(result, GroovyNameSuggestionUtil.suggestVariableNames(initializer, new GroovyInplaceFieldValidator(getContext()), false));
}
mySuggestedNames = ArrayUtil.toStringArray(result);
}
else {
mySuggestedNames = GroovyNameSuggestionUtil.suggestVariableNames(context.getExpression(), new GroovyInplaceFieldValidator(getContext()), false);
}
myApplicablePlaces = getApplicableInitPlaces();
}
示例9: fillChoice
import com.intellij.refactoring.introduce.inplace.OccurrencesChooser; //导入依赖的package包/类
public static Map<OccurrencesChooser.ReplaceChoice, List<Object>> fillChoice(GrIntroduceContext context) {
HashMap<OccurrencesChooser.ReplaceChoice, List<Object>> map = ContainerUtil.newLinkedHashMap();
if (context.getExpression() != null) {
map.put(OccurrencesChooser.ReplaceChoice.NO, Collections.<Object>singletonList(context.getExpression()));
}
else if (context.getStringPart() != null) {
map.put(OccurrencesChooser.ReplaceChoice.NO, Collections.<Object>singletonList(context.getStringPart()));
return map;
}
else if (context.getVar() != null) {
map.put(OccurrencesChooser.ReplaceChoice.ALL, Collections.<Object>singletonList(context.getVar()));
return map;
}
PsiElement[] occurrences = context.getOccurrences();
if (occurrences.length > 1) {
map.put(OccurrencesChooser.ReplaceChoice.ALL, Arrays.<Object>asList(occurrences));
}
return map;
}
示例10: fillChoices
import com.intellij.refactoring.introduce.inplace.OccurrencesChooser; //导入依赖的package包/类
/**
* @return true if write usages found
*/
private static boolean fillChoices(final PsiExpression expr,
final PsiExpression[] occurrences,
final LinkedHashMap<OccurrencesChooser.ReplaceChoice, List<PsiExpression>> occurrencesMap) {
occurrencesMap.put(OccurrencesChooser.ReplaceChoice.NO, Collections.singletonList(expr));
final List<PsiExpression> nonWrite = new ArrayList<PsiExpression>();
boolean cantReplaceAll = false;
for (PsiExpression occurrence : occurrences) {
if (!RefactoringUtil.isAssignmentLHS(occurrence)) {
nonWrite.add(occurrence);
} else if (isFinalVariableOnLHS(occurrence)) {
cantReplaceAll = true;
}
}
final boolean hasWriteAccess = occurrences.length > nonWrite.size() && occurrences.length > 1;
if (hasWriteAccess) {
occurrencesMap.put(OccurrencesChooser.ReplaceChoice.NO_WRITE, nonWrite);
}
if (occurrences.length > 1 && !cantReplaceAll) {
occurrencesMap.put(OccurrencesChooser.ReplaceChoice.ALL, Arrays.asList(occurrences));
}
return hasWriteAccess;
}
示例11: testNameSuggestion
import com.intellij.refactoring.introduce.inplace.OccurrencesChooser; //导入依赖的package包/类
public void testNameSuggestion() throws Exception {
final String expectedTypeName = "Path";
doTest(new MockIntroduceVariableHandler("path", true, false, false, expectedTypeName) {
@Override
public IntroduceVariableSettings getSettings(Project project, Editor editor,
PsiExpression expr, PsiExpression[] occurrences,
TypeSelectorManagerImpl typeSelectorManager,
boolean declareFinalIfAll,
boolean anyAssignmentLHS,
InputValidator validator,
PsiElement anchor, final OccurrencesChooser.ReplaceChoice replaceChoice) {
final PsiType type = typeSelectorManager.getDefaultType();
Assert.assertTrue(type.getPresentableText(), type.getPresentableText().equals(expectedTypeName));
Assert.assertEquals("path", IntroduceVariableBase.getSuggestedName(type, expr).names[0]);
return super.getSettings(project, editor, expr, occurrences, typeSelectorManager, declareFinalIfAll, anyAssignmentLHS,
validator, anchor, replaceChoice);
}
});
}
示例12: testSiblingInnerClassType
import com.intellij.refactoring.introduce.inplace.OccurrencesChooser; //导入依赖的package包/类
public void testSiblingInnerClassType() throws Exception {
doTest(new MockIntroduceVariableHandler("vari", true, false, false, "A.B") {
@Override
public IntroduceVariableSettings getSettings(Project project, Editor editor,
PsiExpression expr, PsiExpression[] occurrences,
TypeSelectorManagerImpl typeSelectorManager,
boolean declareFinalIfAll,
boolean anyAssignmentLHS,
InputValidator validator,
PsiElement anchor, final OccurrencesChooser.ReplaceChoice replaceChoice) {
final PsiType type = typeSelectorManager.getDefaultType();
Assert.assertTrue(type.getPresentableText(), type.getPresentableText().equals("B"));
return super.getSettings(project, editor, expr, occurrences, typeSelectorManager, declareFinalIfAll, anyAssignmentLHS,
validator, anchor, replaceChoice);
}
});
}
示例13: fillChoice
import com.intellij.refactoring.introduce.inplace.OccurrencesChooser; //导入依赖的package包/类
protected Map<OccurrencesChooser.ReplaceChoice, List<Object>> fillChoice(GrIntroduceContext context) {
HashMap<OccurrencesChooser.ReplaceChoice, List<Object>> map = ContainerUtil.newLinkedHashMap();
if (context.getExpression() != null) {
map.put(OccurrencesChooser.ReplaceChoice.NO, Collections.<Object>singletonList(context.getExpression()));
}
else if (context.getStringPart() != null) {
map.put(OccurrencesChooser.ReplaceChoice.NO, Collections.<Object>singletonList(context.getStringPart()));
}
PsiElement[] occurrences = context.getOccurrences();
if (occurrences.length > 1) {
map.put(OccurrencesChooser.ReplaceChoice.ALL, Arrays.<Object>asList(occurrences));
}
return map;
}
示例14: performActionOnElementOccurrences
import com.intellij.refactoring.introduce.inplace.OccurrencesChooser; //导入依赖的package包/类
protected void performActionOnElementOccurrences(final HaxeIntroduceOperation operation) {
final Editor editor = operation.getEditor();
if (editor.getSettings().isVariableInplaceRenameEnabled()) {
ensureName(operation);
if (operation.isReplaceAll() != null) {
performInplaceIntroduce(operation);
}
else {
OccurrencesChooser.simpleChooser(editor).showChooser(
operation.getElement(),
operation.getOccurrences(),
new Pass<OccurrencesChooser.ReplaceChoice>() {
@Override
public void pass(OccurrencesChooser.ReplaceChoice replaceChoice) {
operation.setReplaceAll(replaceChoice == OccurrencesChooser.ReplaceChoice.ALL);
performInplaceIntroduce(operation);
}
});
}
}
else {
performIntroduceWithDialog(operation);
}
}
示例15: getIntroducer
import com.intellij.refactoring.introduce.inplace.OccurrencesChooser; //导入依赖的package包/类
@Override
protected GrAbstractInplaceIntroducer<GrIntroduceConstantSettings> getIntroducer(@NotNull GrIntroduceContext context, @NotNull OccurrencesChooser.ReplaceChoice choice) {
final Ref<GrIntroduceContext> contextRef = Ref.create(context);
if (context.getStringPart() != null) {
extractStringPart(contextRef);
}
return new GrInplaceConstantIntroducer(contextRef.get(), choice);
}