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
.rename
.naming
;
18 import com
.intellij
.openapi
.diagnostic
.Logger
;
19 import com
.intellij
.psi
.PsiNamedElement
;
20 import com
.intellij
.util
.IncorrectOperationException
;
22 import java
.util
.List
;
27 public abstract class PsiNamedElementAutomaticRenamer
<T
extends PsiNamedElement
> extends AutomaticUsageRenamer
<T
> {
28 private static final Logger LOG
= Logger
.getInstance("#com.intellij.refactoring.rename.naming.PsiNamedElementAutomaticRenamer");
30 protected PsiNamedElementAutomaticRenamer(List
<?
extends T
> elements
, String oldName
, String newName
) {
31 super(elements
, oldName
, newName
);
34 protected String
getName(T element
) {
35 return element
.getName();
38 protected void doRenameElement(final T t
) throws IncorrectOperationException
{
39 t
.setName(getNewElementName(t
));
42 protected String
suggestName(T element
) {
43 String elementName
= getName(element
);
44 final NameSuggester suggester
= new NameSuggester(getOldName(), getNewName());
45 String canonicalName
= nameToCanonicalName(elementName
, element
);
46 final String newCanonicalName
= suggester
.suggestName(canonicalName
);
47 if (newCanonicalName
.length() == 0) {
49 "oldName = " + getOldName() +
50 ", newName = " + getNewName() +
51 ", name = " + elementName
+
52 ", canonicalName = " + canonicalName
+
53 ", newCanonicalName = " + newCanonicalName
56 return canonicalNameToName(newCanonicalName
, element
);
59 protected String
canonicalNameToName(String canonicalName
, T element
) {
63 protected String
nameToCanonicalName(String name
, T element
) {