Search in sources :

Example 11 with PerlSubDefinitionElement

use of com.perl5.lang.perl.psi.PerlSubDefinitionElement in project Perl5-IDEA by Camelcade.

the class PodSubReference method resolveInner.

@NotNull
@Override
protected ResolveResult[] resolveInner(boolean incompleteCode) {
    PsiElement element = getElement();
    if (element != null) {
        final Project project = element.getProject();
        String subName = element.getText();
        if (StringUtil.isNotEmpty(subName)) {
            final PsiFile containingFile = element.getContainingFile();
            String packageName = PodFileUtil.getPackageName(containingFile);
            List<ResolveResult> results = new ArrayList<>();
            if (StringUtil.isNotEmpty(packageName)) {
                String canonicalName = packageName + PerlPackageUtil.PACKAGE_SEPARATOR + subName;
                for (PerlSubDefinitionElement target : PerlSubUtil.getSubDefinitions(project, canonicalName)) {
                    results.add(new PsiElementResolveResult(target));
                }
                for (PerlSubDeclarationElement target : PerlSubUtil.getSubDeclarations(project, canonicalName)) {
                    results.add(new PsiElementResolveResult(target));
                }
            }
            if (results.isEmpty()) {
                final PsiFile perlFile = containingFile.getViewProvider().getStubBindingRoot();
                for (PerlSubElement subBase : PsiTreeUtil.findChildrenOfType(perlFile, PerlSubElement.class)) {
                    String subBaseName = subBase.getName();
                    if (subBaseName != null && StringUtil.equals(subBaseName, subName)) {
                        results.add(new PsiElementResolveResult(subBase));
                    }
                }
            }
            return results.toArray(new ResolveResult[results.size()]);
        }
    }
    return ResolveResult.EMPTY_ARRAY;
}
Also used : Project(com.intellij.openapi.project.Project) PerlSubElement(com.perl5.lang.perl.psi.PerlSubElement) ArrayList(java.util.ArrayList) PsiFile(com.intellij.psi.PsiFile) PsiElementResolveResult(com.intellij.psi.PsiElementResolveResult) PerlSubDeclarationElement(com.perl5.lang.perl.psi.PerlSubDeclarationElement) PsiElementResolveResult(com.intellij.psi.PsiElementResolveResult) ResolveResult(com.intellij.psi.ResolveResult) PerlSubDefinitionElement(com.perl5.lang.perl.psi.PerlSubDefinitionElement) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 12 with PerlSubDefinitionElement

use of com.perl5.lang.perl.psi.PerlSubDefinitionElement in project Perl5-IDEA by Camelcade.

the class PerlLightTestCase method serializePsiElement.

protected String serializePsiElement(@Nullable PsiElement element) {
    if (element == null) {
        return "null";
    }
    StringBuilder sb = new StringBuilder();
    sb.append(element);
    if (element instanceof PerlSubDefinitionElement) {
        String argumentsList = ((PerlSubDefinitionElement) element).getSubArgumentsList().stream().map(argument -> {
            if (argument.isOptional()) {
                return "[" + argument.toStringLong() + "]";
            } else {
                return argument.toStringLong();
            }
        }).collect(Collectors.joining(", "));
        if (StringUtil.isNotEmpty(argumentsList)) {
            sb.append("(").append(argumentsList).append(")");
        }
    }
    ASTNode node = element.getNode();
    if (node != null) {
        sb.append(" at ").append(node.getStartOffset()).append(" in ").append(element.getContainingFile().getName());
    }
    PsiElement navigationElement = element.getNavigationElement();
    if (navigationElement == null) {
        sb.append("; no navigation element;");
    } else if (navigationElement != element) {
        sb.append("; navigated to: ").append(serializePsiElement(navigationElement));
    }
    return sb.toString();
}
Also used : InjectedLanguageManager(com.intellij.lang.injection.InjectedLanguageManager) PerlPackageUtil(com.perl5.lang.perl.util.PerlPackageUtil) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiManagerEx(com.intellij.psi.impl.PsiManagerEx) THashSet(gnu.trove.THashSet) PsiTreeUtil(com.intellij.psi.util.PsiTreeUtil) RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) com.perl5.lang.perl.psi(com.perl5.lang.perl.psi) WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) PerlBareStringManipulator(com.perl5.lang.perl.idea.manipulators.PerlBareStringManipulator) FileUtil(com.intellij.openapi.util.io.FileUtil) LanguageStructureViewBuilder(com.intellij.lang.LanguageStructureViewBuilder) PerlDelegatingLightNamedElement(com.perl5.lang.perl.psi.light.PerlDelegatingLightNamedElement) StructureViewBuilder(com.intellij.ide.structureView.StructureViewBuilder) TextRange(com.intellij.openapi.util.TextRange) FileEditor(com.intellij.openapi.fileEditor.FileEditor) HighlightUsagesAction(com.intellij.codeInsight.highlighting.actions.HighlightUsagesAction) MapDataContext(com.intellij.testFramework.MapDataContext) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) StructureViewModel(com.intellij.ide.structureView.StructureViewModel) PerlStringContentManipulator(com.perl5.lang.perl.idea.manipulators.PerlStringContentManipulator) PerlStringManipulator(com.perl5.lang.perl.idea.manipulators.PerlStringManipulator) java.util(java.util) CharsetToolkit(com.intellij.openapi.vfs.CharsetToolkit) com.intellij.openapi.editor(com.intellij.openapi.editor) com.intellij.ide.hierarchy(com.intellij.ide.hierarchy) PerlFileTypeScript(com.perl5.lang.perl.fileTypes.PerlFileTypeScript) ItemPresentation(com.intellij.navigation.ItemPresentation) PerlExportDescriptor(com.perl5.lang.perl.extensions.packageprocessor.PerlExportDescriptor) PerlSharedSettings(com.perl5.lang.perl.idea.configuration.settings.PerlSharedSettings) UsefulTestCase(com.intellij.testFramework.UsefulTestCase) DebugUtil(com.intellij.psi.impl.DebugUtil) BrowseHierarchyActionBase(com.intellij.ide.hierarchy.actions.BrowseHierarchyActionBase) StringUtil(com.intellij.openapi.util.text.StringUtil) VirtualFileFilter(com.intellij.openapi.vfs.VirtualFileFilter) AssertionFailedError(junit.framework.AssertionFailedError) IOException(java.io.IOException) Field(java.lang.reflect.Field) Disposable(com.intellij.openapi.Disposable) File(java.io.File) ASTNode(com.intellij.lang.ASTNode) EditorColors(com.intellij.openapi.editor.colors.EditorColors) Pair(com.intellij.openapi.util.Pair) LightCodeInsightFixtureTestCase(com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase) DeleteNameDescriptionLocation(com.intellij.ide.util.DeleteNameDescriptionLocation) Assert(org.junit.Assert) Application(com.intellij.openapi.application.Application) NonCodeSearchDescriptionLocation(com.intellij.refactoring.util.NonCodeSearchDescriptionLocation) PerlPluginBaseFileType(com.perl5.lang.perl.fileTypes.PerlPluginBaseFileType) InjectLanguageAction(org.intellij.plugins.intelliLang.inject.InjectLanguageAction) EditorColorsManager(com.intellij.openapi.editor.colors.EditorColorsManager) PerlSdkType(com.perl5.lang.perl.idea.sdk.PerlSdkType) IdeActions(com.intellij.openapi.actionSystem.IdeActions) PerlImplicitVariablesProvider(com.perl5.lang.perl.extensions.PerlImplicitVariablesProvider) InjectedFileViewProvider(com.intellij.psi.impl.source.tree.injected.InjectedFileViewProvider) LookupElementPresentation(com.intellij.codeInsight.lookup.LookupElementPresentation) Disposer(com.intellij.openapi.util.Disposer) CommonDataKeys(com.intellij.openapi.actionSystem.CommonDataKeys) MultiMap(com.intellij.util.containers.MultiMap) Method(java.lang.reflect.Method) SelectWordHandler(com.intellij.codeInsight.editorActions.SelectWordHandler) CompletionType(com.intellij.codeInsight.completion.CompletionType) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) Collectors(java.util.stream.Collectors) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) Nullable(org.jetbrains.annotations.Nullable) Function(com.intellij.util.Function) ApplicationManager(com.intellij.openapi.application.ApplicationManager) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) com.intellij.psi(com.intellij.psi) NotNull(org.jetbrains.annotations.NotNull) PerlProjectManager(com.perl5.lang.perl.idea.project.PerlProjectManager) DataContext(com.intellij.openapi.actionSystem.DataContext) TemplateManagerImpl(com.intellij.codeInsight.template.impl.TemplateManagerImpl) ContainerUtil(com.intellij.util.containers.ContainerUtil) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) com.intellij.ide.util.treeView.smartTree(com.intellij.ide.util.treeView.smartTree) PerlVersion(com.perl5.lang.perl.internals.PerlVersion) PerlItemPresentationBase(com.perl5.lang.perl.idea.presentations.PerlItemPresentationBase) PerlStringMixin(com.perl5.lang.perl.psi.mixins.PerlStringMixin) DataManager(com.intellij.ide.DataManager) ProjectJdkImpl(com.intellij.openapi.projectRoots.impl.ProjectJdkImpl) StructureView(com.intellij.ide.structureView.StructureView) CodeInsightTestFixtureImpl(com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl) LookupElement(com.intellij.codeInsight.lookup.LookupElement) StructureViewTreeElement(com.intellij.ide.structureView.StructureViewTreeElement) PerlStringBareMixin(com.perl5.lang.perl.psi.mixins.PerlStringBareMixin) DeleteTypeDescriptionLocation(com.intellij.ide.util.DeleteTypeDescriptionLocation) EditorWindow(com.intellij.injected.editor.EditorWindow) Perl5CodeInsightSettings(com.perl5.lang.perl.idea.codeInsight.Perl5CodeInsightSettings) CodeStyleManager(com.intellij.psi.codeStyle.CodeStyleManager) LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) com.intellij.usageView(com.intellij.usageView) TargetElementUtil(com.intellij.codeInsight.TargetElementUtil) ExpandLiveTemplateByTabAction(com.intellij.codeInsight.template.impl.editorActions.ExpandLiveTemplateByTabAction) ObjectUtils(com.intellij.util.ObjectUtils) TemplateState(com.intellij.codeInsight.template.impl.TemplateState) javax.swing(javax.swing) ASTNode(com.intellij.lang.ASTNode)

Example 13 with PerlSubDefinitionElement

use of com.perl5.lang.perl.psi.PerlSubDefinitionElement in project Perl5-IDEA by Camelcade.

the class MethodsDetectionTest method doTest.

public void doTest(boolean result) {
    initWithFileSmart(getTestName(false).toLowerCase());
    PsiFile file = myFixture.getFile();
    assertNotNull(file);
    PerlSubDefinitionElement subDefinition = PsiTreeUtil.findChildOfType(file, PerlSubDefinitionElement.class);
    assertNotNull(subDefinition);
    if (result) {
        assertTrue(subDefinition.isMethod());
    } else {
        assertFalse(subDefinition.isMethod());
    }
}
Also used : PsiFile(com.intellij.psi.PsiFile) PerlSubDefinitionElement(com.perl5.lang.perl.psi.PerlSubDefinitionElement)

Example 14 with PerlSubDefinitionElement

use of com.perl5.lang.perl.psi.PerlSubDefinitionElement in project Perl5-IDEA by Camelcade.

the class PerlArgsExtractionTest method doTest.

protected void doTest(String fileName, String argsString) {
    initWithFileSmart(fileName);
    PsiElement elementAtCaret = myFixture.getElementAtCaret();
    assertNotNull(elementAtCaret);
    PerlSubDefinitionElement subBase = PsiTreeUtil.getParentOfType(elementAtCaret, PerlSubDefinitionElement.class, false);
    assertNotNull(subBase);
    assertEquals(argsString, subBase.getSubArgumentsListAsString());
}
Also used : PerlSubDefinitionElement(com.perl5.lang.perl.psi.PerlSubDefinitionElement) PsiElement(com.intellij.psi.PsiElement)

Example 15 with PerlSubDefinitionElement

use of com.perl5.lang.perl.psi.PerlSubDefinitionElement in project Perl5-IDEA by Camelcade.

the class PerlPackageUtil method processNotOverridedMethods.

public static void processNotOverridedMethods(final PerlNamespaceDefinitionElement namespaceDefinition, Processor<PerlSubElement> processor) {
    if (namespaceDefinition != null) {
        PsiFile containingFile = namespaceDefinition.getContainingFile();
        String packageName = namespaceDefinition.getPackageName();
        if (packageName == null) {
            return;
        }
        Set<String> namesSet = new THashSet<>();
        // collecting overrided
        for (PerlSubDefinitionElement subDefinitionBase : PsiTreeUtil.findChildrenOfType(containingFile, PerlSubDefinitionElement.class)) {
            if (subDefinitionBase.isValid() && StringUtil.equals(packageName, subDefinitionBase.getPackageName())) {
                namesSet.add(subDefinitionBase.getSubName());
            }
        }
        processParentClassesSubs(namespaceDefinition, namesSet, new THashSet<>(), processor);
    }
}
Also used : PsiFile(com.intellij.psi.PsiFile) PerlSubDefinitionElement(com.perl5.lang.perl.psi.PerlSubDefinitionElement) THashSet(gnu.trove.THashSet)

Aggregations

PsiElement (com.intellij.psi.PsiElement)10 PerlSubDefinitionElement (com.perl5.lang.perl.psi.PerlSubDefinitionElement)10 NotNull (org.jetbrains.annotations.NotNull)8 PsiFile (com.intellij.psi.PsiFile)6 ArrayList (java.util.ArrayList)5 Project (com.intellij.openapi.project.Project)4 ResolveResult (com.intellij.psi.ResolveResult)4 PsiElementResolveResult (com.intellij.psi.PsiElementResolveResult)3 PerlExportDescriptor (com.perl5.lang.perl.extensions.packageprocessor.PerlExportDescriptor)3 PerlSubElement (com.perl5.lang.perl.psi.PerlSubElement)3 THashSet (gnu.trove.THashSet)3 StructureViewTreeElement (com.intellij.ide.structureView.StructureViewTreeElement)2 PerlSubDeclarationElement (com.perl5.lang.perl.psi.PerlSubDeclarationElement)2 PerlDelegatingLightNamedElement (com.perl5.lang.perl.psi.light.PerlDelegatingLightNamedElement)2 Nullable (org.jetbrains.annotations.Nullable)2 TargetElementUtil (com.intellij.codeInsight.TargetElementUtil)1 CompletionType (com.intellij.codeInsight.completion.CompletionType)1 SelectWordHandler (com.intellij.codeInsight.editorActions.SelectWordHandler)1 HighlightUsagesAction (com.intellij.codeInsight.highlighting.actions.HighlightUsagesAction)1 IntentionAction (com.intellij.codeInsight.intention.IntentionAction)1