Java 类com.intellij.lang.refactoring.InlineHandler 实例源码

项目:intellij-ce-playground    文件:GenericInlineHandler.java   
public static Map<Language, InlineHandler.Inliner> initializeInliners(PsiElement element,
                                                                      InlineHandler.Settings settings,
                                                                      Collection<? extends PsiReference> allReferences) {
  final Map<Language, InlineHandler.Inliner> inliners = new HashMap<Language, InlineHandler.Inliner>();
  for (PsiReference ref : allReferences) {
    if (ref == null) {
      LOG.error("element: " + element.getClass()+ ", allReferences contains null!");
      continue;
    }
    PsiElement refElement = ref.getElement();
    LOG.assertTrue(refElement != null, ref.getClass().getName());

    final Language language = refElement.getLanguage();
    if (inliners.containsKey(language)) continue;

    final List<InlineHandler> handlers = InlineHandlers.getInlineHandlers(language);
    for (InlineHandler handler : handlers) {
      InlineHandler.Inliner inliner = handler.createInliner(element, settings);
      if (inliner != null) {
        inliners.put(language, inliner);
        break;
      }
    }
  }
  return inliners;
}
项目:intellij-ce-playground    文件:GenericInlineHandler.java   
public static void collectConflicts(final PsiReference reference,
                                    final PsiElement element,
                                    final Map<Language, InlineHandler.Inliner> inliners,
                                    final MultiMap<PsiElement, String> conflicts) {
  final PsiElement referenceElement = reference.getElement();
  if (referenceElement == null) return;
  final Language language = referenceElement.getLanguage();
  final InlineHandler.Inliner inliner = inliners.get(language);
  if (inliner != null) {
    final MultiMap<PsiElement, String> refConflicts = inliner.getConflicts(reference, element);
    if (refConflicts != null) {
      for (PsiElement psiElement : refConflicts.keySet()) {
        conflicts.putValues(psiElement, refConflicts.get(psiElement));
      }
    }
  }
  else {
    conflicts.putValue(referenceElement, "Cannot inline reference from " + language.getDisplayName());
  }
}
项目:intellij-ce-playground    文件:GrInlineFieldUtil.java   
private static InlineHandler.Settings inlineFieldDialogResult(Project project, GrField field, final boolean invokedOnReference) {
  if (ApplicationManager.getApplication().isUnitTestMode()) {
    return new InlineHandler.Settings() {
      @Override
      public boolean isOnlyOneReferenceToInline() {
        return invokedOnReference;
      }
    };
  }

  final InlineGroovyFieldDialog dialog = new InlineGroovyFieldDialog(project, field, invokedOnReference);
  if (dialog.showAndGet()) {
    return new InlineHandler.Settings() {
      @Override
      public boolean isOnlyOneReferenceToInline() {
        return dialog.isInlineThisOnly();
      }
    };
  }
  else {
    return InlineHandler.Settings.CANNOT_INLINE_SETTINGS;
  }
}
项目:intellij-ce-playground    文件:GroovyInlineHandler.java   
@Override
@Nullable
public Settings prepareInlineElement(@NotNull final PsiElement element, @Nullable Editor editor, boolean invokedOnReference) {
  if (element instanceof GrField) {
    return GrInlineFieldUtil.inlineFieldSettings((GrField)element, editor, invokedOnReference);
  }
  else if (element instanceof GrMethod) {
    return GroovyInlineMethodUtil.inlineMethodSettings((GrMethod)element, editor, invokedOnReference);
  }
  else {
    if (element instanceof GrTypeDefinition || element instanceof GrClassSubstitution) {
      return null;      //todo inline to anonymous class, push members from super class
    }
  }

  if (element instanceof PsiMember) {
    String message = GroovyRefactoringBundle.message("cannot.inline.0.", getFullName(element));
    CommonRefactoringUtil.showErrorHint(element.getProject(), editor, message, "", HelpID.INLINE_FIELD);
    return InlineHandler.Settings.CANNOT_INLINE_SETTINGS;
  }
  return null;
}
项目:tools-idea    文件:GenericInlineHandler.java   
public static Map<Language, InlineHandler.Inliner> initializeInliners(PsiElement element,
                                                                      InlineHandler.Settings settings,
                                                                      Collection<? extends PsiReference> allReferences) {
  final Map<Language, InlineHandler.Inliner> inliners = new HashMap<Language, InlineHandler.Inliner>();
  for (PsiReference ref : allReferences) {
    if (ref == null) {
      LOG.error("element: " + element.getClass()+ ", allReferences contains null!");
      continue;
    }
    PsiElement refElement = ref.getElement();
    LOG.assertTrue(refElement != null, ref.getClass().getName());

    final Language language = refElement.getLanguage();
    if (inliners.containsKey(language)) continue;

    final List<InlineHandler> handlers = InlineHandlers.getInlineHandlers(language);
    for (InlineHandler handler : handlers) {
      InlineHandler.Inliner inliner = handler.createInliner(element, settings);
      if (inliner != null) {
        inliners.put(language, inliner);
        break;
      }
    }
  }
  return inliners;
}
项目:tools-idea    文件:GenericInlineHandler.java   
public static void collectConflicts(final PsiReference reference,
                                    final PsiElement element,
                                    final Map<Language, InlineHandler.Inliner> inliners,
                                    final MultiMap<PsiElement, String> conflicts) {
  final PsiElement referenceElement = reference.getElement();
  if (referenceElement == null) return;
  final Language language = referenceElement.getLanguage();
  final InlineHandler.Inliner inliner = inliners.get(language);
  if (inliner != null) {
    final MultiMap<PsiElement, String> refConflicts = inliner.getConflicts(reference, element);
    if (refConflicts != null) {
      for (PsiElement psiElement : refConflicts.keySet()) {
        conflicts.putValues(psiElement, refConflicts.get(psiElement));
      }
    }
  }
  else {
    conflicts.putValue(referenceElement, "Cannot inline reference from " + language.getID());
  }
}
项目:tools-idea    文件:GrInlineFieldUtil.java   
private static InlineHandler.Settings inlineFieldDialogResult(Project project, GrField field, final boolean invokedOnReference) {
  if (ApplicationManager.getApplication().isUnitTestMode()) {
    return new InlineHandler.Settings() {
      @Override
      public boolean isOnlyOneReferenceToInline() {
        return invokedOnReference;
      }
    };
  }

  final InlineGroovyFieldDialog dialog = new InlineGroovyFieldDialog(project, field, invokedOnReference);
  dialog.show();
  if (dialog.isOK()) {
    return new InlineHandler.Settings() {
      @Override
      public boolean isOnlyOneReferenceToInline() {
        return dialog.isInlineThisOnly();
      }
    };
  }
  else {
    return InlineHandler.Settings.CANNOT_INLINE_SETTINGS;
  }
}
项目:tools-idea    文件:GroovyInlineHandler.java   
@Nullable
public Settings prepareInlineElement(@NotNull final PsiElement element, @Nullable Editor editor, boolean invokedOnReference) {
  if (element instanceof GrField) {
    return GrInlineFieldUtil.inlineFieldSettings((GrField)element, editor, invokedOnReference);
  }
  else if (element instanceof GrMethod) {
    return GroovyInlineMethodUtil.inlineMethodSettings((GrMethod)element, editor, invokedOnReference);
  }
  else {
    if (element instanceof GrTypeDefinition || element instanceof GrClassSubstitution) {
      return null;      //todo inline to anonymous class, push members from super class
    }
  }

  if (element instanceof PsiMember) {
    String message = GroovyRefactoringBundle.message("cannot.inline.0.", getFullName(element));
    CommonRefactoringUtil.showErrorHint(element.getProject(), editor, message, "", HelpID.INLINE_FIELD);
    return InlineHandler.Settings.CANNOT_INLINE_SETTINGS;
  }
  return null;
}
项目:consulo    文件:GenericInlineHandler.java   
public static Map<Language, InlineHandler.Inliner> initializeInliners(PsiElement element,
                                                                      InlineHandler.Settings settings,
                                                                      Collection<? extends PsiReference> allReferences) {
  final Map<Language, InlineHandler.Inliner> inliners = new HashMap<Language, InlineHandler.Inliner>();
  for (PsiReference ref : allReferences) {
    if (ref == null) {
      LOG.error("element: " + element.getClass()+ ", allReferences contains null!");
      continue;
    }
    PsiElement refElement = ref.getElement();
    LOG.assertTrue(refElement != null, ref.getClass().getName());

    final Language language = refElement.getLanguage();
    if (inliners.containsKey(language)) continue;

    final List<InlineHandler> handlers = InlineHandlers.getInlineHandlers(language);
    for (InlineHandler handler : handlers) {
      InlineHandler.Inliner inliner = handler.createInliner(element, settings);
      if (inliner != null) {
        inliners.put(language, inliner);
        break;
      }
    }
  }
  return inliners;
}
项目:consulo    文件:GenericInlineHandler.java   
public static void collectConflicts(final PsiReference reference,
                                    final PsiElement element,
                                    final Map<Language, InlineHandler.Inliner> inliners,
                                    final MultiMap<PsiElement, String> conflicts) {
  final PsiElement referenceElement = reference.getElement();
  if (referenceElement == null) return;
  final Language language = referenceElement.getLanguage();
  final InlineHandler.Inliner inliner = inliners.get(language);
  if (inliner != null) {
    final MultiMap<PsiElement, String> refConflicts = inliner.getConflicts(reference, element);
    if (refConflicts != null) {
      for (PsiElement psiElement : refConflicts.keySet()) {
        conflicts.putValues(psiElement, refConflicts.get(psiElement));
      }
    }
  }
  else {
    conflicts.putValue(referenceElement, "Cannot inline reference from " + language.getID());
  }
}
项目:intellij-ce-playground    文件:InlineAction.java   
@Override
protected RefactoringActionHandler getHandler(@NotNull Language language, PsiElement element) {
  RefactoringActionHandler handler = super.getHandler(language, element);
  if (handler != null) return handler;
  List<InlineHandler> handlers = InlineHandlers.getInlineHandlers(language);
  return handlers.isEmpty() ? null : new InlineRefactoringActionHandler();
}
项目:intellij-ce-playground    文件:InlineRefactoringActionHandler.java   
public static boolean invokeInliner(@Nullable Editor editor, PsiElement element) {
  final List<InlineHandler> handlers = InlineHandlers.getInlineHandlers(element.getLanguage());
  for (InlineHandler handler : handlers) {
    if (GenericInlineHandler.invoke(element, editor, handler)) {
      return true;
    }
  }
  return false;
}
项目:intellij-ce-playground    文件:GenericInlineHandler.java   
public static void inlineReference(final UsageInfo usage,
                                   final PsiElement element,
                                   final Map<Language, InlineHandler.Inliner> inliners) {
  PsiElement usageElement = usage.getElement();
  if (usageElement == null) return;
  final Language language = usageElement.getLanguage();
  final InlineHandler.Inliner inliner = inliners.get(language);
  if (inliner != null) {
    inliner.inlineUsage(usage, element);
  }
}
项目:intellij-ce-playground    文件:GrVariableInliner.java   
public GrVariableInliner(GrVariable variable, InlineHandler.Settings settings) {
  GrExpression initializer;
  if (settings instanceof InlineLocalVarSettings) {
    initializer = ((InlineLocalVarSettings)settings).getInitializer();
  }
  else {
    initializer = variable.getInitializerGroovy();
    PsiUtil.LOG.assertTrue(initializer != null);
  }

  myTempExpr = GrIntroduceHandlerBase.insertExplicitCastIfNeeded(variable, initializer);

}
项目:intellij-ce-playground    文件:GroovyInlineMethodUtil.java   
/**
 * Shows dialog with question to inline
 */
@Nullable
private static InlineHandler.Settings inlineMethodDialogResult(GrMethod method, Project project, boolean invokedOnReference) {
  Application application = ApplicationManager.getApplication();
  if (!application.isUnitTestMode()) {
    final InlineMethodDialog dialog = new InlineMethodDialog(project, method, invokedOnReference, checkMethodForRecursion(method));

    if (!dialog.showAndGet()) {
      WindowManager.getInstance().getStatusBar(project)
        .setInfo(GroovyRefactoringBundle.message("press.escape.to.remove.the.highlighting"));
      return InlineHandler.Settings.CANNOT_INLINE_SETTINGS;
    }
    else {
      return new InlineHandler.Settings() {
        @Override
        public boolean isOnlyOneReferenceToInline() {
          return dialog.isInlineThisOnly();
        }
      };
    }
  }
  return new InlineHandler.Settings() {
    @Override
    public boolean isOnlyOneReferenceToInline() {
      return true;
    }
  };

}
项目:tools-idea    文件:InlineAction.java   
@Override
protected RefactoringActionHandler getHandler(@NotNull Language language, PsiElement element) {
  RefactoringActionHandler handler = super.getHandler(language, element);
  if (handler != null) return handler;
  List<InlineHandler> handlers = InlineHandlers.getInlineHandlers(language);
  return handlers.isEmpty() ? null : new InlineRefactoringActionHandler();
}
项目:tools-idea    文件:InlineRefactoringActionHandler.java   
public static boolean invokeInliner(@Nullable Editor editor, PsiElement element) {
  final List<InlineHandler> handlers = InlineHandlers.getInlineHandlers(element.getLanguage());
  for (InlineHandler handler : handlers) {
    if (GenericInlineHandler.invoke(element, editor, handler)) {
      return true;
    }
  }
  return false;
}
项目:tools-idea    文件:GenericInlineHandler.java   
public static void inlineReference(final UsageInfo usage,
                                   final PsiElement element,
                                   final Map<Language, InlineHandler.Inliner> inliners) {
  PsiElement usageElement = usage.getElement();
  if (usageElement == null) return;
  final Language language = usageElement.getLanguage();
  final InlineHandler.Inliner inliner = inliners.get(language);
  if (inliner != null) {
    inliner.inlineUsage(usage, element);
  }
}
项目:tools-idea    文件:GrVariableInliner.java   
public GrVariableInliner(GrVariable variable, InlineHandler.Settings settings) {
  GrExpression initializer;
  if (settings instanceof InlineLocalVarSettings) {
    initializer = ((InlineLocalVarSettings)settings).getInitializer();
  }
  else {
    initializer = variable.getInitializerGroovy();
    LOG.assertTrue(initializer != null);
  }
  myTempExpr = (GrExpression)skipParentheses(initializer, false);
}
项目:tools-idea    文件:GroovyInlineMethodUtil.java   
/**
 * Shows dialog with question to inline
 */
@Nullable
private static InlineHandler.Settings inlineMethodDialogResult(GrMethod method, Project project, boolean invokedOnReference) {
  Application application = ApplicationManager.getApplication();
  if (!application.isUnitTestMode()) {
    final InlineMethodDialog dialog = new InlineMethodDialog(project, method, invokedOnReference, checkMethodForRecursion(method));

    dialog.show();
    if (!dialog.isOK()) {
      WindowManager.getInstance().getStatusBar(project).setInfo(GroovyRefactoringBundle.message("press.escape.to.remove.the.highlighting"));
      return InlineHandler.Settings.CANNOT_INLINE_SETTINGS;
    }
    else {
      return new InlineHandler.Settings() {
        public boolean isOnlyOneReferenceToInline() {
          return dialog.isInlineThisOnly();
        }
      };
    }
  }
  return new InlineHandler.Settings() {
    public boolean isOnlyOneReferenceToInline() {
      return true;
    }
  };

}
项目:consulo    文件:InlineAction.java   
@Override
protected RefactoringActionHandler getHandler(@Nonnull Language language, PsiElement element) {
  RefactoringActionHandler handler = super.getHandler(language, element);
  if (handler != null) return handler;
  List<InlineHandler> handlers = InlineHandlers.getInlineHandlers(language);
  return handlers.isEmpty() ? null : new InlineRefactoringActionHandler();
}
项目:consulo    文件:InlineRefactoringActionHandler.java   
public static boolean invokeInliner(@Nullable Editor editor, PsiElement element) {
  final List<InlineHandler> handlers = InlineHandlers.getInlineHandlers(element.getLanguage());
  for (InlineHandler handler : handlers) {
    if (GenericInlineHandler.invoke(element, editor, handler)) {
      return true;
    }
  }
  return false;
}
项目:consulo    文件:GenericInlineHandler.java   
public static void inlineReference(final UsageInfo usage,
                                   final PsiElement element,
                                   final Map<Language, InlineHandler.Inliner> inliners) {
  PsiElement usageElement = usage.getElement();
  if (usageElement == null) return;
  final Language language = usageElement.getLanguage();
  final InlineHandler.Inliner inliner = inliners.get(language);
  if (inliner != null) {
    inliner.inlineUsage(usage, element);
  }
}