Search in sources :

Example 1 with GoRenameQuickFix

use of com.goide.quickfix.GoRenameQuickFix in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoReceiverNamesInspection method buildGoVisitor.

@NotNull
@Override
protected GoVisitor buildGoVisitor(@NotNull ProblemsHolder holder, @NotNull LocalInspectionToolSession session) {
    return new GoVisitor() {

        @Override
        public void visitReceiver(@NotNull GoReceiver o) {
            if (genericNamesSet.contains(o.getName())) {
                PsiElement identifier = o.getIdentifier();
                if (identifier == null)
                    return;
                holder.registerProblem(identifier, "Receiver has generic name", new GoRenameQuickFix(o));
            }
        }
    };
}
Also used : GoRenameQuickFix(com.goide.quickfix.GoRenameQuickFix) GoReceiver(com.goide.psi.GoReceiver) NotNull(org.jetbrains.annotations.NotNull) GoVisitor(com.goide.psi.GoVisitor) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with GoRenameQuickFix

use of com.goide.quickfix.GoRenameQuickFix in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoReservedWordUsedAsNameInspection method registerProblem.

private static void registerProblem(@NotNull ProblemsHolder holder, @NotNull GoNamedElement element, @NotNull GoNamedElement builtinElement) {
    PsiElement identifier = element.getIdentifier();
    if (identifier == null)
        return;
    String elementDescription = ElementDescriptionUtil.getElementDescription(element, UsageViewTypeLocation.INSTANCE);
    String builtinElementDescription = ElementDescriptionUtil.getElementDescription(builtinElement, UsageViewTypeLocation.INSTANCE);
    String message = StringUtil.capitalize(elementDescription) + " <code>#ref</code> collides with builtin " + builtinElementDescription;
    holder.registerProblem(identifier, message, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, new GoRenameQuickFix(element));
}
Also used : GoRenameQuickFix(com.goide.quickfix.GoRenameQuickFix) PsiElement(com.intellij.psi.PsiElement)

Example 3 with GoRenameQuickFix

use of com.goide.quickfix.GoRenameQuickFix in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoUnusedImportInspection method checkFile.

@Override
protected void checkFile(@NotNull GoFile file, @NotNull ProblemsHolder problemsHolder) {
    MultiMap<String, GoImportSpec> importMap = file.getImportMap();
    for (PsiElement importIdentifier : GoImportOptimizer.findRedundantImportIdentifiers(importMap)) {
        problemsHolder.registerProblem(importIdentifier, "Redundant alias", ProblemHighlightType.LIKE_UNUSED_SYMBOL, OPTIMIZE_QUICK_FIX);
    }
    Set<GoImportSpec> duplicatedEntries = GoImportOptimizer.findDuplicatedEntries(importMap);
    for (GoImportSpec duplicatedImportSpec : duplicatedEntries) {
        problemsHolder.registerProblem(duplicatedImportSpec, "Redeclared import", ProblemHighlightType.GENERIC_ERROR, OPTIMIZE_QUICK_FIX);
    }
    for (Map.Entry<String, Collection<GoImportSpec>> specs : importMap.entrySet()) {
        Iterator<GoImportSpec> imports = specs.getValue().iterator();
        GoImportSpec originalImport = imports.next();
        if (originalImport.isDot() || originalImport.isForSideEffects()) {
            continue;
        }
        while (imports.hasNext()) {
            GoImportSpec redeclaredImport = imports.next();
            if (!duplicatedEntries.contains(redeclaredImport)) {
                LocalQuickFix[] quickFixes = FindManager.getInstance(redeclaredImport.getProject()).canFindUsages(redeclaredImport) ? new LocalQuickFix[] { new GoRenameQuickFix(redeclaredImport) } : LocalQuickFix.EMPTY_ARRAY;
                problemsHolder.registerProblem(redeclaredImport, "Redeclared import", ProblemHighlightType.GENERIC_ERROR, quickFixes);
            }
        }
    }
    if (importMap.containsKey(".")) {
        if (!problemsHolder.isOnTheFly() || ApplicationManager.getApplication().isUnitTestMode())
            resolveAllReferences(file);
    }
    MultiMap<String, GoImportSpec> unusedImportsMap = GoImportOptimizer.filterUnusedImports(file, importMap);
    Set<GoImportSpec> unusedImportSpecs = ContainerUtil.newHashSet(unusedImportsMap.values());
    for (PsiElement importEntry : unusedImportSpecs) {
        GoImportSpec spec = GoImportOptimizer.getImportSpec(importEntry);
        if (spec != null && spec.getImportString().resolve() != null) {
            problemsHolder.registerProblem(spec, "Unused import", ProblemHighlightType.GENERIC_ERROR, OPTIMIZE_QUICK_FIX, IMPORT_FOR_SIDE_EFFECTS_QUICK_FIX);
        }
    }
}
Also used : GoRenameQuickFix(com.goide.quickfix.GoRenameQuickFix) GoImportSpec(com.goide.psi.GoImportSpec) Collection(java.util.Collection) Map(java.util.Map) MultiMap(com.intellij.util.containers.MultiMap) PsiElement(com.intellij.psi.PsiElement)

Example 4 with GoRenameQuickFix

use of com.goide.quickfix.GoRenameQuickFix in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoImportUsedAsNameInspection method registerProblem.

private static void registerProblem(@NotNull ProblemsHolder holder, @NotNull GoNamedElement element) {
    PsiElement identifier = element.getIdentifier();
    if (identifier != null) {
        String elementDescription = ElementDescriptionUtil.getElementDescription(element, UsageViewTypeLocation.INSTANCE);
        String message = StringUtil.capitalize(elementDescription) + " <code>#ref</code> collides with imported package name #loc";
        holder.registerProblem(identifier, message, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, new GoRenameQuickFix(element));
    }
}
Also used : GoRenameQuickFix(com.goide.quickfix.GoRenameQuickFix) PsiElement(com.intellij.psi.PsiElement)

Aggregations

GoRenameQuickFix (com.goide.quickfix.GoRenameQuickFix)4 PsiElement (com.intellij.psi.PsiElement)4 GoImportSpec (com.goide.psi.GoImportSpec)1 GoReceiver (com.goide.psi.GoReceiver)1 GoVisitor (com.goide.psi.GoVisitor)1 MultiMap (com.intellij.util.containers.MultiMap)1 Collection (java.util.Collection)1 Map (java.util.Map)1 NotNull (org.jetbrains.annotations.NotNull)1