@NotNull private static GoType getInterfaceIfNull(@Nullable GoType type, @NotNull PsiElement context) { return type == null ? GoElementFactory.createType(context.getProject(), GoConstants.INTERFACE_TYPE) : type; }
@NotNull @Override public Project getProject() { return getMirror().getProject(); } }
@Nullable @Override public PsiElement substituteElementToRename(PsiElement element, @Nullable Editor editor) { if (FindManager.getInstance(element.getProject()).canFindUsages(element)) { return element; } String message = RefactoringBundle.message("error.cannot.be.renamed"); CommonRefactoringUtil.showErrorHint(element.getProject(), editor, message, RefactoringBundle.message("rename.title"), null); return null; }
@Override public PsiElement handleElementRename(String newElementName) throws IncorrectOperationException { myElement.replace(GoElementFactory.createIdentifierFromText(myElement.getProject(), newElementName)); return myElement; }
@Override public void apply(@NotNull Editor editor, @NotNull SmartEnterProcessorWithFixers processor, @NotNull PsiElement element) throws IncorrectOperationException { if (element instanceof GoFunctionOrMethodDeclaration && ((GoFunctionOrMethodDeclaration)element).getBlock() == null) { element.add(GoElementFactory.createBlock(element.getProject())); } if (element instanceof GoFunctionLit && ((GoFunctionLit)element).getBlock() == null) { element.add(GoElementFactory.createBlock(element.getProject())); } } }
@Nullable @Override public final PsiElement resolve() { return myElement.isValid() ? ResolveCache.getInstance(myElement.getProject()).resolveWithCaching(this, MY_RESOLVER, false, false) : null; }
@NotNull private static GoType createGoTypeListOrGoType(@NotNull List<GoType> types, @NotNull PsiElement context) { if (types.size() < 2) { return getInterfaceIfNull(ContainerUtil.getFirstItem(types), context); } return GoElementFactory.createTypeList(context.getProject(), StringUtil.join(types, type -> type == null ? GoConstants.INTERFACE_TYPE : type.getText(), ", ")); }
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 PsiElement handleElementRename(String newElementName) throws IncorrectOperationException { myElement.replace(BallerinaElementFactory.createIdentifierFromText(myElement.getProject(), newElementName)); return myElement; }
@NotNull public static ResolveState createContextOnElement(@NotNull PsiElement element) { return ResolveState.initial().put(CONTEXT, SmartPointerManager.getInstance(element.getProject()).createSmartPsiElementPointer(element)); }
@Nullable @Override public final PsiElement resolve() { // return resolveInner(); return myElement.isValid() ? ResolveCache.getInstance(myElement.getProject()).resolveWithCaching(this, MY_RESOLVER, false, true) : null; }
@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; } }
@NotNull public static synchronized List<BallerinaTypeDefinition> suggestBuiltInTypes(@NotNull PsiElement element) { return CachedValuesManager.getCachedValue(element, () -> CachedValueProvider.Result.create(getBuiltInTypes(element), ProjectRootManager.getInstance(element.getProject()))); }
@NotNull public static synchronized List<BallerinaAnnotationDefinition> suggestBuiltInAnnotations(@NotNull PsiElement element) { return CachedValuesManager.getCachedValue(element, () -> CachedValueProvider.Result.create(getBuiltInAnnotations(element), ProjectRootManager.getInstance(element.getProject()))); }
@NotNull public static synchronized List<BallerinaFunctionDefinition> suggestBuiltInFunctions(@NotNull PsiElement type) { if (!hasBuiltInDefinitions(type)) { return new LinkedList<>(); } String key = type.getText(); return CachedValuesManager.getCachedValue(type, () -> CachedValueProvider.Result.create(getBuiltInFunctions(key, type), ProjectRootManager.getInstance(type.getProject()))); }
public void extractNewLine(PsiElement from) { PsiElement newLine = GoElementFactory.createNewLine(from.getProject()); if (myIsEffective) { newLine = from.getParent().addBefore(newLine, from); } if (newLine != null) { addElementToExtract(newLine); } }
@Nullable public static PsiElement getContextElement(@Nullable ConfigurationContext context) { if (context == null) { return null; } PsiElement psiElement = context.getPsiLocation(); if (psiElement == null || !psiElement.isValid()) { return null; } FileIndexFacade indexFacade = FileIndexFacade.getInstance(psiElement.getProject()); PsiFileSystemItem psiFile = psiElement instanceof PsiFileSystemItem ? (PsiFileSystemItem)psiElement : psiElement.getContainingFile(); VirtualFile file = psiFile != null ? psiFile.getVirtualFile() : null; if (file != null && file.getFileType() != ScratchFileType.INSTANCE && (!indexFacade.isInContent(file) || indexFacade.isExcludedFile(file))) { return null; } return psiElement; }
@Override public void apply(@NotNull Editor editor, @NotNull SmartEnterProcessorWithFixers processor, @NotNull PsiElement element) throws IncorrectOperationException { Project project = element.getProject(); if (element instanceof GoGoStatement) { PsiElement expr = GoDeferGoInspection.GoAddParensQuickFix.addParensIfNeeded(project, ((GoGoStatement)element).getExpression()); if (expr != null) { element.replace(GoElementFactory.createGoStatement(project, expr.getText())); } } else if (element instanceof GoDeferStatement) { PsiElement expr = GoDeferGoInspection.GoAddParensQuickFix.addParensIfNeeded(project, ((GoDeferStatement)element).getExpression()); if (expr != null) { element.replace(GoElementFactory.createDeferStatement(project, expr.getText())); } } } }
public static GlobalSearchScope create(@NotNull PsiElement declarationContext, boolean filterByImportList) { if (declarationContext instanceof GoNamedElement && ((GoNamedElement)declarationContext).isBlank()) { return GlobalSearchScope.EMPTY_SCOPE; } PsiFile declarationPsiFile = declarationContext.getContainingFile(); if (!(declarationPsiFile instanceof GoFile)) { return GlobalSearchScope.fileScope(declarationPsiFile); } if (GoPsiImplUtil.isBuiltinFile(declarationPsiFile)) { return GlobalSearchScope.allScope(declarationContext.getProject()); } VirtualFile declarationFile = declarationPsiFile.getVirtualFile(); if (declarationFile == null || declarationFile.getParent() == null) { return GlobalSearchScope.fileScope(declarationPsiFile); } return new GoPathUseScope(declarationPsiFile.getProject(), declarationFile, filterByImportList); }
@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)); } }