use of com.intellij.psi.search.GlobalSearchScope in project intellij-community by JetBrains.
the class PyAbstractTestProcessRunner method assertAllTestsAreResolved.
/**
* Ensures all test locations are resolved (i.e. user may click on test and navigate to it)
* All tests are checked but [root] (it never resolves).
*/
public final void assertAllTestsAreResolved(@NotNull final Project project) {
final List<SMTestProxy> allTests = getTestProxy().getAllTests();
assert !allTests.isEmpty() : "No tests at all.";
final GlobalSearchScope scope = GlobalSearchScope.allScope(project);
EdtTestUtil.runInEdtAndWait(() -> allTests.subList(1, allTests.size()).forEach(t -> Assert.assertNotNull("No location " + t, t.getLocation(project, scope))));
}
use of com.intellij.psi.search.GlobalSearchScope in project intellij-community by JetBrains.
the class CompleteReferenceExpression method getVariantsFromQualifier.
private void getVariantsFromQualifier(@NotNull GrExpression qualifier) {
Project project = qualifier.getProject();
final PsiType qualifierType = TypesUtil.boxPrimitiveType(qualifier.getType(), qualifier.getManager(), qualifier.getResolveScope());
final ResolveState state = ResolveState.initial();
if (qualifierType == null || PsiType.VOID.equals(qualifierType)) {
if (qualifier instanceof GrReferenceExpression) {
PsiElement resolved = ((GrReferenceExpression) qualifier).resolve();
if (resolved instanceof PsiPackage || resolved instanceof PsiVariable) {
resolved.processDeclarations(myProcessor, state, null, myRefExpr);
return;
}
}
getVariantsFromQualifierType(TypesUtil.getJavaLangObject(qualifier), project);
} else if (qualifierType instanceof PsiIntersectionType) {
for (PsiType conjunct : ((PsiIntersectionType) qualifierType).getConjuncts()) {
getVariantsFromQualifierType(conjunct, project);
}
} else if (qualifierType instanceof GrTraitType) {
// Process trait type conjuncts in reversed order because last applied trait matters.
PsiType[] conjuncts = ((GrTraitType) qualifierType).getConjuncts();
for (int i = conjuncts.length - 1; i >= 0; i--) {
getVariantsFromQualifierType(conjuncts[i], project);
}
} else {
getVariantsFromQualifierType(qualifierType, project);
if (qualifier instanceof GrReferenceExpression && !PsiUtil.isSuperReference(qualifier) && !PsiUtil.isInstanceThisRef(qualifier)) {
PsiElement resolved = ((GrReferenceExpression) qualifier).resolve();
if (resolved instanceof PsiClass) {
////omitted .class
GlobalSearchScope scope = myRefExpr.getResolveScope();
PsiClass javaLangClass = PsiUtil.getJavaLangClass(resolved, scope);
if (javaLangClass != null) {
PsiSubstitutor substitutor = PsiSubstitutor.EMPTY;
PsiTypeParameter[] typeParameters = javaLangClass.getTypeParameters();
if (typeParameters.length == 1) {
substitutor = substitutor.put(typeParameters[0], qualifierType);
}
PsiType javaLangClassType = JavaPsiFacade.getElementFactory(myRefExpr.getProject()).createType(javaLangClass, substitutor);
ResolveUtil.processAllDeclarations(javaLangClassType, myProcessor, state, myRefExpr);
}
}
}
}
}
use of com.intellij.psi.search.GlobalSearchScope in project intellij-community by JetBrains.
the class MavenClasspathsAndSearchScopesTest method testLibraryScopeForTwoDependentModules.
public void testLibraryScopeForTwoDependentModules() throws IOException {
VirtualFile m1 = createModulePom("m1", "<groupId>test</groupId>" + "<artifactId>m1</artifactId>" + "<version>1</version>" + "<dependencies>" + " <dependency>" + " <groupId>test</groupId>" + " <artifactId>m2</artifactId>" + " <version>1</version>" + " </dependency>" + "</dependencies>");
VirtualFile m2 = createModulePom("m2", "<groupId>test</groupId>" + "<artifactId>m2</artifactId>" + "<version>1</version>" + " <dependencies>" + " <dependency>" + " <groupId>junit</groupId>" + " <artifactId>junit</artifactId>" + " <version>4.0</version>" + " <scope>provided</scope>" + " </dependency>" + " </dependencies>");
importProjects(m1, m2);
assertModules("m1", "m2");
Module m1m = ModuleManager.getInstance(myProject).findModuleByName("m1");
List<OrderEntry> modules1 = new ArrayList<>();
ModuleRootManager.getInstance(m1m).orderEntries().withoutSdk().withoutModuleSourceEntries().forEach(new CommonProcessors.CollectProcessor<>(modules1));
GlobalSearchScope scope1 = LibraryScopeCache.getInstance(myProject).getLibraryScope(modules1);
assertSearchScope(scope1, getProjectPath() + "/m1/src/main/java", getProjectPath() + "/m1/src/test/java", getProjectPath() + "/m2/src/main/java", getProjectPath() + "/m2/src/test/java");
String libraryPath = getRepositoryPath() + "/junit/junit/4.0/junit-4.0.jar";
String librarySrcPath = getRepositoryPath() + "/junit/junit/4.0/junit-4.0-sources.jar";
Module m2m = ModuleManager.getInstance(myProject).findModuleByName("m2");
List<OrderEntry> modules2 = new ArrayList<>();
ModuleRootManager.getInstance(m2m).orderEntries().withoutSdk().withoutModuleSourceEntries().forEach(new CommonProcessors.CollectProcessor<>(modules2));
GlobalSearchScope scope2 = LibraryScopeCache.getInstance(myProject).getLibraryScope(modules2);
List<String> expectedPaths = ContainerUtil.newArrayList(getProjectPath() + "/m2/src/main/java", getProjectPath() + "/m2/src/test/java", libraryPath);
if (new File(librarySrcPath).exists()) {
expectedPaths.add(librarySrcPath);
}
assertSearchScope(scope2, ArrayUtil.toStringArray(expectedPaths));
}
use of com.intellij.psi.search.GlobalSearchScope in project kotlin by JetBrains.
the class AbstractLoadJavaTest method doTestJavaAgainstKotlin.
protected void doTestJavaAgainstKotlin(String expectedFileName) throws Exception {
File expectedFile = new File(expectedFileName);
File sourcesDir = new File(expectedFileName.replaceFirst("\\.txt$", ""));
FileUtil.copyDir(sourcesDir, new File(tmpdir, "test"), new FileFilter() {
@Override
public boolean accept(@NotNull File pathname) {
return pathname.getName().endsWith(".java");
}
});
CompilerConfiguration configuration = KotlinTestUtils.newConfiguration(ConfigurationKind.JDK_ONLY, getJdkKind());
ContentRootsKt.addKotlinSourceRoot(configuration, sourcesDir.getAbsolutePath());
JvmContentRootsKt.addJavaSourceRoot(configuration, new File("compiler/testData/loadJava/include"));
JvmContentRootsKt.addJavaSourceRoot(configuration, tmpdir);
final KotlinCoreEnvironment environment = KotlinCoreEnvironment.createForTests(getTestRootDisposable(), configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES);
AnalysisResult result = TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(environment.getProject(), environment.getSourceFiles(), new CliLightClassGenerationSupport.NoScopeRecordCliBindingTrace(), configuration, new Function1<GlobalSearchScope, PackagePartProvider>() {
@Override
public PackagePartProvider invoke(GlobalSearchScope scope) {
return new JvmPackagePartProvider(environment, scope);
}
});
PackageViewDescriptor packageView = result.getModuleDescriptor().getPackage(TEST_PACKAGE_FQNAME);
checkJavaPackage(expectedFile, packageView, result.getBindingContext(), COMPARATOR_CONFIGURATION);
}
use of com.intellij.psi.search.GlobalSearchScope in project intellij-community by JetBrains.
the class DefaultSourcePositionProvider method getSourcePositionForField.
@Nullable
private static SourcePosition getSourcePositionForField(@NotNull FieldDescriptor descriptor, @NotNull Project project, @NotNull DebuggerContextImpl context, boolean nearest) {
final ReferenceType type = descriptor.getField().declaringType();
final JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
final String fieldName = descriptor.getField().name();
if (fieldName.startsWith(FieldDescriptorImpl.OUTER_LOCAL_VAR_FIELD_PREFIX)) {
// this field actually mirrors a local variable in the outer class
String varName = fieldName.substring(fieldName.lastIndexOf('$') + 1);
PsiElement element = PositionUtil.getContextElement(context);
if (element == null) {
return null;
}
PsiClass aClass = PsiTreeUtil.getParentOfType(element, PsiClass.class, false);
if (aClass == null) {
return null;
}
PsiElement navigationElement = aClass.getNavigationElement();
if (!(navigationElement instanceof PsiClass)) {
return null;
}
aClass = (PsiClass) navigationElement;
PsiVariable psiVariable = facade.getResolveHelper().resolveReferencedVariable(varName, aClass);
if (psiVariable == null) {
return null;
}
if (nearest) {
return DebuggerContextUtil.findNearest(context, psiVariable, aClass.getContainingFile());
}
return SourcePosition.createFromElement(psiVariable);
} else {
final DebuggerSession session = context.getDebuggerSession();
final GlobalSearchScope scope = session != null ? session.getSearchScope() : GlobalSearchScope.allScope(project);
PsiClass aClass = facade.findClass(type.name().replace('$', '.'), scope);
if (aClass == null) {
// trying to search, assuming declaring class is an anonymous class
final DebugProcessImpl debugProcess = context.getDebugProcess();
if (debugProcess != null) {
try {
final List<Location> locations = type.allLineLocations();
if (!locations.isEmpty()) {
// important: use the last location to be sure the position will be within the anonymous class
final Location lastLocation = locations.get(locations.size() - 1);
final SourcePosition position = debugProcess.getPositionManager().getSourcePosition(lastLocation);
aClass = JVMNameUtil.getClassAt(position);
}
} catch (AbsentInformationException | ClassNotPreparedException ignored) {
}
}
}
if (aClass != null) {
PsiField field = aClass.findFieldByName(fieldName, false);
if (field == null)
return null;
if (nearest) {
return DebuggerContextUtil.findNearest(context, field.getNavigationElement(), aClass.getContainingFile());
}
return SourcePosition.createFromElement(field);
}
return null;
}
}
Aggregations