summaryrefslogtreecommitdiff
path: root/java/java-impl/src/com/intellij/codeInsight/daemon/impl
diff options
context:
space:
mode:
Diffstat (limited to 'java/java-impl/src/com/intellij/codeInsight/daemon/impl')
-rw-r--r--java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/AddMethodQualifierFix.java11
-rw-r--r--java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/AnonymousTargetClassPreselectionUtil.java45
-rw-r--r--java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateFromUsageBaseFix.java9
3 files changed, 62 insertions, 3 deletions
diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/AddMethodQualifierFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/AddMethodQualifierFix.java
index ff851372e208..4ab9d43fbc1d 100644
--- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/AddMethodQualifierFix.java
+++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/AddMethodQualifierFix.java
@@ -69,10 +69,14 @@ public class AddMethodQualifierFix implements IntentionAction {
if (element == null || !element.isValid()) {
return false;
}
+ return getOrFindCandidates().size() != 0;
+ }
+
+ private synchronized List<PsiVariable> getOrFindCandidates() {
if (myCandidates == null) {
findCandidates();
}
- return myCandidates.size() != 0;
+ return myCandidates;
}
private void findCandidates() {
@@ -84,6 +88,9 @@ public class AddMethodQualifierFix implements IntentionAction {
}
for (final PsiVariable var : CreateFromUsageUtils.guessMatchingVariables(methodCallElement)) {
+ if (var.getName() == null) {
+ continue;
+ }
final PsiType type = var.getType();
if (!(type instanceof PsiClassType)) {
continue;
@@ -132,7 +139,7 @@ public class AddMethodQualifierFix implements IntentionAction {
@NotNull
@Override
public String getTextFor(final PsiVariable value) {
- return ObjectUtils.assertNotNull(value.getName());
+ return value.getName();
}
@Override
diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/AnonymousTargetClassPreselectionUtil.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/AnonymousTargetClassPreselectionUtil.java
new file mode 100644
index 000000000000..421c43cabe88
--- /dev/null
+++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/AnonymousTargetClassPreselectionUtil.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2000-2014 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.codeInsight.daemon.impl.quickfix;
+
+import com.intellij.ide.util.PropertiesComponent;
+import com.intellij.psi.PsiAnonymousClass;
+import com.intellij.psi.PsiClass;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.Collection;
+
+public class AnonymousTargetClassPreselectionUtil {
+ private static final String PRESELECT_ANONYMOUS = "create.member.preselect.anonymous";
+
+ public static void rememberSelection(PsiClass aClass, PsiClass firstClass) {
+ if (firstClass instanceof PsiAnonymousClass) {
+ PropertiesComponent.getInstance().setValue(PRESELECT_ANONYMOUS, String.valueOf(aClass == firstClass));
+ }
+ }
+
+ @Nullable
+ public static PsiClass getPreselection(Collection<PsiClass> classes, PsiClass firstClass) {
+ if (firstClass instanceof PsiAnonymousClass && !PropertiesComponent.getInstance().getBoolean(PRESELECT_ANONYMOUS, true)) {
+ for (PsiClass aClass : classes) {
+ if (!(aClass instanceof PsiAnonymousClass)) {
+ return aClass;
+ }
+ }
+ }
+ return null;
+ }
+}
diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateFromUsageBaseFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateFromUsageBaseFix.java
index 09b83e2a489f..abe9368374e8 100644
--- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateFromUsageBaseFix.java
+++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateFromUsageBaseFix.java
@@ -119,7 +119,8 @@ public abstract class CreateFromUsageBaseFix extends BaseIntentionAction {
protected abstract PsiElement getElement();
private void chooseTargetClass(List<PsiClass> classes, final Editor editor) {
- final Project project = classes.get(0).getProject();
+ final PsiClass firstClass = classes.get(0);
+ final Project project = firstClass.getProject();
final JList list = new JBList(classes);
PsiElementListCellRenderer renderer = new PsiClassListCellRenderer();
@@ -128,12 +129,18 @@ public abstract class CreateFromUsageBaseFix extends BaseIntentionAction {
final PopupChooserBuilder builder = new PopupChooserBuilder(list);
renderer.installSpeedSearch(builder);
+ final PsiClass preselection = AnonymousTargetClassPreselectionUtil.getPreselection(classes, firstClass);
+ if (preselection != null) {
+ list.setSelectedValue(preselection, true);
+ }
+
Runnable runnable = new Runnable() {
@Override
public void run() {
int index = list.getSelectedIndex();
if (index < 0) return;
final PsiClass aClass = (PsiClass) list.getSelectedValue();
+ AnonymousTargetClassPreselectionUtil.rememberSelection(aClass, firstClass);
CommandProcessor.getInstance().executeCommand(project, new Runnable() {
@Override
public void run() {