Bug 571661 - [switch] AIOOBE on invoking create local variable quick fix
Change-Id: Ibfdfe27dcc35cd92ad3d65d769b7deb006480e4e
Signed-off-by: Kalyan Prasad Tatavarthi <kalyan_prasad@in.ibm.com>
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/UnresolvedElementsSubProcessor.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/UnresolvedElementsSubProcessor.java
index 0b2ad14..3ba914e 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/UnresolvedElementsSubProcessor.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/UnresolvedElementsSubProcessor.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2020 IBM Corporation and others.
+ * Copyright (c) 2000, 2021 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -323,7 +323,7 @@
addNewFieldProposals(cu, astRoot, binding, declaringTypeBinding, simpleName, isWriteAccess, proposals);
// new parameters and local variables
- if (binding == null) {
+ if (binding == null && !isParentSwitchCase(simpleName)) {
addNewVariableProposals(cu, node, simpleName, proposals);
}
}
@@ -380,7 +380,7 @@
return;
}
- boolean mustBeConst= ASTResolving.isInsideModifiers(simpleName);
+ boolean mustBeConst= (ASTResolving.isInsideModifiers(simpleName) || isParentSwitchCase(simpleName)) ;
addNewFieldForType(targetCU, binding, senderDeclBinding, simpleName, isWriteAccess, mustBeConst, proposals);
@@ -395,6 +395,13 @@
}
}
+ private static boolean isParentSwitchCase(SimpleName simpleName) {
+ if (simpleName != null) {
+ return (simpleName.getParent() instanceof SwitchCase);
+ }
+ return false;
+ }
+
private static void addNewFieldForType(ICompilationUnit targetCU, ITypeBinding binding, ITypeBinding senderDeclBinding, SimpleName simpleName, boolean isWriteAccess, boolean mustBeConst, Collection<ICommandAccess> proposals) {
String name= simpleName.getIdentifier();
String nameLabel= BasicElementLabels.getJavaElementName(name);