Java Code Examples for com.intellij.psi.util.CachedValuesManager#getCachedValue()

The following examples show how to use com.intellij.psi.util.CachedValuesManager#getCachedValue() . 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: TestContextRunConfigurationProducer.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Nullable
private RunConfigurationContext findTestContext(ConfigurationContext context) {
  if (!SmRunnerUtils.getSelectedSmRunnerTreeElements(context).isEmpty()) {
    // handled by a different producer
    return null;
  }
  ContextWrapper wrapper = new ContextWrapper(context);
  PsiElement psi = context.getPsiLocation();
  return psi == null
      ? null
      : CachedValuesManager.getCachedValue(
          psi,
          cacheKey,
          () ->
              CachedValueProvider.Result.create(
                  doFindTestContext(wrapper.context),
                  PsiModificationTracker.MODIFICATION_COUNT,
                  BlazeSyncModificationTracker.getInstance(wrapper.context.getProject())));
}
 
Example 2
Source File: BinaryContextRunConfigurationProducer.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Nullable
private BinaryRunContext findRunContext(ConfigurationContext context) {
  if (!SmRunnerUtils.getSelectedSmRunnerTreeElements(context).isEmpty()) {
    // not a binary run context
    return null;
  }
  ContextWrapper wrapper = new ContextWrapper(context);
  PsiElement psi = context.getPsiLocation();
  return psi == null
      ? null
      : CachedValuesManager.getCachedValue(
          psi,
          () ->
              CachedValueProvider.Result.create(
                  doFindRunContext(wrapper.context),
                  PsiModificationTracker.MODIFICATION_COUNT,
                  BlazeSyncModificationTracker.getInstance(wrapper.context.getProject())));
}
 
Example 3
Source File: VirtualFileTestContextProvider.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public RunConfigurationContext getTestContext(ConfigurationContext context) {
  PsiElement psi = context.getPsiLocation();
  if (!(psi instanceof PsiFileSystemItem) || !(psi instanceof FakePsiElement)) {
    return null;
  }
  VirtualFile vf = ((PsiFileSystemItem) psi).getVirtualFile();
  if (vf == null) {
    return null;
  }
  WorkspacePath path = getWorkspacePath(context.getProject(), vf);
  if (path == null) {
    return null;
  }
  return CachedValuesManager.getCachedValue(
      psi,
      () ->
          CachedValueProvider.Result.create(
              doFindTestContext(context, vf, psi, path),
              PsiModificationTracker.MODIFICATION_COUNT,
              BlazeSyncModificationTracker.getInstance(context.getProject())));
}
 
Example 4
Source File: BlazeSourceJarNavigationPolicy.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public PsiFile getFileNavigationElement(ClsFileImpl file) {
  if (!enabled.getValue()) {
    return null;
  }
  return CachedValuesManager.getCachedValue(
      file,
      () -> {
        Result<PsiFile> result = getPsiFile(file);
        if (result == null) {
          result = notFound(file);
        }
        return result;
      });
}
 
Example 5
Source File: ProducerUtils.java    From intellij with Apache License 2.0 6 votes vote down vote up
/**
 * Based on {@link JUnitUtil#isTestClass}. We don't use that directly because it returns true for
 * all inner classes of a test class, regardless of whether they're also test classes.
 */
public static boolean isTestClass(PsiClass psiClass) {
  if (psiClass.getQualifiedName() == null) {
    return false;
  }
  if (JUnitUtil.isJUnit5(psiClass) && JUnitUtil.isJUnit5TestClass(psiClass, true)) {
    return true;
  }
  if (!PsiClassUtil.isRunnableClass(psiClass, true, true)) {
    return false;
  }
  if (isJUnit4Class(psiClass)) {
    return true;
  }
  if (isTestCaseInheritor(psiClass)) {
    return true;
  }
  return CachedValuesManager.getCachedValue(
      psiClass,
      () ->
          CachedValueProvider.Result.create(
              hasTestOrSuiteMethods(psiClass),
              PsiModificationTracker.JAVA_STRUCTURE_MODIFICATION_COUNT));
}
 
Example 6
Source File: HaxeHierarchyUtils.java    From intellij-haxe with Apache License 2.0 6 votes vote down vote up
/**
 * Retrieve the list of classes implemented in the given File.
 *
 * @param psiRoot - File to search.
 * @return A List of found classes, or an empty array if none.
 */
@NotNull
public static List<HaxeClass> getClassList(@NotNull HaxeFile psiRoot) {
  CachedValuesManager manager = CachedValuesManager.getManager(psiRoot.getProject());
  ArrayList<HaxeClass> classList = manager.getCachedValue(psiRoot, () -> {
    ArrayList<HaxeClass> classes = new ArrayList<>();
    for (PsiElement child : psiRoot.getChildren()) {
      if (child instanceof HaxeClass) {
        classes.add((HaxeClass)child);
      }
    }
    return new CachedValueProvider.Result<>(classes, psiRoot);
  });

  return classList;
}
 
Example 7
Source File: CSharpModifierListImplUtil.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@Nonnull
@RequiredReadAction
public static EnumSet<CSharpModifier> getModifiersCached(@Nonnull CSharpModifierList modifierList)
{
	if(!modifierList.isValid())
	{
		return emptySet;
	}

	return CachedValuesManager.getCachedValue(modifierList, () ->
	{
		Set<CSharpModifier> modifiers = new THashSet<>();
		for(CSharpModifier modifier : CSharpModifier.values())
		{
			if(hasModifier(modifierList, modifier))
			{
				modifiers.add(modifier);
			}
		}
		return CachedValueProvider.Result.create(modifiers.isEmpty() ? emptySet : EnumSet.copyOf(modifiers), PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT);
	});
}
 
Example 8
Source File: BaseMethodBodyLazyElementType.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static Set<String> collectVariableFor(@Nonnull PsiElement element)
{
	return CachedValuesManager.getCachedValue(element, () -> {
		PsiFile psiFile = element.getContainingFile();
		Set<String> defines = CSharpFileStubElementType.getStableDefines(psiFile);
		CSharpPreprocessorVisitor visitor = new CSharpPreprocessorVisitor(defines, element.getStartOffsetInParent());
		psiFile.accept(visitor);
		return CachedValueProvider.Result.create(visitor.getVariables(), element);
	}) ;
}
 
Example 9
Source File: PsiErrorElementUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static boolean hasErrors(@Nonnull final PsiFile psiFile) {
  CachedValuesManager cachedValuesManager = CachedValuesManager.getManager(psiFile.getProject());
  return cachedValuesManager.getCachedValue(psiFile, CONTAINS_ERROR_ELEMENT, () -> {
    boolean error = hasErrorElements(psiFile);
    return CachedValueProvider.Result.create(error, psiFile);
  }, false);
}
 
Example 10
Source File: CSharpCompositeTypeDeclaration.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@RequiredReadAction
@Nullable
public static CSharpCompositeTypeDeclaration findCompositeType(@Nonnull CSharpTypeDeclaration parent)
{
	Object cachedValue = CachedValuesManager.getCachedValue(parent, () -> CachedValueProvider.Result.create(findCompositeTypeImpl(parent), PsiModificationTracker
			.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT));
	return cachedValue == ObjectUtil.NULL ? null : (CSharpCompositeTypeDeclaration) cachedValue;
}
 
Example 11
Source File: CSharpFileImpl.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Override
@Nonnull
@RequiredReadAction
public CSharpUsingListChild[] getUsingStatements()
{
	return CachedValuesManager.getCachedValue(this, () -> CachedValueProvider.Result.create(getUsingStatementsInner(), PsiModificationTracker.MODIFICATION_COUNT)) ;
}
 
Example 12
Source File: CSharpGenericParameterImpl.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@RequiredReadAction
@Nonnull
@Override
public DotNetTypeRef[] getExtendTypeRefs()
{
	return CachedValuesManager.getCachedValue(this, () -> CachedValueProvider.Result.create(CSharpGenericConstraintUtil.getExtendTypes(CSharpGenericParameterImpl.this), PsiModificationTracker
			.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT));
}
 
Example 13
Source File: TemplateManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static OffsetsInFile insertDummyIdentifierWithCache(PsiFile file, int startOffset, int endOffset, String replacement) {
  ProperTextRange editRange = ProperTextRange.create(startOffset, endOffset);
  assertRangeWithinDocument(editRange, file.getViewProvider().getDocument());

  ConcurrentMap<Pair<ProperTextRange, String>, OffsetsInFile> map = CachedValuesManager.getCachedValue(file, () -> CachedValueProvider.Result
          .create(ConcurrentFactoryMap.createMap(key -> copyWithDummyIdentifier(new OffsetsInFile(file), key.first.getStartOffset(), key.first.getEndOffset(), key.second)), file,
                  file.getViewProvider().getDocument()));
  return map.get(Pair.create(editRange, replacement));
}
 
Example 14
Source File: CSharpReferenceExpressionImplUtil.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Nonnull
@RequiredReadAction
public static ResolveResult[] tryResolveFromQualifier(@Nonnull CSharpReferenceExpressionEx expression, @Nonnull PsiElement qualifierElement)
{
	if(!expression.isValid())
	{
		return ResolveResult.EMPTY_ARRAY;
	}

	ParamatizeValue paramatizeValue = CachedValuesManager.getCachedValue(expression, () -> CachedValueProvider.Result.create(new ParamatizeValue(), PsiModificationTracker.MODIFICATION_COUNT));

	return paramatizeValue.get(qualifierElement, element -> tryResolveFromQualifierImpl(expression, element));
}
 
Example 15
Source File: ViewCollector.java    From idea-php-laravel-plugin with MIT License 5 votes vote down vote up
private static void collectIdeJsonBladePaths(@NotNull Project project, @NotNull Collection<TemplatePath> templatePaths) {
    for (PsiFile psiFile : FilenameIndex.getFilesByName(project, "ide-blade.json", GlobalSearchScope.allScope(project))) {
        Collection<TemplatePath> cachedValue = CachedValuesManager.getCachedValue(psiFile, new MyJsonCachedValueProvider(psiFile));
        if(cachedValue != null) {
            templatePaths.addAll(cachedValue);
        }
    }
}
 
Example 16
Source File: BlazeJavaScriptTestRunLineMarkerContributor.java    From intellij with Apache License 2.0 5 votes vote down vote up
private static ImmutableList<Label> getWrapperTests(JSFile file) {
  return CachedValuesManager.getCachedValue(
      file,
      () -> {
        Project project = file.getProject();
        BlazeProjectData projectData =
            BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
        if (projectData == null) {
          return Result.create(
              ImmutableList.of(), BlazeSyncModificationTracker.getInstance(project));
        }
        ImmutableMultimap<TargetKey, TargetKey> rdeps = ReverseDependencyMap.get(project);
        TargetMap targetMap = projectData.getTargetMap();
        return Result.create(
            SourceToTargetFinder.findTargetsForSourceFile(
                    project,
                    VfsUtil.virtualToIoFile(file.getVirtualFile()),
                    Optional.of(RuleType.TEST))
                .stream()
                .filter(t -> t.getKind() != null)
                .filter(t -> t.getKind().getLanguageClass() == LanguageClass.JAVASCRIPT)
                .map(t -> t.label)
                .map(TargetKey::forPlainTarget)
                .map(rdeps::get)
                .filter(Objects::nonNull)
                .flatMap(Collection::stream)
                .filter(
                    key -> {
                      TargetIdeInfo target = targetMap.get(key);
                      return target != null && target.getKind().isWebTest();
                    })
                .map(TargetKey::getLabel)
                .collect(ImmutableList.toImmutableList()),
            BlazeSyncModificationTracker.getInstance(project));
      });
}
 
Example 17
Source File: LombokAugmentProvider.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@NotNull
@Override
public <Psi extends PsiElement> List<Psi> getAugments(@NotNull PsiElement element, @NotNull final Class<Psi> type) {
  final List<Psi> emptyResult = Collections.emptyList();
  if ((type != PsiClass.class && type != PsiField.class && type != PsiMethod.class) || !(element instanceof PsiExtensibleClass)) {
    return emptyResult;
  }

  // Don't filter !isPhysical elements or code auto completion will not work
  if (!element.isValid()) {
    return emptyResult;
  }
  final PsiClass psiClass = (PsiClass) element;
  // Skip processing of Annotations and Interfaces
  if (psiClass.isAnnotationType() || psiClass.isInterface()) {
    return emptyResult;
  }
  // skip processing if plugin is disabled
  final Project project = element.getProject();
  if (!ProjectSettings.isLombokEnabledInProject(project)) {
    return emptyResult;
  }

  final List<Psi> cachedValue;
  if (type == PsiField.class) {
    cachedValue = CachedValuesManager.getCachedValue(element, new FieldLombokCachedValueProvider<>(type, psiClass));
  } else if (type == PsiMethod.class) {
    cachedValue = CachedValuesManager.getCachedValue(element, new MethodLombokCachedValueProvider<>(type, psiClass));
  } else {
    cachedValue = CachedValuesManager.getCachedValue(element, new ClassLombokCachedValueProvider<>(type, psiClass));
  }
  return null != cachedValue ? cachedValue : emptyResult;
}
 
Example 18
Source File: WeaveEditor.java    From mule-intellij-plugins with Apache License 2.0 5 votes vote down vote up
protected void runPreview(boolean forceRefresh) {
    if (!isAutoSync() && !forceRefresh)
        return;

    final Map<String, Object> payload = new HashMap<String, Object>();
    Map<String, Map<String, Object>> flowVars = new HashMap<String, Map<String, Object>>();
    /*
    1. Get input from tabs - if payload exists, use payload, otherwise put in the Map
    2. Get text from DW
    3. Run preview, put the output to the output tab
     */

    int count = inputTabs.getTabCount();
    for (int index = 0; index < count; index++) {
        String title = inputTabs.getTitleAt(index);
        Editor editor = editors.get(title);
        Document document = editor.getDocument();
        String text = document.getText();
        String contentType = contentTypes.get(title);
        Map<String, Object> content = WeavePreview.createContent(contentType, text);
        if ("payload".equalsIgnoreCase(title)) {
            payload.clear();
            payload.putAll(content);
        } else {
            flowVars.put(title, content);
        }
    }

    final CachedValuesManager manager = CachedValuesManager.getManager(project);
    List<String> melFunctions = manager.getCachedValue(psiFile, MEL_STRINGS_KEY, new MelStringsCachedProvider());

    String dwScript = this.textEditor.getEditor().getDocument().getText();

    String output = WeavePreview.runPreview(module, dwScript, payload, flowVars, flowVars, flowVars, flowVars, flowVars, melFunctions);
    if (output != null)
        editors.get("output").getDocument().setText(output);
}
 
Example 19
Source File: CSharpPragmaContext.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
@Nonnull
@RequiredReadAction
public static CSharpPragmaContext get(PsiFile file)
{
	return CachedValuesManager.getCachedValue(file, () -> CachedValueProvider.Result.create(build(file), PsiModificationTracker.MODIFICATION_COUNT));
}
 
Example 20
Source File: CSharpReferenceExpressionImplUtil.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
@Nonnull
@RequiredReadAction
public static ResolveToKind kind(@Nonnull CSharpReferenceExpression referenceExpression)
{
	return CachedValuesManager.getCachedValue(referenceExpression, () -> CachedValueProvider.Result.create(kindImpl(referenceExpression), PsiModificationTracker.MODIFICATION_COUNT));
}