mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
Java: Merge all MethodHandle/VarHandle checks into a single inspection (IDEA-172358, IDEA-171813, IDEA-167318)
This commit is contained in:
@@ -30,7 +30,16 @@ class Main {
|
||||
|
||||
l.<warning descr="Field 'myString' is not static">findStaticVarHandle</warning>(Test.class, "myString", String.class);
|
||||
l.<warning descr="Field 'ourString' is static">findVarHandle</warning>(Test.class, "ourString", String.class);
|
||||
|
||||
MethodHandles.arrayElementVarHandle(Test[].class);
|
||||
MethodHandles.arrayElementVarHandle(int[].class);
|
||||
MethodHandles.arrayElementVarHandle(cloneable().getClass());
|
||||
|
||||
MethodHandles.arrayElementVarHandle(<warning descr="Argument is not an array type">Test.class</warning>);
|
||||
MethodHandles.arrayElementVarHandle(<warning descr="Argument is not an array type">int.class</warning>);
|
||||
}
|
||||
|
||||
static Cloneable cloneable() {return null;}
|
||||
}
|
||||
|
||||
class Test {
|
||||
|
||||
+2
-2
@@ -264,7 +264,7 @@ class Main {
|
||||
|
||||
void compare() throws Throwable {
|
||||
MethodHandles.Lookup lookup = MethodHandles.lookup();
|
||||
final VarHandle handle = lookup.findStaticVarHandle(Test.class, "myS", String.class);
|
||||
final VarHandle handle = lookup.findStaticVarHandle(Test.class, "s", String.class);
|
||||
final Test instance = new Test();
|
||||
|
||||
boolean exactCAS = handle.compareAndSet("a", "b");
|
||||
@@ -289,7 +289,7 @@ class Main {
|
||||
|
||||
void weakCompare() throws Throwable {
|
||||
MethodHandles.Lookup lookup = MethodHandles.lookup();
|
||||
final VarHandle handle = lookup.findStaticVarHandle(Test.class, "myS", String.class);
|
||||
final VarHandle handle = lookup.findStaticVarHandle(Test.class, "s", String.class);
|
||||
final Test instance = new Test();
|
||||
|
||||
boolean exactCAS = handle.weakCompareAndSet("a", "b");
|
||||
|
||||
@@ -318,7 +318,7 @@ class Main {
|
||||
|
||||
void compare() throws Throwable {
|
||||
MethodHandles.Lookup lookup = MethodHandles.lookup();
|
||||
final VarHandle handle = lookup.findVarHandle(Test.class, "myS", String.class);
|
||||
final VarHandle handle = lookup.findVarHandle(Test.class, "s", String.class);
|
||||
final Test instance = new Test();
|
||||
|
||||
boolean exactCAS = handle.compareAndSet(instance, "a", "b");
|
||||
@@ -343,7 +343,7 @@ class Main {
|
||||
|
||||
void weakCompare() throws Throwable {
|
||||
MethodHandles.Lookup lookup = MethodHandles.lookup();
|
||||
final VarHandle handle = lookup.findVarHandle(Test.class, "myS", String.class);
|
||||
final VarHandle handle = lookup.findVarHandle(Test.class, "s", String.class);
|
||||
final Test instance = new Test();
|
||||
|
||||
boolean exactCAS = handle.weakCompareAndSet(instance, "a", "b");
|
||||
|
||||
+2
-2
@@ -16,7 +16,7 @@
|
||||
package com.intellij.codeInspection
|
||||
|
||||
import com.intellij.JavaTestUtil
|
||||
import com.intellij.codeInspection.reflectiveAccess.JavaLangReflectHandleInvocationInspection
|
||||
import com.intellij.codeInspection.reflectiveAccess.JavaLangInvokeHandleSignatureInspection
|
||||
import com.intellij.openapi.roots.LanguageLevelProjectExtension
|
||||
import com.intellij.pom.java.LanguageLevel
|
||||
import com.intellij.testFramework.LightProjectDescriptor
|
||||
@@ -51,7 +51,7 @@ abstract class JavaLangReflectHandleInvocationTestBase(val languageLevel: Langua
|
||||
override fun setUp() {
|
||||
super.setUp()
|
||||
LanguageLevelProjectExtension.getInstance(project).languageLevel = languageLevel
|
||||
myFixture.enableInspections(JavaLangReflectHandleInvocationInspection())
|
||||
myFixture.enableInspections(JavaLangInvokeHandleSignatureInspection())
|
||||
}
|
||||
|
||||
override fun getProjectDescriptor(): LightProjectDescriptor = descriptor
|
||||
|
||||
Reference in New Issue
Block a user