private static PsiDirectory[] suggestMostAppropriateDirectories(PsiPackage psiPackage) {
    final Project project = psiPackage.getProject();
    PsiDirectory[] directories = null;
    final Editor editor = FileEditorManager.getInstance(project).getSelectedTextEditor();
    if (editor != null) {
      final Document document = editor.getDocument();
      final PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(document);
      if (psiFile != null) {
        final Module module = ModuleUtil.findModuleForPsiElement(psiFile);
        if (module != null) {
          directories =
              psiPackage.getDirectories(GlobalSearchScope.moduleWithDependenciesScope(module));
        } else {
          directories =
              psiPackage.getDirectories(
                  GlobalSearchScope.notScope(GlobalSearchScope.projectScope(project)));
        }
      }
    }

    if (directories == null || directories.length == 0) {
      directories = psiPackage.getDirectories();
    }
    return directories;
  }
Exemplo n.º 2
0
 @NotNull
 @Override
 public GlobalSearchScope uniteWith(@NotNull GlobalSearchScope scope) {
   if (scope == this || !scope.isSearchInLibraries() || !scope.isSearchOutsideRootModel())
     return this;
   return super.uniteWith(scope);
 }
 private IntersectionScope(
     @NotNull GlobalSearchScope scope1, @NotNull GlobalSearchScope scope2, String displayName) {
   super(scope1.getProject() == null ? scope2.getProject() : scope1.getProject());
   myScope1 = scope1;
   myScope2 = scope2;
   myDisplayName = displayName;
 }
Exemplo n.º 4
0
  public static boolean isAnnoRefAnywhereInXml(
      @NotNull Project project, @NotNull Module module, @NotNull String refId) {
    if (module == null) {
      throw new IllegalArgumentException(
          String.format(
              "Argument %s for @NotNull parameter of %s.%s must not be null",
              new Object[] {
                "0",
                "com.idi.intellij.plugin.query.sqlref.util.AnnoRefModelUtil",
                "isAnnoRefAnywhereInXml"
              }));
    }
    GlobalSearchScope scope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module);
    GlobalSearchScope searchScope =
        GlobalSearchScope.getScopeRestrictedByFileTypes(scope, XmlFileType.INSTANCE);
    PsiFile[] files =
        CacheManager.SERVICE
            .getInstance(module.getProject())
            .getFilesWithWord(refId, Short.valueOf("255"), searchScope, true);

    for (PsiFile file : files) {
      if (((file instanceof XmlFile))
          && (AnnRefApplication.getInstance(project, SQLRefDataAccessor.class)
              .isPropitiousXmlFile(file))) {
        return true;
      }
    }
    return false;
  }
  public void testAnnotationIndex() throws Exception {
    getJavaFacade()
        .setAssertOnFileLoadingFilter(
            new VirtualFileFilter() {
              @Override
              public boolean accept(final VirtualFile file) {
                return !"package-info.java".equals(file.getName());
              }
            });

    final PsiClass annotationTypeClass =
        myJavaFacade.findClass(
            "annotations.AnnotationType", GlobalSearchScope.moduleScope(myModule));
    assertNotNull(annotationTypeClass);
    assertTrue(annotationTypeClass.isAnnotationType());

    final Collection<PsiMember> all =
        AnnotatedMembersSearch.search(annotationTypeClass, GlobalSearchScope.moduleScope(myModule))
            .findAll();

    assertEquals(2, all.size());
    Set<String> correctNames =
        new HashSet<String>(Arrays.asList("AnnotatedClass", "correctMethod"));
    for (PsiMember member : all) {
      assertTrue(correctNames.contains(member.getName()));
    }

    final Collection<PsiPackage> packages =
        AnnotatedPackagesSearch.search(annotationTypeClass, GlobalSearchScope.moduleScope(myModule))
            .findAll();
    assertEquals(1, packages.size());
    assertEquals("annotated", packages.iterator().next().getQualifiedName());

    teardownLoadingFilter();
  }
Exemplo n.º 6
0
  @Nullable
  public static PsiClass[] getAllTestClasses(final TestClassFilter filter, boolean sync) {
    final PsiClass[][] holder = new PsiClass[1][];
    final Runnable process =
        () -> {
          final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();

          final Collection<PsiClass> set = new LinkedHashSet<>();
          final PsiManager manager = PsiManager.getInstance(filter.getProject());
          final GlobalSearchScope projectScope =
              GlobalSearchScope.projectScope(manager.getProject());
          final GlobalSearchScope scope = projectScope.intersectWith(filter.getScope());
          for (final PsiClass psiClass : AllClassesSearch.search(scope, manager.getProject())) {
            if (filter.isAccepted(psiClass)) {
              if (indicator != null) {
                indicator.setText2(
                    "Found test class " + ReadAction.compute(psiClass::getQualifiedName));
              }
              set.add(psiClass);
            }
          }
          holder[0] = set.toArray(new PsiClass[set.size()]);
        };
    if (sync) {
      ProgressManager.getInstance()
          .runProcessWithProgressSynchronously(
              process, "Searching For Tests...", true, filter.getProject());
    } else {
      process.run();
    }
    return holder[0];
  }
  @Override
  @Nullable
  public GlobalSearchScope getSearchScope() {
    GlobalSearchScope scope = null;

    Module[] modules = getConvertContextModules();
    if (modules.length != 0) {

      PsiFile file = getFile();
      file = file.getOriginalFile();
      VirtualFile virtualFile = file.getVirtualFile();
      if (virtualFile != null) {
        ProjectFileIndex fileIndex =
            ProjectRootManager.getInstance(file.getProject()).getFileIndex();
        boolean tests = fileIndex.isInTestSourceContent(virtualFile);

        for (Module module : modules) {
          if (scope == null) {
            scope = module.getModuleRuntimeScope(tests);
          } else {
            scope = scope.union(module.getModuleRuntimeScope(tests));
          }
        }
      }
    }
    return scope; // ??? scope == null ? GlobalSearchScope.allScope(getProject()) : scope; ???
  }
 @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);
     }
   }
   return selectedNodeElements[0] instanceof PsiDirectory
       ? new PsiDirectory[] {(PsiDirectory) selectedNodeElements[0]}
       : null;
 }
  public void testLocation() {
    assertNull(mySuite.getLocation(getProject(), GlobalSearchScope.allScope(getProject())));

    mySuite.addChild(mySimpleTest);

    assertNull(mySuite.getLocation(getProject(), GlobalSearchScope.allScope(getProject())));
    assertNull(mySimpleTest.getLocation(getProject(), GlobalSearchScope.allScope(getProject())));
  }
 private boolean containsScope(@NotNull GlobalSearchScope scope) {
   if (myScope1.equals(scope) || myScope2.equals(scope) || equals(scope)) return true;
   if (myScope1 instanceof IntersectionScope
       && ((IntersectionScope) myScope1).containsScope(scope)) return true;
   if (myScope2 instanceof IntersectionScope
       && ((IntersectionScope) myScope2).containsScope(scope)) return true;
   return false;
 }
Exemplo n.º 11
0
  private void performAction(
      String from,
      String to,
      final int docCommentPolicy,
      String[] expectedConflicts,
      final String[] toPullUp) {
    final JSClassResolver resolver =
        JSDialectSpecificHandlersFactory.forLanguage(JavaScriptSupportLoader.ECMA_SCRIPT_L4)
            .getClassResolver();
    final JSClass sourceClass =
        (JSClass) resolver.findClassByQName(from, GlobalSearchScope.projectScope(getProject()));
    assertNotNull("source class not found: " + sourceClass, sourceClass);

    final JSClass targetClass =
        (JSClass) resolver.findClassByQName(to, GlobalSearchScope.projectScope(getProject()));
    assertNotNull("target class not found: " + targetClass, targetClass);

    assertTrue(
        "Source should be a subclass of target",
        JSInheritanceUtil.isParentClass(sourceClass, targetClass));

    final List<JSMemberInfo> memberInfos = getMemberInfos(toPullUp, sourceClass, false);

    final JSMemberInfo[] infosArray =
        JSMemberInfo.getSelected(memberInfos, sourceClass, Conditions.<JSMemberInfo>alwaysTrue());
    MultiMap<PsiElement, String> conflicts =
        JSPullUpConflictsUtil.checkConflicts(
            infosArray,
            sourceClass,
            targetClass,
            new JSInterfaceContainmentVerifier() {
              @Override
              public boolean checkedInterfacesContain(JSFunction psiMethod) {
                return JSPullUpHelper.checkedInterfacesContain(memberInfos, psiMethod);
              }
            },
            JSVisibilityUtil.DEFAULT_OPTIONS);

    ArrayList<String> messages = new ArrayList<String>(conflicts.values());
    for (int i = 0; i < messages.size(); i++) {
      messages.set(i, messages.get(i).replaceAll("<[^>]+>", ""));
    }
    assertSameElements(messages, expectedConflicts);
    if (conflicts.isEmpty()) {
      WriteCommandAction.runWriteCommandAction(
          null,
          new Runnable() {
            public void run() {
              new JSPullUpHelper(sourceClass, targetClass, infosArray, docCommentPolicy)
                  .moveMembersToBase();
              myProject.getComponent(PostprocessReformattingAspect.class).doPostponedFormatting();
            }
          });

      FileDocumentManager.getInstance().saveAllDocuments();
    }
  }
    @Override
    public boolean equals(Object o) {
      if (this == o) return true;
      if (!(o instanceof IntersectionScope)) return false;

      IntersectionScope that = (IntersectionScope) o;

      return myScope1.equals(that.myScope1) && myScope2.equals(that.myScope2);
    }
 @NotNull
 @Override
 public String getDisplayName() {
   if (myDisplayName == null) {
     return PsiBundle.message(
         "psi.search.scope.intersection", myScope1.getDisplayName(), myScope2.getDisplayName());
   }
   return myDisplayName;
 }
  public void testExternalFileModificationWhileProjectClosed() throws Exception {
    VirtualFile root = ProjectRootManager.getInstance(myProject).getContentRoots()[0];

    PsiClass objectClass =
        myJavaFacade.findClass(
            CommonClassNames.JAVA_LANG_OBJECT, GlobalSearchScope.allScope(getProject()));
    assertNotNull(objectClass);
    checkUsages(objectClass, new String[] {});
    FileBasedIndex.getInstance()
        .getContainingFiles(
            TodoIndex.NAME,
            new TodoIndexEntry("todo", true),
            GlobalSearchScope.allScope(getProject()));

    final String projectLocation = myProject.getPresentableUrl();
    assert projectLocation != null : myProject;
    PlatformTestUtil.saveProject(myProject);
    final VirtualFile content = ModuleRootManager.getInstance(getModule()).getContentRoots()[0];
    Project project = myProject;
    ProjectUtil.closeAndDispose(project);
    InjectedLanguageManagerImpl.checkInjectorsAreDisposed(project);

    assertTrue("Project was not disposed", myProject.isDisposed());
    myModule = null;

    final File file = new File(root.getPath(), "1.java");
    assertTrue(file.exists());

    FileUtil.writeToFile(file, "class A{ Object o;}".getBytes(CharsetToolkit.UTF8_CHARSET));
    root.refresh(false, true);

    LocalFileSystem.getInstance().refresh(false);

    myProject = ProjectManager.getInstance().loadAndOpenProject(projectLocation);
    InjectedLanguageManagerImpl.pushInjectors(getProject());

    setUpModule();
    setUpJdk();
    ProjectManagerEx.getInstanceEx().openTestProject(myProject);
    UIUtil.dispatchAllInvocationEvents(); // startup activities

    runStartupActivities();
    PsiTestUtil.addSourceContentToRoots(getModule(), content);

    assertNotNull(myProject);
    myPsiManager = (PsiManagerImpl) PsiManager.getInstance(myProject);
    myJavaFacade = JavaPsiFacadeEx.getInstanceEx(myProject);

    objectClass =
        myJavaFacade.findClass(
            CommonClassNames.JAVA_LANG_OBJECT, GlobalSearchScope.allScope(getProject()));
    assertNotNull(objectClass);
    checkUsages(objectClass, new String[] {"1.java"});
  }
 @NotNull
 @Override
 public NavigationItem[] getItemsByName(
     String name, String pattern, Project project, boolean includeNonProjectItems) {
   final GlobalSearchScope scope =
       includeNonProjectItems
           ? GlobalSearchScope.allScope(project)
           : GlobalSearchScope.projectScope(project);
   final Collection<HaxeComponent> result =
       HaxeComponentIndex.getItemsByName(name, project, scope);
   return result.toArray(new NavigationItem[result.size()]);
 }
  @NotNull
  public Collection<PsiElement> findTestsForClass(@NotNull PsiElement element) {
    PsiClass klass = findSourceElement(element);
    if (klass == null) return Collections.emptySet();

    GlobalSearchScope scope;
    Module module = getModule(element);
    if (module != null) {
      scope = GlobalSearchScope.moduleWithDependentsScope(module);
    } else {
      scope = GlobalSearchScope.projectScope(element.getProject());
    }

    PsiShortNamesCache cache = JavaPsiFacade.getInstance(element.getProject()).getShortNamesCache();

    String klassName = klass.getName();
    Pattern pattern = Pattern.compile(".*" + klassName + ".*");

    List<Pair<PsiClass, Integer>> classesWithProximities = new ArrayList<Pair<PsiClass, Integer>>();

    HashSet<String> names = new HashSet<String>();
    cache.getAllClassNames(names);
    for (String eachName : names) {
      if (pattern.matcher(eachName).matches()) {
        for (PsiClass eachClass : cache.getClassesByName(eachName, scope)) {
          if (TestUtil.isTestClass(eachClass)) {
            classesWithProximities.add(
                new Pair<PsiClass, Integer>(eachClass, calcTestNameProximity(klassName, eachName)));
          }
        }
      }
    }

    Collections.sort(
        classesWithProximities,
        new Comparator<Pair<PsiClass, Integer>>() {
          public int compare(Pair<PsiClass, Integer> o1, Pair<PsiClass, Integer> o2) {
            int result = o1.second.compareTo(o2.second);
            if (result == 0) {
              result = o1.first.getName().compareTo(o2.first.getName());
            }
            return result;
          }
        });

    List<PsiElement> result = new ArrayList<PsiElement>();
    for (Pair<PsiClass, Integer> each : classesWithProximities) {
      result.add(each.first);
    }

    return result;
  }
 @NotNull
 public static GlobalSearchScope getMaximalScope(@NotNull FindUsagesHandler handler) {
   PsiElement element = handler.getPsiElement();
   Project project = element.getProject();
   PsiFile file = element.getContainingFile();
   if (file != null
       && ProjectFileIndex.SERVICE
           .getInstance(project)
           .isInContent(file.getViewProvider().getVirtualFile())) {
     return GlobalSearchScope.projectScope(project);
   }
   return GlobalSearchScope.allScope(project);
 }
    @Override
    public int compare(@NotNull VirtualFile file1, @NotNull VirtualFile file2) {
      int res1 = myScope1.compare(file1, file2);
      int res2 = myScope2.compare(file1, file2);

      if (res1 == 0) return res2;
      if (res2 == 0) return res1;

      res1 /= Math.abs(res1);
      res2 /= Math.abs(res2);
      if (res1 == res2) return res1;

      return 0;
    }
 @Nullable
 private static String getSecondInvocationTitle(
     @NotNull FindUsagesOptions options, @NotNull FindUsagesHandler handler) {
   if (getShowUsagesShortcut() != null) {
     GlobalSearchScope maximalScope = FindUsagesManager.getMaximalScope(handler);
     if (!notNullizeScope(options, handler.getProject()).equals(maximalScope)) {
       return "Press "
           + KeymapUtil.getShortcutText(getShowUsagesShortcut())
           + " again to search in "
           + maximalScope.getDisplayName();
     }
   }
   return null;
 }
 @Override
 public String detectParameterValue(Project project) {
   PsiPackage root = JavaPsiFacade.getInstance(project).findPackage("");
   if (root == null) return null;
   String name = getBasePackage(root, GlobalSearchScope.projectScope(project)).getQualifiedName();
   return StringUtil.isEmpty(name) ? null : name;
 }
 public void testLibraryClassUsageFromDecompiledSource() {
   PsiElement decompiled =
       ((PsiCompiledElement)
               myJavaFacade.findClass("javax.swing.JLabel", GlobalSearchScope.allScope(myProject)))
           .getMirror();
   assertEquals(2, ReferencesSearch.search(decompiled).findAll().size());
 }
 public void testProtectedMethodInPackageLocalClass() throws Throwable {
   PsiMethod method =
       myJavaFacade.findClass("foo.PackageLocal", GlobalSearchScope.allScope(myProject))
           .getMethods()[0];
   assertEquals(1, OverridingMethodsSearch.search(method).findAll().size());
   assertEquals(1, ReferencesSearch.search(method).findAll().size());
 }
 public void testEnum() throws Exception {
   setupLoadingFilter();
   final PsiClass enumClass =
       myJavaFacade.findClass("enums.OurEnum", GlobalSearchScope.moduleScope(myModule));
   assertNotNull(enumClass);
   assertTrue(enumClass.isEnum());
   final PsiClass superClass = enumClass.getSuperClass();
   assertNotNull(superClass);
   assertEquals("java.lang.Enum", superClass.getQualifiedName());
   assertTrue(enumClass.isInheritor(superClass, false));
   final PsiClassType[] superTypes = enumClass.getSuperTypes();
   assertEquals(1, superTypes.length);
   assertEquals("java.lang.Enum<enums.OurEnum>", superTypes[0].getCanonicalText());
   final PsiClass[] supers = enumClass.getSupers();
   assertEquals(1, supers.length);
   assertEquals("java.lang.Enum", supers[0].getQualifiedName());
   final PsiClassType[] extendsListTypes = enumClass.getExtendsListTypes();
   assertEquals(1, extendsListTypes.length);
   assertEquals("java.lang.Enum<enums.OurEnum>", extendsListTypes[0].getCanonicalText());
   final PsiSubstitutor superClassSubstitutor =
       TypeConversionUtil.getSuperClassSubstitutor(superClass, enumClass, PsiSubstitutor.EMPTY);
   assertEquals(
       "java.lang.Enum<enums.OurEnum>",
       myJavaFacade
           .getElementFactory()
           .createType(superClass, superClassSubstitutor)
           .getCanonicalText());
   teardownLoadingFilter();
 }
  @NotNull
  @Override
  public Collection<PsiReference> findReferences(final PsiElement element) {
    if (element instanceof GrField) {
      ArrayList<PsiReference> refs = new ArrayList<PsiReference>();

      GrField field = (GrField) element;
      PsiMethod setter = GroovyPropertyUtils.findSetterForField(field);
      GlobalSearchScope projectScope = GlobalSearchScope.projectScope(element.getProject());
      if (setter != null && setter instanceof GrAccessorMethod) {
        refs.addAll(
            RenameAliasedUsagesUtil.filterAliasedRefs(
                MethodReferencesSearch.search(setter, projectScope, true).findAll(), setter));
      }
      GrAccessorMethod[] getters = field.getGetters();
      for (GrAccessorMethod getter : getters) {
        refs.addAll(
            RenameAliasedUsagesUtil.filterAliasedRefs(
                MethodReferencesSearch.search(getter, projectScope, true).findAll(), getter));
      }
      refs.addAll(
          RenameAliasedUsagesUtil.filterAliasedRefs(
              ReferencesSearch.search(field, projectScope, true).findAll(), field));
      return refs;
    }
    return super.findReferences(element);
  }
 private static boolean isIndexOfCall(@NotNull PsiMethodCallExpression expression) {
   final PsiReferenceExpression methodExpression = expression.getMethodExpression();
   final String methodName = methodExpression.getReferenceName();
   if (!HardcodedMethodConstants.INDEX_OF.equals(methodName)) {
     return false;
   }
   final PsiExpressionList argumentList = expression.getArgumentList();
   final PsiExpression[] arguments = argumentList.getExpressions();
   if (arguments.length != 1) {
     return false;
   }
   final PsiExpression qualifier = methodExpression.getQualifierExpression();
   if (qualifier == null) {
     return false;
   }
   final PsiType qualifierType = qualifier.getType();
   if (qualifierType == null) {
     return false;
   }
   final Project project = expression.getProject();
   final GlobalSearchScope projectScope = GlobalSearchScope.allScope(project);
   final JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(project);
   final PsiClass javaUtilListClass =
       psiFacade.findClass(CommonClassNames.JAVA_UTIL_LIST, projectScope);
   if (javaUtilListClass == null) {
     return false;
   }
   final PsiElementFactory factory = psiFacade.getElementFactory();
   final PsiClassType javaUtilListType = factory.createType(javaUtilListClass);
   return javaUtilListType.isAssignableFrom(qualifierType);
 }
Exemplo n.º 26
0
  public void _testCollectedPsiWithChangedDocument() throws IOException {
    VirtualFile dir = getVirtualFile(createTempDirectory());
    PsiTestUtil.addSourceContentToRoots(myModule, dir);

    final VirtualFile vFile = createChildData(dir, "Foo.java");
    VfsUtil.saveText(vFile, "class Foo {}");

    final GlobalSearchScope scope = GlobalSearchScope.allScope(getProject());
    final JavaPsiFacade facade = JavaPsiFacade.getInstance(getProject());
    assertNotNull(facade.findClass("Foo", scope));
    ApplicationManager.getApplication()
        .runWriteAction(
            new Runnable() {
              @Override
              public void run() {
                PsiFile psiFile = PsiManager.getInstance(getProject()).findFile(vFile);
                assertNotNull(psiFile);

                Document document = FileDocumentManager.getInstance().getDocument(vFile);
                document.deleteString(0, document.getTextLength());
                assertNotNull(facade.findClass("Foo", scope));

                psiFile = null;
                PlatformTestUtil.tryGcSoftlyReachableObjects();
                assertNull(
                    ((PsiManagerEx) PsiManager.getInstance(getProject()))
                        .getFileManager()
                        .getCachedPsiFile(vFile));

                // should be assertNull(facade.findClass("Foo", scope));
                // or the file should not be allowed to be gc'ed
                facade.findClass("Foo", scope).getText();
              }
            });
  }
  public void updateThrowsList(PsiClassType exceptionType) {
    if (!getSuperMethods().isEmpty()) {
      for (RefMethod refSuper : getSuperMethods()) {
        ((RefMethodImpl) refSuper).updateThrowsList(exceptionType);
      }
    } else if (myUnThrownExceptions != null) {
      if (exceptionType == null) {
        myUnThrownExceptions = null;
        return;
      }
      PsiClass exceptionClass = exceptionType.resolve();
      JavaPsiFacade facade = JavaPsiFacade.getInstance(myManager.getProject());
      for (int i = myUnThrownExceptions.size() - 1; i >= 0; i--) {
        String exceptionFqn = myUnThrownExceptions.get(i);
        PsiClass classType =
            facade.findClass(
                exceptionFqn, GlobalSearchScope.allScope(getRefManager().getProject()));
        if (InheritanceUtil.isInheritorOrSelf(exceptionClass, classType, true)
            || InheritanceUtil.isInheritorOrSelf(classType, exceptionClass, true)) {
          myUnThrownExceptions.remove(i);
        }
      }

      if (myUnThrownExceptions.isEmpty()) myUnThrownExceptions = null;
    }
  }
  @NotNull
  @Override
  public Collection<PsiReference> findReferences(PsiElement element) {
    assert element instanceof GrField;

    ArrayList<PsiReference> refs = new ArrayList<>();

    GrField field = (GrField) element;
    GlobalSearchScope projectScope = GlobalSearchScope.projectScope(element.getProject());
    PsiMethod setter = field.getSetter();
    if (setter != null) {
      refs.addAll(
          RenameAliasedUsagesUtil.filterAliasedRefs(
              MethodReferencesSearch.search(setter, projectScope, true).findAll(), setter));
    }
    GrAccessorMethod[] getters = field.getGetters();
    for (GrAccessorMethod getter : getters) {
      refs.addAll(
          RenameAliasedUsagesUtil.filterAliasedRefs(
              MethodReferencesSearch.search(getter, projectScope, true).findAll(), getter));
    }
    refs.addAll(
        RenameAliasedUsagesUtil.filterAliasedRefs(
            ReferencesSearch.search(field, projectScope, false).findAll(), field));
    return refs;
  }
Exemplo n.º 29
0
  public void testMultiPackageFunction() {
    myFixture.configureByText(
        JetFileType.INSTANCE,
        "package test.testing\n" + "fun other(v : Int) = 12\n" + "fun other(v : String) {}");

    StubPackageMemberDeclarationProvider provider =
        new StubPackageMemberDeclarationProvider(
            new FqName("test.testing"), getProject(), GlobalSearchScope.projectScope(getProject()));

    List<JetNamedFunction> other =
        Lists.newArrayList(provider.getFunctionDeclarations(Name.identifier("other")));
    Collection<String> functionTexts =
        Collections2.transform(
            other,
            new Function<JetNamedFunction, String>() {
              @Override
              public String apply(JetNamedFunction function) {
                return function.getText();
              }
            });

    assertSize(2, other);
    assertTrue(functionTexts.contains("fun other(v : Int) = 12"));
    assertTrue(functionTexts.contains("fun other(v : String) {}"));
  }
Exemplo n.º 30
0
  private void checkCompoundIds(Class<?> javaClass) throws IOException {
    String javaClassName = javaClass.getCanonicalName();
    PsiClass psiClass =
        myJavaPsiFacade.findClass(
            javaClassName, GlobalSearchScope.moduleWithLibrariesScope(myModule));
    assertNotNull(psiClass);

    for (java.lang.reflect.Method javaMethod : javaClass.getDeclaredMethods()) {
      Method method =
          new Method(
              Type.getType(javaClass).getInternalName(),
              javaMethod.getName(),
              Type.getMethodDescriptor(javaMethod));
      boolean noKey = javaMethod.getAnnotation(ExpectNoPsiKey.class) != null;
      PsiMethod psiMethod = psiClass.findMethodsByName(javaMethod.getName(), false)[0];
      checkCompoundId(method, psiMethod, noKey);
    }

    for (Constructor<?> constructor : javaClass.getDeclaredConstructors()) {
      Method method =
          new Method(
              Type.getType(javaClass).getInternalName(),
              "<init>",
              Type.getConstructorDescriptor(constructor));
      boolean noKey = constructor.getAnnotation(ExpectNoPsiKey.class) != null;
      PsiMethod[] constructors = psiClass.getConstructors();
      PsiMethod psiMethod = constructors[0];
      checkCompoundId(method, psiMethod, noKey);
    }
  }