use of com.intellij.packageDependencies.DependencyValidationManager in project intellij-community by JetBrains.
the class ToolsImpl method isEnabled.
@Override
public boolean isEnabled(PsiElement element) {
if (!myEnabled)
return false;
if (myTools == null || element == null)
return myDefaultState.isEnabled();
final Project project = element.getProject();
final DependencyValidationManager manager = DependencyValidationManager.getInstance(project);
for (ScopeToolState state : myTools) {
final NamedScope scope = state.getScope(project);
if (scope != null) {
final PackageSet set = scope.getValue();
if (set != null && set.contains(element.getContainingFile(), manager)) {
return state.isEnabled();
}
}
}
return myDefaultState.isEnabled();
}
use of com.intellij.packageDependencies.DependencyValidationManager in project intellij-community by JetBrains.
the class ToolsImpl method getLevel.
public HighlightDisplayLevel getLevel(PsiElement element) {
if (myTools == null || element == null)
return myDefaultState.getLevel();
final Project project = element.getProject();
final DependencyValidationManager manager = DependencyValidationManager.getInstance(project);
for (ScopeToolState state : myTools) {
final NamedScope scope = state.getScope(project);
final PackageSet set = scope != null ? scope.getValue() : null;
if (set != null && set.contains(element.getContainingFile(), manager)) {
return state.getLevel();
}
}
return myDefaultState.getLevel();
}
use of com.intellij.packageDependencies.DependencyValidationManager 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.DependencyValidationManager 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.DependencyValidationManager in project intellij-community by JetBrains.
the class EditScopesDialog method doOKAction.
@Override
public void doOKAction() {
Object selectedObject = myConfigurable.getSelectedObject();
mySelectedScope = selectedObject instanceof NamedScope ? (NamedScope) selectedObject : null;
super.doOKAction();
if (myCheckShared && mySelectedScope != null) {
final Project project = myProject;
final DependencyValidationManager manager = DependencyValidationManager.getInstance(project);
NamedScope scope = manager.getScope(mySelectedScope.getName());
if (scope == null) {
if (Messages.showYesNoDialog(IdeBundle.message("scope.unable.to.save.scope.message"), IdeBundle.message("scope.unable.to.save.scope.title"), Messages.getErrorIcon()) == Messages.YES) {
final String newName = Messages.showInputDialog(project, IdeBundle.message("add.scope.name.label"), IdeBundle.message("scopes.save.dialog.title.shared"), Messages.getQuestionIcon(), mySelectedScope.getName(), new InputValidator() {
@Override
public boolean checkInput(String inputString) {
return inputString != null && inputString.length() > 0 && manager.getScope(inputString) == null;
}
@Override
public boolean canClose(String inputString) {
return checkInput(inputString);
}
});
if (newName != null) {
final PackageSet packageSet = mySelectedScope.getValue();
scope = new NamedScope(newName, packageSet != null ? packageSet.createCopy() : null);
mySelectedScope = scope;
manager.addScope(mySelectedScope);
}
}
}
}
}
Aggregations