use of com.intellij.refactoring.typeMigration.usageInfo.TypeMigrationUsageInfo in project intellij-community by JetBrains.
the class TypeMigrationStatementProcessor method findConversionOrFail.
private void findConversionOrFail(PsiExpression expression, PsiExpression toFail, Pair<PsiType, PsiType> typePair) {
final TypeConversionDescriptorBase conversion = myLabeler.getRules().findConversion(typePair.getFirst(), typePair.getSecond(), null, expression, myLabeler);
if (conversion == null) {
myLabeler.markFailedConversion(typePair, toFail);
} else {
myLabeler.setConversionMapping(expression, conversion);
final PsiType psiType = myTypeEvaluator.evaluateType(expression);
LOG.assertTrue(psiType != null, expression);
myTypeEvaluator.setType(new TypeMigrationUsageInfo(expression), psiType);
}
}
use of com.intellij.refactoring.typeMigration.usageInfo.TypeMigrationUsageInfo in project intellij-community by JetBrains.
the class TypeMigrationStatementProcessor method visitReferenceExpression.
@Override
public void visitReferenceExpression(PsiReferenceExpression expression) {
final PsiExpression qualifierExpression = expression.getQualifierExpression();
if (qualifierExpression != null && qualifierExpression.isPhysical()) {
qualifierExpression.accept(this);
final TypeView qualifierView = new TypeView(qualifierExpression);
if (qualifierView.isChanged()) {
final PsiMember member = (PsiMember) expression.advancedResolve(false).getElement();
if (member == null)
return;
final Pair<PsiType, PsiType> typePair = qualifierView.getTypePair();
final TypeConversionDescriptorBase conversion = myLabeler.getRules().findConversion(typePair.getFirst(), typePair.getSecond(), member, expression, false, myLabeler);
if (conversion == null) {
myLabeler.markFailedConversion(typePair, qualifierExpression);
} else {
final PsiElement parent = Util.getEssentialParent(expression);
final PsiType type = conversion.conversionType();
if (parent instanceof PsiMethodCallExpression) {
myLabeler.setConversionMapping((PsiMethodCallExpression) parent, conversion);
myTypeEvaluator.setType(new TypeMigrationUsageInfo(parent), type != null ? type : myTypeEvaluator.evaluateType((PsiExpression) parent));
} else {
myLabeler.setConversionMapping(expression, conversion);
myTypeEvaluator.setType(new TypeMigrationUsageInfo(expression), type != null ? type : myTypeEvaluator.evaluateType(expression));
}
}
}
}
}
use of com.intellij.refactoring.typeMigration.usageInfo.TypeMigrationUsageInfo in project intellij-community by JetBrains.
the class TypeMigrationStatementProcessor method visitArrayAccessExpression.
@Override
public void visitArrayAccessExpression(final PsiArrayAccessExpression expression) {
super.visitArrayAccessExpression(expression);
final PsiExpression indexExpression = expression.getIndexExpression();
if (indexExpression != null) {
checkIndexExpression(indexExpression);
}
final TypeView typeView = new TypeView(expression.getArrayExpression());
if (typeView.isChanged() && typeView.getType() instanceof PsiClassType) {
final TypeConversionDescriptorBase conversion = myLabeler.getRules().findConversion(typeView.getTypePair().first, typeView.getType(), null, expression, false, myLabeler);
if (conversion == null) {
myLabeler.markFailedConversion(typeView.getTypePair(), expression);
} else {
myLabeler.setConversionMapping(expression, conversion);
myTypeEvaluator.setType(new TypeMigrationUsageInfo(expression), myTypeEvaluator.evaluateType(expression));
}
}
}
use of com.intellij.refactoring.typeMigration.usageInfo.TypeMigrationUsageInfo in project intellij-community by JetBrains.
the class MigrationNode method getChildren.
@NotNull
public Collection<? extends AbstractTreeNode> getChildren() {
if (myCachedChildren == null) {
myCachedChildren = new ArrayList<>();
final PsiElement element = myInfo.getElement();
if (element != null) {
try {
myLabeler.setRootAndMigrate(myInfo, myMigrationType, myLabeler.markRootUsages(element, myMigrationType));
} catch (TypeMigrationLabeler.MigrateException e) {
//skip warning
}
final HashSet<Pair<TypeMigrationUsageInfo, PsiType>> roots = myLabeler.getRootsTree().get(myInfo);
if (roots != null) {
for (Pair<TypeMigrationUsageInfo, PsiType> root : roots) {
final TypeMigrationUsageInfo info = root.getFirst();
if (myParents.contains(info))
continue;
final HashSet<TypeMigrationUsageInfo> parents = new HashSet<>(myParents);
parents.add(info);
final MigrationNode migrationNode = new MigrationNode(getProject(), info, root.getSecond(), myLabeler, parents, myProcessed);
if (myInfo.isExcluded()) {
info.setExcluded(true);
}
myCachedChildren.add(migrationNode);
}
}
}
}
return myCachedChildren;
}
use of com.intellij.refactoring.typeMigration.usageInfo.TypeMigrationUsageInfo in project intellij-community by JetBrains.
the class MigrationPanel method createToolbar.
private JComponent createToolbar() {
final JPanel panel = new JPanel(new GridBagLayout());
GridBagConstraints gc = new GridBagConstraints(GridBagConstraints.RELATIVE, 0, 1, 1, 0, 1, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, JBUI.insets(5, 10, 5, 0), 0, 0);
final JButton performButton = new JButton(RefactoringBundle.message("type.migration.migrate.button.text"));
performButton.addActionListener(new ActionListener() {
private void expandTree(MigrationNode migrationNode) {
if (!migrationNode.getInfo().isExcluded() || migrationNode.areChildrenInitialized()) {
//do not walk into excluded collapsed nodes: nothing to migrate can be found
final Collection<? extends AbstractTreeNode> nodes = migrationNode.getChildren();
for (final AbstractTreeNode node : nodes) {
ApplicationManager.getApplication().runReadAction(() -> expandTree((MigrationNode) node));
}
}
}
public void actionPerformed(final ActionEvent e) {
final Object root = myRootsTree.getModel().getRoot();
if (root instanceof DefaultMutableTreeNode) {
final Object userObject = ((DefaultMutableTreeNode) root).getUserObject();
if (userObject instanceof MigrationRootNode) {
ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> {
final HashSet<VirtualFile> files = new HashSet<>();
final TypeMigrationUsageInfo[] usages = ReadAction.compute(() -> {
final Collection<? extends AbstractTreeNode> children = ((MigrationRootNode) userObject).getChildren();
for (AbstractTreeNode child : children) {
expandTree((MigrationNode) child);
}
final TypeMigrationUsageInfo[] usages1 = myLabeler.getMigratedUsages();
for (TypeMigrationUsageInfo usage : usages1) {
if (!usage.isExcluded()) {
final PsiElement element = usage.getElement();
if (element != null) {
files.add(element.getContainingFile().getVirtualFile());
}
}
}
return usages1;
});
ApplicationManager.getApplication().invokeLater(() -> {
if (ReadonlyStatusHandler.getInstance(myProject).ensureFilesWritable(VfsUtilCore.toVirtualFileArray(files)).hasReadonlyFiles()) {
return;
}
new WriteCommandAction(myProject) {
protected void run(@NotNull Result result) throws Throwable {
TypeMigrationProcessor.change(usages, myLabeler, myProject);
}
}.execute();
}, myProject.getDisposed());
}, "Type Migration", false, myProject);
}
}
UsageViewManager.getInstance(myProject).closeContent(myContent);
}
});
panel.add(performButton, gc);
final JButton closeButton = new JButton(CommonBundle.getCancelButtonText());
closeButton.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
UsageViewManager.getInstance(myProject).closeContent(myContent);
}
});
panel.add(closeButton, gc);
final JButton rerunButton = new JButton(RefactoringBundle.message("type.migration.rerun.button.text"));
rerunButton.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
UsageViewManager.getInstance(myProject).closeContent(myContent);
final TypeMigrationDialog.MultipleElements dialog = new TypeMigrationDialog.MultipleElements(myProject, myInitialRoots, myLabeler.getMigrationRootTypeFunction(), myLabeler.getRules());
dialog.show();
}
});
panel.add(rerunButton, gc);
final JButton helpButton = new JButton(CommonBundle.getHelpButtonText());
helpButton.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
HelpManager.getInstance().invokeHelp("reference.typeMigrationPreview");
}
});
gc.weightx = 1;
panel.add(helpButton, gc);
return panel;
}
Aggregations