Java Code Examples for com.intellij.psi.PsiElement#getUserData()

The following examples show how to use com.intellij.psi.PsiElement#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: MethodResolveResult.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@Nonnull
public static MethodResolveResult createResult(@Nonnull MethodResolvePriorityInfo calcResult, @Nullable PsiElement element, @Nullable ResolveResult resolveResult)
{
	PsiElement providerElement = element == null ? null : element.getUserData(FORCE_PROVIDER_ELEMENT);
	if(providerElement == null && resolveResult instanceof CSharpResolveResult)
	{
		providerElement = ((CSharpResolveResult) resolveResult).getProviderElement();
	}
	MethodResolveResult methodResolveResult = new MethodResolveResult(element, calcResult);
	methodResolveResult.setProvider(providerElement);
	if(resolveResult instanceof CSharpUndefinedResolveResult)
	{
		methodResolveResult.myUnknown = true;
	}
	return methodResolveResult;
}
 
Example 2
Source File: AdditionalReferenceSearch.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@Override
public void processQuery(@Nonnull ReferencesSearch.SearchParameters queryParameters, @Nonnull Processor<? super PsiReference> consumer)
{
	PsiElement elementToSearch = queryParameters.getElementToSearch();

	PsiElement declaration = elementToSearch.getUserData(CSharpResolveUtil.EXTENSION_METHOD_WRAPPER);
	if(declaration == null)
	{
		declaration = elementToSearch.getUserData(CSharpResolveUtil.ACCESSOR_VALUE_VARIABLE_OWNER);
	}

	if(declaration == null)
	{
		return;
	}

	ReferencesSearch.search(declaration, queryParameters.getEffectiveSearchScope(), queryParameters.isIgnoreAccessScope()).forEach(consumer);
}
 
Example 3
Source File: CachedValuesManager.java    From consulo with Apache License 2.0 6 votes vote down vote up
/**
 * Create a cached value with the given provider and non-tracked return value, store it in PSI element's user data. If it's already stored, reuse it.
 *
 * @return The cached value
 */
public static <T> T getCachedValue(@Nonnull final PsiElement psi, @Nonnull Key<CachedValue<T>> key, @Nonnull final CachedValueProvider<T> provider) {
  CachedValue<T> value = psi.getUserData(key);
  if (value != null) {
    return value.getValue();
  }

  return getManager(psi.getProject()).getCachedValue(psi, key, () -> {
    CachedValueProvider.Result<T> result = provider.compute();
    if (result != null && !psi.isPhysical()) {
      PsiFile file = psi.getContainingFile();
      if (file != null) {
        return CachedValueProvider.Result.create(result.getValue(), ArrayUtil.append(result.getDependencyItems(), file, ArrayUtil.OBJECT_ARRAY_FACTORY));
      }
    }
    return result;
  }, false);
}
 
Example 4
Source File: CSharpLikeMethodDeclarationImplUtil.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
public static boolean isEquivalentTo(@Nonnull PsiElement o1, @Nullable PsiElement o2)
{
	if(o2 == null)
	{
		return false;
	}
	PsiElement originalElement1 = o1.getOriginalElement();
	PsiElement originalElement2 = o2.getOriginalElement();

	if(o1.getUserData(CSharpResolveUtil.EXTENSION_METHOD_WRAPPER) == originalElement2)
	{
		return true;
	}

	if(originalElement1 == originalElement2)
	{
		return true;
	}

	if(o1 instanceof CSharpConstructorDeclaration && o2 instanceof CSharpTypeDeclaration)
	{
		// default constructor builder
		PsiElement navigationElement = o1.getNavigationElement();
		if(navigationElement == o2)
		{
			return true;
		}
	}

	return false;
}
 
Example 5
Source File: SimpleDuplicatesFinder.java    From consulo with Apache License 2.0 5 votes vote down vote up
private boolean matchPattern(@Nullable final PsiElement pattern,
                             @Nullable final PsiElement candidate,
                             @Nonnull final SimpleMatch match) {
  ProgressManager.checkCanceled();
  if (pattern == null || candidate == null) return pattern == candidate;
  final PsiElement[] children1 = PsiEquivalenceUtil.getFilteredChildren(pattern, null, true);
  final PsiElement[] children2 = PsiEquivalenceUtil.getFilteredChildren(candidate, null, true);
  final PsiElement patternParent = pattern.getParent();
  final PsiElement candidateParent = candidate.getParent();
  if (patternParent == null || candidateParent == null) return false;
  if (pattern.getUserData(PARAMETER) != null && patternParent.getClass() == candidateParent.getClass()) {
    match.changeParameter(pattern.getText(), candidate.getText());
    return true;
  }
  if (children1.length != children2.length) return false;

  for (int i = 0; i < children1.length; i++) {
    final PsiElement child1 = children1[i];
    final PsiElement child2 = children2[i];
    if (!matchPattern(child1, child2, match)) return false;
  }

  if (children1.length == 0) {
    if (pattern.getUserData(PARAMETER) != null && patternParent.getClass() == candidateParent.getClass()) {
      match.changeParameter(pattern.getText(), candidate.getText());
      return true;
    }
    if (myOutputVariables.contains(pattern.getText())) {
      match.changeOutput(candidate.getText());
      return true;
    }
    if (!pattern.textMatches(candidate)) {
      return false;
    }
  }

  return true;
}
 
Example 6
Source File: CppSupportLoader.java    From CppTools with Apache License 2.0 5 votes vote down vote up
public static String getQuickDoc(PsiElement psiElement) {
  OurUsage usage = psiElement.getUserData(ourUsageKey);
  if (usage == null) return null;

  StringBuilder result = new StringBuilder();
  result.append (usage.fileUsage.getFileLocaton()).append("\n");
  if (usage.context != null) result.append(usage.context);
  else result.append(usage.getText());

  return result.toString();
}
 
Example 7
Source File: CSharpMethodImplUtil.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
public static boolean isExtensionWrapper(@Nullable PsiElement element)
{
	return element instanceof CSharpMethodDeclaration && element.getUserData(CSharpResolveUtil.EXTENSION_METHOD_WRAPPER) != null;
}
 
Example 8
Source File: CSharpLambdaResolveResultUtil.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
@Contract("null -> null")
public static CSharpMethodDeclaration getDelegateMethodTypeWrapper(@Nullable PsiElement element)
{
	return element != null ? element.getUserData(CSharpResolveUtil.DELEGATE_METHOD_TYPE) : null;
}
 
Example 9
Source File: ConcatenationInjectorManager.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void injectLanguages(@Nonnull MultiHostRegistrar registrar, @Nonnull PsiElement context) {
  ConcatenationInjectorManager manager = getInstance(myProject);
  if (manager.myConcatenationInjectors.isEmpty()) {
    return;
  }

  final PsiFile containingFile = ((InjectionRegistrarImpl)registrar).getHostPsiFile();
  Project project = containingFile.getProject();
  long modificationCount = PsiManager.getInstance(project).getModificationTracker().getModificationCount();
  Pair<PsiElement, PsiElement[]> pair = computeAnchorAndOperands(context);
  PsiElement anchor = pair.first;
  PsiElement[] operands = pair.second;
  Integer noInjectionTimestamp = anchor.getUserData(NO_CONCAT_INJECTION_TIMESTAMP);

  InjectionResult result;
  ParameterizedCachedValue<InjectionResult, PsiElement> data = null;
  if (operands.length == 0 || noInjectionTimestamp != null && noInjectionTimestamp == modificationCount) {
    result = null;
  }
  else {
    data = anchor.getUserData(INJECTED_PSI_IN_CONCATENATION);

    result = data == null ? null : data.getValue(context);
    if (result == null || !result.isValid()) {
      result = doCompute(containingFile, project, anchor, operands);
    }
  }
  if (result != null) {
    ((InjectionRegistrarImpl)registrar).addToResults(result);

    if (data == null) {
      CachedValueProvider.Result<InjectionResult> cachedResult = CachedValueProvider.Result.create(result, manager);
      data = CachedValuesManager.getManager(project).createParameterizedCachedValue(context1 -> {
        PsiFile containingFile1 = context1.getContainingFile();
        Project project1 = containingFile1.getProject();
        Pair<PsiElement, PsiElement[]> pair1 = computeAnchorAndOperands(context1);
        InjectionResult result1 = pair1.second.length == 0 ? null : doCompute(containingFile1, project1, pair1.first, pair1.second);
        return result1 == null ? null : CachedValueProvider.Result.create(result1, manager);
      }, false);
      ((PsiParameterizedCachedValue<InjectionResult, PsiElement>)data).setValue(cachedResult);

      anchor.putUserData(INJECTED_PSI_IN_CONCATENATION, data);
      if (anchor.getUserData(NO_CONCAT_INJECTION_TIMESTAMP) != null) {
        anchor.putUserData(NO_CONCAT_INJECTION_TIMESTAMP, null);
      }
    }
  }
  else {
    // cache no-injection flag
    if (anchor.getUserData(INJECTED_PSI_IN_CONCATENATION) != null) {
      anchor.putUserData(INJECTED_PSI_IN_CONCATENATION, null);
    }
    anchor.putUserData(NO_CONCAT_INJECTION_TIMESTAMP, (int)modificationCount);
  }
}