mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
write action (IDEA-84255)
This commit is contained in:
+9
-3
@@ -37,6 +37,7 @@ import com.intellij.openapi.progress.ProgressManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.ui.popup.PopupChooserBuilder;
|
||||
import com.intellij.openapi.util.Computable;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.searches.ClassInheritorsSearch;
|
||||
import com.intellij.psi.util.PsiUtilBase;
|
||||
@@ -135,7 +136,7 @@ public class ImplementAbstractMethodHandler {
|
||||
showInBestPositionFor(myEditor);
|
||||
}
|
||||
|
||||
private void implementInClass(final Object[] selection) {
|
||||
public void implementInClass(final Object[] selection) {
|
||||
for (Object o : selection) {
|
||||
if (!((PsiElement)o).isValid()) return;
|
||||
}
|
||||
@@ -143,9 +144,14 @@ public class ImplementAbstractMethodHandler {
|
||||
@Override
|
||||
public void run() {
|
||||
final LinkedHashSet<PsiClass> classes = new LinkedHashSet<PsiClass>();
|
||||
for (Object o : selection) {
|
||||
for (final Object o : selection) {
|
||||
if (o instanceof PsiEnumConstant) {
|
||||
classes.add(((PsiEnumConstant)o).getOrCreateInitializingClass());
|
||||
classes.add(ApplicationManager.getApplication().runWriteAction(new Computable<PsiClass>(){
|
||||
@Override
|
||||
public PsiClass compute() {
|
||||
return ((PsiEnumConstant) o).getOrCreateInitializingClass();
|
||||
}
|
||||
}));
|
||||
}
|
||||
else {
|
||||
classes.add((PsiClass)o);
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright 2000-2012 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.
|
||||
*/
|
||||
enum E{
|
||||
E1 {
|
||||
@Override
|
||||
public void foo() {
|
||||
<selection>//To change body of implemented methods use File | Settings | File Templates.</selection>
|
||||
}
|
||||
};
|
||||
public abstract void foo();
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright 2000-2012 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.
|
||||
*/
|
||||
enum E{
|
||||
E1;
|
||||
public abstract void fo<caret>o();
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package com.intellij.codeInsight;
|
||||
|
||||
import com.intellij.codeInsight.generation.OverrideImplementUtil;
|
||||
import com.intellij.codeInsight.generation.PsiMethodMember;
|
||||
import com.intellij.codeInsight.intention.impl.ImplementAbstractMethodHandler;
|
||||
import com.intellij.lang.java.JavaLanguage;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.*;
|
||||
@@ -97,6 +98,20 @@ public class OverrideImplementTest extends LightCodeInsightTestCase {
|
||||
assertFalse(strings.toString(), strings.contains("HierarchicalMethodSignatureImpl: A([])"));
|
||||
}
|
||||
|
||||
public void testEnumConstant() throws Exception {
|
||||
String name = getTestName(false);
|
||||
configureByFile("/codeInsight/overrideImplement/before" + name + ".java");
|
||||
int offset = getEditor().getCaretModel().getOffset();
|
||||
PsiElement context = getFile().findElementAt(offset);
|
||||
PsiMethod psiMethod = PsiTreeUtil.getParentOfType(context, PsiMethod.class);
|
||||
assert psiMethod != null;
|
||||
final PsiClass aClass = psiMethod.getContainingClass();
|
||||
assert aClass != null && aClass.isEnum();
|
||||
final PsiField[] fields = aClass.getFields();
|
||||
new ImplementAbstractMethodHandler(getProject(), getEditor(), psiMethod).implementInClass(fields);
|
||||
checkResultByFile("/codeInsight/overrideImplement/after" + name + ".java");
|
||||
}
|
||||
|
||||
private void doTest(boolean copyJavadoc) throws Exception {
|
||||
String name = getTestName(false);
|
||||
configureByFile("/codeInsight/overrideImplement/before" + name + ".java");
|
||||
|
||||
Reference in New Issue
Block a user