register make class static for illegal enclosing usage error (IDEA-155700)

This commit is contained in:
Anna Kozlova
2016-05-11 11:13:41 +02:00
parent 1b43dba5eb
commit 9d95879dc2
4 changed files with 66 additions and 1 deletions

View File

@@ -870,7 +870,12 @@ public class HighlightClassUtil {
PsiElement elementToHighlight) {
if (outerClass != null && !PsiTreeUtil.isContextAncestor(outerClass, place, false)) {
String description = JavaErrorMessages.message("is.not.an.enclosing.class", HighlightUtil.formatClass(outerClass));
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(elementToHighlight).descriptionAndTooltip(description).create();
HighlightInfo highlightInfo =
HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(elementToHighlight).descriptionAndTooltip(description).create();
if (aClass != null) {
QuickFixAction.registerQuickFixAction(highlightInfo, QUICK_FIX_FACTORY.createModifierListFix(aClass, PsiModifier.STATIC, true, false));
}
return highlightInfo;
}
PsiModifierListOwner staticParent = PsiUtil.getEnclosingStaticElement(place, outerClass);
if (staticParent != null) {

View File

@@ -0,0 +1,18 @@
// "Make 'C2' static" "true"
class C {
public abstract static class C2 {
abstract void m();
}
}
class Test {
public static void main(String[] args) {
new C.C2() {
@Override
void m() {
}
};
}
}

View File

@@ -0,0 +1,18 @@
// "Make 'C2' static" "true"
class C {
public abstract class C2 {
abstract void m();
}
}
class Test {
public static void main(String[] args) {
new C.<caret>C2() {
@Override
void m() {
}
};
}
}

View File

@@ -0,0 +1,24 @@
/*
* Copyright 2000-2016 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;
public class MakeInnerClassStaticTest extends LightQuickFixParameterizedTestCase {
@Override
protected String getBasePath() {
return "/codeInsight/daemonCodeAnalyzer/quickFix/makeInnerStatic";
}
}