Search in sources :

Example 51 with PsiPackage

use of com.intellij.psi.PsiPackage in project intellij-community by JetBrains.

the class AbstractTestNGPackageConfigurationProducer method setupConfigurationFromContext.

@Override
protected boolean setupConfigurationFromContext(TestNGConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
    final PsiElement element = context.getPsiLocation();
    PsiPackage aPackage = JavaRuntimeConfigurationProducerBase.checkPackage(element);
    if (aPackage == null) {
        return false;
    }
    final Location location = context.getLocation();
    if (location == null) {
        return false;
    }
    if (!LocationUtil.isJarAttached(location, aPackage, TestNGUtil.TEST_ANNOTATION_FQN)) {
        return false;
    }
    final TestData data = configuration.data;
    data.PACKAGE_NAME = aPackage.getQualifiedName();
    data.TEST_OBJECT = TestType.PACKAGE.getType();
    data.setScope(setupPackageConfiguration(context, configuration, data.getScope()));
    configuration.setGeneratedName();
    sourceElement.set(aPackage);
    return true;
}
Also used : TestData(com.theoryinpractice.testng.model.TestData) PsiPackage(com.intellij.psi.PsiPackage) PsiElement(com.intellij.psi.PsiElement) Location(com.intellij.execution.Location)

Example 52 with PsiPackage

use of com.intellij.psi.PsiPackage in project intellij-community by JetBrains.

the class TestData method setMainClass.

public Module setMainClass(PsiClass psiclass) {
    MAIN_CLASS_NAME = JavaExecutionUtil.getRuntimeQualifiedName(psiclass);
    PsiPackage psipackage = JUnitUtil.getContainingPackage(psiclass);
    PACKAGE_NAME = psipackage == null ? "" : psipackage.getQualifiedName();
    return JavaExecutionUtil.findModule(psiclass);
}
Also used : PsiPackage(com.intellij.psi.PsiPackage)

Example 53 with PsiPackage

use of com.intellij.psi.PsiPackage in project intellij-community by JetBrains.

the class PackageBrowser method showDialog.

@Override
protected String showDialog() {
    PackageChooserDialog chooser = new PackageChooserDialog("Choose Package", getProject());
    chooser.show();
    PsiPackage psiPackage = chooser.getSelectedPackage();
    String packageName = psiPackage == null ? null : psiPackage.getQualifiedName();
    return packageName;
}
Also used : PackageChooserDialog(com.intellij.ide.util.PackageChooserDialog) PsiPackage(com.intellij.psi.PsiPackage)

Example 54 with PsiPackage

use of com.intellij.psi.PsiPackage in project intellij-community by JetBrains.

the class CompletionTestBase method doTest.

protected void doTest(String directory) {
    CamelHumpMatcher.forceStartMatching(myFixture.getTestRootDisposable());
    final List<String> stringList = TestUtils.readInput(getTestDataPath() + "/" + getTestName(true) + ".test");
    if (directory.length() != 0)
        directory += "/";
    final String fileName = directory + getTestName(true) + "." + getExtension();
    myFixture.addFileToProject(fileName, stringList.get(0));
    myFixture.configureByFile(fileName);
    boolean old = CodeInsightSettings.getInstance().AUTOCOMPLETE_COMMON_PREFIX;
    CodeInsightSettings.getInstance().AUTOCOMPLETE_COMMON_PREFIX = false;
    CodeInsightSettings.getInstance().AUTOCOMPLETE_ON_CODE_COMPLETION = false;
    String result = "";
    try {
        myFixture.completeBasic();
        final LookupImpl lookup = (LookupImpl) LookupManager.getActiveLookup(myFixture.getEditor());
        if (lookup != null) {
            List<LookupElement> items = lookup.getItems();
            if (!addReferenceVariants()) {
                items = ContainerUtil.findAll(items, lookupElement -> {
                    final Object o = lookupElement.getObject();
                    return !(o instanceof PsiMember) && !(o instanceof GrVariable) && !(o instanceof GroovyResolveResult) && !(o instanceof PsiPackage);
                });
            }
            Collections.sort(items, (o1, o2) -> o1.getLookupString().compareTo(o2.getLookupString()));
            result = "";
            for (LookupElement item : items) {
                result = result + "\n" + item.getLookupString();
            }
            result = result.trim();
            LookupManager.getInstance(myFixture.getProject()).hideActiveLookup();
        }
    } finally {
        CodeInsightSettings.getInstance().AUTOCOMPLETE_ON_CODE_COMPLETION = true;
        CodeInsightSettings.getInstance().AUTOCOMPLETE_COMMON_PREFIX = old;
    }
    assertEquals(StringUtil.trimEnd(stringList.get(1), "\n"), result);
}
Also used : PsiPackage(com.intellij.psi.PsiPackage) LookupImpl(com.intellij.codeInsight.lookup.impl.LookupImpl) PsiMember(com.intellij.psi.PsiMember) JavaCodeInsightFixtureTestCase(com.intellij.testFramework.fixtures.JavaCodeInsightFixtureTestCase) LookupElement(com.intellij.codeInsight.lookup.LookupElement) StringUtil(com.intellij.openapi.util.text.StringUtil) LookupManager(com.intellij.codeInsight.lookup.LookupManager) CodeInsightSettings(com.intellij.codeInsight.CodeInsightSettings) TestUtils(org.jetbrains.plugins.groovy.util.TestUtils) ContainerUtil(com.intellij.util.containers.ContainerUtil) GroovyResolveResult(org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult) List(java.util.List) GrVariable(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable) CamelHumpMatcher(com.intellij.codeInsight.completion.impl.CamelHumpMatcher) Collections(java.util.Collections) GrVariable(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable) LookupImpl(com.intellij.codeInsight.lookup.impl.LookupImpl) GroovyResolveResult(org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult) PsiPackage(com.intellij.psi.PsiPackage) LookupElement(com.intellij.codeInsight.lookup.LookupElement) PsiMember(com.intellij.psi.PsiMember)

Example 55 with PsiPackage

use of com.intellij.psi.PsiPackage in project intellij-community by JetBrains.

the class AbstractAllInDirectoryConfigurationProducer method setupConfigurationFromContext.

@Override
protected boolean setupConfigurationFromContext(JUnitConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
    final Project project = configuration.getProject();
    final PsiElement element = context.getPsiLocation();
    if (!(element instanceof PsiDirectory))
        return false;
    final PsiPackage aPackage = JavaRuntimeConfigurationProducerBase.checkPackage(element);
    if (aPackage == null)
        return false;
    final VirtualFile virtualFile = ((PsiDirectory) element).getVirtualFile();
    final Module module = ModuleUtilCore.findModuleForFile(virtualFile, project);
    if (module == null)
        return false;
    if (!ModuleRootManager.getInstance(module).getFileIndex().isInTestSourceContent(virtualFile))
        return false;
    int testRootCount = ModuleRootManager.getInstance(module).getSourceRoots(JavaSourceRootType.TEST_SOURCE).size();
    if (testRootCount < 2)
        return false;
    if (!LocationUtil.isJarAttached(context.getLocation(), aPackage, JUnitUtil.TESTCASE_CLASS))
        return false;
    setupConfigurationModule(context, configuration);
    final JUnitConfiguration.Data data = configuration.getPersistentData();
    data.setDirName(virtualFile.getPath());
    data.TEST_OBJECT = JUnitConfiguration.TEST_DIRECTORY;
    configuration.setGeneratedName();
    return true;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) PsiDirectory(com.intellij.psi.PsiDirectory) PsiPackage(com.intellij.psi.PsiPackage) Module(com.intellij.openapi.module.Module) PsiElement(com.intellij.psi.PsiElement)

Aggregations

PsiPackage (com.intellij.psi.PsiPackage)79 PsiDirectory (com.intellij.psi.PsiDirectory)17 Module (com.intellij.openapi.module.Module)16 PsiClass (com.intellij.psi.PsiClass)16 JavaAnalysisScope (com.intellij.analysis.JavaAnalysisScope)12 Project (com.intellij.openapi.project.Project)12 VirtualFile (com.intellij.openapi.vfs.VirtualFile)10 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)10 NotNull (org.jetbrains.annotations.NotNull)10 CyclicDependenciesBuilder (com.intellij.cyclicDependencies.CyclicDependenciesBuilder)9 PsiFile (com.intellij.psi.PsiFile)9 AnalysisScope (com.intellij.analysis.AnalysisScope)8 PsiElement (com.intellij.psi.PsiElement)8 JavaPsiFacade (com.intellij.psi.JavaPsiFacade)6 HashSet (java.util.HashSet)6 Nullable (org.jetbrains.annotations.Nullable)6 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)4 PackageElement (com.intellij.ide.projectView.impl.nodes.PackageElement)3 List (java.util.List)3 LookupElement (com.intellij.codeInsight.lookup.LookupElement)2