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
.refactoring
.inheritanceToDelegation
;
18 import com
.intellij
.openapi
.diagnostic
.Logger
;
19 import com
.intellij
.psi
.*;
20 import com
.intellij
.util
.IncorrectOperationException
;
25 public class InnerClassConstructor
extends InnerClassMethod
{
26 private static final Logger LOG
= Logger
.getInstance("#com.intellij.refactoring.inheritanceToDelegation.InnerClassConstructor");
27 public InnerClassConstructor(PsiMethod method
) {
29 LOG
.assertTrue(method
.isConstructor());
32 public void createMethod(PsiClass innerClass
) throws IncorrectOperationException
{
33 final PsiElementFactory factory
= JavaPsiFacade
.getInstance(innerClass
.getProject()).getElementFactory();
34 final PsiMethod constructor
= factory
.createConstructor();
35 constructor
.getNameIdentifier().replace(innerClass
.getNameIdentifier());
36 final PsiParameterList parameterList
= myMethod
.getParameterList();
37 constructor
.getParameterList().replace(parameterList
);
38 PsiExpressionStatement superCallStatement
=
39 (PsiExpressionStatement
) factory
.createStatementFromText("super();", null);
41 PsiExpressionList arguments
= ((PsiMethodCallExpression
) superCallStatement
.getExpression()).getArgumentList();
42 PsiParameter
[] parameters
= parameterList
.getParameters();
43 for (int i
= 0; i
< parameters
.length
; i
++) {
44 arguments
.add(factory
.createExpressionFromText(parameters
[i
].getName(), null));
46 constructor
.getBody().add(superCallStatement
);
47 innerClass
.add(constructor
);