use of com.intellij.psi.JavaPsiFacade in project intellij-community by JetBrains.
the class PyJavaImportResolver method resolveImportReference.
@Nullable
public PsiElement resolveImportReference(QualifiedName name, PyQualifiedNameResolveContext context, boolean withRoots) {
String fqn = name.toString();
final JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(context.getProject());
final PsiPackage aPackage = psiFacade.findPackage(fqn);
if (aPackage != null) {
return aPackage;
}
Module module = context.getModule();
if (module != null) {
final PsiClass aClass = psiFacade.findClass(fqn, module.getModuleWithDependenciesAndLibrariesScope(false));
if (aClass != null)
return aClass;
}
return null;
}
use of com.intellij.psi.JavaPsiFacade in project intellij-community by JetBrains.
the class MvcTargetDialogCompletionUtils method completeClassesAndPackages.
public static List<LookupElement> completeClassesAndPackages(@NotNull String prefix, @NotNull GlobalSearchScope scope) {
if (scope.getProject() == null)
return Collections.emptyList();
JavaPsiFacade facade = JavaPsiFacade.getInstance(scope.getProject());
final List<LookupElement> res = new ArrayList<>();
// Complete class names if prefix is a package name with dot at end.
if (prefix.endsWith(".") && prefix.length() > 1) {
PsiPackage p = facade.findPackage(prefix.substring(0, prefix.length() - 1));
if (p != null) {
for (PsiClass aClass : p.getClasses(scope)) {
String qualifiedName = aClass.getQualifiedName();
if (qualifiedName != null) {
res.add(LookupElementBuilder.create(aClass, qualifiedName));
}
}
}
}
PsiPackage defaultPackage = facade.findPackage("");
if (defaultPackage != null) {
collectClassesAndPackageNames(res, defaultPackage, scope);
}
return res;
}
use of com.intellij.psi.JavaPsiFacade in project intellij-community by JetBrains.
the class SuppressExternalTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
final IdeaTestFixtureFactory fixtureFactory = IdeaTestFixtureFactory.getFixtureFactory();
final TestFixtureBuilder<IdeaProjectTestFixture> testFixtureBuilder = fixtureFactory.createFixtureBuilder(getName());
myFixture = JavaTestFixtureFactory.getFixtureFactory().createCodeInsightFixture(testFixtureBuilder.getFixture());
myFixture.setTestDataPath(PathManagerEx.getTestDataPath() + "/codeInsight/externalAnnotations");
final JavaModuleFixtureBuilder builder = testFixtureBuilder.addModule(JavaModuleFixtureBuilder.class);
new File(myFixture.getTempDirPath() + "/src/").mkdir();
builder.addContentRoot(myFixture.getTempDirPath()).addSourceRoot("src");
builder.setMockJdkLevel(JavaModuleFixtureBuilder.MockJdkLevel.jdk15);
myFixture.setUp();
myFixture.enableInspections(new SillyAssignmentInspection());
addAnnotationsModuleRoot();
final JavaPsiFacade facade = JavaPsiFacade.getInstance(myFixture.getProject());
myLanguageLevel = LanguageLevelProjectExtension.getInstance(facade.getProject()).getLanguageLevel();
LanguageLevelProjectExtension.getInstance(facade.getProject()).setLanguageLevel(LanguageLevel.JDK_1_5);
}
use of com.intellij.psi.JavaPsiFacade in project intellij-community by JetBrains.
the class DescriptionCheckerUtil method allDescriptionDirs.
/**
* Unlike getDescriptionsDirs this includes dirs in dependent modules and even project dirs ordered by
* search scopes (first dirs in current module, then dirs in module dependencies, then dirs in
* dependent modules, finally other project dirs).
*
* @param module module to search description directories for
* @param descriptionType type of description directory to search
* @return lazily populated stream of candidate directories
*/
public static StreamEx<PsiDirectory> allDescriptionDirs(Module module, DescriptionType descriptionType) {
final JavaPsiFacade javaPsiFacade = JavaPsiFacade.getInstance(module.getProject());
final PsiPackage psiPackage = javaPsiFacade.findPackage(descriptionType.getDescriptionFolder());
if (psiPackage == null)
return StreamEx.empty();
return searchScopes(module).flatMap(scope -> StreamEx.of(psiPackage.getDirectories(scope))).distinct();
}
use of com.intellij.psi.JavaPsiFacade in project intellij-community by JetBrains.
the class LocationUtil method isJarAttached.
public static boolean isJarAttached(@NotNull Location location, final PsiDirectory[] directories, final String... fqns) {
final JavaPsiFacade facade = JavaPsiFacade.getInstance(location.getProject());
final Module locationModule = location.getModule();
if (locationModule != null) {
for (String fqn : fqns) {
if (facade.findClass(fqn, GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(locationModule, true)) != null)
return true;
}
} else {
for (PsiDirectory directory : directories) {
final Module module = ModuleUtilCore.findModuleForFile(directory.getVirtualFile(), location.getProject());
if (module != null) {
GlobalSearchScope scope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module, true);
for (String fqn : fqns) {
if (facade.findClass(fqn, scope) != null) {
return true;
}
}
}
}
}
return false;
}
Aggregations