update copyright
[fedora-idea.git] / java / java-impl / src / com / intellij / codeInsight / completion / simple / BracesTailType.java
blobf3c78ed35292b917d70bc8a64fe5b28df61ffc14
1 /*
2 * Copyright 2000-2009 JetBrains s.r.o.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.intellij.codeInsight.completion.simple;
19 import com.intellij.codeInsight.TailType;
20 import com.intellij.codeInsight.editorActions.EnterHandler;
21 import com.intellij.codeInsight.editorActions.enter.EnterAfterUnmatchedBraceHandler;
22 import com.intellij.openapi.editor.Editor;
23 import com.intellij.openapi.editor.actionSystem.EditorActionManager;
24 import com.intellij.openapi.actionSystem.IdeActions;
25 import com.intellij.openapi.fileTypes.StdFileTypes;
26 import com.intellij.psi.codeStyle.CodeStyleSettings;
27 import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
28 import com.intellij.ide.DataManager;
30 /**
31 * @author peter
33 public abstract class BracesTailType extends TailType {
35 protected abstract boolean isSpaceBeforeLBrace(CodeStyleSettings styleSettings, Editor editor, final int tailOffset);
37 public int processTail(final Editor editor, int tailOffset) {
38 CodeStyleSettings styleSettings = CodeStyleSettingsManager.getSettings(editor.getProject());
39 if (isSpaceBeforeLBrace(styleSettings, editor, tailOffset)) {
40 tailOffset = insertChar(editor, tailOffset, ' ');
42 tailOffset = insertChar(editor, tailOffset, '{');
43 if (EnterAfterUnmatchedBraceHandler.isAfterUnmatchedLBrace(editor, tailOffset, StdFileTypes.JAVA)) {
44 new EnterHandler(EditorActionManager.getInstance().getActionHandler(IdeActions.ACTION_EDITOR_ENTER)).executeWriteAction(editor,
45 DataManager.getInstance().getDataContext(editor.getContentComponent()));
46 return editor.getCaretModel().getOffset();
48 return tailOffset;