mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Merge branch 'master' of git.labs.intellij.net:idea/community
This commit is contained in:
+1
-1
@@ -67,7 +67,7 @@ public class AbstractMethodWithMissingImplementationsInspection
|
||||
if (containingClass == null) {
|
||||
return;
|
||||
}
|
||||
if (!containingClass.isInterface() &&
|
||||
if (!containingClass.isInterface() ||
|
||||
!method.hasModifierProperty(PsiModifier.ABSTRACT)) {
|
||||
return;
|
||||
}
|
||||
|
||||
+36
-13
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2007 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2013 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.
|
||||
@@ -15,17 +15,24 @@
|
||||
*/
|
||||
package com.siyeh.ig.maturity;
|
||||
|
||||
import com.intellij.psi.PsiExpressionList;
|
||||
import com.intellij.psi.PsiMethodCallExpression;
|
||||
import com.intellij.codeInspection.ui.SingleCheckboxOptionsPanel;
|
||||
import com.intellij.psi.*;
|
||||
import com.siyeh.HardcodedMethodConstants;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.psiutils.MethodCallUtils;
|
||||
import com.siyeh.ig.psiutils.TestUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class ThrowablePrintStackTraceInspection extends BaseInspection {
|
||||
|
||||
@SuppressWarnings("PublicField")
|
||||
public boolean ignoreInTestCode = false;
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getID() {
|
||||
@@ -35,15 +42,19 @@ public class ThrowablePrintStackTraceInspection extends BaseInspection {
|
||||
@Override
|
||||
@NotNull
|
||||
public String getDisplayName() {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"printstacktrace.call.display.name");
|
||||
return InspectionGadgetsBundle.message("printstacktrace.call.display.name");
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String buildErrorString(Object... infos) {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"printstacktrace.call.problem.descriptor");
|
||||
return InspectionGadgetsBundle.message("printstacktrace.call.problem.descriptor");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public JComponent createOptionsPanel() {
|
||||
return new SingleCheckboxOptionsPanel(InspectionGadgetsBundle.message("ignore.in.test.code"), this, "ignoreInTestCode");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -51,22 +62,34 @@ public class ThrowablePrintStackTraceInspection extends BaseInspection {
|
||||
return new ThrowablePrintStackTraceVisitor();
|
||||
}
|
||||
|
||||
private static class ThrowablePrintStackTraceVisitor
|
||||
extends BaseInspectionVisitor {
|
||||
private class ThrowablePrintStackTraceVisitor extends BaseInspectionVisitor {
|
||||
|
||||
@Override
|
||||
public void visitMethodCallExpression(
|
||||
@NotNull PsiMethodCallExpression expression) {
|
||||
public void visitMethodCallExpression(@NotNull PsiMethodCallExpression expression) {
|
||||
super.visitMethodCallExpression(expression);
|
||||
final String methodName = MethodCallUtils.getMethodName(expression);
|
||||
if (!HardcodedMethodConstants.PRINT_STACK_TRACE.equals(
|
||||
methodName)) {
|
||||
if (!HardcodedMethodConstants.PRINT_STACK_TRACE.equals(methodName)) {
|
||||
return;
|
||||
}
|
||||
final PsiExpressionList argumentList = expression.getArgumentList();
|
||||
if (argumentList.getExpressions().length != 0) {
|
||||
return;
|
||||
}
|
||||
final PsiMethod method = expression.resolveMethod();
|
||||
if (method == null) {
|
||||
return;
|
||||
}
|
||||
final PsiClass containingClass = method.getContainingClass();
|
||||
if (containingClass == null) {
|
||||
return;
|
||||
}
|
||||
final String name = containingClass.getQualifiedName();
|
||||
if (!CommonClassNames.JAVA_LANG_THROWABLE.equals(name)) {
|
||||
return;
|
||||
}
|
||||
if (ignoreInTestCode && TestUtils.isInTestCode(expression)) {
|
||||
return;
|
||||
}
|
||||
registerMethodCallError(expression);
|
||||
}
|
||||
}
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package com.siyeh.igtest.inheritance.abstract_method_with_missing_implementations;
|
||||
|
||||
class WithDefaultMethods {
|
||||
interface A {
|
||||
default void foo() {}
|
||||
}
|
||||
|
||||
class B implements A {}
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<problems/>
|
||||
-16
@@ -1,16 +0,0 @@
|
||||
package com.siyeh.igtest.maturity;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
|
||||
public class ThrowablePrintStackTraceInspection
|
||||
{
|
||||
public ThrowablePrintStackTraceInspection()
|
||||
{
|
||||
}
|
||||
|
||||
public void foo()
|
||||
{
|
||||
new Throwable().printStackTrace();
|
||||
}
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* 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.siyeh.ig;
|
||||
|
||||
import com.intellij.codeInspection.InspectionProfileEntry;
|
||||
import com.siyeh.ig.maturity.ThrowablePrintStackTraceInspection;
|
||||
|
||||
/**
|
||||
* @author Bas Leijdekkers
|
||||
*/
|
||||
public class ThrowablePrintStackTraceInspectionTest extends LightInspectionTestCase {
|
||||
|
||||
public void testSimple() {
|
||||
doStatementTest("new Throwable()./*Call to 'printStackTrace()' should probably be replaced with more robust logging*/printStackTrace/**/();");
|
||||
}
|
||||
|
||||
public void testInTestCode() {
|
||||
addEnvironmentClass("package org.junit;" +
|
||||
"@Retention(RetentionPolicy.RUNTIME) " +
|
||||
"@Target({ElementType.METHOD}) " +
|
||||
"public @interface Test {}");
|
||||
doMemberTest("@org.junit.Test public void testSomething() {" +
|
||||
" new RuntimeException().printStackTrace();" +
|
||||
"}");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InspectionProfileEntry getInspection() {
|
||||
final ThrowablePrintStackTraceInspection inspection = new ThrowablePrintStackTraceInspection();
|
||||
inspection.ignoreInTestCode = true;
|
||||
return inspection;
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* 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.siyeh.ig.inheritance;
|
||||
|
||||
import com.siyeh.ig.IGInspectionTestCase;
|
||||
|
||||
public class AbstractMethodWithMissingImplementationsInspectionTest extends IGInspectionTestCase {
|
||||
|
||||
public void test() throws Exception {
|
||||
final AbstractMethodWithMissingImplementationsInspection tool = new AbstractMethodWithMissingImplementationsInspection();
|
||||
doTest("com/siyeh/igtest/inheritance/abstract_method_with_missing_implementations", tool);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -690,7 +690,7 @@ interface I {}
|
||||
def <T extends PsiElement> T foo1(Class<T> <warning descr="Cannot assign 'Class<String>' to 'Class<? extends PsiElement>'">x</warning> = String ) {}
|
||||
def <T extends PsiElement> T foo2(Class<T> x = PsiElement ) {}
|
||||
def <T> T foo3(Class<T> x = PsiElement ) {}
|
||||
def <T extends PsiElement & I> T foo4(Class<T> <warning descr="Cannot assign 'Class<PsiElement>' to 'Class<? extends PsiElement>'">x</warning> = PsiElement ) {}
|
||||
def <T extends PsiElement & I> T foo4(Class<T> <warning descr="Cannot assign 'Class<PsiElement>' to 'Class<? extends PsiElement & I>'">x</warning> = PsiElement ) {}
|
||||
def <T extends PsiElement & I> T foo5(Class<T> x = Foo ) {}
|
||||
''')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user