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;
}
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");
}
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]);
}
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);
}
Aggregations