Java Code Examples for com.intellij.psi.search.GlobalSearchScope#moduleScope()

The following examples show how to use com.intellij.psi.search.GlobalSearchScope#moduleScope() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: tmc-intellij   File: RunConfigurationFactory.java    License: MIT License 6 votes vote down vote up
/** Ui for the user to pick the Main class. */
@NotNull
public TreeClassChooser chooseMainClassForProject() {
    logger.info("Choosing main class for project.");
    TreeClassChooser chooser;
    Project project = new ObjectFinder().findCurrentProject();
    while (true) {
        TreeClassChooserFactory factory = TreeClassChooserFactory.getInstance(project);
        GlobalSearchScope scope;
        scope = GlobalSearchScope.moduleScope(module);
        PsiClass ecClass = JavaPsiFacade.getInstance(project).findClass("", scope);
        ClassFilter filter = createClassFilter();
        chooser =
                factory.createInheritanceClassChooser(
                        "Choose main class", scope, ecClass, null, filter);
        chooser.showDialog();
        if (chooser.getSelected() == null
                || chooser.getSelected().findMethodsByName("main", true).length > 0) {
            logger.info("Choosing main class aborted.");
            break;
        }
    }
    logger.info("Main class chosen successfully.");
    return chooser;
}
 
Example 2
Source Project: NutzCodeInsight   File: SqlsXmlUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static GlobalSearchScope getSearchScope(Project project, @NotNull PsiElement element) {
    GlobalSearchScope searchScope = GlobalSearchScope.projectScope(project);
    Module module = ProjectRootManager.getInstance(project).getFileIndex().getModuleForFile(element.getContainingFile().getVirtualFile());
    if (module != null) {
        searchScope = GlobalSearchScope.moduleScope(module);
    }
    return searchScope;
}
 
Example 3
Source Project: consulo   File: ClasspathPanelImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {
  final OrderEntry selectedEntry = getSelectedEntry();
  GlobalSearchScope targetScope;
  if (selectedEntry instanceof ModuleOrderEntry) {
    final Module module = ((ModuleOrderEntry)selectedEntry).getModule();
    LOG.assertTrue(module != null);
    targetScope = GlobalSearchScope.moduleScope(module);
  }
  else {
    Library library = ((LibraryOrderEntry)selectedEntry).getLibrary();
    LOG.assertTrue(library != null);
    targetScope = new LibraryScope(getProject(), library);
  }
  new AnalyzeDependenciesOnSpecifiedTargetHandler(getProject(), new AnalysisScope(myState.getRootModel().getModule()), targetScope) {
    @Override
    protected boolean canStartInBackground() {
      return false;
    }

    @Override
    protected boolean shouldShowDependenciesPanel(List<DependenciesBuilder> builders) {
      for (DependenciesBuilder builder : builders) {
        for (Set<PsiFile> files : builder.getDependencies().values()) {
          if (!files.isEmpty()) {
            Messages.showInfoMessage(myEntryTable, "Dependencies were successfully collected in \"" +
                                                   ToolWindowId.DEPENDENCIES + "\" toolwindow",
                                     FindBundle.message("find.pointcut.applications.not.found.title"));
            return true;
          }
        }
      }
      if (Messages.showOkCancelDialog(myEntryTable, "No code dependencies were found. Would you like to remove the dependency?",
                                      CommonBundle.getWarningTitle(), Messages.getWarningIcon()) == DialogWrapper.OK_EXIT_CODE) {
        removeSelectedItems(TableUtil.removeSelectedItems(myEntryTable));
      }
      return false;
    }
  }.analyze();
}
 
Example 4
Source Project: consulo   File: FavoritesTreeViewPanel.java    License: Apache License 2.0 5 votes vote down vote up
@Nullable
private PsiDirectory[] getSelectedDirectories() {
  if (myBuilder == null) return null;
  final Object[] selectedNodeElements = getSelectedNodeElements();
  if (selectedNodeElements.length != 1) return null;
  for (FavoriteNodeProvider nodeProvider : Extensions.getExtensions(FavoriteNodeProvider.EP_NAME, myProject)) {
    final PsiElement psiElement = nodeProvider.getPsiElement(selectedNodeElements[0]);
    if (psiElement instanceof PsiDirectory) {
      return new PsiDirectory[]{(PsiDirectory)psiElement};
    }
    else if (psiElement instanceof PsiDirectoryContainer) {
      final String moduleName = nodeProvider.getElementModuleName(selectedNodeElements[0]);
      GlobalSearchScope searchScope = GlobalSearchScope.projectScope(myProject);
      if (moduleName != null) {
        final Module module = ModuleManager.getInstance(myProject).findModuleByName(moduleName);
        if (module != null) {
          searchScope = GlobalSearchScope.moduleScope(module);
        }
      }
      return ((PsiDirectoryContainer)psiElement).getDirectories(searchScope);
    }
    else if (psiElement != null) {
      PsiFile file = psiElement.getContainingFile();
      if (file != null) {
        PsiDirectory parent = file.getParent();
        if (parent != null) {
          return new PsiDirectory[]{parent};
        }
      }
    }
  }
  return selectedNodeElements[0] instanceof PsiDirectory ? new PsiDirectory[]{(PsiDirectory)selectedNodeElements[0]} : null;
}
 
Example 5
Source Project: consulo   File: TodoPackageNode.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @return read-only iterator of all valid PSI files that can have T.O.D.O items
 *         and which are located under specified <code>psiDirctory</code>.
 */
public Iterator<PsiFile> getFiles(PackageElement packageElement) {
  ArrayList<PsiFile> psiFileList = new ArrayList<PsiFile>();
  GlobalSearchScope scope = packageElement.getModule() != null ? GlobalSearchScope.moduleScope(packageElement.getModule()) :
                            GlobalSearchScope.projectScope(myProject);
  final PsiDirectory[] directories = packageElement.getPackage().getDirectories(scope);
  for (PsiDirectory directory : directories) {
    Iterator<PsiFile> files = myBuilder.getFiles(directory, false);
    for (;files.hasNext();) {
      psiFileList.add(files.next());
    }
  }
  return psiFileList.iterator();
}
 
Example 6
Source Project: consulo   File: TodoTreeHelper.java    License: Apache License 2.0 5 votes vote down vote up
private static void traverseSubPackages(PsiPackage psiPackage,
                                        Module module,
                                        TodoTreeBuilder builder,
                                        Project project,
                                        Set<PsiPackage> packages) {
  if (!isPackageEmpty(new PackageElement(module, psiPackage, false), builder, project)) {
    packages.add(psiPackage);
  }
  GlobalSearchScope scope = module != null ? GlobalSearchScope.moduleScope(module) : GlobalSearchScope.projectScope(project);
  final PsiPackage[] subPackages = psiPackage.getSubPackages(scope);
  for (PsiPackage subPackage : subPackages) {
    traverseSubPackages(subPackage, module, builder, project, packages);
  }
}
 
Example 7
Source Project: consulo   File: TodoTreeHelper.java    License: Apache License 2.0 5 votes vote down vote up
private static boolean isPackageEmpty(PackageElement packageElement,
                                      TodoTreeBuilder builder,
                                      Project project) {
  if (packageElement == null) return true;
  final PsiPackage psiPackage = packageElement.getPackage();
  final Module module = packageElement.getModule();
  GlobalSearchScope scope = module != null ? GlobalSearchScope.moduleScope(module) : GlobalSearchScope.projectScope(project);
  final PsiDirectory[] directories = psiPackage.getDirectories(scope);
  boolean isEmpty = true;
  for (PsiDirectory psiDirectory : directories) {
    isEmpty &= builder.isDirectoryEmpty(psiDirectory);
  }
  return isEmpty;
}
 
Example 8
Source Project: consulo   File: PackageNodeUtil.java    License: Apache License 2.0 5 votes vote down vote up
@Nonnull
private static GlobalSearchScope getScopeToShow(@Nonnull Project project, @Nullable Module module, boolean forLibraries) {
  if (module == null) {
    if (forLibraries) {
      return new ProjectLibrariesSearchScope(project);
    }
    return GlobalSearchScope.projectScope(project);
  }
  else {
    if (forLibraries) {
      return new ModuleLibrariesSearchScope(module);
    }
    return GlobalSearchScope.moduleScope(module);
  }
}
 
Example 9
@Nullable
public static XmlTag findFlow(Module module, String flowName) {
    final GlobalSearchScope searchScope = GlobalSearchScope.moduleScope(module);
    return findFlowInScope(module.getProject(), flowName, searchScope);
}
 
Example 10
@Nullable
@Override
@RequiredReadAction
public String getAssemblyTitle()
{
	GlobalSearchScope moduleScope = GlobalSearchScope.moduleScope(getModule());
	Collection<CSharpAttributeList> attributeLists = AttributeListIndex.getInstance().get(DotNetAttributeTargetType.ASSEMBLY, getProject(), moduleScope);

	loop:
	for(CSharpAttributeList attributeList : attributeLists)
	{
		for(CSharpAttribute attribute : attributeList.getAttributes())
		{
			DotNetTypeDeclaration typeDeclaration = attribute.resolveToType();
			if(typeDeclaration == null)
			{
				continue;
			}

			if(DotNetTypes.System.Reflection.AssemblyTitleAttribute.equals(typeDeclaration.getVmQName()))
			{
				Module attributeModule = ModuleUtilCore.findModuleForPsiElement(attribute);
				if(attributeModule == null || !attributeModule.equals(getModule()))
				{
					continue;
				}
				DotNetExpression[] parameterExpressions = attribute.getParameterExpressions();
				if(parameterExpressions.length == 0)
				{
					break loop;
				}
				String valueAs = new ConstantExpressionEvaluator(parameterExpressions[0]).getValueAs(String.class);
				if(valueAs != null)
				{
					return valueAs;
				}
			}
		}
	}
	return null;
}
 
Example 11
Source Project: consulo   File: AnalysisScope.java    License: Apache License 2.0 4 votes vote down vote up
@Nonnull
public SearchScope toSearchScope() {
  switch (myType) {
    case CUSTOM:
      return myScope;
    case DIRECTORY:
      return GlobalSearchScopesCore.directoryScope((PsiDirectory)myElement, true);
    case FILE:
      return new LocalSearchScope(myElement);
    case INVALID:
      return LocalSearchScope.EMPTY;
    case MODULE:
      GlobalSearchScope moduleScope = GlobalSearchScope.moduleScope(myModule);
      return myIncludeTestSource ? moduleScope : GlobalSearchScope.notScope(GlobalSearchScopesCore.projectTestScope(myModule.getProject())).intersectWith(moduleScope);
    case MODULES:
      SearchScope scope = GlobalSearchScope.EMPTY_SCOPE;
      for (Module module : myModules) {
        scope = scope.union(GlobalSearchScope.moduleScope(module));
      }
      return scope;
    case PROJECT:
      return myIncludeTestSource ? GlobalSearchScope.projectScope(myProject) : GlobalSearchScopesCore.projectProductionScope(myProject);
    case VIRTUAL_FILES:
      return new GlobalSearchScope() {
        @Override
        public boolean contains(@Nonnull VirtualFile file) {
          return myFilesSet.contains(file);
        }

        @Override
        public int compare(@Nonnull VirtualFile file1, @Nonnull VirtualFile file2) {
          return 0;
        }

        @Override
        public boolean isSearchInModuleContent(@Nonnull Module aModule) {
          return false;
        }

        @Override
        public boolean isSearchInLibraries() {
          return false;
        }
      };
    default:
      LOG.error("invalid type " + myType);
      return GlobalSearchScope.EMPTY_SCOPE;
  }
}