Search in sources :

Example 76 with NotNull

use of org.jetbrains.annotations.NotNull in project intellij-community by JetBrains.

the class PyDebuggerEditorsProvider method createDocument.

@NotNull
@Override
public Document createDocument(@NotNull final Project project, @NotNull String text, @Nullable final XSourcePosition sourcePosition, @NotNull EvaluationMode mode) {
    text = text.trim();
    final PyExpressionCodeFragmentImpl fragment = new PyExpressionCodeFragmentImpl(project, "fragment.py", text, true);
    // Bind to context
    final PsiElement element = getContextElement(project, sourcePosition);
    fragment.setContext(element);
    return PsiDocumentManager.getInstance(project).getDocument(fragment);
}
Also used : PyExpressionCodeFragmentImpl(com.jetbrains.python.psi.impl.PyExpressionCodeFragmentImpl) NotNull(org.jetbrains.annotations.NotNull)

Example 77 with NotNull

use of org.jetbrains.annotations.NotNull in project intellij-community by JetBrains.

the class PyUserSkeletonsClassMembersProvider method getMembers.

@NotNull
@Override
public Collection<PyCustomMember> getMembers(@NotNull PyClassType classType, PsiElement location, TypeEvalContext typeEvalContext) {
    final PyClass cls = classType.getPyClass();
    final PyClass skeleton = PyUserSkeletonsUtil.getUserSkeleton(cls);
    if (skeleton != null) {
        return getClassMembers(skeleton, classType.isDefinition());
    }
    return Collections.emptyList();
}
Also used : PyClass(com.jetbrains.python.psi.PyClass) NotNull(org.jetbrains.annotations.NotNull)

Example 78 with NotNull

use of org.jetbrains.annotations.NotNull in project intellij-community by JetBrains.

the class PySmartStepIntoHandler method computeSmartStepVariants.

@Override
@NotNull
public List<PySmartStepIntoVariant> computeSmartStepVariants(@NotNull XSourcePosition position) {
    final Document document = FileDocumentManager.getInstance().getDocument(position.getFile());
    final List<PySmartStepIntoVariant> variants = Lists.newArrayList();
    final Set<PyCallExpression> visitedCalls = Sets.newHashSet();
    final int line = position.getLine();
    XDebuggerUtil.getInstance().iterateLine(mySession.getProject(), document, line, psiElement -> {
        addVariants(document, line, psiElement, variants, visitedCalls);
        return true;
    });
    return variants;
}
Also used : PyCallExpression(com.jetbrains.python.psi.PyCallExpression) Document(com.intellij.openapi.editor.Document) NotNull(org.jetbrains.annotations.NotNull)

Example 79 with NotNull

use of org.jetbrains.annotations.NotNull in project intellij-community by JetBrains.

the class PydevConsoleReference method getVariants.

@NotNull
public Object[] getVariants() {
    Map<String, LookupElement> variants = Maps.newHashMap();
    try {
        final List<PydevCompletionVariant> completions = myCommunication.getCompletions(getText(), myPrefix);
        for (PydevCompletionVariant completion : completions) {
            final PsiManager manager = myElement.getManager();
            final String name = completion.getName();
            final int type = completion.getType();
            LookupElementBuilder builder = LookupElementBuilder.create(new PydevConsoleElement(manager, name, completion.getDescription())).withIcon(PyCodeCompletionImages.getImageForType(type));
            String args = completion.getArgs();
            if (args.equals("(%)")) {
                builder.withPresentableText("%" + completion.getName());
                builder = builder.withInsertHandler(new InsertHandler<LookupElement>() {

                    @Override
                    public void handleInsert(InsertionContext context, LookupElement item) {
                        final Editor editor = context.getEditor();
                        final Document document = editor.getDocument();
                        int offset = context.getStartOffset();
                        if (offset == 0 || !"%".equals(document.getText(TextRange.from(offset - 1, 1)))) {
                            document.insertString(offset, "%");
                        }
                    }
                });
                args = "";
            } else if (!StringUtil.isEmptyOrSpaces(args)) {
                builder = builder.withTailText(args);
            }
            // Set function insert handler
            if (type == IToken.TYPE_FUNCTION || args.endsWith(")")) {
                builder = builder.withInsertHandler(ParenthesesInsertHandler.WITH_PARAMETERS);
            }
            variants.put(name, builder);
        }
    } catch (Exception e) {
    //LOG.error(e);
    }
    return variants.values().toArray();
}
Also used : LookupElement(com.intellij.codeInsight.lookup.LookupElement) InsertionContext(com.intellij.codeInsight.completion.InsertionContext) Document(com.intellij.openapi.editor.Document) PydevCompletionVariant(com.jetbrains.python.console.pydev.PydevCompletionVariant) LookupElementBuilder(com.intellij.codeInsight.lookup.LookupElementBuilder) InsertHandler(com.intellij.codeInsight.completion.InsertHandler) ParenthesesInsertHandler(com.intellij.codeInsight.completion.util.ParenthesesInsertHandler) Editor(com.intellij.openapi.editor.Editor) NotNull(org.jetbrains.annotations.NotNull)

Example 80 with NotNull

use of org.jetbrains.annotations.NotNull in project intellij-community by JetBrains.

the class PyTestCase method findUsage.

/**
   * Finds all usages of element. Works much like method in {@link com.intellij.testFramework.fixtures.CodeInsightTestFixture#findUsages(com.intellij.psi.PsiElement)},
   * but supports {@link com.intellij.find.findUsages.CustomUsageSearcher} and {@link com.intellij.psi.search.searches.ReferencesSearch} as well
   *
   * @param element what to find
   * @return usages
   */
@NotNull
protected Collection<PsiElement> findUsage(@NotNull final PsiElement element) {
    final Collection<PsiElement> result = new ArrayList<>();
    final CollectProcessor<Usage> usageCollector = new CollectProcessor<>();
    for (final CustomUsageSearcher searcher : CustomUsageSearcher.EP_NAME.getExtensions()) {
        searcher.processElementUsages(element, usageCollector, new FindUsagesOptions(myFixture.getProject()));
    }
    for (final Usage usage : usageCollector.getResults()) {
        if (usage instanceof PsiElementUsage) {
            result.add(((PsiElementUsage) usage).getElement());
        }
    }
    for (final PsiReference reference : ReferencesSearch.search(element).findAll()) {
        result.add(reference.getElement());
    }
    for (final UsageInfo info : myFixture.findUsages(element)) {
        result.add(info.getElement());
    }
    return result;
}
Also used : PsiElementUsage(com.intellij.usages.rules.PsiElementUsage) Usage(com.intellij.usages.Usage) CustomUsageSearcher(com.intellij.find.findUsages.CustomUsageSearcher) FindUsagesOptions(com.intellij.find.findUsages.FindUsagesOptions) UsageInfo(com.intellij.usageView.UsageInfo) CollectProcessor(com.intellij.util.CommonProcessors.CollectProcessor) PsiElementUsage(com.intellij.usages.rules.PsiElementUsage) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

NotNull (org.jetbrains.annotations.NotNull)8141 VirtualFile (com.intellij.openapi.vfs.VirtualFile)888 ArrayList (java.util.ArrayList)809 PsiElement (com.intellij.psi.PsiElement)764 Project (com.intellij.openapi.project.Project)647 File (java.io.File)627 Nullable (org.jetbrains.annotations.Nullable)518 List (java.util.List)400 PsiFile (com.intellij.psi.PsiFile)358 Module (com.intellij.openapi.module.Module)336 IOException (java.io.IOException)325 TextRange (com.intellij.openapi.util.TextRange)260 Document (com.intellij.openapi.editor.Document)173 ContainerUtil (com.intellij.util.containers.ContainerUtil)173 BasePhpElementVisitor (com.kalessil.phpStorm.phpInspectionsEA.openApi.BasePhpElementVisitor)169 ASTNode (com.intellij.lang.ASTNode)167 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)167 Map (java.util.Map)156 java.util (java.util)154 IElementType (com.intellij.psi.tree.IElementType)146