Java 类com.intellij.psi.search.ProjectScope 实例源码

项目:tools-idea    文件:ComponentItemDialog.java   
public void actionPerformed(ActionEvent e) {
  final TreeClassChooserFactory factory = TreeClassChooserFactory.getInstance(myProject);
  PsiFile formFile = null;
  if (myTextField.getText().length() > 0) {
    VirtualFile formVFile = ResourceFileUtil.findResourceFileInScope(myTextField.getText(), myProject, ProjectScope.getAllScope(myProject));
    if (formVFile != null) {
      formFile = PsiManager.getInstance(myProject).findFile(formVFile);
    }
  }
  TreeFileChooser fileChooser = factory.createFileChooser(myTitle, formFile, null, myFilter, true, true);
  fileChooser.showDialog();
  PsiFile file = fileChooser.getSelectedFile();
  if (file != null) {
    myTextField.setText(FormEditingUtil.buildResourceName(file));
  }
}
项目:hybris-integration-intellij-idea-plugin    文件:TSMetaModelBuilder.java   
@NotNull
public TSMetaModelImpl buildModel() {
    myResult = new TSMetaModelImpl();
    myFiles.clear();

    StubIndex.getInstance().processElements(
        DomElementClassIndex.KEY,
        Items.class.getName(),
        myProject,
        ProjectScope.getAllScope(myProject),
        PsiFile.class,
        this
    );
    final TSMetaModelImpl result = myResult;
    myResult = null;
    return result;
}
项目:mule-intellij-plugins    文件:MuleConfigUtils.java   
public static List<XmlTag> findFlowRefsForFlow(@NotNull XmlTag flow) {
    List<XmlTag> flowRefs = new ArrayList<>();

    final Project project = flow.getProject();
    final String flowName = flow.getAttributeValue(MuleConfigConstants.NAME_ATTRIBUTE);

    Collection<VirtualFile> vFiles = FileTypeIndex.getFiles(StdFileTypes.XML, ProjectScope.getContentScope(project));
    for (VirtualFile virtualFile : vFiles) {
        PsiFile psiFile = PsiManager.getInstance(project).findFile(virtualFile);
        if (psiFile != null) {
            XmlFile xmlFile = (XmlFile) psiFile;
            XmlTag mule = xmlFile.getRootTag();

            FlowRefsFinder finder = new FlowRefsFinder(flowName);
            mule.accept(finder);
            flowRefs.addAll(finder.getFlowRefs());
        }
    }
    return flowRefs;
}
项目:intellij-ce-playground    文件:ProjectBytecodeAnalysis.java   
private void collectSingleEquation(HKey hKey, Solver solver, @NotNull Map<Bytes, List<HEquations>> cache) throws EquationsLimitException {
  GlobalSearchScope librariesScope = ProjectScope.getLibrariesScope(myProject);

  FileBasedIndex index = FileBasedIndex.getInstance();

  ProgressManager.checkCanceled();
  Bytes bytes = new Bytes(hKey.key);

  List<HEquations> hEquationss = cache.get(bytes);
  if (hEquationss == null) {
    hEquationss = index.getValues(BytecodeAnalysisIndex.NAME, bytes, librariesScope);
    cache.put(bytes, hEquationss);
  }

  for (HEquations hEquations : hEquationss) {
    boolean stable = hEquations.stable;
    for (DirectionResultPair pair : hEquations.results) {
      int dirKey = pair.directionKey;
      if (dirKey == hKey.dirKey) {
        HResult result = pair.hResult;
        solver.addEquation(new HEquation(new HKey(bytes.bytes, dirKey, stable, false), result));
      }
    }
  }
}
项目:intellij-ce-playground    文件:TryWithResourcesPostfixTemplate.java   
@Override
public boolean isApplicable(@NotNull PsiElement element, @NotNull Document copyDocument, int newOffset) {
  if (!PsiUtil.isLanguageLevel7OrHigher(element)) return false;

  PsiExpression initializer = JavaPostfixTemplatesUtils.getTopmostExpression(element);

  if (initializer == null) return false;

  final PsiType type = initializer.getType();
  if (!(type instanceof PsiClassType)) return false;
  final PsiClass aClass = ((PsiClassType)type).resolve();
  Project project = element.getProject();
  final JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
  final PsiClass autoCloseable = facade.findClass(CommonClassNames.JAVA_LANG_AUTO_CLOSEABLE, ProjectScope.getLibrariesScope(project));
  if (!InheritanceUtil.isInheritorOrSelf(aClass, autoCloseable, true)) return false;

  return true;
}
项目:intellij-ce-playground    文件:InlineToAnonymousClassMultifileTest.java   
private void doTest(String className) throws Exception {
  String rootBefore = getRoot() + "/before";
  PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk17());
  final VirtualFile rootDir = PsiTestUtil.createTestProjectStructure(myProject, myModule, rootBefore, myFilesToDelete);
  PsiClass classToInline = myJavaFacade.findClass(className, ProjectScope.getAllScope(myProject));
  assertEquals(null, InlineToAnonymousClassHandler.getCannotInlineMessage(classToInline));
  InlineToAnonymousClassProcessor processor = new InlineToAnonymousClassProcessor(myProject, 
                                                                                  classToInline,
                                                                                  null, false, false, false);
  UsageInfo[] usages = processor.findUsages();
  MultiMap<PsiElement,String> conflicts = processor.getConflicts(usages);
  assertEquals(0, conflicts.size());
  processor.run();

  String rootAfter = getRoot() + "/after";
  VirtualFile rootDir2 = LocalFileSystem.getInstance().findFileByPath(rootAfter.replace(File.separatorChar, '/'));
  myProject.getComponent(PostprocessReformattingAspect.class).doPostponedFormatting();
  PlatformTestUtil.assertDirectoriesEqual(rootDir2, rootDir);
}
项目:intellij-ce-playground    文件:InlineMethodMultifileTest.java   
private void doTest(String className, String methodName) throws Exception {
  String rootBefore = getRoot() + "/before";
  PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk17());
  final VirtualFile rootDir = PsiTestUtil.createTestProjectStructure(myProject, myModule, rootBefore, myFilesToDelete);
  PsiClass aClass = myJavaFacade.findClass(className, ProjectScope.getAllScope(myProject));
  assertTrue(aClass != null);
  PsiElement element = aClass.findMethodsByName(methodName, false)[0];
  assertTrue(element instanceof PsiMethod);
  PsiMethod method = (PsiMethod)element;
  final boolean condition = InlineMethodProcessor.checkBadReturns(method) && !InlineUtil.allUsagesAreTailCalls(method);
  assertFalse("Bad returns found", condition);

  InlineOptions options = new MockInlineMethodOptions();
  final InlineMethodProcessor processor = new InlineMethodProcessor(getProject(), method, null, myEditor, options.isInlineThisOnly());
  processor.run();

  String rootAfter = getRoot() + "/after";
  VirtualFile rootDir2 = LocalFileSystem.getInstance().findFileByPath(rootAfter.replace(File.separatorChar, '/'));
  myProject.getComponent(PostprocessReformattingAspect.class).doPostponedFormatting();
  PlatformTestUtil.assertDirectoriesEqual(rootDir2, rootDir);
}
项目:intellij-ce-playground    文件:MoveMembersTest.java   
private void performAction(String sourceClassName, String targetClassName, int[] memberIndices, final String visibility) throws Exception {
  PsiClass sourceClass = myJavaFacade.findClass(sourceClassName, ProjectScope.getProjectScope(myProject));
  assertNotNull("Class " + sourceClassName + " not found", sourceClass);
  PsiClass targetClass = myJavaFacade.findClass(targetClassName, ProjectScope.getProjectScope(myProject));
  assertNotNull("Class " + targetClassName + " not found", targetClass);

  PsiElement[] children = sourceClass.getChildren();
  ArrayList<PsiMember> members = new ArrayList<>();
  for (PsiElement child : children) {
    if (child instanceof PsiMember) {
      members.add(((PsiMember) child));
    }
  }

  LinkedHashSet<PsiMember> memberSet = new LinkedHashSet<>();
  for (int index : memberIndices) {
    PsiMember member = members.get(index);
    assertTrue(member.hasModifierProperty(PsiModifier.STATIC));
    memberSet.add(member);
  }

  MockMoveMembersOptions options = new MockMoveMembersOptions(targetClass.getQualifiedName(), memberSet);
  options.setMemberVisibility(visibility);
  new MoveMembersProcessor(myProject, null, options).run();
  FileDocumentManager.getInstance().saveAllDocuments();
}
项目:intellij-ce-playground    文件:FindUsagesOptions.java   
public FindUsagesOptions(@NotNull Project project, @Nullable final DataContext dataContext) {
  String defaultScopeName = FindSettings.getInstance().getDefaultScopeName();
  List<SearchScope> predefined = PredefinedSearchScopeProvider.getInstance().getPredefinedScopes(project, dataContext, true, false, false,
                                                                                                 false);
  SearchScope resultScope = null;
  for (SearchScope scope : predefined) {
    if (scope.getDisplayName().equals(defaultScopeName)) {
      resultScope = scope;
      break;
    }
  }
  if (resultScope == null) {
    resultScope = ProjectScope.getProjectScope(project);
  }
  searchScope = resultScope;
}
项目:intellij-ce-playground    文件:HighlightingSettingsPerFile.java   
@Override
public boolean shouldInspect(@NotNull PsiElement psiRoot) {
  if (ApplicationManager.getApplication().isUnitTestMode()) return true;

  final FileHighlightingSetting settingForRoot = getHighlightingSettingForRoot(psiRoot);
  if (settingForRoot == FileHighlightingSetting.SKIP_HIGHLIGHTING ||
      settingForRoot == FileHighlightingSetting.SKIP_INSPECTION) {
    return false;
  }
  final Project project = psiRoot.getProject();
  final VirtualFile virtualFile = psiRoot.getContainingFile().getVirtualFile();
  if (virtualFile == null || !virtualFile.isValid()) return false;

  if (ProjectCoreUtil.isProjectOrWorkspaceFile(virtualFile)) return false;

  final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
  if (ProjectScope.getLibrariesScope(project).contains(virtualFile) && !fileIndex.isInContent(virtualFile)) return false;

  return !SingleRootFileViewProvider.isTooLargeForIntelligence(virtualFile);
}
项目:intellij-ce-playground    文件:PyQualifiedReference.java   
private int getImplicitResultRate(PyElement target, List<QualifiedName> imports) {
  int rate = RatedResolveResult.RATE_LOW;
  if (target.getContainingFile() == myElement.getContainingFile()) {
    rate += 200;
  }
  else {
    final VirtualFile vFile = target.getContainingFile().getVirtualFile();
    if (vFile != null) {
      if (ProjectScope.getProjectScope(myElement.getProject()).contains(vFile)) {
        rate += 80;
      }
      final QualifiedName qName = QualifiedNameFinder.findShortestImportableQName(myElement, vFile);
      if (qName != null && imports.contains(qName)) {
        rate += 70;
      }
    }
  }
  if (myElement.getParent() instanceof PyCallExpression) {
    if (target instanceof PyFunction) rate += 50;
  }
  else {
    if (!(target instanceof PyFunction)) rate += 50;
  }
  return rate;
}
项目:intellij-ce-playground    文件:PyMoveTest.java   
@Nullable
private PsiNamedElement findFirstNamedElement(String name) {
  final Project project = myFixture.getProject();
  final Collection<PyClass> classes = PyClassNameIndex.find(name, project, false);
  if (classes.size() > 0) {
    return classes.iterator().next();
  }
  final Collection<PyFunction> functions = PyFunctionNameIndex.find(name, project);
  if (functions.size() > 0) {
    return functions.iterator().next();
  }
  final Collection<PyTargetExpression> targets = PyVariableNameIndex.find(name, project, ProjectScope.getAllScope(project));
  if (targets.size() > 0) {
    return targets.iterator().next();
  }
  return null;
}
项目:intellij-ce-playground    文件:AndroidInheritingClassBrowser.java   
@Override
protected TreeClassChooser createTreeClassChooser(@NotNull Project project,
                                                  @NotNull GlobalSearchScope scope,
                                                  @Nullable PsiClass initialSelection,
                                                  @NotNull final ClassFilter classFilter) {
  final PsiClass baseClass = JavaPsiFacade.getInstance(project).findClass(myBaseClassName, ProjectScope.getAllScope(project));

  if (baseClass == null) {
    Messages.showErrorDialog(project, AndroidBundle.message("cant.find.class.error", myBaseClassName), CommonBundle.getErrorTitle());
    return null;
  }
  return TreeClassChooserFactory.getInstance(project).createInheritanceClassChooser(
    myDialogTitle, scope, baseClass, initialSelection, new ClassFilter() {
    @Override
    public boolean isAccepted(PsiClass aClass) {
      if (aClass.getManager().areElementsEquivalent(aClass, baseClass)) {
        return false;
      }
      return classFilter.isAccepted(aClass);
    }
  });
}
项目:intellij-ce-playground    文件:AddComponentAction.java   
private static void assignDefaultIcon(final Project project, final ComponentItem itemToBeAdded) {
  Palette palette = Palette.getInstance(project);
  if (itemToBeAdded.getIconPath() == null || itemToBeAdded.getIconPath().length() == 0) {
    PsiClass aClass =
      JavaPsiFacade.getInstance(project).findClass(itemToBeAdded.getClassName().replace('$', '.'), ProjectScope.getAllScope(project));
    while(aClass != null) {
      final ComponentItem item = palette.getItem(aClass.getQualifiedName());
      if (item != null) {
        String iconPath = item.getIconPath();
        if (iconPath != null && iconPath.length() > 0) {
          itemToBeAdded.setIconPath(iconPath);
          return;
        }
      }
      aClass = aClass.getSuperClass();
    }
  }
}
项目:intellij-ce-playground    文件:AddComponentAction.java   
@Nullable
private static PsiElement findElementToAdd(final PsiFile psiFile) {
  if (psiFile.getFileType().equals(StdFileTypes.GUI_DESIGNER_FORM)) {
    return psiFile;
  }
  else if (psiFile.getFileType().equals(StdFileTypes.JAVA)) {
    final PsiClass psiClass = PsiTreeUtil.getChildOfType(psiFile, PsiClass.class);
    Project project = psiFile.getProject();
    final PsiClass componentClass =
      JavaPsiFacade.getInstance(project).findClass(JComponent.class.getName(), ProjectScope.getAllScope(project));
    if (psiClass != null && componentClass != null && psiClass.isInheritor(componentClass, true) && psiClass.getQualifiedName() != null) {
      return psiClass;
    }
  }
  return null;
}
项目:intellij-ce-playground    文件:ComponentItemDialog.java   
@Override
public void actionPerformed(ActionEvent e) {
  final TreeClassChooserFactory factory = TreeClassChooserFactory.getInstance(myProject);
  PsiFile formFile = null;
  if (myTextField.getText().length() > 0) {
    VirtualFile formVFile = ResourceFileUtil.findResourceFileInScope(myTextField.getText(), myProject, ProjectScope.getAllScope(myProject));
    if (formVFile != null) {
      formFile = PsiManager.getInstance(myProject).findFile(formVFile);
    }
  }
  TreeFileChooser fileChooser = factory.createFileChooser(myTitle, formFile, null, myFilter, true, true);
  fileChooser.showDialog();
  PsiFile file = fileChooser.getSelectedFile();
  if (file != null) {
    myTextField.setText(FormEditingUtil.buildResourceName(file));
  }
}
项目:intellij-ce-playground    文件:FormSourceCodeGeneratorTest.java   
private void doTest() throws IOException {
  final VirtualFile form = myTestProjectRoot.findChild("Test.form");
  assertNotNull(form);
  CommandProcessor.getInstance().executeCommand(myProject, new Runnable() {
    @Override
    public void run() {
      try {
        myGenerator.generate(form);
      }
      catch (Exception e) {
        fail(e.getMessage());
      }
    }
  }, "", null);

  final PsiClass bindingTestClass = myJavaFacade.findClass("BindingTest", ProjectScope.getAllScope(myProject));
  assertNotNull(bindingTestClass);
  final VirtualFile testAfter = myTestProjectRoot.findChild("BindingTest.java.after");
  assertNotNull(testAfter);
  String expectedText = StringUtil.convertLineSeparators(VfsUtil.loadText(testAfter));
  final PsiFile psiFile = bindingTestClass.getContainingFile();
  assertNotNull(psiFile);
  final String text = StringUtil.convertLineSeparators(psiFile.getText());
  assertEquals(expectedText, text);
}
项目:tools-idea    文件:PsiUtil.java   
@Nullable
public static PsiMethod getResourceCloserMethod(@NotNull final PsiResourceVariable resource) {
  final PsiType resourceType = resource.getType();
  if (!(resourceType instanceof PsiClassType)) return null;
  final PsiClass resourceClass = ((PsiClassType)resourceType).resolve();
  if (resourceClass == null) return null;

  final Project project = resource.getProject();
  final JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
  final PsiClass autoCloseable = facade.findClass(CommonClassNames.JAVA_LANG_AUTO_CLOSEABLE, ProjectScope.getLibrariesScope(project));
  if (autoCloseable == null) return null;

  if (!InheritanceUtil.isInheritorOrSelf(resourceClass, autoCloseable, true)) return null;

  final PsiMethod[] closes = autoCloseable.findMethodsByName("close", false);
  return closes.length == 1 ? resourceClass.findMethodBySignature(closes[0], true) : null;
}
项目:tools-idea    文件:SurroundAutoCloseableAction.java   
@Override
public boolean isAvailable(@NotNull final Project project, final Editor editor, @NotNull final PsiElement element) {
  if (!element.getLanguage().isKindOf(JavaLanguage.INSTANCE)) return false;
  if (!PsiUtil.getLanguageLevel(element).isAtLeast(LanguageLevel.JDK_1_7)) return false;

  final PsiLocalVariable variable = PsiTreeUtil.getParentOfType(element, PsiLocalVariable.class);
  if (variable == null) return false;
  final PsiExpression initializer = variable.getInitializer();
  if (initializer == null) return false;
  final PsiElement declaration = variable.getParent();
  if (!(declaration instanceof PsiDeclarationStatement)) return false;
  final PsiElement codeBlock = declaration.getParent();
  if (!(codeBlock instanceof PsiCodeBlock)) return false;

  final PsiType type = variable.getType();
  if (!(type instanceof PsiClassType)) return false;
  final PsiClass aClass = ((PsiClassType)type).resolve();
  final JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
  final PsiClass autoCloseable = facade.findClass(CommonClassNames.JAVA_LANG_AUTO_CLOSEABLE, ProjectScope.getLibrariesScope(project));
  if (!InheritanceUtil.isInheritorOrSelf(aClass, autoCloseable, true)) return false;

  return true;
}
项目:tools-idea    文件:InlineToAnonymousClassMultifileTest.java   
private void doTest(String className) throws Exception {
  String rootBefore = getRoot() + "/before";
  PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk17());
  final VirtualFile rootDir = PsiTestUtil.createTestProjectStructure(myProject, myModule, rootBefore, myFilesToDelete);
  PsiClass classToInline = myJavaFacade.findClass(className, ProjectScope.getAllScope(myProject));
  assertEquals(null, InlineToAnonymousClassHandler.getCannotInlineMessage(classToInline));
  InlineToAnonymousClassProcessor processor = new InlineToAnonymousClassProcessor(myProject, 
                                                                                  classToInline,
                                                                                  null, false, false, false);
  UsageInfo[] usages = processor.findUsages();
  MultiMap<PsiElement,String> conflicts = processor.getConflicts(usages);
  assertEquals(0, conflicts.size());
  processor.run();

  String rootAfter = getRoot() + "/after";
  VirtualFile rootDir2 = LocalFileSystem.getInstance().findFileByPath(rootAfter.replace(File.separatorChar, '/'));
  myProject.getComponent(PostprocessReformattingAspect.class).doPostponedFormatting();
  PlatformTestUtil.assertDirectoriesEqual(rootDir2, rootDir);
}
项目:tools-idea    文件:InlineMethodMultifileTest.java   
private void doTest(String className, String methodName) throws Exception {
  String rootBefore = getRoot() + "/before";
  PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk17());
  final VirtualFile rootDir = PsiTestUtil.createTestProjectStructure(myProject, myModule, rootBefore, myFilesToDelete);
  PsiClass aClass = myJavaFacade.findClass(className, ProjectScope.getAllScope(myProject));
  assertTrue(aClass != null);
  PsiElement element = aClass.findMethodsByName(methodName, false)[0];
  assertTrue(element instanceof PsiMethod);
  PsiMethod method = (PsiMethod)element;
  final boolean condition = InlineMethodProcessor.checkBadReturns(method) && !InlineUtil.allUsagesAreTailCalls(method);
  assertFalse("Bad returns found", condition);

  InlineOptions options = new MockInlineMethodOptions();
  final InlineMethodProcessor processor = new InlineMethodProcessor(getProject(), method, null, myEditor, options.isInlineThisOnly());
  processor.run();

  String rootAfter = getRoot() + "/after";
  VirtualFile rootDir2 = LocalFileSystem.getInstance().findFileByPath(rootAfter.replace(File.separatorChar, '/'));
  myProject.getComponent(PostprocessReformattingAspect.class).doPostponedFormatting();
  PlatformTestUtil.assertDirectoriesEqual(rootDir2, rootDir);
}
项目:tools-idea    文件:MoveMembersTest.java   
private void performAction(String sourceClassName, String targetClassName, int[] memberIndices, final String visibility) throws Exception {
  PsiClass sourceClass = myJavaFacade.findClass(sourceClassName, ProjectScope.getProjectScope(myProject));
  assertNotNull("Class " + sourceClassName + " not found", sourceClass);
  PsiClass targetClass = myJavaFacade.findClass(targetClassName, ProjectScope.getProjectScope(myProject));
  assertNotNull("Class " + targetClassName + " not found", targetClass);

  PsiElement[] children = sourceClass.getChildren();
  ArrayList<PsiMember> members = new ArrayList<PsiMember>();
  for (PsiElement child : children) {
    if (child instanceof PsiMember) {
      members.add(((PsiMember) child));
    }
  }

  LinkedHashSet<PsiMember> memberSet = new LinkedHashSet<PsiMember>();
  for (int index : memberIndices) {
    PsiMember member = members.get(index);
    assertTrue(member.hasModifierProperty(PsiModifier.STATIC));
    memberSet.add(member);
  }

  MockMoveMembersOptions options = new MockMoveMembersOptions(targetClass.getQualifiedName(), memberSet);
  options.setMemberVisibility(visibility);
  new MoveMembersProcessor(myProject, null, options).run();
  FileDocumentManager.getInstance().saveAllDocuments();
}
项目:tools-idea    文件:HighlightLevelUtil.java   
public static boolean shouldInspect(@NotNull PsiElement psiRoot) {
  if (ApplicationManager.getApplication().isUnitTestMode()) return true;

  if (!shouldHighlight(psiRoot)) return false;
  final Project project = psiRoot.getProject();
  final VirtualFile virtualFile = psiRoot.getContainingFile().getVirtualFile();
  if (virtualFile == null || !virtualFile.isValid()) return false;

  if (ProjectCoreUtil.isProjectOrWorkspaceFile(virtualFile)) return false;

  final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
  if (ProjectScope.getLibrariesScope(project).contains(virtualFile) && !fileIndex.isInContent(virtualFile)) return false;

  if (SingleRootFileViewProvider.isTooLargeForIntelligence(virtualFile)) return false;

  final HighlightingSettingsPerFile component = HighlightingSettingsPerFile.getInstance(project);
  if (component == null) return true;

  final FileHighlightingSetting settingForRoot = component.getHighlightingSettingForRoot(psiRoot);
  return settingForRoot != FileHighlightingSetting.SKIP_INSPECTION;
}
项目:tools-idea    文件:UniqueVFilePathBuilderImpl.java   
@NotNull
@Override
public String getUniqueVirtualFilePath(Project project, VirtualFile file) {
  final Collection<VirtualFile> filesWithSameName = FilenameIndex.getVirtualFilesByName(project, file.getName(),
                                                                                        ProjectScope.getProjectScope(project));
  if (filesWithSameName.size() > 1 && filesWithSameName.contains(file)) {
    String path = project.getBasePath();
    path = path == null ? "" : FileUtil.toSystemIndependentName(path);
    UniqueNameBuilder<VirtualFile> builder = new UniqueNameBuilder<VirtualFile>(path, File.separator, 25);
    for (VirtualFile virtualFile: filesWithSameName) {
      builder.addPath(virtualFile, virtualFile.getPath());
    }
    return builder.getShortPath(file);
  }
  return file.getName();
}
项目:tools-idea    文件:AddComponentAction.java   
private static void assignDefaultIcon(final Project project, final ComponentItem itemToBeAdded) {
  Palette palette = Palette.getInstance(project);
  if (itemToBeAdded.getIconPath() == null || itemToBeAdded.getIconPath().length() == 0) {
    PsiClass aClass =
      JavaPsiFacade.getInstance(project).findClass(itemToBeAdded.getClassName().replace('$', '.'), ProjectScope.getAllScope(project));
    while(aClass != null) {
      final ComponentItem item = palette.getItem(aClass.getQualifiedName());
      if (item != null) {
        String iconPath = item.getIconPath();
        if (iconPath != null && iconPath.length() > 0) {
          itemToBeAdded.setIconPath(iconPath);
          return;
        }
      }
      aClass = aClass.getSuperClass();
    }
  }
}
项目:tools-idea    文件:AddComponentAction.java   
@Nullable
private static PsiElement findElementToAdd(final PsiFile psiFile) {
  if (psiFile.getFileType().equals(StdFileTypes.GUI_DESIGNER_FORM)) {
    return psiFile;
  }
  else if (psiFile.getFileType().equals(StdFileTypes.JAVA)) {
    final PsiClass psiClass = PsiTreeUtil.getChildOfType(psiFile, PsiClass.class);
    Project project = psiFile.getProject();
    final PsiClass componentClass =
      JavaPsiFacade.getInstance(project).findClass(JComponent.class.getName(), ProjectScope.getAllScope(project));
    if (psiClass != null && componentClass != null && psiClass.isInheritor(componentClass, true) && psiClass.getQualifiedName() != null) {
      return psiClass;
    }
  }
  return null;
}
项目:tools-idea    文件:FormSourceCodeGeneratorTest.java   
private void doTest() throws IOException {
  final VirtualFile form = myTestProjectRoot.findChild("Test.form");
  assertNotNull(form);
  CommandProcessor.getInstance().executeCommand(myProject, new Runnable() {
    @Override
    public void run() {
      try {
        myGenerator.generate(form);
      }
      catch (Exception e) {
        fail(e.getMessage());
      }
    }
  }, "", null);

  final PsiClass bindingTestClass = myJavaFacade.findClass("BindingTest", ProjectScope.getAllScope(myProject));
  assertNotNull(bindingTestClass);
  final VirtualFile testAfter = myTestProjectRoot.findChild("BindingTest.java.after");
  assertNotNull(testAfter);
  String expectedText = StringUtil.convertLineSeparators(VfsUtil.loadText(testAfter));
  final PsiFile psiFile = bindingTestClass.getContainingFile();
  assertNotNull(psiFile);
  final String text = StringUtil.convertLineSeparators(psiFile.getText());
  assertEquals(expectedText, text);
}
项目:tools-idea    文件:GroovyPsiElementFactoryImpl.java   
public GrMethod createMethodFromText(String modifier, String name, @Nullable String type, String[] paramTypes, PsiElement context) {
  PsiType psiType;
  List<PsiType> res = new ArrayList<PsiType>();
  final GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(myProject);

  for (String paramType : paramTypes) {
    try {
      psiType = factory.createTypeElement(paramType).getType();
    }
    catch (IncorrectOperationException e) {
      psiType = PsiType.getJavaLangObject(PsiManager.getInstance(myProject), ProjectScope.getAllScope(myProject));
    }
    res.add(psiType);
  }

  String[] paramNames = QuickfixUtil.getMethodArgumentsNames(myProject, res.toArray(new PsiType[res.size()]));
  final CharSequence text = generateMethodText(modifier, name, type, paramTypes, paramNames, null, false);
  return createMethodFromText(text.toString(), context);
}
项目:consulo-ui-designer    文件:AddComponentAction.java   
private static void assignDefaultIcon(final Project project, final ComponentItem itemToBeAdded) {
  Palette palette = Palette.getInstance(project);
  if (itemToBeAdded.getIconPath() == null || itemToBeAdded.getIconPath().length() == 0) {
    PsiClass aClass =
      JavaPsiFacade.getInstance(project).findClass(itemToBeAdded.getClassName().replace('$', '.'), ProjectScope.getAllScope(project));
    while(aClass != null) {
      final ComponentItem item = palette.getItem(aClass.getQualifiedName());
      if (item != null) {
        String iconPath = item.getIconPath();
        if (iconPath != null && iconPath.length() > 0) {
          itemToBeAdded.setIconPath(iconPath);
          return;
        }
      }
      aClass = aClass.getSuperClass();
    }
  }
}
项目:consulo-ui-designer    文件:AddComponentAction.java   
@Nullable
private static PsiElement findElementToAdd(final PsiFile psiFile) {
  if (psiFile.getFileType().equals(GuiFormFileType.INSTANCE)) {
    return psiFile;
  }
  else if (psiFile.getFileType().equals(JavaFileType.INSTANCE)) {
    final PsiClass psiClass = PsiTreeUtil.getChildOfType(psiFile, PsiClass.class);
    Project project = psiFile.getProject();
    final PsiClass componentClass =
      JavaPsiFacade.getInstance(project).findClass(JComponent.class.getName(), ProjectScope.getAllScope(project));
    if (psiClass != null && componentClass != null && psiClass.isInheritor(componentClass, true) && psiClass.getQualifiedName() != null) {
      return psiClass;
    }
  }
  return null;
}
项目:consulo-ui-designer    文件:ComponentItemDialog.java   
public void actionPerformed(ActionEvent e) {
  final TreeClassChooserFactory factory = TreeClassChooserFactory.getInstance(myProject);
  PsiFile formFile = null;
  if (myTextField.getText().length() > 0) {
    VirtualFile formVFile = ResourceFileUtil.findResourceFileInScope(myTextField.getText(), myProject, ProjectScope.getAllScope(myProject));
    if (formVFile != null) {
      formFile = PsiManager.getInstance(myProject).findFile(formVFile);
    }
  }
  TreeFileChooser fileChooser = factory.createFileChooser(myTitle, formFile, null, myFilter, true, true);
  fileChooser.showDialog();
  PsiFile file = fileChooser.getSelectedFile();
  if (file != null) {
    myTextField.setText(FormEditingUtil.buildResourceName(file));
  }
}
项目:consulo-ui-designer    文件:FormSourceCodeGeneratorTest.java   
private void doTest() throws IOException {
  final VirtualFile form = myTestProjectRoot.findChild("Test.form");
  assertNotNull(form);
  CommandProcessor.getInstance().executeCommand(myProject, new Runnable() {
    @Override
    public void run() {
      try {
        myGenerator.generate(form);
      }
      catch (Exception e) {
        fail(e.getMessage());
      }
    }
  }, "", null);

  final PsiClass bindingTestClass = myJavaFacade.findClass("BindingTest", ProjectScope.getAllScope(myProject));
  assertNotNull(bindingTestClass);
  final VirtualFile testAfter = myTestProjectRoot.findChild("BindingTest.java.after");
  assertNotNull(testAfter);
  String expectedText = StringUtil.convertLineSeparators(VfsUtil.loadText(testAfter));
  final PsiFile psiFile = bindingTestClass.getContainingFile();
  assertNotNull(psiFile);
  final String text = StringUtil.convertLineSeparators(psiFile.getText());
  assertEquals(expectedText, text);
}
项目:consulo    文件:HighlightingSettingsPerFile.java   
@Override
public boolean shouldInspect(@Nonnull PsiElement psiRoot) {
  if (ApplicationManager.getApplication().isUnitTestMode()) return true;

  if (!shouldHighlight(psiRoot)) return false;
  final Project project = psiRoot.getProject();
  final VirtualFile virtualFile = psiRoot.getContainingFile().getVirtualFile();
  if (virtualFile == null || !virtualFile.isValid()) return false;

  if (ProjectCoreUtil.isProjectOrWorkspaceFile(virtualFile)) return false;

  final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
  if (ProjectScope.getLibrariesScope(project).contains(virtualFile) && !fileIndex.isInContent(virtualFile)) return false;

  if (SingleRootFileViewProvider.isTooLargeForIntelligence(virtualFile)) return false;

  final FileHighlightingSetting settingForRoot = getHighlightingSettingForRoot(psiRoot);
  return settingForRoot != FileHighlightingSetting.SKIP_INSPECTION;
}
项目:consulo    文件:HighlightLevelUtil.java   
public static boolean shouldInspect(@Nonnull PsiElement psiRoot) {
  if (ApplicationManager.getApplication().isUnitTestMode()) return true;

  if (!shouldHighlight(psiRoot)) return false;
  final Project project = psiRoot.getProject();
  final VirtualFile virtualFile = psiRoot.getContainingFile().getVirtualFile();
  if (virtualFile == null || !virtualFile.isValid()) return false;

  if (ProjectCoreUtil.isProjectOrWorkspaceFile(virtualFile)) return false;

  final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
  if (ProjectScope.getLibrariesScope(project).contains(virtualFile) && !fileIndex.isInContent(virtualFile)) return false;

  if (SingleRootFileViewProvider.isTooLargeForIntelligence(virtualFile)) return false;

  final HighlightingSettingsPerFile component = HighlightingSettingsPerFile.getInstance(project);
  if (component == null) return true;

  final FileHighlightingSetting settingForRoot = component.getHighlightingSettingForRoot(psiRoot);
  return settingForRoot != FileHighlightingSetting.SKIP_INSPECTION;
}
项目:consulo    文件:FindUsagesOptions.java   
@Nonnull
private static SearchScope calcScope(@Nonnull Project project, @Nullable DataContext dataContext) {
  String defaultScopeName = FindSettings.getInstance().getDefaultScopeName();
  List<SearchScope> predefined = PredefinedSearchScopeProvider.getInstance().getPredefinedScopes(project, dataContext, true, false, false,
                                                                                                 false);
  SearchScope resultScope = null;
  for (SearchScope scope : predefined) {
    if (scope.getDisplayName().equals(defaultScopeName)) {
      resultScope = scope;
      break;
    }
  }
  if (resultScope == null) {
    resultScope = ProjectScope.getProjectScope(project);
  }
  return resultScope;
}
项目:consulo-java    文件:PsiUtil.java   
@Nullable
public static PsiMethod getResourceCloserMethodForType(@NotNull final PsiClassType resourceType)
{
    final PsiClass resourceClass = resourceType.resolve();
    if(resourceClass == null)
    {
        return null;
    }

    final Project project = resourceClass.getProject();
    final JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
    final PsiClass autoCloseable = facade.findClass(CommonClassNames.JAVA_LANG_AUTO_CLOSEABLE, ProjectScope.getLibrariesScope(project));
    if(autoCloseable == null)
    {
        return null;
    }

    if(JavaClassSupers.getInstance().getSuperClassSubstitutor(autoCloseable, resourceClass, resourceType.getResolveScope(), PsiSubstitutor.EMPTY) == null)
    {
        return null;
    }

    final PsiMethod[] closes = autoCloseable.findMethodsByName("close", false);
    return closes.length == 1 ? resourceClass.findMethodBySignature(closes[0], true) : null;
}
项目:consulo-java    文件:JavaModuleCompletion.java   
private static void addModuleReferences(PsiElement context, Consumer<LookupElement> result)
{
    PsiElement statement = context.getParent();
    if(!(statement instanceof PsiJavaModule))
    {
        PsiElement host = statement.getParent();
        if(host instanceof PsiJavaModule)
        {
            String hostName = ((PsiJavaModule) host).getName();
            Project project = context.getProject();
            JavaModuleNameIndex index = JavaModuleNameIndex.getInstance();
            GlobalSearchScope scope = ProjectScope.getAllScope(project);
            for(String name : index.getAllKeys(project))
            {
                if(!name.equals(hostName) && index.get(name, project, scope).size() == 1)
                {
                    result.consume(new OverrideableSpace(LookupElementBuilder.create(name), TailType.SEMICOLON));
                }
            }
        }
    }
}
项目:consulo-java    文件:TryWithResourcesPostfixTemplate.java   
@Override
public boolean isApplicable(@NotNull PsiElement element, @NotNull Document copyDocument, int newOffset) {
  if (!PsiUtil.isLanguageLevel7OrHigher(element)) return false;

  PsiExpression initializer = JavaPostfixTemplatesUtils.getTopmostExpression(element);

  if (initializer == null) return false;

  final PsiType type = initializer.getType();
  if (!(type instanceof PsiClassType)) return false;
  final PsiClass aClass = ((PsiClassType)type).resolve();
  Project project = element.getProject();
  final JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
  final PsiClass autoCloseable = facade.findClass(CommonClassNames.JAVA_LANG_AUTO_CLOSEABLE, ProjectScope.getLibrariesScope(project));
  if (!InheritanceUtil.isInheritorOrSelf(aClass, autoCloseable, true)) return false;

  return true;
}
项目:consulo-java    文件:SurroundAutoCloseableAction.java   
@Override
public boolean isAvailable(@NotNull final Project project, final Editor editor, @NotNull final PsiElement element) {
  if (!element.getLanguage().isKindOf(JavaLanguage.INSTANCE)) return false;
  if (!PsiUtil.getLanguageLevel(element).isAtLeast(LanguageLevel.JDK_1_7)) return false;

  final PsiLocalVariable variable = PsiTreeUtil.getParentOfType(element, PsiLocalVariable.class);
  if (variable == null) return false;
  final PsiExpression initializer = variable.getInitializer();
  if (initializer == null) return false;
  final PsiElement declaration = variable.getParent();
  if (!(declaration instanceof PsiDeclarationStatement)) return false;
  final PsiElement codeBlock = declaration.getParent();
  if (!(codeBlock instanceof PsiCodeBlock)) return false;

  final PsiType type = variable.getType();
  if (!(type instanceof PsiClassType)) return false;
  final PsiClass aClass = ((PsiClassType)type).resolve();
  final JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
  final PsiClass autoCloseable = facade.findClass(CommonClassNames.JAVA_LANG_AUTO_CLOSEABLE, ProjectScope.getLibrariesScope(project));
  if (!InheritanceUtil.isInheritorOrSelf(aClass, autoCloseable, true)) return false;

  return true;
}
项目:consulo-java    文件:InlineToAnonymousClassMultifileTest.java   
private void doTest(String className) throws Exception {
  String rootBefore = getRoot() + "/before";
  PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk17());
  final VirtualFile rootDir = PsiTestUtil.createTestProjectStructure(myProject, myModule, rootBefore, myFilesToDelete);
  PsiClass classToInline = myJavaFacade.findClass(className, ProjectScope.getAllScope(myProject));
  assertEquals(null, InlineToAnonymousClassHandler.getCannotInlineMessage(classToInline));
  InlineToAnonymousClassProcessor processor = new InlineToAnonymousClassProcessor(myProject, 
                                                                                  classToInline,
                                                                                  null, false, false, false);
  UsageInfo[] usages = processor.findUsages();
  MultiMap<PsiElement,String> conflicts = processor.getConflicts(usages);
  assertEquals(0, conflicts.size());
  processor.run();

  String rootAfter = getRoot() + "/after";
  VirtualFile rootDir2 = LocalFileSystem.getInstance().findFileByPath(rootAfter.replace(File.separatorChar, '/'));
  myProject.getComponent(PostprocessReformattingAspect.class).doPostponedFormatting();
  PlatformTestUtil.assertDirectoriesEqual(rootDir2, rootDir);
}