PageRenderTime 65ms CodeModel.GetById 38ms RepoModel.GetById 1ms app.codeStats 0ms

/src/org/jetbrains/plugins/clojure/actions/editor/SlurpForwardsAction.java

https://github.com/jevgeni/clojure-plugin
Java | 57 lines | 27 code | 7 blank | 23 comment | 2 complexity | 9781c774ebd1a5cd2e07db432b7504b0 MD5 | raw file
  1. /*
  2. * Copyright 2009 JetBrains s.r.o.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.jetbrains.plugins.clojure.actions.editor;
  17. import com.intellij.openapi.actionSystem.DataContext;
  18. import com.intellij.openapi.editor.Editor;
  19. import com.intellij.openapi.project.Project;
  20. import com.intellij.psi.PsiElement;
  21. import com.intellij.psi.util.PsiTreeUtil;
  22. import org.jetbrains.plugins.clojure.psi.ClojurePsiElement;
  23. import org.jetbrains.plugins.clojure.psi.api.ClBraced;
  24. import org.jetbrains.plugins.clojure.psi.util.ClojurePsiUtil;
  25. /**
  26. * An action to mimic the slurp command from <i>paredit.el</i>.
  27. * <p>
  28. * Slurping a sexp makes it 'swallow' the following expression.
  29. *
  30. * @author <a href="mailto:ianp@ianp.org">Ian Phillips</a>
  31. */
  32. public final class SlurpForwardsAction extends ClojureEditorAction {
  33. // TODO: Automatically reindent the slurped s-exp.
  34. public SlurpForwardsAction() {
  35. super(new SlurpForwardsActionHandler());
  36. }
  37. private static class SlurpForwardsActionHandler extends AbstractSexpActionHandler {
  38. protected SlurpForwardsActionHandler() {
  39. super(false);
  40. }
  41. @Override
  42. protected void executeWriteAction(ClBraced sexp, Editor editor, Project project, DataContext dataContext) {
  43. PsiElement slurpee = PsiTreeUtil.getNextSiblingOfType(sexp, ClojurePsiElement.class);
  44. if (slurpee == null) { return; }
  45. PsiElement copy = slurpee.copy();
  46. slurpee.delete();
  47. sexp.addAfter(copy, ClojurePsiUtil.lastChildSexp(sexp));
  48. }
  49. }
  50. }