Package de.halirutan.mathematica.codeinsight.smartenter

Source Code of de.halirutan.mathematica.codeinsight.smartenter.CompoundExpressionFixer

package de.halirutan.mathematica.codeinsight.smartenter;

import com.intellij.lang.SmartEnterProcessorWithFixers;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.psi.PsiElement;
import com.intellij.util.IncorrectOperationException;
import de.halirutan.mathematica.parsing.psi.api.CompoundExpression;
import org.jetbrains.annotations.NotNull;

import static de.halirutan.mathematica.parsing.MathematicaElementTypes.SEMICOLON;

/**
* @author patrick (11/12/13)
*/
public class CompoundExpressionFixer extends SmartEnterProcessorWithFixers.Fixer<MathematicaSmartEnter> {
  @Override
  public void apply(@NotNull Editor editor, @NotNull MathematicaSmartEnter processor, @NotNull PsiElement element) throws IncorrectOperationException {
    Document doc = editor.getDocument();
    if (element instanceof CompoundExpression && element.getTextOffset()+element.getTextLength() == editor.getCaretModel().getOffset()) {
      final PsiElement lastChild = element.getLastChild();
      if (!lastChild.getNode().getElementType().equals(SEMICOLON)) {
        final int offset = lastChild.getTextOffset() + lastChild.getTextLength();
        doc.insertString(offset, ";\n");
        editor.getCaretModel().moveToOffset(offset + 2);
      }
    }
  }
}
TOP

Related Classes of de.halirutan.mathematica.codeinsight.smartenter.CompoundExpressionFixer

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.