@Override public boolean process(T s) { ProgressManager.checkCanceled(); return super.process(s); } }
@Override public void processNames(@NotNull Processor<String> processor, @NotNull GlobalSearchScope scope, IdFilter filter) { for (StubIndexKey<String, T> key : myIndexKeys) { ProgressManager.checkCanceled(); StubIndex.getInstance().processAllKeys(key, processor, scope, filter); } }
private static boolean hasImportUsers(@NotNull GoImportSpec spec) { //noinspection SynchronizationOnLocalVariableOrMethodParameter synchronized (spec) { List<PsiElement> list = spec.getUserData(GoReferenceBase.IMPORT_USERS); if (list != null) { for (PsiElement e : list) { if (e.isValid()) { return true; } ProgressManager.checkCanceled(); } } } return false; }
private static void processLiteralValue(@NotNull ProblemsHolder holder, @NotNull GoLiteralValue o, @NotNull List<GoFieldDeclaration> fields) { List<GoElement> vals = o.getElementList(); for (int elemId = 0; elemId < vals.size(); elemId++) { ProgressManager.checkCanceled(); GoElement element = vals.get(elemId); if (element.getKey() == null && elemId < fields.size()) { String structFieldName = getFieldName(fields.get(elemId)); LocalQuickFix[] fixes = structFieldName != null ? new LocalQuickFix[]{new GoReplaceWithNamedStructFieldQuickFix(structFieldName)} : LocalQuickFix.EMPTY_ARRAY; holder.registerProblem(element, "Unnamed field initialization", ProblemHighlightType.GENERIC_ERROR_OR_WARNING, fixes); } } }
private static void visitParameterList(@NotNull ProblemsHolder holder, @Nullable GoParameters parameters, @NotNull String ownerType, @NotNull String what) { if (parameters == null || parameters.getParameterDeclarationList().isEmpty()) return; boolean hasNamed = false; boolean hasUnnamed = false; for (GoParameterDeclaration parameterDeclaration : parameters.getParameterDeclarationList()) { ProgressManager.checkCanceled(); if (parameterDeclaration.getParamDefinitionList().isEmpty()) { hasUnnamed = true; } else { hasNamed = true; } if (hasNamed && hasUnnamed) { holder.registerProblem(parameters, ownerType + " has both named and unnamed " + what + " <code>#ref</code> #loc", ProblemHighlightType.GENERIC_ERROR_OR_WARNING); return; } } } }
@Override public void processElementsWithName(@NotNull String s, @NotNull Processor<NavigationItem> processor, @NotNull FindSymbolParameters parameters) { for (StubIndexKey<String, T> key : myIndexKeys) { ProgressManager.checkCanceled(); StubIndex.getInstance().processElements(key, s, parameters.getProject(), parameters.getSearchScope(), parameters.getIdFilter(), myClazz, processor); } }
private static void check(@NotNull GoNamedElement element, @NotNull GoFile builtinFile, @NotNull ProblemsHolder holder) { String name = element.getName(); if (name == null || GoTypeReference.DOC_ONLY_TYPES.contains(name)) return; for (GoTypeSpec builtinTypeDeclaration : builtinFile.getTypes()) { if (name.equals(builtinTypeDeclaration.getName())) { registerProblem(holder, element, builtinTypeDeclaration); return; } } ProgressManager.checkCanceled(); for (GoFunctionDeclaration builtinFunctionsDeclaration : builtinFile.getFunctions()) { if (name.equals(builtinFunctionsDeclaration.getName())) { registerProblem(holder, element, builtinFunctionsDeclaration); return; } } }
@Override public boolean process(@NotNull GoNamedElement element) { ProgressManager.checkCanceled(); Boolean allowed = null; ExistingImportData importData = null; for (ElementProcessor processor : myProcessors) { if (processor.isMine(myName, element)) { importData = cachedImportData(element, importData); allowed = cachedAllowed(element, allowed); if (allowed == Boolean.FALSE || importData.isDot) break; if (!processor.process(myName, element, importData, myResult)) { return false; } } } return true; }
ProgressManager.checkCanceled(); ProgressManager.checkCanceled(); if (matcher.isStartMatch(name)) { result.add(name);
private static IdFilter createIdFilter(@NotNull Project project, @NotNull Key<CachedValue<IdFilter>> cacheKey, @NotNull Condition<VirtualFile> filterCondition) { return CachedValuesManager.getManager(project).getCachedValue(project, cacheKey, () -> { BitSet bitSet = new BitSet(); ContentIterator iterator = fileOrDir -> { if (filterCondition.value(fileOrDir)) { addToBitSet(bitSet, fileOrDir); } ProgressManager.checkCanceled(); return true; }; FileBasedIndex.getInstance().iterateIndexableFiles(iterator, project, null); return CachedValueProvider.Result.create(new GoIdFilter(bitSet), ProjectRootManager.getInstance(project), VirtualFileManager.VFS_STRUCTURE_MODIFICATIONS); }, false); }
private void visitExpr(GoBinaryExpr o, boolean and) { if (!isTopmostOperationOfType(o, and)) return; List<GoExpression> elements = collect(o, and); for (int i = 0; i < elements.size(); i++) { GoExpression l = elements.get(i); if (l instanceof GoReferenceExpression && (l.textMatches("true") || l.textMatches("false")) && GoPsiImplUtil.builtin(((GoReferenceExpression)l).resolve())) { registerProblem(o, holder); return; } for (int j = i + 1; j < elements.size(); j++) { ProgressManager.checkCanceled(); GoExpression r = elements.get(j); if (isEqualsWithNot(l, r) || isEqualsWithNot(r, l) || GoExpressionUtil.identical(l, r)) { registerProblem(o, holder); return; } // todo expr evaluating! x != c1 || x != c2 (c1, c2 const, c1 != c2) } } }
private List<ProblemDescriptor> getUnresolvedNameReferenceDescriptors(@NotNull InspectionManager manager, boolean isOnTheFly, @NotNull LocalQuickFix[] availableFixes, @NotNull Collection<BallerinaIdentifier> identifiers) { List<ProblemDescriptor> problemDescriptors = new LinkedList<>(); for (BallerinaIdentifier identifier : identifiers) { ProgressManager.checkCanceled(); if (identifier == null || "_".equals(identifier.getText())) { continue; } BallerinaOrgName orgName = PsiTreeUtil.getParentOfType(identifier, BallerinaOrgName.class); if (orgName != null) { continue; } BallerinaPackageName packageNameNode = PsiTreeUtil.getParentOfType(identifier, BallerinaPackageName.class); if (packageNameNode != null) { continue; } PsiElement parent = identifier.getParent(); if (parent instanceof BallerinaPackageReference) { PsiReference reference = parent.getReference(); if (reference == null || reference.resolve() == null) { availableFixes = new LocalQuickFix[]{new BallerinaImportPackageQuickFix(identifier)}; problemDescriptors.add(createProblemDescriptor(manager, identifier, isOnTheFly, availableFixes)); } } } return problemDescriptors; }
@Override public boolean execute(@NotNull PsiElement element, @NotNull ResolveState state) { ProgressManager.checkCanceled(); if (accept(element)) { List<BallerinaDefinition> definitions = ((BallerinaFile) element).getDefinitions(); for (BallerinaDefinition definition : definitions) { ProgressManager.checkCanceled(); PsiElement lastChild = definition.getLastChild(); if (lastChild instanceof BallerinaDefinition) { lastChild = lastChild.getLastChild(); } if (lastChild instanceof BallerinaTypeDefinition) { BallerinaTypeDefinition child = (BallerinaTypeDefinition) lastChild; PsiElement identifier = child.getIdentifier(); if (identifier != null) { if (myResult != null) { myResult.addElement(BallerinaCompletionUtils.createTypeLookupElement(child)); } else if (myElement.getText().equals(identifier.getText())) { add(identifier); } } } } } return true; }
@Override public boolean execute(@NotNull PsiElement element, @NotNull ResolveState state) { ProgressManager.checkCanceled(); if (accept(element)) { PsiElement prevVisibleLeaf = PsiTreeUtil.prevVisibleLeaf(myElement); if (prevVisibleLeaf != null && prevVisibleLeaf instanceof LeafPsiElement) { if (((LeafPsiElement) prevVisibleLeaf).getElementType() == BallerinaTypes.RARROW) { PsiElement connector = PsiTreeUtil.prevVisibleLeaf(prevVisibleLeaf); if (connector == null) { return true; } PsiReference reference = connector.getReference(); if (reference == null) { return true; } PsiElement resolvedElement = reference.resolve(); if (resolvedElement == null) { return true; } } } } return true; }
private void visitParameterList(List<GoParameterDeclaration> parameters, String what) { for (GoParameterDeclaration parameterDeclaration : parameters) { for (GoParamDefinition parameter : parameterDeclaration.getParamDefinitionList()) { ProgressManager.checkCanceled(); if (parameter.isBlank()) continue; Query<PsiReference> search = ReferencesSearch.search(parameter, parameter.getUseScope()); if (search.findFirst() != null) continue; holder.registerProblem(parameter, "Unused " + what + " <code>#ref</code> #loc", ProblemHighlightType.LIKE_UNUSED_SYMBOL); } } } };
public static void addCompletions(@NotNull CompletionResultSet result, @NotNull Module module, @Nullable PsiElement context, @NotNull GlobalSearchScope scope, boolean allowMain) { Project project = module.getProject(); boolean vendoringEnabled = GoVendoringUtil.isVendoringEnabled(module); String contextImportPath = GoCompletionUtil.getContextImportPath(context, vendoringEnabled); GoExcludedPathsSettings excludedSettings = GoExcludedPathsSettings.getInstance(project); PsiFile contextFile = context != null ? context.getContainingFile() : null; boolean testFileWithTestPackage = GoTestFinder.isTestFileWithTestPackage(contextFile); for (VirtualFile file : FileTypeIndex.getFiles(GoFileType.INSTANCE, scope)) { ProgressManager.checkCanceled(); PsiFile psiFile = PsiManager.getInstance(project).findFile(file); if (!(psiFile instanceof GoFile)) continue; PsiDirectory directory = psiFile.getContainingDirectory(); if (directory == null) continue; GoFile goFile = (GoFile)psiFile; if (!GoPsiImplUtil.canBeAutoImported(goFile, allowMain, module)) continue; String importPath = goFile.getImportPath(vendoringEnabled); if (StringUtil.isNotEmpty(importPath) && !excludedSettings.isExcluded(importPath) && (testFileWithTestPackage || !importPath.equals(contextImportPath))) { result.addElement(GoCompletionUtil.createPackageLookupElement(importPath, contextImportPath, directory, false)); } } } }
@Override public void visitFunctionDeclaration(@NotNull GoFunctionDeclaration func) { if (func.isBlank()) return; String funcName = func.getName(); if (funcName == null) return; if (INIT.equals(funcName) && zeroArity(func)) return; GoFile file = func.getContainingFile(); boolean isMainFunction = MAIN.equals(funcName) && MAIN.equals(file.getPackageName()) && zeroArity(func); Module module = ModuleUtilCore.findModuleForPsiElement(file); GlobalSearchScope scope = GoPackageUtil.packageScope(file); IdFilter idFilter = GoIdFilter.getFilesFilter(scope); GoFunctionIndex.process(funcName, file.getProject(), scope, idFilter, declaration -> { ProgressManager.checkCanceled(); if (!func.isEquivalentTo(declaration) && GoPsiImplUtil.allowed(declaration.getContainingFile(), file, module)) { if (!isMainFunction || Comparing.equal(declaration.getContainingFile(), file)) { PsiElement identifier = func.getNameIdentifier(); holder.registerProblem(identifier == null ? func : identifier, "Duplicate function name"); return false; } } return true; }); } };
@Override public boolean execute(@NotNull PsiElement element, @NotNull ResolveState state) { ProgressManager.checkCanceled(); if (accept(element)) { PsiElement owner = ((BallerinaTypeDefinition) element).getIdentifier();
@Override public void visitMethodDeclaration(@NotNull GoMethodDeclaration method) { if (method.isBlank()) return; String methodName = method.getName(); if (methodName == null) return; String typeText = GoMethodDeclarationStubElementType.calcTypeText(method); if (typeText == null) return; GoFile file = method.getContainingFile(); GlobalSearchScope scope = GoPackageUtil.packageScope(file); IdFilter idFilter = GoIdFilter.getFilesFilter(scope); Module module = ModuleUtilCore.findModuleForPsiElement(file); String key = file.getPackageName() + "." + typeText; GoMethodIndex.process(key, file.getProject(), scope, idFilter, declaration -> { ProgressManager.checkCanceled(); if (!method.isEquivalentTo(declaration)) { if (Comparing.equal(declaration.getName(), methodName) && GoPsiImplUtil.allowed(declaration.getContainingFile(), file, module)) { PsiElement identifier = method.getNameIdentifier(); holder.registerProblem(identifier == null ? method : identifier, "Duplicate method name"); return false; } } return true; }); }
if (resolve != null) return; boolean foundReference = !ReferencesSearch.search(o, o.getUseScope()).forEach(reference1 -> { ProgressManager.checkCanceled(); PsiElement element = reference1.getElement(); if (element == null) return true;