update copyright
[fedora-idea.git] / java / java-impl / src / com / intellij / codeInsight / editorActions / smartEnter / ParameterListFixer.java
blob5435e668c983bd95dabe7493549fbc173926e362
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.
16 package com.intellij.codeInsight.editorActions.smartEnter;
18 import com.intellij.openapi.editor.Editor;
19 import com.intellij.openapi.util.text.StringUtil;
20 import com.intellij.psi.PsiElement;
21 import com.intellij.psi.PsiParameter;
22 import com.intellij.psi.PsiParameterList;
23 import com.intellij.util.IncorrectOperationException;
25 /**
26 * Created by IntelliJ IDEA.
27 * User: max
28 * Date: Sep 5, 2003
29 * Time: 9:30:02 PM
30 * To change this template use Options | File Templates.
32 public class ParameterListFixer implements Fixer {
33 public void apply(Editor editor, JavaSmartEnterProcessor processor, PsiElement psiElement) throws IncorrectOperationException {
34 if (psiElement instanceof PsiParameterList) {
35 if (!StringUtil.endsWithChar(psiElement.getText(), ')')) {
36 int offset;
37 PsiParameterList list = (PsiParameterList) psiElement;
38 final PsiParameter[] params = list.getParameters();
39 if (params == null || params.length == 0) {
40 offset = list.getTextRange().getStartOffset() + 1;
41 } else {
42 offset = params[params.length - 1].getTextRange().getEndOffset();
44 editor.getDocument().insertString(offset, ")");