IDEA-97282 (disable pointless quickfixes)

This commit is contained in:
Roman Shevchenko
2013-01-11 18:12:50 +01:00
parent aca15e7760
commit 7f67356440
7 changed files with 74 additions and 12 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
* Copyright 2000-2013 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.
@@ -190,10 +190,12 @@ public class CreateClassFromNewFix extends CreateFromUsageBaseFix {
if (aClass.isInterface()) {
PsiReferenceList implementsList = targetClass.getImplementsList();
assert implementsList != null : targetClass;
implementsList.add(factory.createReferenceElementByType(classType));
}
else {
PsiReferenceList extendsList = targetClass.getExtendsList();
assert extendsList != null : targetClass;
if (extendsList.getReferencedTypes().length == 0 && !CommonClassNames.JAVA_LANG_OBJECT.equals(classType.getCanonicalText())) {
extendsList.add(factory.createReferenceElementByType(classType));
}
@@ -201,7 +203,6 @@ public class CreateClassFromNewFix extends CreateFromUsageBaseFix {
}
}
private static PsiFile getTargetFile(PsiElement element) {
PsiJavaCodeReferenceElement referenceElement = getReferenceElement((PsiNewExpression)element);
@@ -242,14 +243,18 @@ public class CreateClassFromNewFix extends CreateFromUsageBaseFix {
@Override
protected boolean isAvailableImpl(int offset) {
PsiElement nameElement = getNameElement(getNewExpression());
PsiNewExpression expression = getNewExpression();
if (expression.getQualifier() != null) {
return false;
}
PsiFile targetFile = getTargetFile(getNewExpression());
PsiFile targetFile = getTargetFile(expression);
if (targetFile != null && !targetFile.getManager().isInProject(targetFile)) {
return false;
}
if (CreateFromUsageUtils.shouldShowTag(offset, nameElement, getNewExpression())) {
PsiElement nameElement = getNameElement(expression);
if (CreateFromUsageUtils.shouldShowTag(offset, nameElement, expression)) {
String varName = nameElement.getText();
setText(getText(varName));
return true;
@@ -268,8 +273,7 @@ public class CreateClassFromNewFix extends CreateFromUsageBaseFix {
private static PsiElement getNameElement(PsiNewExpression targetElement) {
PsiJavaCodeReferenceElement referenceElement = getReferenceElement(targetElement);
if (referenceElement == null) return null;
return referenceElement.getReferenceNameElement();
return referenceElement != null ? referenceElement.getReferenceNameElement() : null;
}
@Override
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
* Copyright 2000-2013 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.
@@ -69,6 +69,12 @@ public abstract class ImportClassFixBase<T extends PsiElement & PsiReference> im
if (!myRef.isValid()) {
return false;
}
PsiElement parent = myRef.getParent();
if (parent instanceof PsiNewExpression && ((PsiNewExpression)parent).getQualifier() != null) {
return false;
}
PsiManager manager = file.getManager();
return manager.isInProject(file) && !getClassesToImport().isEmpty();
}
@@ -0,0 +1,6 @@
// "Create Class 'ArrayList'" "false"
public class Test {
public static void main() {
q.new <caret>ArrayList();
}
}
@@ -0,0 +1,6 @@
// "Create Inner Class 'ArrayList'" "false"
public class Test {
public static void main() {
q.new <caret>ArrayList();
}
}
@@ -0,0 +1,9 @@
// "Create Inner Class 'ArrayList'" "false"
public class Test {
public static void main() {
Inner q = new Inner();
q.new <caret>ArrayList();
}
static class Inner { }
}
@@ -1,3 +1,18 @@
/*
* Copyright 2000-2013 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.quickFix;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
@@ -6,10 +21,9 @@ import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
* @author ven
*/
public class CreateClassFromNewTest extends LightQuickFixTestCase {
public void test() throws Exception {
CodeStyleSettingsManager.getSettings(getProject()).SPACE_BEFORE_CLASS_LBRACE = true;
doAllTests();
doAllTests();
}
@Override
@@ -1,13 +1,30 @@
/*
* Copyright 2000-2013 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.quickFix;
/**
* @author yole
*/
public class CreateInnerClassFromNewTest extends LightQuickFixTestCase {
public void test() throws Exception { doAllTests(); }
public void test() throws Exception {
doAllTests();
}
@Override
protected String getBasePath() {
return "/codeInsight/daemonCodeAnalyzer/quickFix/createInnerClassFromNew";
}
}
}