update copyright
[fedora-idea.git] / java / java-impl / src / com / intellij / refactoring / inlineSuperClass / usageInfo / ReplaceStaticImportUsageInfo.java
blob501e26e3d900273130e3af2334cd7a13090cfee4
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.
18 * User: anna
19 * Date: 02-Oct-2008
21 package com.intellij.refactoring.inlineSuperClass.usageInfo;
23 import com.intellij.openapi.util.text.StringUtil;
24 import com.intellij.psi.JavaPsiFacade;
25 import com.intellij.psi.PsiClass;
26 import com.intellij.psi.PsiImportStaticStatement;
27 import com.intellij.refactoring.util.FixableUsageInfo;
28 import com.intellij.util.Function;
29 import com.intellij.util.IncorrectOperationException;
31 public class ReplaceStaticImportUsageInfo extends FixableUsageInfo {
32 private final PsiImportStaticStatement myStaticImportStatement;
33 private final PsiClass[] myTargetClasses;
35 public ReplaceStaticImportUsageInfo(final PsiImportStaticStatement staticImportStatement, final PsiClass[] targetClass) {
36 super(staticImportStatement);
37 myStaticImportStatement = staticImportStatement;
38 myTargetClasses = targetClass;
41 public void fixUsage() throws IncorrectOperationException {
42 final String memberName = myStaticImportStatement.getReferenceName();
43 myStaticImportStatement.replace(JavaPsiFacade.getInstance(myStaticImportStatement.getProject()).getElementFactory().createImportStaticStatement(myTargetClasses[0],
44 memberName != null ? memberName : "*"));
47 @Override
48 public String getConflictMessage() {
49 if (myTargetClasses.length != 1) {
50 return "Static import can be replaced with any of " + StringUtil.join(myTargetClasses, new Function<PsiClass, String>() {
51 public String fun(final PsiClass psiClass) {
52 return psiClass.getQualifiedName();
54 }, ", ");
56 return super.getConflictMessage();