Skip to content

Commit

Permalink
Documenting intentions and fixing bug in SplitIntoDeclarationAndAssig…
Browse files Browse the repository at this point in the history
…nment
  • Loading branch information
m0rkeulv committed Jan 21, 2024
1 parent afd6d91 commit 643b4c4
Show file tree
Hide file tree
Showing 40 changed files with 245 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,15 @@ public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
PsiElement elementAt = file.findElementAt(editor.getCaretModel().getOffset());
HaxeLocalVarDeclaration localVarDeclaration = PsiTreeUtil.getParentOfType(elementAt, HaxeLocalVarDeclaration.class);
HaxeLocalVarDeclarationList localVarDeclarationList = PsiTreeUtil.getParentOfType(elementAt, HaxeLocalVarDeclarationList.class);

if (localVarDeclaration == null) return;
String name = localVarDeclaration.getComponentName().getName();
HaxeTypeTag typeTag = localVarDeclaration.getTypeTag();
HaxeVarInit varInit = localVarDeclaration.getVarInit();
if (localVarDeclarationList == null) return;
List<HaxeLocalVarDeclaration> list = localVarDeclarationList.getLocalVarDeclarationList();
if (list.size() != 1) return;
HaxeLocalVarDeclaration declaration = list.get(0);
String name = declaration.getComponentName().getName();
HaxeTypeTag typeTag = declaration.getTypeTag();
HaxeVarInit varInit = declaration.getVarInit();

String text = "var " + name;
if (typeTag != null) {
Expand All @@ -83,8 +86,8 @@ public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws
PsiElement statementFromText = HaxeElementGenerator.createStatementFromText(project, text);
statementFromText.getNode().addLeaf(HaxeTokenTypes.OSEMI, ";", null);

localVarDeclaration.getParent().addBefore(varDeclaration, localVarDeclaration);
PsiElement replace = localVarDeclaration.replace(statementFromText);
localVarDeclarationList.getParent().addBefore(varDeclaration, localVarDeclarationList);
PsiElement replace = localVarDeclarationList.replace(statementFromText);

final TextRange range = replace.getTextRange();
final PsiFile baseFile = file.getViewProvider().getPsi(file.getViewProvider().getBaseLanguage());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package ;
class SomeClass {
public function myFunction()<spot>:String</spot> {
var stringVar = "MyString";
return stringVar;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package ;
class SomeClass {
public function myFunction()<spot></spot> {
var stringVar = "MyString";
return stringVar;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<html>
<body>
Resolves return type and adds it to the method declarations
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package ;
class SomeClass {
public function myFunction() {
var stringVar<spot>:String</spot> = "MyString";
return stringVar;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package ;
class SomeClass {
public function myFunction() {
var stringVar<spot></spot> = "MyString";
return stringVar;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<html>
<body>
Resolves variable type and adds it to the variable declarations
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package ;
class SomeClass {
public var variable<spot></spot>:String;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package ;
class SomeClass {
public var variable<spot>(default, default)</spot>:String;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<html>
<body>
Converts a property into a variable
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package ;
class SomeClass {
function myFun(intValue:Int) {
return <spot>'</spot>value = $intValue<spot>'</spot>;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package ;
class SomeClass {
function myFun(intValue:Int) {
return <spot>"</spot>value = $intValue<spot>"</spot>;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<html>
<body>
Replaces double quotes with single quotes for string interpolation support
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package ;
class SomeClass {
public var variable<spot>(default, default)</spot>:String;
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package ;
class SomeClass {
public var variable<spot></spot>:String;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<html>
<body>
Converts a variable into a property with default accessors
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package ;
class SomeClass {
public var variable<spot>(get, set)</spot>:String;
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package ;
class SomeClass {
public var variable<spot></spot>:String;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<html>
<body>
Converts a variable into a property with getter and setter accessors
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package ;
class SomeClass {
public var variable<spot>(get, never)</spot>:String;
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package ;
class SomeClass {
public var variable<spot></spot>:String;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<html>
<body>
Converts a variable into a property with read-only accessors
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package ;
class SomeClass {
function myFun() {
var myArray = ["A", "B", "C"];
<spot>for (itr in myArray) {

}</spot>
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package ;
class SomeClass {
function myFun() {
var myArray = ["A", "B", "C"];
myArray<spot></spot>
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<html>
<body>
Introduces a for-loop using iterator from selected variable
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package ;
class SomeClass {
function myFun() {
var myMap = ["A" => 1, "B" => 2, "C" => 3];
<spot>for (key => value in myMap) {

}</spot>
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package ;
class SomeClass {
function myFun() {
var myMap = ["A" => 1, "B" => 2, "C" => 3];
myMap<spot></spot>
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<html>
<body>
Introduces a for-each loop using key-value iterator from selected variable
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package ;
class SomeClass {
public function myFunction()<spot></spot> {
var stringVar = "MyString";
return stringVar;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package ;
class SomeClass {
public function myFunction()<spot>:String</spot> {
var stringVar = "MyString";
return stringVar;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<html>
<body>
Removes type information from method declaration
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package ;
class SomeClass {
public function myFunction() {
var stringVar<spot></spot> = "MyString";
return stringVar;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package ;
class SomeClass {
public function myFunction() {
var stringVar<spot>:String</spot> = "MyString";
return stringVar;
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<html>
<body>
Removes type information from variable declaration
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package ;

<spot>import sys.Http;
import sys.FileSystem;</spot>

class SomeClass {
public function myFunction() {
var url = Http.requestUrl("url");
var path = FileSystem.absolutePath("path");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package ;

import sys.*<spot></spot>;

class SomeClass {
public function myFunction() {
var url = Http.requestUrl("url");
var path = FileSystem.absolutePath("path");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<html>
<body>
Replaces wildcard import statement with concrete import statements for each reference used.
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package ;
class SomeClass {
public function myFunction() {
<spot>var stringVar;
stringVar = "MyString";</spot>
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package ;
class SomeClass {
public function myFunction() {
<spot>var stringVar = "MyString";</spot>
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<html>
<body>
Splits variable declaration and variable assignment into separate expressions
</body>
</html>

0 comments on commit 643b4c4

Please sign in to comment.