@Override public boolean canSelect(@NotNull PsiElement e) { return e.getContainingFile() instanceof GoFile; }
@Override public boolean accepts(@NotNull PsiElement element, ProcessingContext context) { return GoTestFinder.isTestFile(element.getContainingFile()); } }
@Nullable private static String getImportPathForElement(@Nullable PsiElement element) { PsiFile file = element != null ? element.getContainingFile() : null; return file instanceof GoFile ? ((GoFile)file).getImportPath(false) : null; }
@Nullable static PsiFile getContextFile(@NotNull ResolveState state) { PsiElement element = getContextElement(state); return element != null ? element.getContainingFile() : null; }
@Nullable private static GoFile getFileFromContext(@Nullable ConfigurationContext context) { PsiElement contextElement = GoRunUtil.getContextElement(context); PsiFile psiFile = contextElement != null ? contextElement.getContainingFile() : null; return psiFile instanceof GoFile ? (GoFile)psiFile : null; } }
@Nullable protected PsiElement findAnchor(@NotNull PsiElement reference) { PsiFile file = reference.getContainingFile(); return GoRefactoringUtil.findAnchor(GoRefactoringUtil.getOccurrences(reference, file), file); } }
public GoFieldProcessor(@NotNull PsiElement element) { super(element); PsiFile containingFile = myOrigin.getContainingFile(); myModule = containingFile != null ? ModuleUtilCore.findModuleForPsiElement(containingFile.getOriginalFile()) : null; }
@Override protected boolean crossOff(@NotNull PsiElement e) { if (!(e instanceof GoFieldDefinition) && !(e instanceof GoAnonymousFieldDefinition)) return true; GoNamedElement named = (GoNamedElement)e; PsiFile myFile = myOrigin.getContainingFile(); PsiFile file = e.getContainingFile(); if (!(myFile instanceof GoFile) || !GoPsiImplUtil.allowed(file, myFile, myModule)) return true; boolean localResolve = GoReference.isLocalResolve(myFile, file); return !e.isValid() || !(named.isPublic() || localResolve); } }
@Nullable private PsiDirectory getDirectory() { PsiElement originalElement = CompletionUtil.getOriginalElement(getElement()); PsiFile file = originalElement != null ? originalElement.getContainingFile() : getElement().getContainingFile(); return file.getParent(); } }
public static GlobalSearchScope create(@NotNull Project project, @Nullable Module module, @Nullable PsiElement context) { VirtualFile referenceFile = context != null ? context.getContainingFile().getVirtualFile() : null; return new GoPathResolveScope(project, referenceFile, GoPathScopeHelper.fromReferenceFile(project, module, referenceFile)); }
@Override public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) { PsiElement element = descriptor.getPsiElement(); if (element != null) { applyFix(project, ModuleUtilCore.findModuleForPsiElement(element.getContainingFile()), myPackage, true); } } }
@Nullable private static String getImportPathFromContext(@Nullable PsiElement contextElement) { if (GoRunUtil.isPackageContext(contextElement)) { PsiFile file = contextElement.getContainingFile(); if (file instanceof GoFile) { return ((GoFile)file).getImportPath(false); } } else if (contextElement instanceof PsiDirectory) { return GoSdkUtil.getImportPath((PsiDirectory)contextElement, false); } return null; }
public static GlobalSearchScope goPathResolveScope(@NotNull PsiElement context) { // it's important to ask module on file, otherwise module won't be found for elements in libraries files [zolotov] Module module = ModuleUtilCore.findModuleForPsiElement(context.getContainingFile()); return GoPathResolveScope.create(context.getProject(), module, context); }
@Override public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) { PsiElement element = PsiTreeUtil.getNonStrictParentOfType(descriptor.getPsiElement(), GoImportSpec.class); PsiFile file = element != null ? element.getContainingFile() : null; if (!(file instanceof GoFile)) return; WriteCommandAction.runWriteCommandAction(project, () -> ((GoFile)file).deleteImport((GoImportSpec)element)); } }
@Override public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) { PsiElement element = descriptor.getPsiElement(); if (element == null) { return; } PsiFile file = element.getContainingFile(); WriteCommandAction.runWriteCommandAction(project, new GoImportOptimizer().processFile(file)); } };
@NotNull @Override public FormattingModel createModel(@NotNull PsiElement element, @NotNull CodeStyleSettings settings) { Block block = new GoFormattingBlock(element.getNode(), null, Indent.getNoneIndent(), null, settings, createSpacingBuilder(settings)); return FormattingModelProvider.createFormattingModelForPsiFile(element.getContainingFile(), block, settings); }
@Override public boolean isAppEngineEnabled(@Nullable PsiElement context) { if (context != null) { // it's important to ask module on file, otherwise module won't be found for elements in libraries files [zolotov] Module module = ModuleUtilCore.findModuleForPsiElement(context.getContainingFile()); if (GoSdkService.getInstance(context.getProject()).isAppEngineSdk(module)) { return true; } } return false; } }
private static boolean stdLibCall(@NotNull GoCallExpr o, @NotNull String name) { GoExpression e = o.getExpression(); if (e.textMatches(name) && e instanceof GoReferenceExpression) { PsiReference reference = e.getReference(); PsiElement resolve = reference != null ? reference.resolve() : null; if (!(resolve instanceof GoFunctionDeclaration)) return false; return isBuiltinFile(resolve.getContainingFile()); } return false; }
@Override public void fillActions(LookupElement element, Lookup lookup, Consumer<LookupElementAction> consumer) { PsiElement psiElement = element.getPsiElement(); PsiFile file = psiElement != null && psiElement.isValid() ? psiElement.getContainingFile() : null; String importPath = file instanceof GoFile ? ((GoFile)file).getImportPath(false) : null; if (importPath != null) { Project project = psiElement.getProject(); for (String path : getPaths(importPath)) { consumer.consume(new ExcludePathAction(project, path)); } consumer.consume(new EditExcludedAction(project)); } }
public void testSdkTestDataDirectory() { myFixture.configureByText("a.go", "package a; import `doc/testdata`; func _() { println(pkg.ExportedConst<caret>ant) } "); PsiReference reference = myFixture.getFile().findReferenceAt(myFixture.getCaretOffset()); PsiElement resolve = reference != null ? reference.resolve() : null; assertNotNull(resolve); assertEquals("pkg.go", resolve.getContainingFile().getName()); assertEmpty(myFixture.findUsages(resolve)); }