mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IG: ignore optional parameter in overriding method (IDEA-168410)
This commit is contained in:
+11
-5
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
* Copyright 2000-2017 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.
|
||||
@@ -15,13 +15,11 @@
|
||||
*/
|
||||
package com.siyeh.ig.abstraction;
|
||||
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiField;
|
||||
import com.intellij.psi.PsiParameter;
|
||||
import com.intellij.psi.PsiTypeElement;
|
||||
import com.intellij.psi.*;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.psiutils.MethodUtils;
|
||||
import com.siyeh.ig.psiutils.TypeUtils;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -70,6 +68,14 @@ public class OptionalUsedAsFieldOrParameterTypeInspection extends BaseInspection
|
||||
@Override
|
||||
public void visitParameter(PsiParameter parameter) {
|
||||
super.visitParameter(parameter);
|
||||
final PsiElement scope = parameter.getDeclarationScope();
|
||||
if (!(scope instanceof PsiMethod)) {
|
||||
return;
|
||||
}
|
||||
final PsiMethod method = (PsiMethod)scope;
|
||||
if (MethodUtils.hasSuper(method)) {
|
||||
return;
|
||||
}
|
||||
checkTypeElement(parameter.getTypeElement());
|
||||
}
|
||||
|
||||
|
||||
+29
-9
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
* Copyright 2000-2017 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.
|
||||
@@ -16,7 +16,9 @@
|
||||
package com.siyeh.ig.abstraction;
|
||||
|
||||
import com.intellij.codeInspection.InspectionProfileEntry;
|
||||
import com.intellij.testFramework.LightProjectDescriptor;
|
||||
import com.siyeh.ig.LightInspectionTestCase;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
@@ -55,20 +57,38 @@ public class OptionalUsedAsFieldOrParameterTypeInspectionTest extends LightInspe
|
||||
"}");
|
||||
}
|
||||
|
||||
public void testParameterInOverridingMethod() {
|
||||
doTest("import java.util.Optional;" +
|
||||
"import java.util.function.Function;" +
|
||||
"class X {" +
|
||||
" Function<Optional<Long>, Long> homebrewOrElseNull = new Function<Optional<Long>, Long>() {" +
|
||||
" @Override\n" +
|
||||
" public Long apply(Optional<Long> input) {" +
|
||||
" return input.isPresent() ? input.get() : null;" +
|
||||
" }" +
|
||||
" };" +
|
||||
"}");
|
||||
}
|
||||
|
||||
public void testForeach() {
|
||||
doTest("import java.util.Optional;" +
|
||||
"class X {" +
|
||||
" void x(Optional<String>[] array) {" +
|
||||
" for(Optional<String> optional : array) {" +
|
||||
" }" +
|
||||
" }" +
|
||||
"}");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected InspectionProfileEntry getInspection() {
|
||||
return new OptionalUsedAsFieldOrParameterTypeInspection();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected String[] getEnvironmentClasses() {
|
||||
return new String[] {
|
||||
"package java.util;" +
|
||||
"public final class Optional<T> {}",
|
||||
|
||||
"package java.util;" +
|
||||
"public final class OptionalDouble {}"
|
||||
};
|
||||
protected LightProjectDescriptor getProjectDescriptor() {
|
||||
return JAVA_8;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user