use of com.intellij.packageDependencies.DependencyRule in project intellij-community by JetBrains.
the class ImportClassFixBase method reduceSuggestedClassesBasedOnDependencyRuleViolation.
private static void reduceSuggestedClassesBasedOnDependencyRuleViolation(PsiFile file, List<PsiClass> availableClasses) {
final Project project = file.getProject();
final DependencyValidationManager validationManager = DependencyValidationManager.getInstance(project);
for (int i = availableClasses.size() - 1; i >= 0; i--) {
PsiClass psiClass = availableClasses.get(i);
PsiFile targetFile = psiClass.getContainingFile();
if (targetFile == null)
continue;
final DependencyRule[] violated = validationManager.getViolatorDependencyRules(file, targetFile);
if (violated.length != 0) {
availableClasses.remove(i);
if (availableClasses.size() == 1)
break;
}
}
}
use of com.intellij.packageDependencies.DependencyRule in project intellij-community by JetBrains.
the class DependencyInspectionBase method checkFile.
@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;
}
final DependencyValidationManager validationManager = DependencyValidationManager.getInstance(file.getProject());
if (!validationManager.hasRules() || validationManager.getApplicableRules(file).length == 0) {
return null;
}
final List<ProblemDescriptor> problems = ContainerUtil.newSmartList();
DependenciesBuilder.analyzeFileDependencies(file, new DependenciesBuilder.DependencyProcessor() {
@SuppressWarnings("MismatchedQueryAndUpdateOfCollection")
private final Map<PsiFile, DependencyRule[]> violations = new FactoryMap<PsiFile, DependencyRule[]>() {
@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)) {
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()]);
}
use of com.intellij.packageDependencies.DependencyRule in project intellij-community by JetBrains.
the class DependencyConfigurable method isModified.
@Override
public boolean isModified() {
final DependencyValidationManager validationManager = DependencyValidationManager.getInstance(myProject);
if (validationManager.skipImportStatements() != mySkipImports.isSelected())
return true;
final List<DependencyRule> rules = new ArrayList<>();
rules.addAll(myDenyRulesModel.getItems());
rules.addAll(myAllowRulesModel.getItems());
return !Arrays.asList(validationManager.getAllRules()).equals(rules);
}
use of com.intellij.packageDependencies.DependencyRule in project intellij-community by JetBrains.
the class DependencyConfigurable method apply.
@Override
public void apply() throws ConfigurationException {
stopTableEditing();
DependencyValidationManager validationManager = DependencyValidationManager.getInstance(myProject);
validationManager.removeAllRules();
final HashMap<String, PackageSet> unUsed = new HashMap<>(validationManager.getUnnamedScopes());
List<DependencyRule> modelItems = new ArrayList<>();
modelItems.addAll(myDenyRulesModel.getItems());
modelItems.addAll(myAllowRulesModel.getItems());
for (DependencyRule rule : modelItems) {
validationManager.addRule(rule);
final NamedScope fromScope = rule.getFromScope();
if (fromScope instanceof NamedScope.UnnamedScope) {
final PackageSet fromPackageSet = fromScope.getValue();
LOG.assertTrue(fromPackageSet != null);
unUsed.remove(fromPackageSet.getText());
}
final NamedScope toScope = rule.getToScope();
if (toScope instanceof NamedScope.UnnamedScope) {
final PackageSet toPackageSet = toScope.getValue();
LOG.assertTrue(toPackageSet != null);
unUsed.remove(toPackageSet.getText());
}
}
for (String text : unUsed.keySet()) {
//cleanup
validationManager.getUnnamedScopes().remove(text);
}
validationManager.setSkipImportStatements(mySkipImports.isSelected());
DaemonCodeAnalyzer.getInstance(myProject).restart();
}
use of com.intellij.packageDependencies.DependencyRule in project intellij-community by JetBrains.
the class DependencyConfigurable method reset.
@Override
public void reset() {
final DependencyValidationManager validationManager = DependencyValidationManager.getInstance(myProject);
DependencyRule[] rules = validationManager.getAllRules();
final ArrayList<DependencyRule> denyList = new ArrayList<>();
final ArrayList<DependencyRule> allowList = new ArrayList<>();
for (DependencyRule rule : rules) {
if (rule.isDenyRule()) {
denyList.add(rule.createCopy());
} else {
allowList.add(rule.createCopy());
}
}
myDenyRulesModel.setItems(denyList);
myAllowRulesModel.setItems(allowList);
mySkipImports.setSelected(validationManager.skipImportStatements());
}
Aggregations