Java Code Examples for com.intellij.psi.util.PsiTreeUtil#getTopmostParentOfType()

The following examples show how to use com.intellij.psi.util.PsiTreeUtil#getTopmostParentOfType() . 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: HaxeResolveUtil.java    From intellij-haxe with Apache License 2.0 6 votes vote down vote up
private static String tryResolveFullyQualifiedHaxeReferenceExpression(PsiElement type) {
  if (type instanceof HaxeReferenceExpression) {
    HaxeReferenceExpression topmostParentOfType = PsiTreeUtil.getTopmostParentOfType(type, HaxeReferenceExpression.class);

    if (topmostParentOfType == null) {
      topmostParentOfType = (HaxeReferenceExpression)type;
    }

    HaxeClass haxeClass = findClassByQName(topmostParentOfType.getText(), topmostParentOfType.getContext());
    if (haxeClass != null) {
      return topmostParentOfType.getText();
    }

    PsiElement parent = type.getParent();
    HaxeClass classByQName = findClassByQName(parent.getText(), parent.getContext());
    if (classByQName != null) {
      return parent.getText();
    }
  }

  return null;
}
 
Example 2
Source File: MisplacedCommentHighlighter.java    From intellij-xquery with Apache License 2.0 5 votes vote down vote up
public void highlight(PsiElement element, AnnotationHolder holder) {
    XQueryMisplacedComment misplacedComment = PsiTreeUtil.getTopmostParentOfType(element, XQueryMisplacedComment.class);
    if (isTheStartingElementOfMisplacedComment(element, misplacedComment)) {
        Annotation annotation = holder.createErrorAnnotation(misplacedComment, "Comments cannot be used here.");
        annotation.setHighlightType(ProblemHighlightType.GENERIC_ERROR);
    }
}
 
Example 3
Source File: CS0136.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
@RequiredReadAction
@Nullable
@Override
public HighlightInfoFactory checkImpl(@Nonnull CSharpLanguageVersion languageVersion, @Nonnull CSharpHighlightContext highlightContext, @Nonnull DotNetVariable element)
{
	String name = element.getName();
	if(name == null)
	{
		return null;
	}

	CSharpSimpleLikeMethodAsElement method = PsiTreeUtil.getTopmostParentOfType(element, CSharpSimpleLikeMethodAsElement.class);
	if(method == null)
	{
		return null;
	}

	AnalyzeContext context = CachedValuesManager.getCachedValue(method, () -> CachedValueProvider.Result.create(new AnalyzeContext(method), PsiModificationTracker.MODIFICATION_COUNT));

	Collection<DotNetVariable> variables = context.myVariables.get(name);
	if(variables.size() <= 1)
	{
		return null;
	}

	DotNetVariable prevVariable = null;
	for(DotNetVariable variable : variables)
	{
		if(variable == element)
		{
			break;
		}

		prevVariable = variable;
	}

	if(prevVariable != null)
	{
		//return newBuilder(getNameIdentifier(element), name, name, getScope(prevVariable, element));
	}
	return null;
}
 
Example 4
Source File: XQueryContextType.java    From intellij-xquery with Apache License 2.0 4 votes vote down vote up
@Override
protected boolean isInContext(PsiElement element) {
    PsiElement topmostExpressionElement = PsiTreeUtil.getTopmostParentOfType(element, XQueryExprSingle.class);
    PsiElement topmostElement = XQueryPsiImplUtil.getTopmostElementWithTheSameOffset(element);
    return topmostExpressionElement != null && isNotBeforeModuleDeclaration(topmostElement);
}