Search in sources :

Example 1 with PomDeclarationSearcher

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);
}
Also used : PomTarget(com.intellij.pom.PomTarget) Language(com.intellij.lang.Language) InjectedLanguageManager(com.intellij.lang.injection.InjectedLanguageManager) NavigationItem(com.intellij.navigation.NavigationItem) Lookup(com.intellij.codeInsight.lookup.Lookup) Document(com.intellij.openapi.editor.Document) EditorUtil(com.intellij.openapi.editor.ex.util.EditorUtil) DaemonCodeAnalyzer(com.intellij.codeInsight.daemon.DaemonCodeAnalyzer) SearchScope(com.intellij.psi.search.SearchScope) ContainerUtil(com.intellij.util.containers.ContainerUtil) ArrayList(java.util.ArrayList) PsiTreeUtil(com.intellij.psi.util.PsiTreeUtil) PomService(com.intellij.pom.references.PomService) Project(com.intellij.openapi.project.Project) EditorEx(com.intellij.openapi.editor.ex.EditorEx) PomTarget(com.intellij.pom.PomTarget) CompletionUtil(com.intellij.codeInsight.completion.CompletionUtil) Extensions(com.intellij.openapi.extensions.Extensions) PsiSearchHelper(com.intellij.psi.search.PsiSearchHelper) PsiDeclaredTarget(com.intellij.pom.PsiDeclaredTarget) ThreeState(com.intellij.util.ThreeState) LookupElement(com.intellij.codeInsight.lookup.LookupElement) Collection(java.util.Collection) LookupManager(com.intellij.codeInsight.lookup.LookupManager) LanguageExtension(com.intellij.lang.LanguageExtension) TextRange(com.intellij.openapi.util.TextRange) Editor(com.intellij.openapi.editor.Editor) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) ServiceManager(com.intellij.openapi.components.ServiceManager) PomDeclarationSearcher(com.intellij.pom.PomDeclarationSearcher) EditSourceUtil(com.intellij.ide.util.EditSourceUtil) BitUtil(com.intellij.util.BitUtil) ApplicationManager(com.intellij.openapi.application.ApplicationManager) Navigatable(com.intellij.pom.Navigatable) com.intellij.psi(com.intellij.psi) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) Consumer(com.intellij.util.Consumer) TextRange(com.intellij.openapi.util.TextRange) PsiDeclaredTarget(com.intellij.pom.PsiDeclaredTarget) PomDeclarationSearcher(com.intellij.pom.PomDeclarationSearcher) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with PomDeclarationSearcher

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;
}
Also used : PomTarget(com.intellij.pom.PomTarget) CollectConsumer(com.intellij.util.CollectConsumer) PomDeclarationSearcher(com.intellij.pom.PomDeclarationSearcher)

Aggregations

PomDeclarationSearcher (com.intellij.pom.PomDeclarationSearcher)2 PomTarget (com.intellij.pom.PomTarget)2 CompletionUtil (com.intellij.codeInsight.completion.CompletionUtil)1 DaemonCodeAnalyzer (com.intellij.codeInsight.daemon.DaemonCodeAnalyzer)1 Lookup (com.intellij.codeInsight.lookup.Lookup)1 LookupElement (com.intellij.codeInsight.lookup.LookupElement)1 LookupManager (com.intellij.codeInsight.lookup.LookupManager)1 EditSourceUtil (com.intellij.ide.util.EditSourceUtil)1 Language (com.intellij.lang.Language)1 LanguageExtension (com.intellij.lang.LanguageExtension)1 InjectedLanguageManager (com.intellij.lang.injection.InjectedLanguageManager)1 NavigationItem (com.intellij.navigation.NavigationItem)1 ApplicationManager (com.intellij.openapi.application.ApplicationManager)1 ServiceManager (com.intellij.openapi.components.ServiceManager)1 Document (com.intellij.openapi.editor.Document)1 Editor (com.intellij.openapi.editor.Editor)1 EditorEx (com.intellij.openapi.editor.ex.EditorEx)1 EditorUtil (com.intellij.openapi.editor.ex.util.EditorUtil)1 Extensions (com.intellij.openapi.extensions.Extensions)1 Project (com.intellij.openapi.project.Project)1