use of com.intellij.psi.search.scope.packageSet.NamedScope in project intellij-community by JetBrains.
the class ScopeConfigurable method setDisplayName.
@Override
public void setDisplayName(final String name) {
if (Comparing.strEqual(myScope.getName(), name)) {
return;
}
final PackageSet packageSet = myScope.getValue();
myScope = new NamedScope(name, packageSet != null ? packageSet.createCopy() : null);
}
use of com.intellij.psi.search.scope.packageSet.NamedScope in project intellij-community by JetBrains.
the class ColorAndFontOptions method initScopesDescriptors.
private static void initScopesDescriptors(@NotNull List<EditorSchemeAttributeDescriptor> descriptions, @NotNull MyColorScheme scheme) {
Set<Pair<NamedScope, NamedScopesHolder>> namedScopes = new THashSet<>(new TObjectHashingStrategy<Pair<NamedScope, NamedScopesHolder>>() {
@Override
public int computeHashCode(@NotNull final Pair<NamedScope, NamedScopesHolder> object) {
return object.getFirst().getName().hashCode();
}
@Override
public boolean equals(@NotNull final Pair<NamedScope, NamedScopesHolder> o1, @NotNull final Pair<NamedScope, NamedScopesHolder> o2) {
return o1.getFirst().getName().equals(o2.getFirst().getName());
}
});
Project[] projects = ProjectManager.getInstance().getOpenProjects();
for (Project project : projects) {
DependencyValidationManagerImpl validationManager = (DependencyValidationManagerImpl) DependencyValidationManager.getInstance(project);
List<Pair<NamedScope, NamedScopesHolder>> cachedScopes = validationManager.getScopeBasedHighlightingCachedScopes();
namedScopes.addAll(cachedScopes);
}
List<Pair<NamedScope, NamedScopesHolder>> list = new ArrayList<>(namedScopes);
Collections.sort(list, (o1, o2) -> o1.getFirst().getName().compareToIgnoreCase(o2.getFirst().getName()));
for (Pair<NamedScope, NamedScopesHolder> pair : list) {
NamedScope namedScope = pair.getFirst();
String name = namedScope.getName();
TextAttributesKey textAttributesKey = ScopeAttributesUtil.getScopeTextAttributeKey(name);
if (scheme.getAttributes(textAttributesKey) == null) {
scheme.setAttributes(textAttributesKey, new TextAttributes());
}
NamedScopesHolder holder = pair.getSecond();
PackageSet value = namedScope.getValue();
String toolTip = holder.getDisplayName() + (value == null ? "" : ": " + value.getText());
addSchemedDescription(descriptions, name, SCOPES_GROUP, textAttributesKey, scheme, holder.getIcon(), toolTip);
}
}
use of com.intellij.psi.search.scope.packageSet.NamedScope in project intellij-community by JetBrains.
the class InspectionApplication method run.
private void run() {
File tmpDir = null;
try {
myProjectPath = myProjectPath.replace(File.separatorChar, '/');
VirtualFile vfsProject = LocalFileSystem.getInstance().findFileByPath(myProjectPath);
if (vfsProject == null) {
logError(InspectionsBundle.message("inspection.application.file.cannot.be.found", myProjectPath));
printHelp();
}
logMessage(1, InspectionsBundle.message("inspection.application.opening.project"));
final ConversionService conversionService = ConversionService.getInstance();
if (conversionService.convertSilently(myProjectPath, createConversionListener()).openingIsCanceled()) {
gracefulExit();
return;
}
myProject = ProjectUtil.openOrImport(myProjectPath, null, false);
if (myProject == null) {
logError("Unable to open project");
gracefulExit();
return;
}
ApplicationManager.getApplication().runWriteAction(() -> VirtualFileManager.getInstance().refreshWithoutFileWatcher(false));
PatchProjectUtil.patchProject(myProject);
logMessageLn(1, InspectionsBundle.message("inspection.done"));
logMessage(1, InspectionsBundle.message("inspection.application.initializing.project"));
InspectionProfileImpl inspectionProfile = loadInspectionProfile();
if (inspectionProfile == null)
return;
final InspectionManagerEx im = (InspectionManagerEx) InspectionManager.getInstance(myProject);
im.createNewGlobalContext(true).setExternalProfile(inspectionProfile);
im.setProfile(inspectionProfile.getName());
final AnalysisScope scope;
if (mySourceDirectory == null) {
final String scopeName = System.getProperty("idea.analyze.scope");
final NamedScope namedScope = scopeName != null ? NamedScopesHolder.getScope(myProject, scopeName) : null;
scope = namedScope != null ? new AnalysisScope(GlobalSearchScopesCore.filterScope(myProject, namedScope), myProject) : new AnalysisScope(myProject);
} else {
mySourceDirectory = mySourceDirectory.replace(File.separatorChar, '/');
VirtualFile vfsDir = LocalFileSystem.getInstance().findFileByPath(mySourceDirectory);
if (vfsDir == null) {
logError(InspectionsBundle.message("inspection.application.directory.cannot.be.found", mySourceDirectory));
printHelp();
}
PsiDirectory psiDirectory = PsiManager.getInstance(myProject).findDirectory(vfsDir);
scope = new AnalysisScope(psiDirectory);
}
logMessageLn(1, InspectionsBundle.message("inspection.done"));
if (!myRunWithEditorSettings) {
logMessageLn(1, InspectionsBundle.message("inspection.application.chosen.profile.log.message", inspectionProfile.getName()));
}
InspectionsReportConverter reportConverter = getReportConverter(myOutputFormat);
if (reportConverter == null && myOutputFormat != null && myOutputFormat.endsWith(".xsl")) {
// xslt converter
reportConverter = new XSLTReportConverter(myOutputFormat);
}
final String resultsDataPath;
if (// use default xml converter(if null( or don't store default xml report in tmp dir
(reportConverter == null || !reportConverter.useTmpDirForRawData()) && myOutPath != null) {
// and don't use STDOUT stream
resultsDataPath = myOutPath;
} else {
try {
tmpDir = FileUtil.createTempDirectory("inspections", "data");
resultsDataPath = tmpDir.getPath();
} catch (IOException e) {
LOG.error(e);
System.err.println("Cannot create tmp directory.");
System.exit(1);
return;
}
}
final List<File> inspectionsResults = new ArrayList<>();
ProgressManager.getInstance().runProcess(() -> {
if (!GlobalInspectionContextUtil.canRunInspections(myProject, false)) {
gracefulExit();
return;
}
im.createNewGlobalContext(true).launchInspectionsOffline(scope, resultsDataPath, myRunGlobalToolsOnly, inspectionsResults);
logMessageLn(1, "\n" + InspectionsBundle.message("inspection.capitalized.done") + "\n");
if (!myErrorCodeRequired) {
closeProject();
}
}, new ProgressIndicatorBase() {
private String lastPrefix = "";
private int myLastPercent = -1;
@Override
public void setText(String text) {
if (myVerboseLevel == 0)
return;
if (myVerboseLevel == 1) {
String prefix = getPrefix(text);
if (prefix == null)
return;
if (prefix.equals(lastPrefix)) {
logMessage(1, ".");
return;
}
lastPrefix = prefix;
logMessageLn(1, "");
logMessageLn(1, prefix);
return;
}
if (myVerboseLevel == 3) {
if (!isIndeterminate() && getFraction() > 0) {
final int percent = (int) (getFraction() * 100);
if (myLastPercent == percent)
return;
String prefix = getPrefix(text);
myLastPercent = percent;
String msg = (prefix != null ? prefix : InspectionsBundle.message("inspection.display.name")) + " " + percent + "%";
logMessageLn(2, msg);
}
return;
}
logMessageLn(2, text);
}
});
final String descriptionsFile = resultsDataPath + File.separatorChar + DESCRIPTIONS + XML_EXTENSION;
describeInspections(descriptionsFile, myRunWithEditorSettings ? null : inspectionProfile.getName(), inspectionProfile);
inspectionsResults.add(new File(descriptionsFile));
// convert report
if (reportConverter != null) {
try {
reportConverter.convert(resultsDataPath, myOutPath, im.createNewGlobalContext(true).getTools(), inspectionsResults);
} catch (InspectionsReportConverter.ConversionException e) {
logError("\n" + e.getMessage());
printHelp();
}
}
} catch (IOException e) {
LOG.error(e);
logError(e.getMessage());
printHelp();
} catch (Throwable e) {
LOG.error(e);
logError(e.getMessage());
gracefulExit();
} finally {
// delete tmp dir
if (tmpDir != null) {
FileUtil.delete(tmpDir);
}
}
}
use of com.intellij.psi.search.scope.packageSet.NamedScope in project intellij-community by JetBrains.
the class ScopePaneSelectInTarget method isSubIdSelectable.
@Override
public boolean isSubIdSelectable(@NotNull String subId, @NotNull SelectInContext context) {
PsiFileSystemItem file = getContextPsiFile(context);
if (!(file instanceof PsiFile))
return false;
final NamedScope scope = NamedScopesHolder.getScope(myProject, subId);
PackageSet packageSet = scope != null ? scope.getValue() : null;
if (packageSet == null)
return false;
NamedScopesHolder holder = NamedScopesHolder.getHolder(myProject, subId, DependencyValidationManager.getInstance(myProject));
return packageSet.contains((PsiFile) file, holder);
}
use of com.intellij.psi.search.scope.packageSet.NamedScope in project intellij-community by JetBrains.
the class FileColorConfigurationEditDialog method createNorthPanel.
@Override
protected JComponent createNorthPanel() {
final List<NamedScope> scopeList = new ArrayList<>();
final Project project = myManager.getProject();
final NamedScopesHolder[] scopeHolders = NamedScopeManager.getAllNamedScopeHolders(project);
for (final NamedScopesHolder scopeHolder : scopeHolders) {
final NamedScope[] scopes = scopeHolder.getScopes();
Collections.addAll(scopeList, scopes);
}
CustomScopesProviderEx.filterNoSettingsScopes(project, scopeList);
for (final NamedScope scope : scopeList) {
myScopeNames.put(scope.getName(), scope);
}
myScopeComboBox = new JComboBox(ArrayUtil.toStringArray(myScopeNames.keySet()));
myScopeComboBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
updateCustomButton();
updateOKButton();
}
});
new ComboboxSpeedSearch(myScopeComboBox);
final JLabel pathLabel = new JLabel("Scope:");
pathLabel.setDisplayedMnemonic('S');
pathLabel.setLabelFor(myScopeComboBox);
final JLabel colorLabel = new JLabel("Color:");
JPanel result = new JPanel(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.fill = GridBagConstraints.BOTH;
gbc.insets = JBUI.insets(5);
gbc.gridx = 0;
result.add(pathLabel, gbc);
result.add(colorLabel, gbc);
gbc.gridx = 1;
gbc.weightx = 1;
result.add(myScopeComboBox, gbc);
result.add(myColorSelectionComponent, gbc);
return result;
}
Aggregations