use of com.intellij.psi.PsiPackage in project intellij-community by JetBrains.
the class PackagePrefixElementFinder method getSubPackages.
@NotNull
@Override
public PsiPackage[] getSubPackages(@NotNull PsiPackage psiPackage, @NotNull GlobalSearchScope scope) {
final Map<String, PsiPackage> packagesMap = new HashMap<>();
final String qualifiedName = psiPackage.getQualifiedName();
for (final String prefix : myPackagePrefixIndex.getAllPackagePrefixes(scope)) {
if (StringUtil.isEmpty(qualifiedName) || StringUtil.startsWithConcatenation(prefix, qualifiedName, ".")) {
final int i = prefix.indexOf('.', qualifiedName.length() + 1);
String childName = i >= 0 ? prefix.substring(0, i) : prefix;
if (!packagesMap.containsKey(childName)) {
packagesMap.put(childName, new PsiPackageImpl(psiPackage.getManager(), childName));
}
}
}
// avoid SOE caused by returning a package as a subpackage of itself
packagesMap.remove(qualifiedName);
return packagesMap.values().toArray(new PsiPackage[packagesMap.size()]);
}
use of com.intellij.psi.PsiPackage in project intellij-community by JetBrains.
the class JavaClassListReferenceProvider method getReferencesByString.
@Override
@NotNull
public PsiReference[] getReferencesByString(String str, @NotNull final PsiElement position, int offsetInPosition) {
if (position instanceof XmlTag && ((XmlTag) position).getValue().getTextElements().length == 0) {
return PsiReference.EMPTY_ARRAY;
}
if (str.length() < 2) {
return PsiReference.EMPTY_ARRAY;
}
int offset = position.getTextRange().getStartOffset() + offsetInPosition;
for (PsiElement child = position.getFirstChild(); child != null; child = child.getNextSibling()) {
if (child instanceof OuterLanguageElement && child.getTextRange().contains(offset)) {
return PsiReference.EMPTY_ARRAY;
}
}
NotNullLazyValue<Set<String>> topLevelPackages = new NotNullLazyValue<Set<String>>() {
@NotNull
@Override
protected Set<String> compute() {
final Set<String> knownTopLevelPackages = new HashSet<>();
final List<PsiElement> defaultPackages = getDefaultPackages(position.getProject());
for (final PsiElement pack : defaultPackages) {
if (pack instanceof PsiPackage) {
knownTopLevelPackages.add(((PsiPackage) pack).getName());
}
}
return knownTopLevelPackages;
}
};
final List<PsiReference> results = new ArrayList<>();
for (int dot = str.indexOf('.'); dot > 0; dot = str.indexOf('.', dot + 1)) {
int start = dot;
while (start > 0 && Character.isLetterOrDigit(str.charAt(start - 1))) start--;
if (dot == start) {
continue;
}
String candidate = str.substring(start, dot);
if (topLevelPackages.getValue().contains(candidate)) {
int end = dot;
while (end < str.length() - 1) {
end++;
char ch = str.charAt(end);
if (ch != '.' && !Character.isJavaIdentifierPart(ch)) {
break;
}
}
String s = str.substring(start, end + 1);
ContainerUtil.addAll(results, new JavaClassReferenceSet(s, position, offsetInPosition + start, false, this) {
@Override
public boolean isSoft() {
return true;
}
@Override
public boolean isAllowDollarInNames() {
return true;
}
}.getAllReferences());
ProgressManager.checkCanceled();
}
}
return ContainerUtil.toArray(results, new PsiReference[results.size()]);
}
use of com.intellij.psi.PsiPackage in project intellij-community by JetBrains.
the class PatternPackageReferenceSet method resolvePackageName.
@Override
public Collection<PsiPackage> resolvePackageName(@Nullable final PsiPackage context, final String packageName) {
if (context == null)
return Collections.emptySet();
if (packageName.contains("*")) {
final Set<PsiPackage> packages = new LinkedHashSet<>();
int indexOf = packageName.indexOf("*");
if (indexOf == 0 || context.getQualifiedName().startsWith(packageName.substring(0, indexOf))) {
final Pattern pattern = PatternUtil.fromMask(packageName);
processSubPackages(context, psiPackage -> {
String name = psiPackage.getName();
if (name != null && pattern.matcher(name).matches()) {
packages.add(psiPackage);
}
return true;
});
}
return packages;
}
return super.resolvePackageName(context, packageName);
}
use of com.intellij.psi.PsiPackage in project intellij-community by JetBrains.
the class PsiMigrationImpl method createClass.
@Override
public PsiClass createClass(String qualifiedName) {
assertValid();
ApplicationManager.getApplication().assertWriteAccessAllowed();
final MigrationClassImpl migrationClass = new MigrationClassImpl(this, qualifiedName);
final MigrationClassImpl oldMigrationClass = myQNameToClassMap.put(qualifiedName, migrationClass);
LOG.assertTrue(oldMigrationClass == null, qualifiedName);
String packageName = parentPackageName(qualifiedName);
final PsiPackage aPackage = myFacade.findPackage(packageName);
if (aPackage == null) {
createPackage(packageName);
}
List<PsiClass> psiClasses = getClassesList(packageName);
psiClasses.add(migrationClass);
myMigrationManager.migrationModified(false);
return migrationClass;
}
use of com.intellij.psi.PsiPackage in project intellij-community by JetBrains.
the class CyclicDependenciesTest method testNoCycle.
public void testNoCycle() {
//B->A
final CyclicDependenciesBuilder builder = new CyclicDependenciesBuilder(myProject, new AnalysisScope(myProject));
builder.analyze();
final HashMap<PsiPackage, Set<List<PsiPackage>>> cyclicDependencies = builder.getCyclicDependencies();
HashMap<String, String[][]> expected = new HashMap<>();
expected.put("com.b", new String[0][0]);
expected.put("com.a", new String[0][0]);
checkResult(expected, cyclicDependencies, true);
}
Aggregations