mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
allow to fetch predefined scopes by name (IDEA-82350)
This commit is contained in:
@@ -23,7 +23,7 @@ package com.intellij.analysis;
|
||||
import com.intellij.openapi.extensions.Extensions;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.search.scope.ProjectProductionScope;
|
||||
import com.intellij.psi.search.scope.packageSet.CustomScopesProvider;
|
||||
import com.intellij.psi.search.scope.packageSet.CustomScopesProviderEx;
|
||||
import com.intellij.psi.search.scope.packageSet.NamedScope;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -33,7 +33,7 @@ import java.util.List;
|
||||
/**
|
||||
* @author Konstantin Bulenkov
|
||||
*/
|
||||
public class PackagesScopesProvider implements CustomScopesProvider {
|
||||
public class PackagesScopesProvider extends CustomScopesProviderEx {
|
||||
private final NamedScope myProjectProductionScope;
|
||||
private final List<NamedScope> myScopes;
|
||||
|
||||
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2000-2012 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.psi.search.scope.packageSet;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* User: anna
|
||||
* Date: 3/14/12
|
||||
*/
|
||||
public abstract class CustomScopesProviderEx implements CustomScopesProvider {
|
||||
@Nullable
|
||||
public NamedScope getCustomScope(String name) {
|
||||
final List<NamedScope> predefinedScopes = getCustomScopes();
|
||||
return findPredefinedScope(name, predefinedScopes);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static NamedScope findPredefinedScope(String name, List<NamedScope> predefinedScopes) {
|
||||
for (NamedScope scope : predefinedScopes) {
|
||||
if (name.equals(scope.getName())) return scope;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+6
-5
@@ -179,17 +179,18 @@ public abstract class NamedScopesHolder implements PersistentStateComponent<Elem
|
||||
for (NamedScope scope : myScopes) {
|
||||
if (name.equals(scope.getName())) return scope;
|
||||
}
|
||||
final List<NamedScope> predefinedScopes = getPredefinedScopes();
|
||||
for (NamedScope scope : predefinedScopes) {
|
||||
if (name.equals(scope.getName())) return scope;
|
||||
}
|
||||
return null;
|
||||
return getPredefinedScope(name);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<NamedScope> getPredefinedScopes(){
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public NamedScope getPredefinedScope(String name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Project getProject() {
|
||||
return myProject;
|
||||
|
||||
+32
-17
@@ -18,10 +18,7 @@ package com.intellij.packageDependencies;
|
||||
import com.intellij.ide.IdeBundle;
|
||||
import com.intellij.openapi.extensions.Extensions;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vcs.changes.Change;
|
||||
import com.intellij.openapi.vcs.changes.ChangeList;
|
||||
import com.intellij.openapi.vcs.changes.ChangeListManager;
|
||||
import com.intellij.openapi.vcs.changes.ContentRevision;
|
||||
import com.intellij.openapi.vcs.changes.*;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.search.scope.packageSet.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -34,7 +31,7 @@ import java.util.List;
|
||||
/**
|
||||
* @author anna
|
||||
*/
|
||||
public class ChangeListsScopesProvider implements CustomScopesProvider {
|
||||
public class ChangeListsScopesProvider extends CustomScopesProviderEx {
|
||||
private Project myProject;
|
||||
|
||||
public static ChangeListsScopesProvider getInstance(Project project) {
|
||||
@@ -55,22 +52,40 @@ public class ChangeListsScopesProvider implements CustomScopesProvider {
|
||||
final List<NamedScope> result = new ArrayList<NamedScope>();
|
||||
result.add(createScope(changeListManager.getAffectedFiles(), IdeBundle.message("scope.modified.files")));
|
||||
for (ChangeList list : changeListManager.getChangeListsCopy()) {
|
||||
final List<VirtualFile> files = new ArrayList<VirtualFile>();
|
||||
final Collection<Change> changes = list.getChanges();
|
||||
for (Change change : changes) {
|
||||
final ContentRevision afterRevision = change.getAfterRevision();
|
||||
if (afterRevision != null) {
|
||||
final VirtualFile vFile = afterRevision.getFile().getVirtualFile();
|
||||
if (vFile != null) {
|
||||
files.add(vFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
result.add(createScope(files, list.getName()));
|
||||
result.add(createChangeListScope(list));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static NamedScope createChangeListScope(@NotNull ChangeList list) {
|
||||
final List<VirtualFile> files = new ArrayList<VirtualFile>();
|
||||
final Collection<Change> changes = list.getChanges();
|
||||
for (Change change : changes) {
|
||||
final ContentRevision afterRevision = change.getAfterRevision();
|
||||
if (afterRevision != null) {
|
||||
final VirtualFile vFile = afterRevision.getFile().getVirtualFile();
|
||||
if (vFile != null) {
|
||||
files.add(vFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
return createScope(files, list.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public NamedScope getCustomScope(String name) {
|
||||
if (myProject.isDefault()) return null;
|
||||
final ChangeListManager changeListManager = ChangeListManager.getInstance(myProject);
|
||||
if (IdeBundle.message("scope.modified.files").equals(name)) {
|
||||
return createScope(changeListManager.getAffectedFiles(), IdeBundle.message("scope.modified.files"));
|
||||
}
|
||||
final LocalChangeList changeList = changeListManager.getChangeList(name);
|
||||
if (changeList != null) {
|
||||
return createChangeListScope(changeList);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static NamedScope createScope(final List<VirtualFile> files, String changeListName) {
|
||||
return new NamedScope(changeListName, new PackageSetBase() {
|
||||
@Override
|
||||
|
||||
@@ -35,7 +35,7 @@ import java.util.List;
|
||||
* @author anna
|
||||
* @author Konstantin Bulenkov
|
||||
*/
|
||||
public class DefaultScopesProvider implements CustomScopesProvider {
|
||||
public class DefaultScopesProvider extends CustomScopesProviderEx {
|
||||
private final NamedScope myProblemsScope;
|
||||
private final Project myProject;
|
||||
private final List<NamedScope> myScopes;
|
||||
|
||||
+16
@@ -80,6 +80,22 @@ public class DependencyValidationManagerImpl extends DependencyValidationManager
|
||||
return predefinedScopes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NamedScope getPredefinedScope(String name) {
|
||||
final CustomScopesProvider[] scopesProviders = myProject.getExtensions(CustomScopesProvider.CUSTOM_SCOPES_PROVIDER);
|
||||
if (scopesProviders != null) {
|
||||
for (CustomScopesProvider scopesProvider : scopesProviders) {
|
||||
final NamedScope scope = scopesProvider instanceof CustomScopesProviderEx
|
||||
? ((CustomScopesProviderEx)scopesProvider).getCustomScope(name)
|
||||
: CustomScopesProviderEx.findPredefinedScope(name, scopesProvider.getCustomScopes());
|
||||
if (scope != null) {
|
||||
return scope;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean hasRules() {
|
||||
return !myRules.isEmpty();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user