Search in sources :

Example 31 with NotNull

use of org.jetbrains.annotations.NotNull in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoCodeInsightFixtureTestCase method findElementAtCaretOrInSelection.

@NotNull
protected PsiElement findElementAtCaretOrInSelection() {
    SelectionModel selectionModel = myFixture.getEditor().getSelectionModel();
    if (selectionModel.hasSelection()) {
        PsiElement left = myFixture.getFile().findElementAt(selectionModel.getSelectionStart());
        PsiElement right = myFixture.getFile().findElementAt(selectionModel.getSelectionEnd() - 1);
        assertNotNull(left);
        assertNotNull(right);
        return ObjectUtils.assertNotNull(PsiTreeUtil.findCommonParent(left, right));
    } else {
        return ObjectUtils.assertNotNull(myFixture.getFile().findElementAt(myFixture.getEditor().getCaretModel().getOffset()));
    }
}
Also used : SelectionModel(com.intellij.openapi.editor.SelectionModel) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 32 with NotNull

use of org.jetbrains.annotations.NotNull in project go-lang-idea-plugin by go-lang-plugin-org.

the class GotestGenerateAction method importTestingPackageIfNeeded.

@NotNull
public static String importTestingPackageIfNeeded(@NotNull GoFile file) {
    GoImportSpec alreadyImportedPackage = file.getImportedPackagesMap().get(GoConstants.TESTING_PATH);
    String qualifier = GoPsiImplUtil.getImportQualifierToUseInFile(alreadyImportedPackage, GoConstants.TESTING_PATH);
    if (qualifier != null) {
        return qualifier;
    }
    String localName = UniqueNameGenerator.generateUniqueName(GoConstants.TESTING_PATH, file.getImportMap().keySet());
    file.addImport(GoConstants.TESTING_PATH, !GoConstants.TESTING_PATH.equals(localName) ? localName : null);
    return localName;
}
Also used : GoImportSpec(com.goide.psi.GoImportSpec) NotNull(org.jetbrains.annotations.NotNull)

Example 33 with NotNull

use of org.jetbrains.annotations.NotNull in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoPackageUtil method getAllPackageFiles.

@NotNull
public static List<GoFile> getAllPackageFiles(@NotNull GoFile file) {
    String packageName = file.getPackageName();
    PsiDirectory parent = file.getParent();
    if (parent == null || StringUtil.isEmpty(packageName))
        return ContainerUtil.list(file);
    return getAllPackageFiles(parent, packageName);
}
Also used : PsiDirectory(com.intellij.psi.PsiDirectory) NotNull(org.jetbrains.annotations.NotNull)

Example 34 with NotNull

use of org.jetbrains.annotations.NotNull in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoPackageUtil method getAllPackagesInDirectory.

@NotNull
public static Collection<String> getAllPackagesInDirectory(@Nullable PsiDirectory dir, @Nullable Module contextModule, boolean trimTestSuffices) {
    if (dir == null)
        return Collections.emptyList();
    if (contextModule != null) {
        return getAllPackagesInDirectoryInner(dir, contextModule, trimTestSuffices);
    }
    Key<CachedValue<Collection<String>>> key = trimTestSuffices ? PACKAGES_TEST_TRIMMED_CACHE : PACKAGES_CACHE;
    return CachedValuesManager.getManager(dir.getProject()).getCachedValue(dir, key, () -> {
        Module module = ModuleUtilCore.findModuleForPsiElement(dir);
        GoBuildTargetSettings buildTargetSettings = module != null ? GoModuleSettings.getInstance(module).getBuildTargetSettings() : null;
        // todo[zolotov]: implement package modification tracker
        return buildTargetSettings != null ? CachedValueProvider.Result.create(getAllPackagesInDirectoryInner(dir, module, trimTestSuffices), dir, buildTargetSettings) : CachedValueProvider.Result.create(getAllPackagesInDirectoryInner(dir, null, trimTestSuffices), dir);
    }, false);
}
Also used : GoBuildTargetSettings(com.goide.project.GoBuildTargetSettings) CachedValue(com.intellij.psi.util.CachedValue) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull)

Example 35 with NotNull

use of org.jetbrains.annotations.NotNull 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)

Aggregations

NotNull (org.jetbrains.annotations.NotNull)6308 VirtualFile (com.intellij.openapi.vfs.VirtualFile)829 ArrayList (java.util.ArrayList)621 File (java.io.File)551 Project (com.intellij.openapi.project.Project)540 PsiElement (com.intellij.psi.PsiElement)461 Nullable (org.jetbrains.annotations.Nullable)394 Module (com.intellij.openapi.module.Module)315 PsiFile (com.intellij.psi.PsiFile)296 List (java.util.List)274 IOException (java.io.IOException)273 TextRange (com.intellij.openapi.util.TextRange)245 ContainerUtil (com.intellij.util.containers.ContainerUtil)170 Document (com.intellij.openapi.editor.Document)158 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)154 ASTNode (com.intellij.lang.ASTNode)145 Pair (com.intellij.openapi.util.Pair)141 StringUtil (com.intellij.openapi.util.text.StringUtil)133 Logger (com.intellij.openapi.diagnostic.Logger)127 Editor (com.intellij.openapi.editor.Editor)120