コード例 #1
0
 protected static void ensureName(IntroduceOperation operation) {
   if (operation.getName() == null) {
     final Collection<String> suggestedNames = operation.getSuggestedNames();
     if (suggestedNames.size() > 0) {
       operation.setName(suggestedNames.iterator().next());
     } else {
       operation.setName("x");
     }
   }
 }
コード例 #2
0
 protected void performInplaceIntroduce(IntroduceOperation operation) {
   final PsiElement statement = performRefactoring(operation);
   if (statement instanceof PyAssignmentStatement) {
     PyTargetExpression target =
         (PyTargetExpression) ((PyAssignmentStatement) statement).getTargets()[0];
     final List<PsiElement> occurrences = operation.getOccurrences();
     final PsiElement occurrence = findOccurrenceUnderCaret(occurrences, operation.getEditor());
     PsiElement elementForCaret = occurrence != null ? occurrence : target;
     operation
         .getEditor()
         .getCaretModel()
         .moveToOffset(elementForCaret.getTextRange().getStartOffset());
     final InplaceVariableIntroducer<PsiElement> introducer =
         new PyInplaceVariableIntroducer(target, operation, occurrences);
     introducer.performInplaceRefactoring(
         new LinkedHashSet<String>(operation.getSuggestedNames()));
   }
 }