update copyright
[fedora-idea.git] / java / java-impl / src / com / intellij / refactoring / wrapreturnvalue / usageInfo / ReturnWrappedValue.java
blobffa1c9f8924aab3b7312b24d9457ffad3c68d2e7
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.refactoring.wrapreturnvalue.usageInfo;
18 import com.intellij.psi.PsiExpression;
19 import com.intellij.psi.PsiMethodCallExpression;
20 import com.intellij.psi.PsiReturnStatement;
21 import com.intellij.refactoring.psi.MutationUtils;
22 import com.intellij.refactoring.util.FixableUsageInfo;
23 import com.intellij.util.IncorrectOperationException;
24 import org.jetbrains.annotations.NonNls;
26 public class ReturnWrappedValue extends FixableUsageInfo {
27 private final PsiReturnStatement statement;
29 public ReturnWrappedValue(PsiReturnStatement statement) {
30 super(statement);
31 this.statement = statement;
34 public void fixUsage() throws IncorrectOperationException{
35 final PsiMethodCallExpression returnValue =
36 (PsiMethodCallExpression) statement.getReturnValue();
37 assert returnValue != null;
38 final PsiExpression qualifier =
39 returnValue.getMethodExpression().getQualifierExpression();
40 assert qualifier != null;
41 @NonNls final String newExpression = qualifier.getText();
42 MutationUtils.replaceExpression(newExpression, returnValue);