use of org.jetbrains.kotlin.psi.KtNamedDeclaration in project kotlin by JetBrains.
the class MoveKotlinTopLevelDeclarationsDialog method doAction.
@Override
protected void doAction() {
KotlinMoveTarget target = selectMoveTarget();
if (target == null)
return;
saveRefactoringSettings();
List<KtNamedDeclaration> elementsToMove = getSelectedElementsToMove();
List<KtFile> sourceFiles = getSourceFiles(elementsToMove);
final PsiDirectory sourceDirectory = getSourceDirectory(sourceFiles);
for (PsiElement element : elementsToMove) {
String message = target.verify(element.getContainingFile());
if (message != null) {
CommonRefactoringUtil.showErrorMessage(RefactoringBundle.message("error.title"), message, null, myProject);
return;
}
}
try {
boolean deleteSourceFile = false;
if (isFullFileMove()) {
if (isMoveToPackage()) {
Pair<VirtualFile, ? extends MoveDestination> sourceRootWithMoveDestination = selectPackageBasedTargetDirAndDestination(false);
//noinspection ConstantConditions
final MoveDestination moveDestination = sourceRootWithMoveDestination.getSecond();
PsiDirectory targetDir = moveDestination.getTargetIfExists(sourceDirectory);
String targetFileName = sourceFiles.size() > 1 ? null : tfFileNameInPackage.getText();
List<PsiFile> filesExistingInTargetDir = getFilesExistingInTargetDir(sourceFiles, targetFileName, targetDir);
if (filesExistingInTargetDir.isEmpty()) {
PsiDirectory targetDirectory = ApplicationUtilsKt.runWriteAction(new Function0<PsiDirectory>() {
@Override
public PsiDirectory invoke() {
return moveDestination.getTargetDirectory(sourceDirectory);
}
});
for (KtFile sourceFile : sourceFiles) {
MoveUtilsKt.setUpdatePackageDirective(sourceFile, cbUpdatePackageDirective.isSelected());
}
invokeRefactoring(new MoveFilesWithDeclarationsProcessor(myProject, sourceFiles, targetDirectory, targetFileName, isSearchInComments(), isSearchInNonJavaFiles(), moveCallback));
return;
}
}
int ret = Messages.showYesNoCancelDialog(myProject, "You are about to move all declarations out of the source file(s). Do you want to delete empty files?", RefactoringBundle.message("move.title"), Messages.getQuestionIcon());
if (ret == Messages.CANCEL)
return;
deleteSourceFile = ret == Messages.YES;
}
MoveDeclarationsDescriptor options = new MoveDeclarationsDescriptor(elementsToMove, target, MoveDeclarationsDelegate.TopLevel.INSTANCE, isSearchInComments(), isSearchInNonJavaFiles(), true, deleteSourceFile, moveCallback, false);
invokeRefactoring(new MoveKotlinDeclarationsProcessor(myProject, options, Mover.Default.INSTANCE));
} catch (IncorrectOperationException e) {
CommonRefactoringUtil.showErrorMessage(RefactoringBundle.message("error.title"), e.getMessage(), null, myProject);
}
}
use of org.jetbrains.kotlin.psi.KtNamedDeclaration in project kotlin by JetBrains.
the class CFGraphToDotFilePrinter method dumpDot.
public static void dumpDot(File file, Collection<Pseudocode> pseudocodes) throws FileNotFoundException {
File target = KotlinTestUtils.replaceExtension(file, "dot");
PrintStream out = new PrintStream(target);
out.println("digraph " + FileUtil.getNameWithoutExtension(file) + " {");
int[] count = new int[1];
Map<Instruction, String> nodeToName = new HashMap<Instruction, String>();
for (Pseudocode pseudocode : pseudocodes) {
dumpNodes(pseudocode.getInstructionsIncludingDeadCode(), out, count, nodeToName, Sets.newHashSet(pseudocode.getInstructions()));
}
int i = 0;
for (Pseudocode pseudocode : pseudocodes) {
String label;
KtElement correspondingElement = pseudocode.getCorrespondingElement();
if (correspondingElement instanceof KtNamedDeclaration) {
KtNamedDeclaration namedDeclaration = (KtNamedDeclaration) correspondingElement;
label = namedDeclaration.getName();
} else {
label = "anonymous_" + i;
}
out.println("subgraph cluster_" + i + " {\n" + "label=\"" + label + "\";\n" + "color=blue;\n");
dumpEdges(pseudocode.getInstructionsIncludingDeadCode(), out, count, nodeToName);
out.println("}");
i++;
}
out.println("}");
out.close();
}
use of org.jetbrains.kotlin.psi.KtNamedDeclaration in project kotlin by JetBrains.
the class MoveKotlinTopLevelDeclarationsDialog method initMemberInfo.
private void initMemberInfo(@NotNull final Set<KtNamedDeclaration> elementsToMove, @NotNull List<KtFile> sourceFiles) {
final List<KotlinMemberInfo> memberInfos = CollectionsKt.map(getAllDeclarations(sourceFiles), new Function1<KtNamedDeclaration, KotlinMemberInfo>() {
@Override
public KotlinMemberInfo invoke(KtNamedDeclaration declaration) {
KotlinMemberInfo memberInfo = new KotlinMemberInfo(declaration, false);
memberInfo.setChecked(elementsToMove.contains(declaration));
return memberInfo;
}
});
KotlinMemberSelectionPanel selectionPanel = new KotlinMemberSelectionPanel(getTitle(), memberInfos, null);
memberTable = selectionPanel.getTable();
MemberInfoModelImpl memberInfoModel = new MemberInfoModelImpl();
memberInfoModel.memberInfoChanged(new MemberInfoChange<KtNamedDeclaration, KotlinMemberInfo>(memberInfos));
selectionPanel.getTable().setMemberInfoModel(memberInfoModel);
selectionPanel.getTable().addMemberInfoChangeListener(memberInfoModel);
selectionPanel.getTable().addMemberInfoChangeListener(new MemberInfoChangeListener<KtNamedDeclaration, KotlinMemberInfo>() {
private boolean shouldUpdateFileNameField(final Collection<KotlinMemberInfo> changedMembers) {
if (!tfFileNameInPackage.isEnabled())
return true;
Collection<KtNamedDeclaration> previousDeclarations = CollectionsKt.filterNotNull(CollectionsKt.map(memberInfos, new Function1<KotlinMemberInfo, KtNamedDeclaration>() {
@Override
public KtNamedDeclaration invoke(KotlinMemberInfo info) {
return changedMembers.contains(info) != info.isChecked() ? info.getMember() : null;
}
}));
String suggestedText = previousDeclarations.isEmpty() ? "" : MoveUtilsKt.guessNewFileName(previousDeclarations);
return tfFileNameInPackage.getText().equals(suggestedText);
}
@Override
public void memberInfoChanged(MemberInfoChange<KtNamedDeclaration, KotlinMemberInfo> event) {
updatePackageDirectiveCheckBox();
updateFileNameInPackageField();
// Update file name field only if it user hasn't changed it to some non-default value
if (shouldUpdateFileNameField(event.getChangedMembers())) {
updateSuggestedFileName();
}
}
});
memberInfoPanel.add(selectionPanel, BorderLayout.CENTER);
}
use of org.jetbrains.kotlin.psi.KtNamedDeclaration in project kotlin by JetBrains.
the class KotlinFindPropertyUsagesDialog method addUsagesOptions.
@Override
protected void addUsagesOptions(JPanel optionsPanel) {
super.addUsagesOptions(optionsPanel);
KtNamedDeclaration property = (KtNamedDeclaration) getPsiElement();
boolean isAbstract = property.hasModifier(KtTokens.ABSTRACT_KEYWORD);
boolean isOpen = property.hasModifier(KtTokens.OPEN_KEYWORD);
if (isOpen || isAbstract) {
cbOverrides = addCheckboxToPanel(isAbstract ? KotlinBundle.message("find.what.implementing.properties.checkbox") : KotlinBundle.message("find.what.overriding.properties.checkbox"), FindSettings.getInstance().isSearchOverloadedMethods(), optionsPanel, false);
}
}
Aggregations