Search in sources :

Example 36 with NotNull

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

the class GoCoverageCalculationTest method parseData.

@NotNull
private GoCoverageProjectData parseData(@NotNull String coverageSource) throws IOException {
    try (BufferedReader reader = new BufferedReader(new FileReader(new File(getTestDataPath(), coverageSource)))) {
        GoCoverageProjectData data = GoCoverageRunner.parseCoverage(reader, myFixture.getProject(), myModule);
        assertNotNull(data);
        return data;
    }
}
Also used : GoCoverageProjectData(com.goide.runconfig.testing.coverage.GoCoverageProjectData) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Example 37 with NotNull

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

the class GoCoverageCalculationTest method getRoot.

@NotNull
private VirtualFile getRoot() {
    VirtualFile root = myFixture.getTempDirFixture().getFile("");
    assertNotNull(root);
    return root;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) NotNull(org.jetbrains.annotations.NotNull)

Example 38 with NotNull

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

the class GoSdkUtil method getGoPathSources.

@NotNull
public static Collection<VirtualFile> getGoPathSources(@NotNull Project project, @Nullable Module module) {
    if (module != null) {
        return CachedValuesManager.getManager(project).getCachedValue(module, () -> {
            Collection<VirtualFile> result = newLinkedHashSet();
            Project project1 = module.getProject();
            GoSdkService sdkService = GoSdkService.getInstance(project1);
            if (sdkService.isAppEngineSdk(module)) {
                ContainerUtil.addAllNotNull(result, ContainerUtil.mapNotNull(YamlFilesModificationTracker.getYamlFiles(project1, module), VirtualFile::getParent));
            }
            result.addAll(getInnerGoPathSources(project1, module));
            return CachedValueProvider.Result.create(result, getSdkAndLibrariesCacheDependencies(project1, module, YamlFilesModificationTracker.getInstance(project1)));
        });
    }
    return CachedValuesManager.getManager(project).getCachedValue(project, (CachedValueProvider<Collection<VirtualFile>>) () -> CachedValueProvider.Result.create(getInnerGoPathSources(project, null), getSdkAndLibrariesCacheDependencies(project, null, YamlFilesModificationTracker.getInstance(project))));
}
Also used : Project(com.intellij.openapi.project.Project) NotNull(org.jetbrains.annotations.NotNull)

Example 39 with NotNull

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

the class GoRefactoringUtil method getOccurrences.

@NotNull
public static List<PsiElement> getOccurrences(@NotNull PsiElement pattern, @Nullable PsiElement context) {
    if (context == null)
        return Collections.emptyList();
    List<PsiElement> occurrences = ContainerUtil.newArrayList();
    PsiRecursiveElementVisitor visitor = new PsiRecursiveElementVisitor() {

        @Override
        public void visitElement(@NotNull PsiElement element) {
            if (PsiEquivalenceUtil.areElementsEquivalent(element, pattern)) {
                occurrences.add(element);
                return;
            }
            super.visitElement(element);
        }
    };
    context.acceptChildren(visitor);
    return occurrences;
}
Also used : PsiRecursiveElementVisitor(com.intellij.psi.PsiRecursiveElementVisitor) NotNull(org.jetbrains.annotations.NotNull) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 40 with NotNull

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

the class GoRefactoringUtil method getSuggestedNames.

@NotNull
private static LinkedHashSet<String> getSuggestedNames(GoExpression expression, PsiElement context) {
    // todo rewrite with names resolve; check occurrences contexts
    if (expression.isEquivalentTo(context)) {
        context = PsiTreeUtil.getParentOfType(context, GoBlock.class);
    }
    LinkedHashSet<String> usedNames = getNamesInContext(context);
    LinkedHashSet<String> names = ContainerUtil.newLinkedHashSet();
    NamesValidator namesValidator = LanguageNamesValidation.INSTANCE.forLanguage(GoLanguage.INSTANCE);
    if (expression instanceof GoCallExpr) {
        GoReferenceExpression callReference = PsiTreeUtil.getChildOfType(expression, GoReferenceExpression.class);
        if (callReference != null) {
            String name = StringUtil.decapitalize(callReference.getIdentifier().getText());
            for (String candidate : NameUtil.getSuggestionsByName(name, "", "", false, false, false)) {
                if (usedNames.contains(candidate))
                    continue;
                if (!isValidName(namesValidator, candidate))
                    continue;
                names.add(candidate);
            }
        }
    }
    GoType type = expression.getGoType(null);
    String typeText = GoPsiImplUtil.getText(type);
    if (StringUtil.isNotEmpty(typeText)) {
        boolean array = GoTypeUtil.isIterable(type) && !GoTypeUtil.isString(type);
        for (String candidate : NameUtil.getSuggestionsByName(typeText, "", "", false, false, array)) {
            if (usedNames.contains(candidate) || typeText.equals(candidate))
                continue;
            if (!isValidName(namesValidator, candidate))
                continue;
            names.add(candidate);
        }
    }
    if (names.isEmpty()) {
        names.add(UniqueNameGenerator.generateUniqueName("i", usedNames));
    }
    return names;
}
Also used : NamesValidator(com.intellij.lang.refactoring.NamesValidator) 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