Search in sources :

Example 36 with VirtualFile

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);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile)

Example 37 with VirtualFile

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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) GoFile(com.goide.psi.GoFile) GoImportSpec(com.goide.psi.GoImportSpec) PsiManager(com.intellij.psi.PsiManager) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module)

Example 38 with VirtualFile

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();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile)

Example 39 with VirtualFile

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();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) IOException(java.io.IOException) VirtualFileVisitor(com.intellij.openapi.vfs.VirtualFileVisitor) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Example 40 with VirtualFile

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());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) AnalysisScope(com.intellij.analysis.AnalysisScope) InspectionManagerEx(com.intellij.codeInspection.ex.InspectionManagerEx) GlobalInspectionContextForTests(com.intellij.testFramework.fixtures.impl.GlobalInspectionContextForTests) InspectionToolWrapper(com.intellij.codeInspection.ex.InspectionToolWrapper) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Aggregations

VirtualFile (com.intellij.openapi.vfs.VirtualFile)5443 File (java.io.File)757 Nullable (org.jetbrains.annotations.Nullable)719 Project (com.intellij.openapi.project.Project)718 NotNull (org.jetbrains.annotations.NotNull)703 PsiFile (com.intellij.psi.PsiFile)564 Module (com.intellij.openapi.module.Module)495 IOException (java.io.IOException)327 ArrayList (java.util.ArrayList)258 Document (com.intellij.openapi.editor.Document)241 PsiElement (com.intellij.psi.PsiElement)205 Test (org.junit.Test)193 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)124 PsiDirectory (com.intellij.psi.PsiDirectory)124 XmlFile (com.intellij.psi.xml.XmlFile)124 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)116 Editor (com.intellij.openapi.editor.Editor)114 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)100 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)91 List (java.util.List)90