Search in sources :

Example 31 with PsiPackage

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

the class PackageWrapper method getDirectories.

public PsiDirectory[] getDirectories() {
    String qName = myQualifiedName;
    while (qName.endsWith(".")) {
        qName = StringUtil.trimEnd(qName, ".");
    }
    final PsiPackage aPackage = JavaPsiFacade.getInstance(myManager.getProject()).findPackage(qName);
    if (aPackage != null) {
        return aPackage.getDirectories();
    } else {
        return PsiDirectory.EMPTY_ARRAY;
    }
}
Also used : PsiPackage(com.intellij.psi.PsiPackage)

Example 32 with PsiPackage

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

the class JamConventionLightTestCase method getPackageJam.

/**
   * Gets the JAM-element for the given package.
   *
   * @param packageName FQN of package.
   * @param meta        JAM-Meta.
   * @param <Jam>       JAM-Type.
   * @return JAM.
   */
@NotNull
protected <Jam extends JamElement> Jam getPackageJam(final String packageName, final JamPackageMeta<Jam> meta) {
    final PsiPackage myPackage = myFixture.findPackage(packageName);
    assertNotNull(packageName, myPackage);
    final Jam jam = meta.getJamElement(myPackage);
    assertNotNull("JAM was null for " + meta + " in '" + packageName + "'", jam);
    return jam;
}
Also used : PsiPackage(com.intellij.psi.PsiPackage) NotNull(org.jetbrains.annotations.NotNull)

Example 33 with PsiPackage

use of com.intellij.psi.PsiPackage in project ServiceStack.Java by ServiceStack.

the class AddServiceStackRefHandler method getDtoPath.

private static String getDtoPath(Module module, String qualifiedPackageName, String selectedDirectory, String fileName, StringBuilder errorMessage) throws FileNotFoundException {
    VirtualFile moduleFile = module.getModuleFile();
    if (moduleFile == null) {
        throw new FileNotFoundException("Module file not found. Unable to add DTO to project.");
    }
    String fullDtoPath;
    PsiPackage mainPackage = JavaPsiFacade.getInstance(module.getProject()).findPackage(qualifiedPackageName);
    if (mainPackage != null && mainPackage.isValid() && mainPackage.getDirectories().length > 0) {
        File file = new File(selectedDirectory);
        VirtualFile selectedFolder = LocalFileSystem.getInstance().findFileByIoFile(file);
        if (selectedFolder == null) {
            errorMessage.append("Unable to determine path for DTO file.");
            throw new FileNotFoundException();
        }
        PsiDirectory rootPackageDir = PsiManager.getInstance(module.getProject()).findDirectory(selectedFolder);
        if (rootPackageDir == null) {
            errorMessage.append("Unable to determine path for DTO file.");
            throw new FileNotFoundException();
        }
        fullDtoPath = rootPackageDir.getVirtualFile().getPath() + File.separator + getDtoFileName(fileName);
    } else {
        String moduleSourcePath;
        if (moduleFile.getParent() == null) {
            moduleSourcePath = moduleFile.getPath() + "/main/java";
        } else {
            moduleSourcePath = moduleFile.getParent().getPath() + "/src/main/java";
        }
        fullDtoPath = moduleSourcePath + File.separator + getDtoFileName(fileName);
    }
    return fullDtoPath;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiDirectory(com.intellij.psi.PsiDirectory) PsiPackage(com.intellij.psi.PsiPackage) VirtualFile(com.intellij.openapi.vfs.VirtualFile)

Example 34 with PsiPackage

use of com.intellij.psi.PsiPackage in project moe-ide-integration by multi-os-engine.

the class MOEJUnitUtil method checkConfiguration.

public static void checkConfiguration(Module module, int TESTING_TYPE, String PACKAGE_NAME, String CLASS_NAME) throws RuntimeConfigurationException {
    JavaPsiFacade facade = JavaPsiFacade.getInstance(module.getProject());
    switch(TESTING_TYPE) {
        case TEST_ALL_IN_PACKAGE:
            if (PACKAGE_NAME == null || PACKAGE_NAME.isEmpty()) {
                throw new RuntimeConfigurationWarning("No test package specified");
            }
            final PsiPackage testPackage = facade.findPackage(PACKAGE_NAME);
            if (testPackage == null) {
                throw new RuntimeConfigurationWarning(ExecutionBundle.message("package.does.not.exist.error.message", PACKAGE_NAME));
            }
            Vector<PsiClass> packageTestClasses = MOEJUnitUtil.getTestClasses(module, PACKAGE_NAME);
            if (packageTestClasses == null || packageTestClasses.size() == 0) {
                throw new RuntimeConfigurationWarning("Not found test class in package: " + PACKAGE_NAME);
            }
            break;
        case TEST_CLASS:
            JavaRunConfigurationModule configurationModule = new JavaRunConfigurationModule(module.getProject(), false);
            configurationModule.setModule(module);
            final PsiClass testClass = configurationModule.checkModuleAndClassName(CLASS_NAME, ExecutionBundle.message("no.test.class.specified.error.text"));
            if (!JUnitUtil.isTestClass(testClass)) {
                throw new RuntimeConfigurationWarning(ExecutionBundle.message("class.isnt.test.class.error.message", CLASS_NAME));
            }
            break;
        case TEST_METHOD:
            // Already not used
            break;
    }
}
Also used : JavaPsiFacade(com.intellij.psi.JavaPsiFacade) RuntimeConfigurationWarning(com.intellij.execution.configurations.RuntimeConfigurationWarning) PsiClass(com.intellij.psi.PsiClass) PsiPackage(com.intellij.psi.PsiPackage) JavaRunConfigurationModule(com.intellij.execution.configurations.JavaRunConfigurationModule)

Example 35 with PsiPackage

use of com.intellij.psi.PsiPackage in project google-cloud-intellij by GoogleCloudPlatform.

the class AppEngineWebSchemaProvider method getSchema.

@Override
public XmlFile getSchema(@NotNull @NonNls String url, @Nullable Module module, @NotNull PsiFile baseFile) {
    if (module == null) {
        return null;
    }
    if (url.startsWith("http://appengine.google.com/ns/")) {
        AppEngineStandardFacet facet = AppEngineStandardFacet.getAppEngineFacetByModule(module);
        if (facet != null) {
            final File file = CloudSdkInternals.getInstance().getWebSchemeFile();
            if (file == null) {
                return null;
            }
            final VirtualFile virtualFile = LocalFileSystem.getInstance().findFileByIoFile(file);
            if (virtualFile != null) {
                final PsiFile psiFile = PsiManager.getInstance(module.getProject()).findFile(virtualFile);
                if (psiFile instanceof XmlFile) {
                    return (XmlFile) psiFile;
                }
            }
        }
    } else if (url.startsWith("http://java.sun.com/xml/ns/jdo/jdoconfig")) {
        final PsiPackage jdoPackage = JavaPsiFacade.getInstance(module.getProject()).findPackage("javax.jdo");
        final GlobalSearchScope scope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module);
        if (jdoPackage != null) {
            for (PsiDirectory directory : jdoPackage.getDirectories(scope)) {
                final PsiFile file = directory.findFile("jdoconfig_2_3.xsd");
                if (file instanceof XmlFile) {
                    return (XmlFile) file;
                }
            }
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) XmlFile(com.intellij.psi.xml.XmlFile) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiDirectory(com.intellij.psi.PsiDirectory) AppEngineStandardFacet(com.google.cloud.tools.intellij.appengine.facet.standard.AppEngineStandardFacet) PsiFile(com.intellij.psi.PsiFile) PsiPackage(com.intellij.psi.PsiPackage) XmlFile(com.intellij.psi.xml.XmlFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) PsiFile(com.intellij.psi.PsiFile)

Aggregations

PsiPackage (com.intellij.psi.PsiPackage)93 PsiDirectory (com.intellij.psi.PsiDirectory)24 PsiClass (com.intellij.psi.PsiClass)22 Module (com.intellij.openapi.module.Module)19 Project (com.intellij.openapi.project.Project)14 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)14 VirtualFile (com.intellij.openapi.vfs.VirtualFile)13 JavaAnalysisScope (com.intellij.analysis.JavaAnalysisScope)12 PsiFile (com.intellij.psi.PsiFile)12 PsiElement (com.intellij.psi.PsiElement)11 JavaPsiFacade (com.intellij.psi.JavaPsiFacade)10 NotNull (org.jetbrains.annotations.NotNull)10 CyclicDependenciesBuilder (com.intellij.cyclicDependencies.CyclicDependenciesBuilder)9 Nullable (org.jetbrains.annotations.Nullable)9 AnalysisScope (com.intellij.analysis.AnalysisScope)8 HashSet (java.util.HashSet)6 List (java.util.List)5 LookupElement (com.intellij.codeInsight.lookup.LookupElement)4 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)4 ArrayList (java.util.ArrayList)4