-
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.
adding intents for variable/property conversion and iterate in variab…
…le with iterator
- Loading branch information
Showing
23 changed files
with
634 additions
and
34 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
...main/java/com/intellij/plugins/haxe/ide/intention/ConvertPropertyToVariableIntention.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.intention; | ||
|
||
import com.intellij.codeInsight.intention.impl.BaseIntentionAction; | ||
import com.intellij.openapi.editor.Editor; | ||
import com.intellij.openapi.project.Project; | ||
import com.intellij.plugins.haxe.HaxeBundle; | ||
import com.intellij.plugins.haxe.HaxeLanguage; | ||
import com.intellij.plugins.haxe.lang.psi.*; | ||
import com.intellij.psi.PsiElement; | ||
import com.intellij.psi.PsiFile; | ||
import com.intellij.psi.util.PsiTreeUtil; | ||
import com.intellij.util.IncorrectOperationException; | ||
import org.jetbrains.annotations.Nls; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
|
||
public class ConvertPropertyToVariableIntention extends BaseIntentionAction { | ||
|
||
private HaxeFieldDeclaration myField; | ||
|
||
@Nls | ||
@NotNull | ||
@Override | ||
public String getFamilyName() { | ||
return getText(); | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public String getText() { | ||
return HaxeBundle.message("haxe.quickfix.property.to.var"); | ||
} | ||
|
||
|
||
@Override | ||
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { | ||
if (file.getLanguage() != HaxeLanguage.INSTANCE) return false; | ||
attemptToFindField(editor, file); | ||
|
||
if (myField == null) return false; | ||
if (myField.getTypeTag() == null) return false; | ||
if (myField.getPropertyDeclaration() == null) return false; | ||
|
||
return true; | ||
} | ||
|
||
|
||
@Override | ||
public void invoke(@NotNull final Project project, Editor editor, PsiFile file) throws IncorrectOperationException { | ||
myField.getPropertyDeclaration().delete(); | ||
} | ||
|
||
|
||
|
||
|
||
|
||
private void attemptToFindField(Editor editor, PsiFile file) { | ||
PsiElement place = file.findElementAt(editor.getCaretModel().getOffset()); | ||
if (place instanceof HaxeFieldDeclaration psiField) { | ||
myField = psiField; | ||
} else { | ||
myField = PsiTreeUtil.getParentOfType(place, HaxeFieldDeclaration.class); | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...va/com/intellij/plugins/haxe/ide/intention/ConvertVariableToPropertyDefaultIntention.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,29 @@ | ||
package com.intellij.plugins.haxe.ide.intention; | ||
|
||
import com.intellij.plugins.haxe.HaxeBundle; | ||
import org.jetbrains.annotations.Nls; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.List; | ||
|
||
public class ConvertVariableToPropertyDefaultIntention extends ConvertVariableToPropertyIntentionBase { | ||
|
||
@Nls | ||
@NotNull | ||
@Override | ||
public String getFamilyName() { | ||
return HaxeBundle.message("haxe.quickfix.var.to.property"); | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public String getText() { | ||
return HaxeBundle.message("haxe.quickfix.var.to.property.default"); | ||
} | ||
|
||
|
||
@NotNull | ||
protected String getPropertyElementString() { | ||
return "var tmp (default, default) :Int;"; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...ava/com/intellij/plugins/haxe/ide/intention/ConvertVariableToPropertyGetSetIntention.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,29 @@ | ||
package com.intellij.plugins.haxe.ide.intention; | ||
|
||
import com.intellij.plugins.haxe.HaxeBundle; | ||
import org.jetbrains.annotations.Nls; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.List; | ||
|
||
public class ConvertVariableToPropertyGetSetIntention extends ConvertVariableToPropertyIntentionBase { | ||
|
||
@Nls | ||
@NotNull | ||
@Override | ||
public String getFamilyName() { | ||
return HaxeBundle.message("haxe.quickfix.var.to.property"); | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public String getText() { | ||
return HaxeBundle.message("haxe.quickfix.var.to.property.getset"); | ||
} | ||
|
||
|
||
@NotNull | ||
protected String getPropertyElementString() { | ||
return "var tmp (get, set) :Int;"; | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
.../java/com/intellij/plugins/haxe/ide/intention/ConvertVariableToPropertyIntentionBase.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,85 @@ | ||
package com.intellij.plugins.haxe.ide.intention; | ||
|
||
import com.intellij.codeInsight.intention.impl.BaseIntentionAction; | ||
import com.intellij.openapi.editor.Editor; | ||
import com.intellij.openapi.project.Project; | ||
import com.intellij.plugins.haxe.HaxeLanguage; | ||
import com.intellij.plugins.haxe.lang.psi.*; | ||
import com.intellij.plugins.haxe.model.HaxeFieldModel; | ||
import com.intellij.plugins.haxe.util.HaxeElementGenerator; | ||
import com.intellij.psi.PsiElement; | ||
import com.intellij.psi.PsiFile; | ||
import com.intellij.psi.util.PsiTreeUtil; | ||
import com.intellij.util.IncorrectOperationException; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.List; | ||
|
||
public abstract class ConvertVariableToPropertyIntentionBase extends BaseIntentionAction { | ||
|
||
private HaxePsiField myField; | ||
|
||
|
||
@Override | ||
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { | ||
if (file.getLanguage() != HaxeLanguage.INSTANCE) return false; | ||
attemptToFindField(editor, file); | ||
|
||
if (myField == null) return false; | ||
|
||
if (myField.getTypeTag() == null) return false; | ||
if (myField.getVarInit() != null) return false; | ||
if (myField.getModel() instanceof HaxeFieldModel model) { | ||
if (model.hasModifier(HaxePsiModifier.INLINE)) return false; | ||
if (model.isProperty()) return false; | ||
}else { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
|
||
@Override | ||
public void invoke(@NotNull final Project project, Editor editor, PsiFile file) throws IncorrectOperationException { | ||
HaxePsiField element = getTempProperty(project); | ||
PsiElement copy = HaxeElementGenerator.createVarDeclaration(project, element.getText()).copy(); | ||
myField.replace(copy); | ||
|
||
} | ||
|
||
@NotNull | ||
private HaxePsiField getTempProperty(@NotNull Project project) { | ||
HaxePsiField element = (HaxePsiField)myField.copy(); | ||
HaxePropertyDeclaration declaration = generateTmpDeclaration(project); | ||
HaxeComponentName name = element.getComponentName(); | ||
HaxeIdentifier identifier = name.getIdentifier(); | ||
|
||
name.addAfter(declaration, identifier); | ||
return element; | ||
} | ||
|
||
private HaxePropertyDeclaration generateTmpDeclaration(@NotNull Project project) { | ||
return (HaxePropertyDeclaration)HaxeElementGenerator.createVarDeclaration(project, getPropertyElementString()) | ||
.getPropertyDeclaration().copy(); | ||
} | ||
|
||
@NotNull | ||
protected abstract String getPropertyElementString(); | ||
|
||
|
||
private void attemptToFindField(Editor editor, PsiFile file) { | ||
PsiElement place = file.findElementAt(editor.getCaretModel().getOffset()); | ||
HaxeLocalVarDeclarationList varDeclarationList = PsiTreeUtil.getParentOfType(place, HaxeLocalVarDeclarationList.class); | ||
if (varDeclarationList != null) { | ||
List<HaxeLocalVarDeclaration> list = varDeclarationList.getLocalVarDeclarationList(); | ||
if (!list.isEmpty()) myField = list.get(list.size() - 1); | ||
} | ||
else if (place instanceof HaxePsiField psiField) { | ||
myField = psiField; | ||
} | ||
else { | ||
myField = PsiTreeUtil.getParentOfType(place, HaxePsiField.class); | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...a/com/intellij/plugins/haxe/ide/intention/ConvertVariableToPropertyReadOnlyIntention.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,27 @@ | ||
package com.intellij.plugins.haxe.ide.intention; | ||
|
||
import com.intellij.plugins.haxe.HaxeBundle; | ||
import org.jetbrains.annotations.Nls; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class ConvertVariableToPropertyReadOnlyIntention extends ConvertVariableToPropertyIntentionBase { | ||
|
||
@Nls | ||
@NotNull | ||
@Override | ||
public String getFamilyName() { | ||
return HaxeBundle.message("haxe.quickfix.var.to.property"); | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public String getText() { | ||
return HaxeBundle.message("haxe.quickfix.var.to.property.read.only"); | ||
} | ||
|
||
|
||
@NotNull | ||
protected String getPropertyElementString() { | ||
return "var tmp (get, never) :Int;"; | ||
} | ||
} |
Oops, something went wrong.