From 4467c9f3e4e73950d93988b3bb1316915e18fead Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Mon, 13 Apr 2015 15:07:21 +0200 Subject: [PATCH] Cleanup (formatting) --- .../DependencyInspectionBase.java | 66 ++++++++++--------- 1 file changed, 35 insertions(+), 31 deletions(-) diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/dependencyViolation/DependencyInspectionBase.java b/java/java-analysis-impl/src/com/intellij/codeInspection/dependencyViolation/DependencyInspectionBase.java index 5eca5fe765f9..d911b4302525 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/dependencyViolation/DependencyInspectionBase.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/dependencyViolation/DependencyInspectionBase.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,7 @@ package com.intellij.codeInspection.dependencyViolation; import com.intellij.codeHighlighting.HighlightDisplayLevel; +import com.intellij.codeInsight.daemon.GroupNames; import com.intellij.codeInspection.*; import com.intellij.lang.java.JavaLanguage; import com.intellij.packageDependencies.DependenciesBuilder; @@ -23,81 +24,84 @@ import com.intellij.packageDependencies.DependencyRule; import com.intellij.packageDependencies.DependencyValidationManager; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; +import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.FactoryMap; -import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.ArrayList; import java.util.List; +import java.util.Map; public class DependencyInspectionBase extends BaseJavaBatchLocalInspectionTool { - private static final String GROUP_DISPLAY_NAME = ""; - private static final String DISPLAY_NAME = InspectionsBundle.message("illegal.package.dependencies"); - @NonNls private static final String SHORT_NAME = "Dependency"; - @Override public boolean isEnabledByDefault() { return true; } + @Override + @NotNull + public HighlightDisplayLevel getDefaultLevel() { + return HighlightDisplayLevel.ERROR; + } + @Override @NotNull public String getGroupDisplayName() { - return GROUP_DISPLAY_NAME; + return GroupNames.DEPENDENCY_GROUP_NAME; } @Override @NotNull public String getDisplayName() { - return DISPLAY_NAME; + return InspectionsBundle.message("illegal.package.dependencies"); } @Override @NotNull public String getShortName() { - return SHORT_NAME; + return "Dependency"; } @Override @Nullable public ProblemDescriptor[] checkFile(@NotNull final PsiFile file, @NotNull final InspectionManager manager, final boolean isOnTheFly) { - if (file.getViewProvider().getPsi(JavaLanguage.INSTANCE) == null) return null; + if (file.getViewProvider().getPsi(JavaLanguage.INSTANCE) == null) { + return null; + } + final DependencyValidationManager validationManager = DependencyValidationManager.getInstance(file.getProject()); - if (!validationManager.hasRules()) return null; - if (validationManager.getApplicableRules(file).length == 0) return null; - final List problems = new ArrayList(); - final FactoryMap violations = new FactoryMap() { - @Nullable - @Override - protected DependencyRule[] create(PsiFile dependencyFile) { - return validationManager.getViolatorDependencyRules(file, dependencyFile); - } - }; + if (!validationManager.hasRules() || validationManager.getApplicableRules(file).length == 0) { + return null; + } + + final List problems = ContainerUtil.newSmartList(); DependenciesBuilder.analyzeFileDependencies(file, new DependenciesBuilder.DependencyProcessor() { + @SuppressWarnings("MismatchedQueryAndUpdateOfCollection") + private final Map violations = new FactoryMap() { + @Nullable + @Override + protected DependencyRule[] create(PsiFile dependencyFile) { + return validationManager.getViolatorDependencyRules(file, dependencyFile); + } + }; + @Override public void process(PsiElement place, PsiElement dependency) { PsiFile dependencyFile = dependency.getContainingFile(); if (dependencyFile != null && dependencyFile.isPhysical() && dependencyFile.getVirtualFile() != null) { for (DependencyRule dependencyRule : violations.get(dependencyFile)) { - problems.add(manager.createProblemDescriptor(place, InspectionsBundle - .message("inspection.dependency.violator.problem.descriptor", dependencyRule.getDisplayText()), isOnTheFly, - createEditDependencyFixes(dependencyRule), - ProblemHighlightType.GENERIC_ERROR_OR_WARNING)); + String message = InspectionsBundle.message("inspection.dependency.violator.problem.descriptor", dependencyRule.getDisplayText()); + LocalQuickFix[] fixes = createEditDependencyFixes(dependencyRule); + problems.add(manager.createProblemDescriptor(place, message, isOnTheFly, fixes, ProblemHighlightType.GENERIC_ERROR_OR_WARNING)); } } } }); + return problems.isEmpty() ? null : problems.toArray(new ProblemDescriptor[problems.size()]); } protected LocalQuickFix[] createEditDependencyFixes(DependencyRule dependencyRule) { return null; } - - @Override - @NotNull - public HighlightDisplayLevel getDefaultLevel() { - return HighlightDisplayLevel.ERROR; - } }