use of com.intellij.openapi.vfs.VirtualFile in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoPathScopeHelper method fromReferenceFile.
public static GoPathScopeHelper fromReferenceFile(@NotNull Project project, @Nullable Module module, @Nullable VirtualFile referenceFile) {
VirtualFile sdkHome = GoSdkUtil.getSdkSrcDir(project, module);
String sdkVersion = GoSdkService.getInstance(project).getSdkVersion(module);
boolean supportsInternalPackages = GoVendoringUtil.supportsInternalPackages(sdkVersion);
boolean supportsSdkInternalPackages = GoVendoringUtil.supportsSdkInternalPackages(sdkVersion);
boolean vendoringEnabled = GoVendoringUtil.isVendoringEnabled(module);
Set<VirtualFile> sourceRoots = vendoringEnabled ? GoSdkUtil.getVendoringAwareSourcesPathsToLookup(project, module, referenceFile) : GoSdkUtil.getSourcesPathsToLookup(project, module);
return new GoPathScopeHelper(sourceRoots, sdkHome, supportsInternalPackages, supportsSdkInternalPackages, vendoringEnabled);
}
use of com.intellij.openapi.vfs.VirtualFile in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoPathUseScope method contains.
@Override
public boolean contains(@NotNull VirtualFile referenceFile) {
VirtualFile referenceDirectory = referenceFile.isDirectory() ? referenceFile : referenceFile.getParent();
if (referenceDirectory == null) {
return false;
}
VirtualFile declarationDirectory = myDeclarationFile.getParent();
if (referenceDirectory.equals(declarationDirectory)) {
return true;
}
Project project = ObjectUtils.assertNotNull(getProject());
PsiManager psiManager = PsiManager.getInstance(project);
PsiFile referencePsiFile = psiManager.findFile(referenceFile);
Module module = referencePsiFile != null ? ModuleUtilCore.findModuleForPsiElement(referencePsiFile) : null;
GoPathScopeHelper scopeHelper = GoPathScopeHelper.fromReferenceFile(project, module, referenceFile);
if (!scopeHelper.couldBeReferenced(myDeclarationFile, referenceFile)) {
return false;
}
if (!myFilterByImportList) {
return true;
}
if (!(referencePsiFile instanceof GoFile)) {
// it's some injection or cross-reference, so we cannot check its imports
return true;
}
PsiFile declarationPsiFile = psiManager.findFile(myDeclarationFile);
if (declarationPsiFile instanceof GoFile) {
String importPath = ((GoFile) declarationPsiFile).getImportPath(scopeHelper.isVendoringEnabled());
Map<String, GoImportSpec> importedPackagesMap = ((GoFile) referencePsiFile).getImportedPackagesMap();
if (importedPackagesMap.containsKey(importPath)) {
return true;
}
if (hasRelativeImportOfTargetPackage(importedPackagesMap.keySet(), referenceDirectory, declarationDirectory)) {
return true;
}
for (GoFile packageFile : GoPackageUtil.getAllPackageFiles(referencePsiFile.getContainingDirectory(), null)) {
if (packageFile != referencePsiFile && referencePsiFile.getOriginalFile() != packageFile) {
Map<String, GoImportSpec> packagesMap = packageFile.getImportedPackagesMap();
if (packagesMap.containsKey(importPath)) {
return true;
}
if (hasRelativeImportOfTargetPackage(packagesMap.keySet(), referenceDirectory, declarationDirectory)) {
return true;
}
}
}
}
return false;
}
use of com.intellij.openapi.vfs.VirtualFile in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoSdkType method setupSdkPaths.
@Override
public void setupSdkPaths(@NotNull Sdk sdk) {
String versionString = sdk.getVersionString();
if (versionString == null)
throw new RuntimeException("SDK version is not defined");
SdkModificator modificator = sdk.getSdkModificator();
String path = sdk.getHomePath();
if (path == null)
return;
modificator.setHomePath(path);
for (VirtualFile file : GoSdkUtil.getSdkDirectoriesToAttach(path, versionString)) {
modificator.addRoot(file, OrderRootType.CLASSES);
modificator.addRoot(file, OrderRootType.SOURCES);
}
modificator.commitChanges();
}
use of com.intellij.openapi.vfs.VirtualFile in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoPerformanceTest method testParserAndStubs.
public void testParserAndStubs() {
File go = new File(getTestDataPath(), "go");
if (!go.exists()) {
System.err.println("For performance tests you need to have a go sources (https://storage.googleapis.com/golang/go1.4.2.src.tar.gz) inside testData/" + getBasePath() + " directory");
return;
}
PlatformTestUtil.startPerformanceTest(getTestName(true), (int) TimeUnit.MINUTES.toMillis(1), () -> {
VirtualFile root = LocalFileSystem.getInstance().findFileByIoFile(go);
assertNotNull(root);
VfsUtilCore.visitChildrenRecursively(root, new VirtualFileVisitor() {
@NotNull
@Override
public Result visitFileEx(@NotNull VirtualFile file) {
if (file.isDirectory() && "testdata".equals(file.getName()))
return SKIP_CHILDREN;
if (file.isDirectory() && "test".equals(file.getName()) && file.getParent().equals(root))
return SKIP_CHILDREN;
if (file.getFileType() != GoFileType.INSTANCE)
return CONTINUE;
try {
System.out.print(".");
buildStubTreeText(getProject(), file, FileUtil.loadFile(new File(file.getPath()), "UTF-8", true).trim(), true);
} catch (IOException ignored) {
}
return CONTINUE;
}
});
}).usesAllCPUCores().assertTiming();
}
use of com.intellij.openapi.vfs.VirtualFile in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoPerformanceTest method doInspectionTest.
private void doInspectionTest(@NotNull InspectionProfileEntry tool, long expected) {
VirtualFile sourceDir = installTestData("docker");
if (sourceDir == null)
return;
//noinspection ConstantConditions
AnalysisScope scope = new AnalysisScope(getPsiManager().findDirectory(sourceDir));
scope.invalidate();
InspectionManagerEx inspectionManager = (InspectionManagerEx) InspectionManager.getInstance(getProject());
InspectionToolWrapper wrapper = InspectionToolRegistrar.wrapTool(tool);
GlobalInspectionContextForTests globalContext = CodeInsightTestFixtureImpl.createGlobalContextForTool(scope, getProject(), inspectionManager, wrapper);
PlatformTestUtil.startPerformanceTest(getTestName(true), (int) expected, () -> InspectionTestUtil.runTool(wrapper, scope, globalContext)).cpuBound().usesAllCPUCores().assertTiming();
InspectionTestUtil.compareToolResults(globalContext, wrapper, false, new File(getTestDataPath(), wrapper.getShortName()).getPath());
}
Aggregations