mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IG: consider lambda's and anonymous/inner classes when determining if in synchronized context
This commit is contained in:
+4
-6
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2010 Bas Leijdekkers
|
||||
* Copyright 2006-2015 Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -25,16 +25,14 @@ public class SynchronizationUtil {
|
||||
|
||||
public static boolean isInSynchronizedContext(PsiElement element) {
|
||||
final PsiElement context =
|
||||
PsiTreeUtil.getParentOfType(element, PsiMethod.class,
|
||||
PsiSynchronizedStatement.class);
|
||||
PsiTreeUtil.getParentOfType(element, PsiMethod.class, PsiSynchronizedStatement.class, PsiClass.class, PsiLambdaExpression.class);
|
||||
if (context instanceof PsiSynchronizedStatement) {
|
||||
return true;
|
||||
}
|
||||
if (context == null) {
|
||||
if (!(context instanceof PsiMethod)) {
|
||||
return false;
|
||||
}
|
||||
final PsiModifierListOwner modifierListOwner =
|
||||
(PsiModifierListOwner)context;
|
||||
final PsiModifierListOwner modifierListOwner = (PsiModifierListOwner)context;
|
||||
return modifierListOwner.hasModifierProperty(PsiModifier.SYNCHRONIZED);
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package com.siyeh.igtest.threading.call_to_native_method_while_locked;
|
||||
|
||||
public class CallToNativeMethodWhileLocked {
|
||||
|
||||
synchronized void a() {
|
||||
Double.<warning descr="Call to native method 'doubleToLongBits()' in a synchronized context">doubleToLongBits</warning>(9.7);
|
||||
Runnable r = () -> {
|
||||
Double.doubleToLongBits(123.4);
|
||||
};
|
||||
new Object() {
|
||||
long l = Double.doubleToLongBits(42.0);
|
||||
};
|
||||
}
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2000-2015 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.threading;
|
||||
|
||||
import com.intellij.codeInspection.InspectionProfileEntry;
|
||||
import com.siyeh.ig.LightInspectionTestCase;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author Bas Leijdekkers
|
||||
*/
|
||||
public class CallToNativeMethodWhileLockedInspectionTest extends LightInspectionTestCase {
|
||||
|
||||
public void testCallToNativeMethodWhileLocked() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected InspectionProfileEntry getInspection() {
|
||||
return new CallToNativeMethodWhileLockedInspection();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user