use of com.intellij.pom.PomDeclarationSearcher in project intellij-community by JetBrains.
the class TargetElementUtil method getNamedElement.
@Override
@Nullable
public PsiElement getNamedElement(@Nullable final PsiElement element, final int offsetInElement) {
if (element == null)
return null;
final List<PomTarget> targets = ContainerUtil.newArrayList();
final Consumer<PomTarget> consumer = target -> {
if (target instanceof PsiDeclaredTarget) {
final PsiDeclaredTarget declaredTarget = (PsiDeclaredTarget) target;
final PsiElement navigationElement = declaredTarget.getNavigationElement();
final TextRange range = declaredTarget.getNameIdentifierRange();
if (range != null && !range.shiftRight(navigationElement.getTextRange().getStartOffset()).contains(element.getTextRange().getStartOffset() + offsetInElement)) {
return;
}
}
targets.add(target);
};
PsiElement parent = element;
int offset = offsetInElement;
while (parent != null) {
for (PomDeclarationSearcher searcher : PomDeclarationSearcher.EP_NAME.getExtensions()) {
searcher.findDeclarationsAt(parent, offset, consumer);
if (!targets.isEmpty()) {
final PomTarget target = targets.get(0);
return target == null ? null : PomService.convertToPsi(element.getProject(), target);
}
}
offset += parent.getStartOffsetInParent();
parent = parent.getParent();
}
return getNamedElement(element);
}
use of com.intellij.pom.PomDeclarationSearcher in project intellij-community by JetBrains.
the class GrUnresolvedAccessChecker method shouldHighlightAsUnresolved.
private static boolean shouldHighlightAsUnresolved(@NotNull GrReferenceExpression referenceExpression) {
if (GrHighlightUtil.isDeclarationAssignment(referenceExpression))
return false;
GrExpression qualifier = referenceExpression.getQualifier();
if (qualifier != null && qualifier.getType() == null && !isRefToPackage(qualifier))
return false;
if (qualifier != null && referenceExpression.getDotTokenType() == GroovyTokenTypes.mMEMBER_POINTER && referenceExpression.multiResolve(false).length > 0) {
return false;
}
if (!GroovyUnresolvedHighlightFilter.shouldHighlight(referenceExpression))
return false;
CollectConsumer<PomTarget> consumer = new CollectConsumer<>();
for (PomDeclarationSearcher searcher : PomDeclarationSearcher.EP_NAME.getExtensions()) {
searcher.findDeclarationsAt(referenceExpression, 0, consumer);
if (!consumer.getResult().isEmpty())
return false;
}
return true;
}
Aggregations