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

The following examples show how to use com.intellij.openapi.project.Project#getUserData() . These examples are extracted from open source projects. 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
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 2
Source Project: consulo   File: ChooseByNamePopup.java    License: 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 3
@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 4
Source Project: consulo   File: SetShortcutAction.java    License: 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 5
Source Project: buck   File: ChooseTargetContributor.java    License: 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 6
Source Project: idea-php-shopware-plugin   File: ShopwareUtil.java    License: 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 7
@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 8
Source Project: consulo   File: VfsIconUtil.java    License: 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 9
Source Project: idea-php-typo3-plugin   File: TCAUtil.java    License: 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 10
Source Project: consulo   File: PlatformTestCase.java    License: 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 11
@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 12
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 13
Source Project: intellij-haxe   File: HaxeProjectModel.java    License: 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 14
Source Project: consulo   File: RunAnythingUtil.java    License: 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 15
Source Project: idea-php-toolbox   File: ExtensionProviderUtil.java    License: 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 16
Source Project: consulo   File: LightPlatformTestCase.java    License: 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 17
@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 18
@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 19
@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 20
Source Project: consulo-unity3d   File: LightShaderDef.java    License: 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;
}