mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
+9
-14
@@ -16,20 +16,15 @@
|
||||
package com.intellij.codeInspection.concurrencyAnnotations;
|
||||
|
||||
import com.intellij.codeInsight.AnnotationUtil;
|
||||
import com.intellij.codeInsight.ConcurrencyAnnotationsManager;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.javadoc.PsiDocComment;
|
||||
import com.intellij.psi.javadoc.PsiDocTag;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
class JCiPUtil {
|
||||
@NonNls
|
||||
private static final String IMMUTABLE = "net.jcip.annotations.Immutable";
|
||||
@NonNls
|
||||
private static final String GUARDED_BY = "net.jcip.annotations.GuardedBy";
|
||||
|
||||
static boolean isJCiPAnnotation(String ref) {
|
||||
return "Immutable".equals(ref) || "GuardedBy".equals(ref) || "ThreadSafe".equals(ref) || "NotThreadSafe".equals(ref);
|
||||
}
|
||||
@@ -37,8 +32,8 @@ class JCiPUtil {
|
||||
private JCiPUtil() {
|
||||
}
|
||||
|
||||
public static boolean isImmutable(PsiClass aClass) {
|
||||
final PsiAnnotation annotation = AnnotationUtil.findAnnotation(aClass, IMMUTABLE);
|
||||
public static boolean isImmutable(@NotNull PsiClass aClass) {
|
||||
final PsiAnnotation annotation = AnnotationUtil.findAnnotation(aClass, ConcurrencyAnnotationsManager.getInstance(aClass.getProject()).getImmutableAnnotations());
|
||||
if (annotation != null) {
|
||||
return true;
|
||||
}
|
||||
@@ -47,8 +42,8 @@ class JCiPUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static String findGuardForMember(PsiMember member) {
|
||||
final PsiAnnotation annotation = AnnotationUtil.findAnnotation(member, GUARDED_BY);
|
||||
static String findGuardForMember(@NotNull PsiMember member) {
|
||||
final PsiAnnotation annotation = AnnotationUtil.findAnnotation(member, ConcurrencyAnnotationsManager.getInstance(member.getProject()).getGuardedByAnnotations());
|
||||
if (annotation != null) {
|
||||
return getGuardValue(annotation);
|
||||
}
|
||||
@@ -63,9 +58,9 @@ class JCiPUtil {
|
||||
return visitor.getGuardString();
|
||||
}
|
||||
|
||||
static boolean isGuardedBy(PsiMember member, String guard) {
|
||||
static boolean isGuardedBy(@NotNull PsiMember member, String guard) {
|
||||
|
||||
final PsiAnnotation annotation = AnnotationUtil.findAnnotation(member, GUARDED_BY);
|
||||
final PsiAnnotation annotation = AnnotationUtil.findAnnotation(member, ConcurrencyAnnotationsManager.getInstance(member.getProject()).getGuardedByAnnotations());
|
||||
if (annotation != null) {
|
||||
final PsiAnnotationParameterList parameters = annotation.getParameterList();
|
||||
final PsiNameValuePair[] pairs = parameters.getAttributes();
|
||||
@@ -87,8 +82,8 @@ class JCiPUtil {
|
||||
return isGuardedBy(member, field.getName());
|
||||
}
|
||||
|
||||
static boolean isGuardedByAnnotation(PsiAnnotation annotation) {
|
||||
return GUARDED_BY.equals(annotation.getQualifiedName());
|
||||
static boolean isGuardedByAnnotation(@NotNull PsiAnnotation annotation) {
|
||||
return ConcurrencyAnnotationsManager.getInstance(annotation.getProject()).getGuardedByAnnotations().contains(annotation.getQualifiedName());
|
||||
}
|
||||
|
||||
static boolean isGuardedByTag(PsiDocTag tag) {
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* 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.intellij.codeInsight;
|
||||
|
||||
import com.intellij.openapi.components.ServiceManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ConcurrencyAnnotationsManager {
|
||||
private static final String[] FRAMEWORKS = {"net.jcip.annotations", "javax.annotation.concurrent", "org.apache.http.annotation"};
|
||||
|
||||
private static final String IMMUTABLE = "Immutable";
|
||||
private static final String GUARDED_BY = "GuardedBy";
|
||||
private static final String THREAD_SAFE = "ThreadSafe";
|
||||
private static final String NOT_THREAD_SAFE = "NotThreadSafe";
|
||||
|
||||
private List<String> myImmutableList = new ArrayList<String>();
|
||||
private List<String> myGuardedByList = new ArrayList<String>();
|
||||
private List<String> myThreadSafeList = new ArrayList<String>();
|
||||
private List<String> myNotThreadSafeList = new ArrayList<String>();
|
||||
|
||||
public ConcurrencyAnnotationsManager() {
|
||||
fillDefaults(myImmutableList, IMMUTABLE);
|
||||
fillDefaults(myGuardedByList, GUARDED_BY);
|
||||
fillDefaults(myThreadSafeList, THREAD_SAFE);
|
||||
fillDefaults(myNotThreadSafeList, NOT_THREAD_SAFE);
|
||||
}
|
||||
|
||||
private static void fillDefaults(List<String> list, final String annoName) {
|
||||
list.addAll(ContainerUtil.map(FRAMEWORKS, new Function<String, String>() {
|
||||
@Override
|
||||
public String fun(String framework) {
|
||||
return framework + "." + annoName;
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
public static ConcurrencyAnnotationsManager getInstance(Project project) {
|
||||
return ServiceManager.getService(project, ConcurrencyAnnotationsManager.class);
|
||||
}
|
||||
|
||||
public List<String> getImmutableAnnotations() {
|
||||
return myImmutableList;
|
||||
}
|
||||
|
||||
public List<String> getGuardedByAnnotations() {
|
||||
return myGuardedByList;
|
||||
}
|
||||
|
||||
public List<String> getThreadSafeList() {
|
||||
return myThreadSafeList;
|
||||
}
|
||||
|
||||
public List<String> getNotThreadSafeList() {
|
||||
return myNotThreadSafeList;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import javax.annotation.concurrent.GuardedBy;
|
||||
|
||||
import java.lang.String;
|
||||
|
||||
class A {
|
||||
|
||||
@GuardedBy("itself")
|
||||
private String _foo;
|
||||
|
||||
public String getFoo() {
|
||||
synchronized (_foo) {
|
||||
return _foo;
|
||||
}
|
||||
}
|
||||
|
||||
public void setFoo(String foo) {
|
||||
<warning descr="Access to field '_foo' outside of declared guards">_foo</warning> = foo;
|
||||
}
|
||||
}
|
||||
+15
-7
@@ -18,21 +18,29 @@ package com.intellij.codeInspection;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.codeInspection.concurrencyAnnotations.FieldAccessNotGuardedInspection;
|
||||
import com.intellij.openapi.application.PluginPathManager;
|
||||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class FieldAccessedNotGuardedInspectionTest extends LightCodeInsightFixtureTestCase {
|
||||
public void testItself() throws Exception {
|
||||
myFixture.addClass("package net.jcip.annotations;\n" +
|
||||
"@java.lang.annotation.Target({java.lang.annotation.ElementType.FIELD, java.lang.annotation.ElementType.METHOD})\n" +
|
||||
"@java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.RUNTIME)\n" +
|
||||
"public @interface GuardedBy {\n" +
|
||||
" java.lang.String value();\n" +
|
||||
"}");
|
||||
myFixture.addClass("package net.jcip.annotations;\n" + getGuardedByAnnotationText());
|
||||
myFixture.testHighlighting(true, false, false, getTestName(true) + ".java");
|
||||
}
|
||||
|
||||
public void testJavax_itself() throws Exception {
|
||||
myFixture.addClass("package javax.annotation.concurrent;\n" + getGuardedByAnnotationText());
|
||||
myFixture.testHighlighting(true, false, false, getTestName(true) + ".java");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String getGuardedByAnnotationText() {
|
||||
return "@java.lang.annotation.Target({java.lang.annotation.ElementType.FIELD, java.lang.annotation.ElementType.METHOD})\n" +
|
||||
"@java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.RUNTIME)\n" +
|
||||
"public @interface GuardedBy {\n" +
|
||||
" java.lang.String value();\n" +
|
||||
"}";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
|
||||
@@ -538,6 +538,9 @@
|
||||
<projectService serviceInterface="com.intellij.codeInsight.NullableNotNullManager"
|
||||
serviceImplementation="com.intellij.codeInsight.NullableNotNullManagerImpl"/>
|
||||
|
||||
<projectService serviceInterface="com.intellij.codeInsight.ConcurrencyAnnotationsManager"
|
||||
serviceImplementation="com.intellij.codeInsight.ConcurrencyAnnotationsManager"/>
|
||||
|
||||
<projectService serviceInterface="com.intellij.psi.search.PsiShortNamesCache"
|
||||
serviceImplementation="com.intellij.psi.impl.CompositeShortNamesCache"/>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user