Search in sources :

Example 76 with PsiPackage

use of com.intellij.psi.PsiPackage in project android by JetBrains.

the class DataBindingProjectComponent method getOrCreateDataBindingPsiPackage.

/**
   * Returns a {@linkplain PsiPackage} instance for the given package name.
   * <p>
   * If it does not exist in the cache, a new one is created.
   *
   * @param packageName The qualified package name
   * @return A {@linkplain PsiPackage} that represents the given qualified name
   */
public synchronized PsiPackage getOrCreateDataBindingPsiPackage(String packageName) {
    PsiPackage pkg = myDataBindingPsiPackages.get(packageName);
    if (pkg == null) {
        pkg = new PsiPackageImpl(PsiManager.getInstance(myProject), packageName) {

            @Override
            public boolean isValid() {
                return true;
            }
        };
        myDataBindingPsiPackages.put(packageName, pkg);
    }
    return pkg;
}
Also used : PsiPackageImpl(com.intellij.psi.impl.file.PsiPackageImpl) PsiPackage(com.intellij.psi.PsiPackage)

Example 77 with PsiPackage

use of com.intellij.psi.PsiPackage in project android by JetBrains.

the class AndroidMultiModuleRenameTest method testLibraryPackageRename.

// Check that renaming package in a library module would rename corresponding reference in AndroidManifest.xml
public void testLibraryPackageRename() throws Exception {
    final VirtualFile manifestFile = myFixture.copyFileToProject("rename/AndroidManifest_library_before.xml", LIBRARY_PATH + "/src/AndroidManifest.xml");
    myFixture.configureFromExistingVirtualFile(manifestFile);
    // At least one Java source has to be copied for .findPackage to return non-null instance
    myFixture.copyFileToProject("rename/LibraryClass.java", LIBRARY_PATH + "/src/com/works/customization/my/library/LibraryClass.java");
    final PsiPackage aPackage = JavaPsiFacade.getInstance(getProject()).findPackage("com.works.customization.my.library");
    assertNotNull(aPackage);
    new RenameProcessor(getProject(), aPackage, "com.works.customization.my.library2", true, true).run();
    FileDocumentManager.getInstance().saveAllDocuments();
    myFixture.checkResultByFile("rename/AndroidManifest_library_after.xml");
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) RenameProcessor(com.intellij.refactoring.rename.RenameProcessor) PsiPackage(com.intellij.psi.PsiPackage)

Example 78 with PsiPackage

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

the class BasePackageParser method getPackageReferences.

protected static PsiReference[] getPackageReferences(PsiElement psiElement) {
    String packageName = psiElement.getText();
    if (StringUtil.isEmptyOrSpaces(packageName)) {
        return PsiReference.EMPTY_ARRAY;
    }
    int offset = 0;
    if (packageName.charAt(0) == '!') {
        packageName = packageName.substring(1);
        offset = 1;
    }
    int size = packageName.length() - 1;
    if (packageName.charAt(size) == '?') {
        packageName = packageName.substring(0, size);
    }
    PackageReferenceSet refSet = new PackageReferenceSet(packageName, psiElement, offset) {

        @Override
        public Collection<PsiPackage> resolvePackageName(@Nullable PsiPackage context, String packageName) {
            if (context == null)
                return Collections.emptyList();
            String unwrappedPackageName = packageName.replaceAll("\\s+", "");
            return ContainerUtil.filter(context.getSubPackages(), pkg -> unwrappedPackageName.equals(pkg.getName()));
        }
    };
    return refSet.getReferences().toArray(new PsiPackageReference[0]);
}
Also used : PackageReferenceSet(com.intellij.psi.impl.source.resolve.reference.impl.providers.PackageReferenceSet) PsiPackage(com.intellij.psi.PsiPackage) Nullable(org.jetbrains.annotations.Nullable)

Example 79 with PsiPackage

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

the class StrutsConstantValueReference method getVariants.

@NotNull
@SuppressWarnings({ "unchecked" })
public Object[] getVariants() {
    if (elementConverterPair == null) {
        return ArrayUtil.EMPTY_OBJECT_ARRAY;
    }
    final Converter converter = elementConverterPair.second;
    if (!(converter instanceof ResolvingConverter)) {
        return ArrayUtil.EMPTY_OBJECT_ARRAY;
    }
    final ResolvingConverter resolvingConverter = (ResolvingConverter) converter;
    // merge "normal" + additional variants
    final DomElement paramValueElement = elementConverterPair.first;
    final ConvertContext convertContext = ConvertContextFactory.createConvertContext(paramValueElement);
    // wrap explicitly for empty list
    final Collection converterVariants = new ArrayList(resolvingConverter.getVariants(convertContext));
    final Collection variants;
    if (!converterVariants.isEmpty() && converterVariants.iterator().next() instanceof DomElement) {
        variants = Arrays.asList(ElementPresentationManager.getInstance().createVariants(converterVariants));
    } else {
        variants = converterVariants;
    }
    variants.addAll(resolvingConverter.getAdditionalVariants(convertContext));
    // add custom created references
    if (resolvingConverter instanceof CustomReferenceConverter) {
        final PsiReference[] references = ((CustomReferenceConverter) resolvingConverter).createReferences((GenericDomValue) paramValueElement, myElement, convertContext);
        for (final PsiReference customReference : references) {
            if (customReference instanceof JavaClassReference) {
                JavaClassReference javaClassReference = (JavaClassReference) customReference;
                String[] names = javaClassReference.getExtendClassNames();
                PsiElement context = javaClassReference.getCompletionContext();
                if (names != null && context instanceof PsiPackage) {
                    javaClassReference.processSubclassVariants((PsiPackage) context, names, element -> variants.add(element));
                    continue;
                }
            }
            Collections.addAll(variants, customReference.getVariants());
        }
    }
    return ArrayUtil.toObjectArray(variants);
}
Also used : JavaClassReference(com.intellij.psi.impl.source.resolve.reference.impl.providers.JavaClassReference) PsiReference(com.intellij.psi.PsiReference) PsiPackage(com.intellij.psi.PsiPackage) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

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