mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
@Nullable
This commit is contained in:
+9
-11
@@ -24,7 +24,6 @@ import com.intellij.psi.search.searches.MethodReferencesSearch;
|
||||
import com.intellij.psi.search.searches.OverridingMethodsSearch;
|
||||
import com.intellij.psi.search.searches.ReferencesSearch;
|
||||
import com.intellij.refactoring.BaseRefactoringProcessor;
|
||||
import com.intellij.refactoring.listeners.RefactoringElementListener;
|
||||
import com.intellij.refactoring.rename.RenameProcessor;
|
||||
import com.intellij.refactoring.rename.RenameUtil;
|
||||
import com.intellij.refactoring.util.MoveRenameUsageInfo;
|
||||
@@ -62,11 +61,13 @@ public class InvertBooleanProcessor extends BaseRefactoringProcessor {
|
||||
mySmartPointerManager = SmartPointerManager.getInstance(project);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
protected UsageViewDescriptor createUsageViewDescriptor(UsageInfo[] usages) {
|
||||
return new InvertBooleanUsageViewDescriptor(myElement);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean preprocessUsages(Ref<UsageInfo[]> refUsages) {
|
||||
if (myRenameProcessor.preprocessUsages(refUsages)) {
|
||||
prepareSuccessful();
|
||||
@@ -75,6 +76,7 @@ public class InvertBooleanProcessor extends BaseRefactoringProcessor {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
protected UsageInfo[] findUsages() {
|
||||
final List<SmartPsiElementPointer> toInvert = new ArrayList<SmartPsiElementPointer>();
|
||||
@@ -175,7 +177,7 @@ public class InvertBooleanProcessor extends BaseRefactoringProcessor {
|
||||
for (PsiReference ref : refs) {
|
||||
final PsiElement element = ref.getElement();
|
||||
if (element instanceof PsiReferenceExpression) {
|
||||
final PsiReferenceExpression refExpr = ((PsiReferenceExpression)element);
|
||||
final PsiReferenceExpression refExpr = (PsiReferenceExpression)element;
|
||||
PsiElement parent = refExpr.getParent();
|
||||
if (parent instanceof PsiAssignmentExpression && refExpr.equals(((PsiAssignmentExpression)parent).getLExpression())) {
|
||||
toInvert.add(mySmartPointerManager.createSmartPsiElementPointer(((PsiAssignmentExpression)parent).getRExpression()));
|
||||
@@ -203,9 +205,10 @@ public class InvertBooleanProcessor extends BaseRefactoringProcessor {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void refreshElements(PsiElement[] elements) {
|
||||
LOG.assertTrue(elements.length == 1 && elements[0] instanceof PsiMethod);
|
||||
myElement = ((PsiMethod)elements[0]);
|
||||
myElement = (PsiMethod)elements[0];
|
||||
}
|
||||
|
||||
private static UsageInfo[] extractUsagesForElement(PsiElement element, UsageInfo[] usages) {
|
||||
@@ -222,17 +225,11 @@ public class InvertBooleanProcessor extends BaseRefactoringProcessor {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void performRefactoring(UsageInfo[] usages) {
|
||||
|
||||
for (final PsiElement element : myRenameProcessor.getElements()) {
|
||||
try {
|
||||
RenameUtil.doRename(element, myRenameProcessor.getNewName(element), extractUsagesForElement(element, usages), myProject, new RefactoringElementListener() {
|
||||
public void elementMoved(@NotNull PsiElement newElement) {
|
||||
}
|
||||
|
||||
public void elementRenamed(@NotNull PsiElement newElement) {
|
||||
}
|
||||
});
|
||||
RenameUtil.doRename(element, myRenameProcessor.getNewName(element), extractUsagesForElement(element, usages), myProject, null);
|
||||
}
|
||||
catch (final IncorrectOperationException e) {
|
||||
RenameUtil.showErrorMessage(e, element, myProject);
|
||||
@@ -263,6 +260,7 @@ public class InvertBooleanProcessor extends BaseRefactoringProcessor {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getCommandName() {
|
||||
return InvertBooleanHandler.REFACTORING_NAME;
|
||||
}
|
||||
|
||||
@@ -61,7 +61,8 @@ public class RenameJavaClassProcessor extends RenamePsiElementProcessor {
|
||||
|
||||
public void renameElement(final PsiElement element,
|
||||
final String newName,
|
||||
final UsageInfo[] usages, final RefactoringElementListener listener) throws IncorrectOperationException {
|
||||
final UsageInfo[] usages,
|
||||
@Nullable RefactoringElementListener listener) throws IncorrectOperationException {
|
||||
PsiClass aClass = (PsiClass) element;
|
||||
ArrayList<UsageInfo> postponedCollisions = new ArrayList<UsageInfo>();
|
||||
List<MemberHidesOuterMemberUsageInfo> hidesOut = new ArrayList<MemberHidesOuterMemberUsageInfo>();
|
||||
@@ -111,7 +112,9 @@ public class RenameJavaClassProcessor extends RenamePsiElementProcessor {
|
||||
}*/
|
||||
|
||||
|
||||
listener.elementRenamed(aClass);
|
||||
if (listener != null) {
|
||||
listener.elementRenamed(aClass);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -59,7 +59,8 @@ public class RenameJavaMethodProcessor extends RenameJavaMemberProcessor {
|
||||
|
||||
public void renameElement(final PsiElement psiElement,
|
||||
final String newName,
|
||||
final UsageInfo[] usages, final RefactoringElementListener listener) throws IncorrectOperationException {
|
||||
final UsageInfo[] usages,
|
||||
@Nullable RefactoringElementListener listener) throws IncorrectOperationException {
|
||||
PsiMethod method = (PsiMethod) psiElement;
|
||||
Set<PsiMethod> methodAndOverriders = new HashSet<PsiMethod>();
|
||||
Set<PsiClass> containingClasses = new HashSet<PsiClass>();
|
||||
@@ -115,7 +116,9 @@ public class RenameJavaMethodProcessor extends RenameJavaMemberProcessor {
|
||||
((PsiMethod)element).setName(newName);
|
||||
}
|
||||
}
|
||||
listener.elementRenamed(method);
|
||||
if (listener != null) {
|
||||
listener.elementRenamed(method);
|
||||
}
|
||||
|
||||
for (PsiElement element: renamedReferences) {
|
||||
fixNameCollisionsWithInnerClassMethod(element, newName, methodAndOverriders, containingClasses,
|
||||
|
||||
@@ -57,7 +57,8 @@ public class RenameJavaVariableProcessor extends RenameJavaMemberProcessor {
|
||||
|
||||
public void renameElement(final PsiElement psiElement,
|
||||
final String newName,
|
||||
final UsageInfo[] usages, final RefactoringElementListener listener) throws IncorrectOperationException {
|
||||
final UsageInfo[] usages,
|
||||
@Nullable RefactoringElementListener listener) throws IncorrectOperationException {
|
||||
PsiVariable variable = (PsiVariable) psiElement;
|
||||
List<MemberHidesOuterMemberUsageInfo> outerHides = new ArrayList<MemberHidesOuterMemberUsageInfo>();
|
||||
List<MemberHidesStaticImportUsageInfo> staticImportHides = new ArrayList<MemberHidesStaticImportUsageInfo>();
|
||||
@@ -104,7 +105,9 @@ public class RenameJavaVariableProcessor extends RenameJavaMemberProcessor {
|
||||
}
|
||||
// do actual rename
|
||||
variable.setName(newName);
|
||||
listener.elementRenamed(variable);
|
||||
if (listener != null) {
|
||||
listener.elementRenamed(variable);
|
||||
}
|
||||
|
||||
if (variable instanceof PsiField) {
|
||||
for (PsiElement occurrence : occurrencesToCheckForConflict) {
|
||||
|
||||
@@ -56,7 +56,8 @@ public class RenamePsiDirectoryProcessor extends RenamePsiElementProcessor {
|
||||
|
||||
public void renameElement(final PsiElement element,
|
||||
final String newName,
|
||||
final UsageInfo[] usages, final RefactoringElementListener listener) throws IncorrectOperationException {
|
||||
final UsageInfo[] usages,
|
||||
@Nullable RefactoringElementListener listener) throws IncorrectOperationException {
|
||||
PsiDirectory aDirectory = (PsiDirectory) element;
|
||||
// rename all non-package statement references
|
||||
for (UsageInfo usage : usages) {
|
||||
@@ -71,7 +72,9 @@ public class RenamePsiDirectoryProcessor extends RenamePsiElementProcessor {
|
||||
}
|
||||
|
||||
aDirectory.setName(newName);
|
||||
listener.elementRenamed(aDirectory);
|
||||
if (listener != null) {
|
||||
listener.elementRenamed(aDirectory);
|
||||
}
|
||||
}
|
||||
|
||||
public String getQualifiedNameAfterRename(final PsiElement element, final String newName, final boolean nonJava) {
|
||||
|
||||
@@ -44,7 +44,8 @@ public class RenamePsiPackageProcessor extends RenamePsiElementProcessor {
|
||||
|
||||
public void renameElement(final PsiElement element,
|
||||
final String newName,
|
||||
final UsageInfo[] usages, final RefactoringElementListener listener) throws IncorrectOperationException {
|
||||
final UsageInfo[] usages,
|
||||
@Nullable RefactoringElementListener listener) throws IncorrectOperationException {
|
||||
final PsiPackage psiPackage = (PsiPackage)element;
|
||||
psiPackage.handleQualifiedNameChange(PsiUtilCore.getQualifiedNameAfterRename(psiPackage.getQualifiedName(), newName));
|
||||
RenameUtil.doRenameGenericNamedElement(element, newName, usages, listener);
|
||||
|
||||
+1
-1
@@ -55,7 +55,7 @@ public abstract class RenamePsiElementProcessor {
|
||||
}
|
||||
|
||||
public void renameElement(final PsiElement element, String newName, UsageInfo[] usages,
|
||||
RefactoringElementListener listener) throws IncorrectOperationException {
|
||||
@Nullable RefactoringElementListener listener) throws IncorrectOperationException {
|
||||
RenameUtil.doRenameGenericNamedElement(element, newName, usages, listener);
|
||||
}
|
||||
|
||||
|
||||
@@ -164,7 +164,7 @@ public class RenameUtil {
|
||||
}
|
||||
|
||||
public static void doRename(final PsiElement element, String newName, UsageInfo[] usages, final Project project,
|
||||
final RefactoringElementListener listener) throws IncorrectOperationException{
|
||||
@Nullable final RefactoringElementListener listener) throws IncorrectOperationException{
|
||||
final RenamePsiElementProcessor processor = RenamePsiElementProcessor.forElement(element);
|
||||
final String fqn = element instanceof PsiFile ? ((PsiFile)element).getVirtualFile().getPath() : CopyReferenceAction.elementToFqn(element);
|
||||
if (fqn != null) {
|
||||
|
||||
@@ -251,7 +251,7 @@ public class AndroidRenameResourceProcessor extends RenamePsiElementProcessor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renameElement(PsiElement element, final String newName, UsageInfo[] usages, RefactoringElementListener listener)
|
||||
public void renameElement(PsiElement element, final String newName, UsageInfo[] usages, @Nullable RefactoringElementListener listener)
|
||||
throws IncorrectOperationException {
|
||||
if (element instanceof PsiField) {
|
||||
new RenameJavaVariableProcessor().renameElement(element, newName, usages, listener);
|
||||
|
||||
+1
-1
@@ -70,7 +70,7 @@ public class RenameAliasImportedMethodProcessor extends RenameJavaMethodProcesso
|
||||
public void renameElement(PsiElement psiElement,
|
||||
String newName,
|
||||
UsageInfo[] usages,
|
||||
RefactoringElementListener listener) throws IncorrectOperationException {
|
||||
@Nullable RefactoringElementListener listener) throws IncorrectOperationException {
|
||||
boolean isGetter = isSimplePropertyGetter((PsiMethod)psiElement);
|
||||
boolean isSetter = isSimplePropertySetter((PsiMethod)psiElement);
|
||||
|
||||
|
||||
+2
-1
@@ -24,6 +24,7 @@ import com.intellij.refactoring.rename.RenameJavaMethodProcessor;
|
||||
import com.intellij.usageView.UsageInfo;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrAccessorMethod;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.util.GroovyPropertyUtils;
|
||||
|
||||
@@ -46,7 +47,7 @@ public class RenameGrAccessorProcessor extends RenameJavaMethodProcessor {
|
||||
public void renameElement(PsiElement psiElement,
|
||||
String newName,
|
||||
UsageInfo[] usages,
|
||||
RefactoringElementListener listener) throws IncorrectOperationException {
|
||||
@Nullable RefactoringElementListener listener) throws IncorrectOperationException {
|
||||
|
||||
}
|
||||
|
||||
|
||||
+5
-2
@@ -33,6 +33,7 @@ import com.intellij.util.containers.MultiMap;
|
||||
import com.intellij.util.containers.hash.HashMap;
|
||||
import com.intellij.util.containers.hash.LinkedHashMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.groovy.lang.GrReferenceAdjuster;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult;
|
||||
@@ -84,7 +85,7 @@ public class RenameGrFieldProcessor extends RenameJavaVariableProcessor {
|
||||
public void renameElement(final PsiElement psiElement,
|
||||
String newName,
|
||||
final UsageInfo[] usages,
|
||||
final RefactoringElementListener listener) throws IncorrectOperationException {
|
||||
@Nullable RefactoringElementListener listener) throws IncorrectOperationException {
|
||||
final GrField field = (GrField)psiElement;
|
||||
String fieldName = field.getName();
|
||||
Map<PsiElement, String> renames = new HashMap<PsiElement, String>();
|
||||
@@ -164,7 +165,9 @@ public class RenameGrFieldProcessor extends RenameJavaVariableProcessor {
|
||||
rename(element, info, newName, true, manager);
|
||||
}
|
||||
}
|
||||
listener.elementRenamed(field);
|
||||
if (listener != null) {
|
||||
listener.elementRenamed(field);
|
||||
}
|
||||
}
|
||||
|
||||
private static void rename(PsiNamedElement element,
|
||||
|
||||
+2
-1
@@ -23,6 +23,7 @@ import com.intellij.refactoring.rename.RenamePsiElementProcessor;
|
||||
import com.intellij.usageView.UsageInfo;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.util.GroovyPropertyUtils;
|
||||
@@ -57,7 +58,7 @@ public class RenameGroovyPropertyProcessor extends RenamePsiElementProcessor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renameElement(PsiElement element, String newName, UsageInfo[] usages, RefactoringElementListener listener)
|
||||
public void renameElement(PsiElement element, String newName, UsageInfo[] usages, @Nullable RefactoringElementListener listener)
|
||||
throws IncorrectOperationException {
|
||||
|
||||
//do nothing
|
||||
|
||||
@@ -30,6 +30,7 @@ import com.intellij.usageView.UsageInfo;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.containers.Queue;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class RenameXmlAttributeProcessor extends RenamePsiElementProcessor {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.refactoring.rename.RenameXmlAttributeProcessor");
|
||||
@@ -41,7 +42,7 @@ public class RenameXmlAttributeProcessor extends RenamePsiElementProcessor {
|
||||
public void renameElement(final PsiElement element,
|
||||
final String newName,
|
||||
final UsageInfo[] usages,
|
||||
final RefactoringElementListener listener) throws IncorrectOperationException {
|
||||
@Nullable RefactoringElementListener listener) throws IncorrectOperationException {
|
||||
if (element instanceof XmlAttribute) {
|
||||
doRenameXmlAttribute((XmlAttribute)element, newName, listener);
|
||||
}
|
||||
@@ -52,10 +53,12 @@ public class RenameXmlAttributeProcessor extends RenamePsiElementProcessor {
|
||||
|
||||
private static void doRenameXmlAttribute(XmlAttribute attribute,
|
||||
String newName,
|
||||
RefactoringElementListener listener) {
|
||||
@Nullable RefactoringElementListener listener) {
|
||||
try {
|
||||
final PsiElement element = attribute.setName(newName);
|
||||
listener.elementRenamed(element);
|
||||
if (listener != null) {
|
||||
listener.elementRenamed(element);
|
||||
}
|
||||
}
|
||||
catch (IncorrectOperationException e) {
|
||||
LOG.error(e);
|
||||
@@ -65,7 +68,7 @@ public class RenameXmlAttributeProcessor extends RenamePsiElementProcessor {
|
||||
private static void doRenameXmlAttributeValue(@NotNull XmlAttributeValue value,
|
||||
String newName,
|
||||
UsageInfo[] infos,
|
||||
RefactoringElementListener listener)
|
||||
@Nullable RefactoringElementListener listener)
|
||||
throws IncorrectOperationException {
|
||||
LOG.assertTrue(value.isValid());
|
||||
|
||||
@@ -75,7 +78,9 @@ public class RenameXmlAttributeProcessor extends RenamePsiElementProcessor {
|
||||
LOG.assertTrue(psiManager != null);
|
||||
XmlFile file = (XmlFile)PsiFileFactory.getInstance(psiManager.getProject()).createFileFromText("dummy.xml", "<a attr=\"" + newName + "\"/>");
|
||||
final PsiElement element = value.replace(file.getDocument().getRootTag().getAttributes()[0].getValueElement());
|
||||
listener.elementRenamed(element);
|
||||
if (listener != null) {
|
||||
listener.elementRenamed(element);
|
||||
}
|
||||
}
|
||||
|
||||
private static void renameAll(PsiElement originalElement, UsageInfo[] infos, String newName,
|
||||
|
||||
Reference in New Issue
Block a user