下面列出了com.intellij.psi.util.PsiTreeUtil#getTopmostParentOfType ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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;
}
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);
}
}
@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;
}
@Override
protected boolean isInContext(PsiElement element) {
PsiElement topmostExpressionElement = PsiTreeUtil.getTopmostParentOfType(element, XQueryExprSingle.class);
PsiElement topmostElement = XQueryPsiImplUtil.getTopmostElementWithTheSameOffset(element);
return topmostExpressionElement != null && isNotBeforeModuleDeclaration(topmostElement);
}