IG: fix quick fix for anonymous class (IDEA-196200)

for "Cloneable class in secure context" inspection
This commit is contained in:
Bas Leijdekkers
2018-07-31 23:32:42 +02:00
parent c7f4269d9c
commit c33973fa38
4 changed files with 40 additions and 4 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2003-2017 Dave Griffith, Bas Leijdekkers
* Copyright 2003-2018 Dave Griffith, Bas Leijdekkers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -53,7 +53,7 @@ public class CloneableClassInSecureContextInspection extends BaseInspection {
@Override
protected boolean buildQuickFixesOnlyForOnTheFlyErrors() {
// the quickfixes below probably require some thought and shouldn't be applied blindly on many classes at once
// the quick fixes below probably require some thought and shouldn't be applied blindly on many classes at once
return true;
}
@@ -125,7 +125,18 @@ public class CloneableClassInSecureContextInspection extends BaseInspection {
JavaCodeStyleSettings.getInstance(aClass.getContainingFile()).INSERT_OVERRIDE_ANNOTATION) {
methodText.append("@java.lang.Override ");
}
methodText.append("protected ").append(aClass.getName());
methodText.append("protected ");
final String name = aClass.getName();
if (name != null) {
methodText.append(name);
}
else if (aClass instanceof PsiAnonymousClass) {
final PsiClassType baseClassType = ((PsiAnonymousClass)aClass).getBaseClassType();
methodText.append(baseClassType.getCanonicalText());
}
else {
methodText.append(CommonClassNames.JAVA_LANG_OBJECT);
}
final PsiTypeParameterList typeParameterList = aClass.getTypeParameterList();
if (typeParameterList != null) {
methodText.append(typeParameterList.getText());
@@ -0,0 +1,14 @@
class C {
{
new CsvParserSettings() {
@Override
protected CsvParserSettings clone() throws CloneNotSupportedException {
throw new CloneNotSupportedException();
}
};
}
}
class CsvParserSettings implements Cloneable { }
@@ -0,0 +1,10 @@
class C {
{
new CsvParserSettings<caret>() {
};
}
}
class CsvParserSettings implements Cloneable { }
@@ -1,4 +1,4 @@
// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.siyeh.ig.fixes.security;
import com.siyeh.InspectionGadgetsBundle;
@@ -21,5 +21,6 @@ public class CreateExceptionCloneMethodFixTest extends IGQuickFixesTestCase {
public void testSimple() { doTest(); }
public void testPublicNoThrows() { doTest(); }
public void testGeneric() { doTest(); }
public void testAnonymous() { doTest(); }
}