Java Code Examples for com.intellij.openapi.project.Project#getUserData()

The following examples show how to use com.intellij.openapi.project.Project#getUserData() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InjectedLanguageManagerImpl.java    From consulo with Apache License 2.0 7 votes vote down vote up
@TestOnly
public static void checkInjectorsAreDisposed(@Nullable Project project) {
  InjectedLanguageManagerImpl cachedManager = project == null ? null : (InjectedLanguageManagerImpl)project.getUserData(INSTANCE_CACHE);
  if (cachedManager == null) return;

  try {
    ClassMapCachingNulls<MultiHostInjector> cached = cachedManager.cachedInjectors;
    if (cached == null) return;
    for (Map.Entry<Class<?>, MultiHostInjector[]> entry : cached.getBackingMap().entrySet()) {
      Class<?> key = entry.getKey();
      if (cachedManager.myInjectorsClone.isEmpty()) return;
      MultiHostInjector[] oldInjectors = cachedManager.myInjectorsClone.get(key);
      for (MultiHostInjector injector : entry.getValue()) {
        if (ArrayUtil.indexOf(oldInjectors, injector) == -1) {
          throw new AssertionError("Injector was not disposed: " + key + " -> " + injector);
        }
      }
    }
  }
  finally {
    cachedManager.myInjectorsClone.clear();
  }
}
 
Example 2
Source File: AttachToProcessActionBase.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static void addToRecent(@Nonnull Project project, @Nonnull AttachToProcessItem item) {
  Map<XAttachHost, LinkedHashSet<RecentItem>> recentItems = project.getUserData(RECENT_ITEMS_KEY);

  if (recentItems == null) {
    project.putUserData(RECENT_ITEMS_KEY, recentItems = new HashMap<>());
  }

  XAttachHost host = item.getHost();

  LinkedHashSet<RecentItem> hostRecentItems = recentItems.get(host);

  if (hostRecentItems == null) {
    recentItems.put(host, new LinkedHashSet<>());
    hostRecentItems = recentItems.get(host);
  }

  final RecentItem newRecentItem = new RecentItem(host, item);

  hostRecentItems.remove(newRecentItem);

  hostRecentItems.add(newRecentItem);

  while (hostRecentItems.size() > 4) {
    hostRecentItems.remove(hostRecentItems.iterator().next());
  }
}
 
Example 3
Source File: ShopwareUtil.java    From idea-php-shopware-plugin with MIT License 6 votes vote down vote up
public static Set<String> getPluginsWithLogger(@NotNull Project project)
{
    CachedValue<Set<String>> cachedPluginLogger = project.getUserData(PLUGIN_LOGGER_KEY);
    if (cachedPluginLogger != null && cachedPluginLogger.hasUpToDateValue()) {
        return cachedPluginLogger.getValue();
    }

    CachedValue<Set<String>> cachedValue = CachedValuesManager.getManager(project).createCachedValue(() -> {
        Set<String> plugins = new HashSet<>();

        Collection<PhpClass> loggerCompilerPass = PhpIndex.getInstance(project).getClassesByFQN(ShopwareFQDN.PLUGIN_LOGGER_COMPILERPASS);

        // Feature detection is CompilerPass available
        if (!loggerCompilerPass.isEmpty()) {
            for(PhpClass phpClass: PhpIndex.getInstance(project).getAllSubclasses(ShopwareFQDN.PLUGIN_BOOTSTRAP)) {
                plugins.add(phpClass.getName());
            }
        }

        return CachedValueProvider.Result.create(plugins, PsiModificationTracker.MODIFICATION_COUNT);
    }, false);

    project.putUserData(PLUGIN_LOGGER_KEY, cachedValue);

    return cachedValue.getValue();
}
 
Example 4
Source File: ChooseTargetContributor.java    From buck with Apache License 2.0 6 votes vote down vote up
CurrentInputText(Project project) {
  ChooseByNamePopup chooseByNamePopup =
      project.getUserData(ChooseByNamePopup.CHOOSE_BY_NAME_POPUP_IN_PROJECT_KEY);
  if (chooseByNamePopup == null) {
    buildDir = null;
    hasBuildRule = false;
    return;
  }
  String currentText =
      chooseByNamePopup
          .getEnteredText()
          // Remove the begining //
          .replaceFirst("^/*", "");

  // check if we have as input a proper target
  int targetSeparatorIndex = currentText.lastIndexOf(TARGET_NAME_SEPARATOR);
  if (targetSeparatorIndex != -1) {
    hasBuildRule = true;
    buildDir = currentText.substring(0, targetSeparatorIndex);
  } else {
    hasBuildRule = false;
    buildDir = currentText;
  }
}
 
Example 5
Source File: SetShortcutAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void actionPerformed(@Nonnull AnActionEvent e) {
  Project project = e.getProject();
  JBPopup seDialog = project == null ? null : project.getUserData(SearchEverywhereManager.SEARCH_EVERYWHERE_POPUP);
  if (seDialog == null) {
    return;
  }

  KeymapManager km = KeymapManager.getInstance();
  Keymap activeKeymap = km != null ? km.getActiveKeymap() : null;
  if (activeKeymap == null) {
    return;
  }

  AnAction action = e.getData(SELECTED_ACTION);
  Component component = e.getData(PlatformDataKeys.CONTEXT_COMPONENT);
  if (action == null || component == null) {
    return;
  }

  seDialog.cancel();
  String id = ActionManager.getInstance().getId(action);
  KeymapPanel.addKeyboardShortcut(id, ActionShortcutRestrictions.getInstance().getForActionId(id), activeKeymap, component);
}
 
Example 6
Source File: ChooseByNamePopup.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static ChooseByNamePopup createPopup(final Project project,
                                            @Nonnull final ChooseByNameModel model,
                                            @Nonnull ChooseByNameItemProvider provider,
                                            @Nullable final String predefinedText,
                                            boolean mayRequestOpenInCurrentWindow,
                                            final int initialIndex) {
  final ChooseByNamePopup oldPopup = project == null ? null : project.getUserData(CHOOSE_BY_NAME_POPUP_IN_PROJECT_KEY);
  if (oldPopup != null) {
    oldPopup.close(false);
  }
  ChooseByNamePopup newPopup = new ChooseByNamePopup(project, model, provider, oldPopup, predefinedText, mayRequestOpenInCurrentWindow, initialIndex);

  if (project != null) {
    project.putUserData(CHOOSE_BY_NAME_POPUP_IN_PROJECT_KEY, newPopup);
  }
  return newPopup;
}
 
Example 7
Source File: PlatformTestCase.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static String getCreationPlace(@Nonnull Project project) {
  String place = project.getUserData(CREATION_PLACE);
  Object base;
  try {
    base = project.isDisposed() ? "" : project.getBaseDir();
  }
  catch (Exception e) {
    base = " (" + e + " while getting base dir)";
  }
  return project.toString() + (place != null ? place : "") + base;
}
 
Example 8
Source File: ExtensionProviderUtil.java    From idea-php-toolbox with MIT License 5 votes vote down vote up
@NotNull
synchronized public static Collection<JsonRegistrar> getRegistrar(final @NotNull Project project, final @NotNull PhpToolboxApplicationService phpToolboxApplicationService) {
    CachedValue<Collection<JsonRegistrar>> cache = project.getUserData(REGISTRAR_CACHE);

    if(cache == null) {
        cache = CachedValuesManager.getManager(project).createCachedValue(() -> CachedValueProvider.Result.create(getRegistrarInner(project, phpToolboxApplicationService), PsiModificationTracker.MODIFICATION_COUNT), false);

        project.putUserData(REGISTRAR_CACHE, cache);
    }

    return cache.getValue();
}
 
Example 9
Source File: RunAnythingUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static Collection<Pair<String, String>> getOrCreateWrappedCommands(@Nonnull Project project) {
  Collection<Pair<String, String>> list = project.getUserData(RUN_ANYTHING_WRAPPED_COMMANDS);
  if (list == null) {
    list = new ArrayList<>();
    project.putUserData(RUN_ANYTHING_WRAPPED_COMMANDS, list);
  }
  return list;
}
 
Example 10
Source File: HaxeProjectModel.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
public static HaxeProjectModel fromProject(Project project) {
  HaxeProjectModel model = project.getUserData(HAXE_PROJECT_MODEL_KEY);
  if (model == null) {
    model = new HaxeProjectModel(project);
    project.putUserData(HAXE_PROJECT_MODEL_KEY, model);
  }

  return model;
}
 
Example 11
Source File: ProjectActions.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static void registerAction(@NotNull Project project, @NotNull String id, @NotNull AnAction action) {
  Map<String, AnAction> actions = project.getUserData(PROJECT_ACTIONS_KEY);
  if (actions == null) {
    actions = new HashMap<>();
    project.putUserData(PROJECT_ACTIONS_KEY, actions);
  }
  actions.put(id, action);
}
 
Example 12
Source File: ImagesProjectNode.java    From intellij-sdk-docs with Apache License 2.0 5 votes vote down vote up
@NotNull
private Set<VirtualFile> getImagesFiles(Project project) {
  Set<VirtualFile> files = project.getUserData(IMAGES_PROJECT_DIRS);
  if (files == null) {
    files = new HashSet<>();
    project.putUserData(IMAGES_PROJECT_DIRS, files);
  }
  return files;
}
 
Example 13
Source File: InferredTypesService.java    From reasonml-idea-plugin with MIT License 5 votes vote down vote up
@NotNull
private static CodeLensView.CodeLensInfo getCodeLensData(@NotNull Project project) {
    CodeLensView.CodeLensInfo userData = project.getUserData(CodeLensView.CODE_LENS);
    if (userData == null) {
        userData = new CodeLensView.CodeLensInfo();
        project.putUserData(CodeLensView.CODE_LENS, userData);
    }
    return userData;
}
 
Example 14
Source File: TCAUtil.java    From idea-php-typo3-plugin with MIT License 5 votes vote down vote up
@NotNull
private synchronized static Set<String> getAvailableRenderTypes(Project project) {
    CachedValue<Set<String>> cachedRenderTypes = project.getUserData(RENDER_TYPES_KEY);
    if (cachedRenderTypes != null && cachedRenderTypes.hasUpToDateValue()) {
        return cachedRenderTypes.getValue();
    }

    CachedValue<Set<String>> cachedValue = CachedValuesManager.getManager(project).createCachedValue(() -> {
        Set<PsiElement> elementsFromExtLocalConf = findAvailableRenderTypes(project);

        // add static list of render types
        Set<String> renderTypes = new HashSet<>(Arrays.asList(TCA_V8_CORE_RENDER_TYPES));

        // add dynamic list of render types from nodeRegistry
        for (PsiElement el : elementsFromExtLocalConf) {
            if (el instanceof StringLiteralExpression) {
                renderTypes.add(((StringLiteralExpression) el).getContents());
            }
        }

        return CachedValueProvider.Result.create(renderTypes, PsiModificationTracker.MODIFICATION_COUNT);
    }, false);

    project.putUserData(RENDER_TYPES_KEY, cachedValue);

    return cachedValue.getValue();
}
 
Example 15
Source File: VfsIconUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static boolean wasEverInitialized(@Nonnull Project project) {
  Boolean was = project.getUserData(PROJECT_WAS_EVER_INITIALIZED);
  if (was == null) {
    if (project.isInitialized()) {
      was = Boolean.valueOf(true);
      project.putUserData(PROJECT_WAS_EVER_INITIALIZED, was);
    }
    else {
      was = Boolean.valueOf(false);
    }
  }

  return was.booleanValue();
}
 
Example 16
Source File: AttachToProcessActionBase.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
public static List<RecentItem> getRecentItems(@Nonnull XAttachHost host, @Nonnull Project project) {
  Map<XAttachHost, LinkedHashSet<RecentItem>> recentItems = project.getUserData(RECENT_ITEMS_KEY);
  return recentItems == null || !recentItems.containsKey(host) ? Collections.emptyList() : Collections.unmodifiableList(new ArrayList<>(recentItems.get(host)));
}
 
Example 17
Source File: ProjectActions.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Nullable
public static AnAction getAction(@NotNull Project project, @NotNull String id) {
  final Map<String, AnAction> actions = project.getUserData(PROJECT_ACTIONS_KEY);
  return actions == null ? null : actions.get(id);
}
 
Example 18
Source File: AttachDebuggerAction.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void startCommand(@NotNull Project project, @NotNull FlutterSdk sdk, @Nullable PubRoot root, @NotNull DataContext context) {
  // NOTE: When making changes here, consider making similar changes to RunFlutterAction.
  FlutterInitializer.sendAnalyticsAction(this);

  RunConfiguration configuration = findRunConfig(project);
  if (configuration == null) {
    RunnerAndConfigurationSettings settings = RunManagerEx.getInstanceEx(project).getSelectedConfiguration();
    if (settings == null) {
      showSelectConfigDialog();
      return;
    }
    configuration = settings.getConfiguration();
    if (!(configuration instanceof SdkRunConfig)) {
      if (project.isDefault() || !FlutterSdkUtil.hasFlutterModules(project)) {
        return;
      }
      showSelectConfigDialog();
      return;
    }
  }

  SdkAttachConfig sdkRunConfig = new SdkAttachConfig((SdkRunConfig)configuration);
  SdkFields fields = sdkRunConfig.getFields();
  String additionalArgs = fields.getAdditionalArgs();

  String flavorArg = null;
  if (fields.getBuildFlavor() != null) {
    flavorArg = "--flavor=" + fields.getBuildFlavor();
  }

  List<String> args = new ArrayList<>();
  if (additionalArgs != null) {
    args.add(additionalArgs);
  }
  if (flavorArg != null) {
    args.add(flavorArg);
  }
  if (!args.isEmpty()) {
    fields.setAdditionalArgs(Joiner.on(" ").join(args));
  }

  Executor executor = RunFlutterAction.getExecutor(ToolWindowId.DEBUG);
  if (executor == null) {
    return;
  }

  ExecutionEnvironmentBuilder builder = ExecutionEnvironmentBuilder.create(executor, sdkRunConfig);

  ExecutionEnvironment env = builder.activeTarget().dataContext(context).build();
  FlutterLaunchMode.addToEnvironment(env, FlutterLaunchMode.DEBUG);

  if (project.getUserData(ATTACH_IS_ACTIVE) == null) {
    project.putUserData(ATTACH_IS_ACTIVE, ThreeState.fromBoolean(false));
    onAttachTermination(project, (p) -> p.putUserData(ATTACH_IS_ACTIVE, null));
  }
  ProgramRunnerUtil.executeConfiguration(env, false, true);
}
 
Example 19
Source File: LightPlatformTestCase.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static boolean isLight(Project project) {
  String creationPlace = project.getUserData(CREATION_PLACE);
  return creationPlace != null && StringUtil.startsWith(creationPlace, LIGHT_PROJECT_MARK);
}
 
Example 20
Source File: LightShaderDef.java    From consulo-unity3d with Apache License 2.0 4 votes vote down vote up
@Nonnull
public static Map<String, ShaderDef> getDefaultShaders(@Nonnull Project project)
{
	Map<String, ShaderDef> data = project.getUserData(ourKey);
	if(data != null)
	{
		return data;
	}

	data = new HashMap<>();

	String[] keys = new String[]{
			"Vertex-Lit",
			"Diffuse",
			"Specular",
			"Bumped Diffuse",
			"Bumped Specular",
			"Parallax Diffuse",
			"Parallax Bumped Specular",
			"Decal",
			"Diffuse",
			"Detail",
			"Transparent Vertex-Lit",
			"Transparent Diffuse",
			"Transparent Specular",
			"Transparent Bumped Diffuse",
			"Transparent Bumped Specular",
			"Transparent Parallax Diffuse",
			"Transparent Parallax Specular",
			"Transparent Cutout Vertex-Lit",
			"Transparent Cutout Diffuse",
			"Transparent Cutout Specular",
			"Transparent Cutout Bumped Diffuse",
			"Transparent Cutout Bumped Specular",
			"Self-Illuminated Vertex-Lit",
			"Self-Illuminated Diffuse",
			"Self-Illuminated Specular",
			"Self-Illuminated Normal mapped Diffuse",
			"Self-Illuminated Normal mapped Specular",
			"Self-Illuminated Parallax Diffuse",
			"Self-Illuminated Parallax Specular",
			"Reflective Vertex-Lit",
			"Reflective Diffuse",
			"Reflective Specular",
			"Reflective Bumped Diffuse",
			"Reflective Bumped Specular",
			"Reflective Parallax Diffuse",
			"Reflective Parallax Specular",
			"Reflective Normal Mapped Unlit",
			"Reflective Normal mapped Vertex-lit",
	};

	for(String key : keys)
	{
		String quoted = StringUtil.QUOTER.fun(key);
		data.put(quoted, new LightShaderDef(project, quoted));
	}

	project.putUserData(ourKey, data);

	return data;
}