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

The following examples show how to use com.intellij.openapi.project.Project#putUserData() . 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: XVariablesViewBase.java    From consulo with Apache License 2.0 6 votes vote down vote up
protected void buildTreeAndRestoreState(@Nonnull final XStackFrame stackFrame) {
  XSourcePosition position = stackFrame.getSourcePosition();
  XDebuggerTree tree = getTree();
  tree.setSourcePosition(position);
  createNewRootNode(stackFrame);
  final Project project = tree.getProject();
  project.putUserData(XVariablesView.DEBUG_VARIABLES, new XVariablesView.InlineVariablesInfo());
  project.putUserData(XVariablesView.DEBUG_VARIABLES_TIMESTAMPS, new ObjectLongHashMap<>());
  clearInlays(tree);
  Object newEqualityObject = stackFrame.getEqualityObject();
  if (myFrameEqualityObject != null && newEqualityObject != null && myFrameEqualityObject.equals(newEqualityObject) && myTreeState != null) {
    disposeTreeRestorer();
    myTreeRestorer = myTreeState.restoreState(tree);
  }
  if (position != null && XDebuggerSettingsManager.getInstance().getDataViewSettings().isValueTooltipAutoShowOnSelection()) {
    registerInlineEvaluator(stackFrame, position, project);
  }
}
 
Example 2
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 3
Source File: ShopwareUtil.java    From idea-php-shopware-plugin with MIT License 6 votes vote down vote up
public static Set<String> getPluginsWithFilesystem(@NotNull Project project)
{
    CachedValue<Set<String>> cachedPluginFilesystem = project.getUserData(PLUGIN_FILESYSTEM_KEY);
    if (cachedPluginFilesystem != null && cachedPluginFilesystem.hasUpToDateValue()) {
        return cachedPluginFilesystem.getValue();
    }

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

        Collection<PhpClass> prefixFilesystem = PhpIndex.getInstance(project).getClassesByFQN(ShopwareFQDN.PREFIX_FILESYSTEM);

        // If PrefixFilesystem does not exist, we have not running Shopware 5.5 where the new services are implemented
        if (!prefixFilesystem.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_FILESYSTEM_KEY, cachedValue);

    return cachedValue.getValue();
}
 
Example 4
Source File: GotoActionAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void gotoActionPerformed(@Nonnull AnActionEvent e) {
  Project project = e.getProject();
  Component component = e.getData(PlatformDataKeys.CONTEXT_COMPONENT);
  Editor editor = e.getData(CommonDataKeys.EDITOR);

  FeatureUsageTracker.getInstance().triggerFeatureUsed("navigation.popup.action");
  GotoActionModel model = new GotoActionModel(project, component, editor);
  GotoActionCallback<Object> callback = new GotoActionCallback<Object>() {
    @Override
    public void elementChosen(@Nonnull ChooseByNamePopup popup, @Nonnull Object element) {
      if (project != null) {
        // if the chosen action displays another popup, don't populate it automatically with the text from this popup
        project.putUserData(ChooseByNamePopup.CHOOSE_BY_NAME_POPUP_IN_PROJECT_KEY, null);
      }
      String enteredText = popup.getTrimmedText();
      int modifiers = popup.isClosedByShiftEnter() ? InputEvent.SHIFT_MASK : 0;
      openOptionOrPerformAction(((GotoActionModel.MatchedValue)element).value, enteredText, project, component, modifiers);
    }
  };

  Pair<String, Integer> start = getInitialText(false, e);
  showNavigationPopup(callback, null, createPopup(project, model, start.first, start.second, component, e), false);
}
 
Example 5
Source File: PantsOpenProjectProvider.java    From intellij-pants-plugin with Apache License 2.0 6 votes vote down vote up
private void link(@NotNull VirtualFile projectFile, @NotNull Project project, AddModuleWizard dialog) {
  if (dialog == null) return;

  ProjectBuilder builder = dialog.getBuilder(project);
  if (builder == null) return;

  try {
    ApplicationManager.getApplication().runWriteAction(() -> {
      Optional.ofNullable(dialog.getNewProjectJdk())
        .ifPresent(jdk -> NewProjectUtil.applyJdkToProject(project, jdk));

      URI output = projectDir(projectFile).resolve(".out").toUri();
      Optional.ofNullable(CompilerProjectExtension.getInstance(project))
        .ifPresent(ext -> ext.setCompilerOutputUrl(output.toString()));
    });

    builder.commit(project, null, ModulesProvider.EMPTY_MODULES_PROVIDER);
    project.putUserData(ExternalSystemDataKeys.NEWLY_IMPORTED_PROJECT, Boolean.TRUE);

    project.save();
  }
  finally {
    builder.cleanup();
  }
}
 
Example 6
Source File: CSharpFilePropertyPusher.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@Override
public void afterRootsChanged(@Nonnull Project project)
{
	Set<String> changedModules = project.getUserData(ourChangedModulesKey);
	if(changedModules == null)
	{
		return;
	}

	project.putUserData(ourChangedModulesKey, null);

	if(!changedModules.isEmpty())
	{
		PushedFilePropertiesUpdater.getInstance(project).pushAll(this);
	}
}
 
Example 7
Source File: ResourcePathIndex.java    From idea-php-typo3-plugin with MIT License 6 votes vote down vote up
@NotNull
private synchronized static Collection<String> getAllResourceKeys(@NotNull Project project) {
    CachedValue<Collection<String>> userData = project.getUserData(RESOURCE_KEYS);
    if (userData != null && userData.hasUpToDateValue()) {
        return RESOURCE_KEYS_LOCAL_CACHE.getOrDefault(project, new ArrayList<>());
    }

    CachedValue<Collection<String>> cachedValue = CachedValuesManager.getManager(project).createCachedValue(() -> {
        Collection<String> allKeys = FileBasedIndex.getInstance().getAllKeys(ResourcePathIndex.KEY, project);
        if (RESOURCE_KEYS_LOCAL_CACHE.containsKey(project)) {
            RESOURCE_KEYS_LOCAL_CACHE.replace(project, allKeys);
        } else {
            RESOURCE_KEYS_LOCAL_CACHE.put(project, allKeys);
        }

        return CachedValueProvider.Result.create(new ArrayList<>(), PsiModificationTracker.MODIFICATION_COUNT);
    }, false);
    project.putUserData(RESOURCE_KEYS, cachedValue);

    return RESOURCE_KEYS_LOCAL_CACHE.getOrDefault(project, cachedValue.getValue());
}
 
Example 8
Source File: CSharpFilePropertyPusher.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
private void addChanged(Project project, ModuleExtension<?> newExtension)
{
	Set<String> changedModules = project.getUserData(ourChangedModulesKey);
	if(changedModules == null)
	{
		changedModules = new HashSet<>();
	}

	project.putUserData(ourChangedModulesKey, changedModules);

	changedModules.add(newExtension.getModule().getName());
}
 
Example 9
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 10
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 11
Source File: JSGraphQLLanguageUIProjectService.java    From js-graphql-intellij-plugin with MIT License 5 votes vote down vote up
public JSGraphQLLanguageUIProjectService(@NotNull final Project project) {

        myProject = project;

        final MessageBusConnection messageBusConnection = project.getMessageBus().connect(this);

        // tool window
        myToolWindowManager = new JSGraphQLLanguageToolWindowManager(project, GRAPH_QL_TOOL_WINDOW_NAME, GRAPH_QL_TOOL_WINDOW_NAME, JSGraphQLIcons.UI.GraphQLToolwindow);
        Disposer.register(this, this.myToolWindowManager);

        // listen for editor file tab changes to update the list of current errors
        messageBusConnection.subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, this);

        // add editor headers to already open files since we've only just added the listener for fileOpened()
        final FileEditorManager fileEditorManager = FileEditorManager.getInstance(project);
        for (VirtualFile virtualFile : fileEditorManager.getOpenFiles()) {
            UIUtil.invokeLaterIfNeeded(() -> {
                insertEditorHeaderComponentIfApplicable(fileEditorManager, virtualFile);
            });
        }

        // listen for configuration changes
        messageBusConnection.subscribe(JSGraphQLConfigurationListener.TOPIC, this);

        // finally init the tool window tabs
        initToolWindow();

        // and notify to configure the schema
        project.putUserData(GraphQLParserDefinition.JSGRAPHQL_ACTIVATED, true);
        EditorNotifications.getInstance(project).updateAllNotifications();
    }
 
Example 12
Source File: PantsOpenProjectProvider.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
private Project createProject(VirtualFile file, AddModuleWizard dialog) {
  Project project = PantsUtil.findBuildRoot(file)
    .map(root -> Paths.get(root.getPath()))
    .map(root -> ProjectManagerEx.getInstanceEx().newProject(root, dialog.getProjectName(), new OpenProjectTask()))
    .orElse(null);
  if (project != null) {
    project.putUserData(ExternalSystemDataKeys.NEWLY_IMPORTED_PROJECT, true);
  }
  return project;
}
 
Example 13
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 14
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 15
Source File: ExtensionProviderUtil.java    From idea-php-toolbox with MIT License 5 votes vote down vote up
synchronized public static Collection<JsonConfigFile> getJsonConfigs(final @NotNull Project project, final @NotNull PhpToolboxApplicationService phpToolboxApplicationService) {
    CachedValue<Collection<JsonConfigFile>> cache = project.getUserData(CONFIGS_CACHE);

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

    Collection<JsonConfigFile> jsonConfigFiles = new ArrayList<>(cache.getValue());

    // prevent reindex issues
    if (!DumbService.getInstance(project).isDumb()) {
        CachedValue<Collection<JsonConfigFile>> indexCache = project.getUserData(CONFIGS_CACHE_INDEX);

        if (indexCache == null) {
            indexCache = CachedValuesManager.getManager(project).createCachedValue(() -> {
                Collection<JsonConfigFile> jsonConfigFiles1 = new ArrayList<>();

                for (final PsiFile psiFile : FilenameIndex.getFilesByName(project, ".ide-toolbox.metadata.json", GlobalSearchScope.allScope(project))) {
                    JsonConfigFile cachedValue = CachedValuesManager.getCachedValue(psiFile, () -> new CachedValueProvider.Result<>(
                        JsonParseUtil.getDeserializeConfig(psiFile.getText()),
                        psiFile,
                        psiFile.getVirtualFile()
                    ));

                    if(cachedValue != null) {
                        jsonConfigFiles1.add(cachedValue);
                    }
                }

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

        project.putUserData(CONFIGS_CACHE_INDEX, indexCache);
        jsonConfigFiles.addAll(indexCache.getValue());
    }

    return jsonConfigFiles;
}
 
Example 16
Source File: ExtensionProviderUtil.java    From idea-php-toolbox with MIT License 5 votes vote down vote up
@NotNull
synchronized public static Collection<PhpToolboxProviderInterface> getProviders(final @NotNull Project project) {
    CachedValue<Collection<PhpToolboxProviderInterface>> cache = project.getUserData(PROVIDER_CACHE);

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

        project.putUserData(PROVIDER_CACHE, cache);
    }

    return cache.getValue();
}
 
Example 17
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 18
Source File: AbstractExternalModuleImportProvider.java    From consulo with Apache License 2.0 4 votes vote down vote up
@RequiredReadAction
@Override
public void process(@Nonnull ExternalModuleImportContext<C> context, @Nonnull final Project project, @Nonnull ModifiableModuleModel model, @Nonnull Consumer<Module> newModuleConsumer) {
  project.putUserData(ExternalSystemDataKeys.NEWLY_IMPORTED_PROJECT, Boolean.TRUE);
  final DataNode<ProjectData> externalProjectNode = getExternalProjectNode();
  if (externalProjectNode != null) {
    beforeCommit(externalProjectNode, project);
  }

  StartupManager.getInstance(project).runWhenProjectIsInitialized(new Runnable() {
    @SuppressWarnings("unchecked")
    @Override
    public void run() {
      AbstractExternalSystemSettings systemSettings = ExternalSystemApiUtil.getSettings(project, myExternalSystemId);
      final ExternalProjectSettings projectSettings = getCurrentExternalProjectSettings();
      Set<ExternalProjectSettings> projects = ContainerUtilRt.<ExternalProjectSettings>newHashSet(systemSettings.getLinkedProjectsSettings());
      // add current importing project settings to linked projects settings or replace if similar already exist
      projects.remove(projectSettings);
      projects.add(projectSettings);

      systemSettings.copyFrom(myControl.getSystemSettings());
      systemSettings.setLinkedProjectsSettings(projects);

      if (externalProjectNode != null) {
        ExternalSystemUtil.ensureToolWindowInitialized(project, myExternalSystemId);
        ExternalSystemApiUtil.executeProjectChangeAction(new DisposeAwareProjectChange(project) {
          @RequiredUIAccess
          @Override
          public void execute() {
            ProjectRootManagerEx.getInstanceEx(project).mergeRootsChangesDuring(new Runnable() {
              @Override
              public void run() {
                myProjectDataManager.importData(externalProjectNode.getKey(), Collections.singleton(externalProjectNode), project, true);
                myExternalProjectNode = null;
              }
            });
          }
        });

        final Runnable resolveDependenciesTask = new Runnable() {
          @Override
          public void run() {
            String progressText = ExternalSystemBundle.message("progress.resolve.libraries", myExternalSystemId.getReadableName());
            ProgressManager.getInstance().run(new Task.Backgroundable(project, progressText, false) {
              @Override
              public void run(@Nonnull final ProgressIndicator indicator) {
                if (project.isDisposed()) return;
                ExternalSystemResolveProjectTask task = new ExternalSystemResolveProjectTask(myExternalSystemId, project, projectSettings.getExternalProjectPath(), false);
                task.execute(indicator, ExternalSystemTaskNotificationListener.EP_NAME.getExtensions());
                DataNode<ProjectData> projectWithResolvedLibraries = task.getExternalProject();
                if (projectWithResolvedLibraries == null) {
                  return;
                }

                setupLibraries(projectWithResolvedLibraries, project);
              }
            });
          }
        };
        UIUtil.invokeLaterIfNeeded(resolveDependenciesTask);
      }
    }
  });
}
 
Example 19
Source File: FileTreeModelBuilder.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static void clearCaches(Project project) {
  project.putUserData(FILE_COUNT, null);
}
 
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;
}