-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Attempting to restore broken refactoring features
- Loading branch information
Showing
20 changed files
with
363 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
src/main/java/com/intellij/plugins/haxe/ide/refactoring/MoveUpDownUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package com.intellij.plugins.haxe.ide.refactoring; | ||
|
||
import com.intellij.plugins.haxe.lang.lexer.HaxeTokenTypeSets; | ||
import com.intellij.plugins.haxe.metadata.psi.HaxeMeta; | ||
import com.intellij.psi.PsiComment; | ||
import com.intellij.psi.PsiElement; | ||
import com.intellij.psi.PsiMember; | ||
import com.intellij.psi.impl.source.JavaDummyHolder; | ||
import com.intellij.psi.impl.source.tree.LazyParseablePsiElement; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class MoveUpDownUtil { | ||
|
||
|
||
public static void addMetadataAndDocs(List<PsiElement> list, PsiMember element, boolean deleteOriginal) { | ||
Collections.reverse(list); | ||
// insert after new member | ||
for (PsiElement psiElement : list) { | ||
element.getParent().addBefore(psiElement.copy(), element); | ||
} | ||
// remove from old member | ||
if (deleteOriginal) { | ||
for (PsiElement psiElement : list) { | ||
if (psiElement.getParent() != null | ||
&& !(psiElement.getParent() instanceof JavaDummyHolder)) { | ||
psiElement.delete(); | ||
} | ||
} | ||
} | ||
} | ||
|
||
public static List<PsiElement> collectRelatedDocsAndMetadata(PsiMember member) { | ||
List<PsiElement> psiElements = new ArrayList<PsiElement>(); | ||
List<PsiElement> tempList = new ArrayList<PsiElement>(); | ||
PsiElement sibling = member.getPrevSibling(); | ||
// we want to copy all relevant metadata, comments and docs when moving a member | ||
// but we dont want to copy comments that might not belong so we only collect | ||
// elements until we dont get any more relevant elements or we reach a different member. | ||
while (sibling != null && !(sibling instanceof PsiMember)) { | ||
tempList.add(sibling); | ||
if (sibling instanceof LazyParseablePsiElement lazy) { | ||
for (PsiElement child : lazy.getChildren()) { | ||
if (child instanceof HaxeMeta) { | ||
psiElements.addAll(tempList); | ||
tempList.clear(); | ||
} | ||
} | ||
} | ||
if (sibling instanceof HaxeMeta) { | ||
psiElements.addAll(tempList); | ||
tempList.clear(); | ||
} | ||
if (sibling instanceof PsiComment comment && comment.getTokenType() == HaxeTokenTypeSets.DOC_COMMENT) { | ||
psiElements.addAll(tempList); | ||
tempList.clear(); | ||
} | ||
|
||
sibling = sibling.getPrevSibling(); | ||
} | ||
return psiElements; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.