com.intellij.psi.search.GlobalSearchScope#moduleScope ( )源码实例Demo

下面列出了com.intellij.psi.search.GlobalSearchScope#moduleScope ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: tmc-intellij   文件: RunConfigurationFactory.java
/** 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;
}
 
源代码2 项目: NutzCodeInsight   文件: SqlsXmlUtil.java
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;
}
 
源代码3 项目: consulo   文件: ClasspathPanelImpl.java
@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();
}
 
源代码4 项目: consulo   文件: FavoritesTreeViewPanel.java
@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;
}
 
源代码5 项目: consulo   文件: TodoPackageNode.java
/**
 * @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();
}
 
源代码6 项目: consulo   文件: TodoTreeHelper.java
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);
  }
}
 
源代码7 项目: consulo   文件: TodoTreeHelper.java
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;
}
 
源代码8 项目: consulo   文件: PackageNodeUtil.java
@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);
  }
}
 
源代码9 项目: mule-intellij-plugins   文件: MuleConfigUtils.java
@Nullable
public static XmlTag findFlow(Module module, String flowName) {
    final GlobalSearchScope searchScope = GlobalSearchScope.moduleScope(module);
    return findFlowInScope(module.getProject(), flowName, searchScope);
}
 
源代码10 项目: consulo-csharp   文件: BaseCSharpModuleExtension.java
@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;
}
 
源代码11 项目: consulo   文件: AnalysisScope.java
@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;
  }
}