Search in sources :

Example 16 with NavigationItem

use of com.intellij.navigation.NavigationItem in project intellij-community by JetBrains.

the class PsiElementListCellRenderer method getNavigationItemAttributes.

@Nullable
protected TextAttributes getNavigationItemAttributes(Object value) {
    TextAttributes attributes = null;
    if (value instanceof NavigationItem) {
        TextAttributesKey attributesKey = null;
        final ItemPresentation presentation = ((NavigationItem) value).getPresentation();
        if (presentation instanceof ColoredItemPresentation)
            attributesKey = ((ColoredItemPresentation) presentation).getTextAttributesKey();
        if (attributesKey != null) {
            attributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(attributesKey);
        }
    }
    return attributes;
}
Also used : NavigationItem(com.intellij.navigation.NavigationItem) ColoredItemPresentation(com.intellij.navigation.ColoredItemPresentation) ColoredItemPresentation(com.intellij.navigation.ColoredItemPresentation) ItemPresentation(com.intellij.navigation.ItemPresentation) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) TextAttributesKey(com.intellij.openapi.editor.colors.TextAttributesKey) Nullable(org.jetbrains.annotations.Nullable)

Example 17 with NavigationItem

use of com.intellij.navigation.NavigationItem in project intellij-community by JetBrains.

the class GotoImplementationHandler method getChooserTitle.

@Override
@NotNull
protected String getChooserTitle(@NotNull PsiElement sourceElement, String name, int length, boolean finished) {
    ItemPresentation presentation = ((NavigationItem) sourceElement).getPresentation();
    String fullName;
    if (presentation == null) {
        fullName = name;
    } else {
        PsiElement container = getContainer(sourceElement);
        ItemPresentation containerPresentation = container == null || container instanceof PsiFile ? null : ((NavigationItem) container).getPresentation();
        String containerText = containerPresentation == null ? null : containerPresentation.getPresentableText();
        fullName = (containerText == null ? "" : containerText + ".") + presentation.getPresentableText();
    }
    return CodeInsightBundle.message("goto.implementation.chooserTitle", fullName, length, finished ? "" : " so far");
}
Also used : NavigationItem(com.intellij.navigation.NavigationItem) ItemPresentation(com.intellij.navigation.ItemPresentation) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 18 with NavigationItem

use of com.intellij.navigation.NavigationItem in project intellij-community by JetBrains.

the class AbstractMvcPsiNodeDescriptor method updateImpl.

@Override
protected void updateImpl(final PresentationData data) {
    final PsiElement psiElement = extractPsiFromValue();
    if (psiElement instanceof NavigationItem) {
        final ItemPresentation presentation = ((NavigationItem) psiElement).getPresentation();
        assert presentation != null;
        data.setPresentableText(presentation.getPresentableText());
    }
}
Also used : NavigationItem(com.intellij.navigation.NavigationItem) ItemPresentation(com.intellij.navigation.ItemPresentation) PsiElement(com.intellij.psi.PsiElement)

Example 19 with NavigationItem

use of com.intellij.navigation.NavigationItem in project intellij-community by JetBrains.

the class XsltElementImpl method navigate.

@Override
public void navigate(boolean b) {
    final XmlAttributeValue nameElement = getNameElement();
    assert nameElement != null;
    ((NavigationItem) nameElement).navigate(b);
}
Also used : NavigationItem(com.intellij.navigation.NavigationItem) PsiElementNavigationItem(com.intellij.navigation.PsiElementNavigationItem) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue)

Example 20 with NavigationItem

use of com.intellij.navigation.NavigationItem in project intellij-community by JetBrains.

the class SourceCodeChecker method check.

private static ThreeState check(Location location, SourcePosition position, Project project) {
    Method method = DebuggerUtilsEx.getMethod(location);
    // for now skip constructors, bridges, lambdas etc.
    if (method == null || method.isConstructor() || method.isSynthetic() || method.isBridge() || method.isStaticInitializer() || (method.declaringType() instanceof ClassType && ((ClassType) method.declaringType()).isEnum()) || DebuggerUtilsEx.isLambda(method)) {
        return ThreeState.UNSURE;
    }
    List<Location> locations = DebuggerUtilsEx.allLineLocations(method);
    if (ContainerUtil.isEmpty(locations)) {
        return ThreeState.UNSURE;
    }
    if (position != null) {
        return ReadAction.compute(() -> {
            PsiFile psiFile = position.getFile();
            if (!psiFile.getLanguage().isKindOf(JavaLanguage.INSTANCE)) {
                // only for java for now
                return ThreeState.UNSURE;
            }
            Document document = PsiDocumentManager.getInstance(project).getDocument(psiFile);
            if (document == null) {
                return ThreeState.UNSURE;
            }
            boolean res = false;
            PsiElement psiMethod = DebuggerUtilsEx.getContainingMethod(position);
            if (psiMethod != null) {
                TextRange range = psiMethod.getTextRange();
                if (psiMethod instanceof PsiDocCommentOwner) {
                    PsiDocComment comment = ((PsiDocCommentOwner) psiMethod).getDocComment();
                    if (comment != null) {
                        range = new TextRange(comment.getTextRange().getEndOffset() + 1, range.getEndOffset());
                    }
                }
                int startLine = document.getLineNumber(range.getStartOffset()) + 1;
                int endLine = document.getLineNumber(range.getEndOffset()) + 1;
                res = getLinesStream(locations, psiFile).allMatch(line -> startLine <= line && line <= endLine);
                if (!res) {
                    LOG.debug("Source check failed: Method " + method.name() + ", source: " + ((NavigationItem) psiMethod).getName() + "\nLines: " + getLinesStream(locations, psiFile).joining(", ") + "\nExpected range: " + startLine + "-" + endLine);
                }
            } else {
                LOG.debug("Source check failed: method " + method.name() + " not found in sources");
            }
            if (!res) {
                FileEditor editor = FileEditorManager.getInstance(project).getSelectedEditor(position.getFile().getVirtualFile());
                if (editor instanceof TextEditor) {
                    AppUIUtil.invokeOnEdt(() -> HintManager.getInstance().showErrorHint(((TextEditor) editor).getEditor(), DebuggerBundle.message("warning.source.code.not.match")));
                } else {
                    XDebugSessionImpl.NOTIFICATION_GROUP.createNotification(DebuggerBundle.message("warning.source.code.not.match"), NotificationType.WARNING).notify(project);
                }
                return ThreeState.NO;
            }
            return ThreeState.YES;
        });
    }
    return ThreeState.YES;
}
Also used : PsiDocComment(com.intellij.psi.javadoc.PsiDocComment) NavigationItem(com.intellij.navigation.NavigationItem) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Document(com.intellij.openapi.editor.Document) ContainerUtil(com.intellij.util.containers.ContainerUtil) XDebugSessionImpl(com.intellij.xdebugger.impl.XDebugSessionImpl) ReadAction(com.intellij.openapi.application.ReadAction) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) PositionManagerImpl(com.intellij.debugger.engine.PositionManagerImpl) SuspendContextImpl(com.intellij.debugger.engine.SuspendContextImpl) Project(com.intellij.openapi.project.Project) DebuggerBundle(com.intellij.debugger.DebuggerBundle) Logger(com.intellij.openapi.diagnostic.Logger) JavaLanguage(com.intellij.lang.java.JavaLanguage) TextEditor(com.intellij.openapi.fileEditor.TextEditor) SuspendContextCommandImpl(com.intellij.debugger.engine.events.SuspendContextCommandImpl) StackFrameProxyImpl(com.intellij.debugger.jdi.StackFrameProxyImpl) EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) NoDataException(com.intellij.debugger.NoDataException) AppUIUtil(com.intellij.ui.AppUIUtil) ThreeState(com.intellij.util.ThreeState) DebugProcessImpl(com.intellij.debugger.engine.DebugProcessImpl) TextRange(com.intellij.openapi.util.TextRange) FileEditor(com.intellij.openapi.fileEditor.FileEditor) NotificationType(com.intellij.notification.NotificationType) TestOnly(org.jetbrains.annotations.TestOnly) PsiDocComment(com.intellij.psi.javadoc.PsiDocComment) List(java.util.List) LineNumbersMapping(com.intellij.execution.filters.LineNumbersMapping) StreamEx(one.util.streamex.StreamEx) Registry(com.intellij.openapi.util.registry.Registry) com.sun.jdi(com.sun.jdi) IntStreamEx(one.util.streamex.IntStreamEx) com.intellij.psi(com.intellij.psi) HintManager(com.intellij.codeInsight.hint.HintManager) SourcePosition(com.intellij.debugger.SourcePosition) FileEditor(com.intellij.openapi.fileEditor.FileEditor) TextRange(com.intellij.openapi.util.TextRange) Document(com.intellij.openapi.editor.Document) NavigationItem(com.intellij.navigation.NavigationItem) TextEditor(com.intellij.openapi.fileEditor.TextEditor)

Aggregations

NavigationItem (com.intellij.navigation.NavigationItem)25 ItemPresentation (com.intellij.navigation.ItemPresentation)8 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 NotNull (org.jetbrains.annotations.NotNull)6 PsiFile (com.intellij.psi.PsiFile)5 PsiElementNavigationItem (com.intellij.navigation.PsiElementNavigationItem)4 PsiElement (com.intellij.psi.PsiElement)4 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)4 ArrayList (java.util.ArrayList)4 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)3 Project (com.intellij.openapi.project.Project)3 ChooseByNameContributor (com.intellij.navigation.ChooseByNameContributor)2 Logger (com.intellij.openapi.diagnostic.Logger)2 com.intellij.psi (com.intellij.psi)2 HintManager (com.intellij.codeInsight.hint.HintManager)1 DebuggerBundle (com.intellij.debugger.DebuggerBundle)1 NoDataException (com.intellij.debugger.NoDataException)1 SourcePosition (com.intellij.debugger.SourcePosition)1 DebugProcessImpl (com.intellij.debugger.engine.DebugProcessImpl)1 PositionManagerImpl (com.intellij.debugger.engine.PositionManagerImpl)1