Example #1
0
  public static boolean canBeMigrated(final PsiElement e) {
    if (e == null) {
      return false;
    }

    final PsiElement element = normalizeElement(e);

    if (!element.getManager().isInProject(element)) {
      return false;
    }

    final PsiType type = TypeMigrationLabeler.getElementType(element);

    if (type != null) {
      final PsiType elemenType = type instanceof PsiArrayType ? type.getDeepComponentType() : type;

      if (elemenType instanceof PsiPrimitiveType) {
        return !elemenType.equals(PsiType.VOID);
      }

      final PsiClass aClass = ((PsiClassType) elemenType).resolve();

      return aClass != null /* && !aClass.hasTypeParameters()*/;
    }

    return false;
  }
Example #2
0
 @Override
 protected void previewRefactoring(@NotNull final UsageInfo[] usages) {
   MigrationPanel panel = new MigrationPanel(myRoot, myLabeler, myProject, isPreviewUsages());
   String name;
   if (myRoot.length == 1) {
     String fromType =
         assertNotNull(TypeMigrationLabeler.getElementType(myRoot[0])).getPresentableText();
     String toType = myRootTypes.fun(myRoot[0]).getPresentableText();
     String text;
     text = getPresentation(myRoot[0]);
     name = "Migrate Type of " + text + " from \'" + fromType + "\' to \'" + toType + "\'";
   } else {
     final int rootsInPresentationCount =
         myRoot.length > MAX_ROOT_IN_PREVIEW_PRESENTATION
             ? MAX_ROOT_IN_PREVIEW_PRESENTATION
             : myRoot.length;
     String[] rootsPresentation = new String[rootsInPresentationCount];
     for (int i = 0; i < rootsInPresentationCount; i++) {
       final PsiElement root = myRoot[i];
       rootsPresentation[i] =
           root instanceof PsiNamedElement ? ((PsiNamedElement) root).getName() : root.getText();
     }
     rootsPresentation = StringUtil.surround(rootsPresentation, "\'", "\'");
     name = "Migrate Type of " + StringUtil.join(rootsPresentation, ", ");
     if (myRoot.length > MAX_ROOT_IN_PREVIEW_PRESENTATION) {
       name += "...";
     }
   }
   Content content =
       UsageViewManager.getInstance(myProject).addContent(name, false, panel, true, true);
   panel.setContent(content);
   ToolWindowManager.getInstance(myProject).getToolWindow(ToolWindowId.FIND).activate(null);
 }
 @Override
 protected void previewRefactoring(final UsageInfo[] usages) {
   MigrationPanel panel = new MigrationPanel(myRoot[0], myLabeler, myProject, isPreviewUsages());
   String text;
   if (myRoot[0] instanceof PsiField) {
     text = "field \'" + ((PsiField) myRoot[0]).getName() + "\'";
   } else if (myRoot[0] instanceof PsiParameter) {
     text = "parameter \'" + ((PsiParameter) myRoot[0]).getName() + "\'";
   } else if (myRoot[0] instanceof PsiLocalVariable) {
     text = "variable \'" + ((PsiLocalVariable) myRoot[0]).getName() + "\'";
   } else if (myRoot[0] instanceof PsiMethod) {
     text = "method \'" + ((PsiMethod) myRoot[0]).getName() + "\' return";
   } else {
     text = Arrays.toString(myRoot);
   }
   Content content =
       UsageViewManager.getInstance(myProject)
           .addContent(
               "Migrate Type of "
                   + text
                   + " from \'"
                   + TypeMigrationLabeler.getElementType(myRoot[0]).getPresentableText()
                   + "\' to \'"
                   + myRules.getMigrationRootType().getPresentableText()
                   + "\'",
               false,
               panel,
               true,
               true);
   panel.setContent(content);
   ToolWindowManager.getInstance(myProject).getToolWindow(ToolWindowId.FIND).activate(null);
 }
  private void processMemberType(
      final PsiElement element,
      final TypeParameterSearcher parameterSearcher,
      final PsiClass psiClass,
      final PsiSubstitutor substitutor,
      final Map<PsiElement, Pair<PsiReference[], PsiType>> roots) {
    final PsiType elementType = TypeMigrationLabeler.getElementType(element);
    if (elementType != null && elementType.accept(parameterSearcher).booleanValue()) {
      final PsiType memberType = substitutor.substitute(elementType);

      prepareMethodsChangeSignature(psiClass, element, memberType);

      final List<PsiReference> refs =
          TypeMigrationLabeler.filterReferences(
              psiClass, ReferencesSearch.search(element, psiClass.getUseScope()));

      roots.put(
          element,
          Pair.create(
              myLabeler.markRootUsages(
                  element, memberType, refs.toArray(new PsiReference[refs.size()])),
              memberType));
    }
  }