// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.codeInsight;

import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.project.Project;
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",
    "com.android.annotations.concurrency",
    "androidx.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 final List<String> myImmutableList = new ArrayList<>();
  private final List<String> myGuardedByList = new ArrayList<>();
  private final List<String> myThreadSafeList = new ArrayList<>();
  private final List<String> myNotThreadSafeList = new ArrayList<>();

  public ConcurrencyAnnotationsManager() {
    fillDefaults(myImmutableList, IMMUTABLE);
    fillDefaults(myGuardedByList, GUARDED_BY);
    fillDefaults(myThreadSafeList, THREAD_SAFE);
    fillDefaults(myNotThreadSafeList, NOT_THREAD_SAFE);

    myImmutableList.add("com.google.auto.value.AutoValue");
    myImmutableList.add("com.google.errorprone.annotations.Immutable");
    myGuardedByList.add("com.google.errorprone.annotations.concurrent.GuardedBy");
  }

  private static void fillDefaults(List<? super String> list, final String annoName) {
    list.addAll(ContainerUtil.map(FRAMEWORKS, framework -> 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;
  }
}

@@ -611,40 +611,132 @@
 ,%0A  
-  %22androidx.annotation%22,%0A  %7D;%0A  
+%7D;%0A%0A  private static final String%5B%5D ANDROID_FRAMEWORKS = %7B%0A    %22androidx.annotation%22,%0A    %22android.support.annotation%22%0A  %7D;%0A
 %0A  p
@@ -1479,16 +1479,179 @@
 SAFE);%0A%0A
+    for (String framework: ANDROID_FRAMEWORKS) %7B%0A      myGuardedByList.add(framework + %22.GuardedBy%22);%0A      myThreadSafeList.add(framework + %22.AnyThread%22);%0A    %7D%0A%0A
     myIm

Support android.support.annotation.{GuardedBy,AnyThread} (IDEA-240073)