generated from JetBrains/intellij-platform-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
421e152
commit d5f7ef0
Showing
9 changed files
with
95 additions
and
51 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
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
12 changes: 12 additions & 0 deletions
12
.../com/xtu/plugin/flutter/action/generate/json/action/DartGenerateFromJSONMethodAction.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,12 @@ | ||
package com.xtu.plugin.flutter.action.generate.json.action; | ||
|
||
import com.jetbrains.lang.dart.psi.DartClass; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class DartGenerateFromJSONMethodAction extends DartGenerateJSONMethodAction { | ||
|
||
@Override | ||
protected boolean needGenToJson(@NotNull DartClass dartClass) { | ||
return false; | ||
} | ||
} |
32 changes: 16 additions & 16 deletions
32
...te/json/DartGenerateJSONMethodAction.java → .../action/DartGenerateJSONMethodAction.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 |
---|---|---|
@@ -1,46 +1,46 @@ | ||
package com.xtu.plugin.flutter.action.generate.json; | ||
package com.xtu.plugin.flutter.action.generate.json.action; | ||
|
||
import com.intellij.psi.util.PsiTreeUtil; | ||
import com.jetbrains.lang.dart.ide.generation.BaseDartGenerateAction; | ||
import com.jetbrains.lang.dart.ide.generation.BaseDartGenerateHandler; | ||
import com.jetbrains.lang.dart.psi.DartClass; | ||
import com.jetbrains.lang.dart.psi.DartFactoryConstructorDeclaration; | ||
import com.jetbrains.lang.dart.util.DartResolveUtil; | ||
import com.xtu.plugin.flutter.action.generate.json.DartGenerateJSONMethodHandler; | ||
import com.xtu.plugin.flutter.base.utils.StringUtils; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class DartGenerateJSONMethodAction extends BaseDartGenerateAction { | ||
|
||
private boolean hasFromJson; | ||
private boolean hasToJson; | ||
private boolean createFromJson; | ||
private boolean createToJson; | ||
|
||
protected boolean doEnable(@Nullable DartClass dartClass) { | ||
if (dartClass == null) return false; | ||
return !doesClassContainFromJsonAndToJson(dartClass); | ||
this.createFromJson = needGenFromJson(dartClass); | ||
this.createToJson = needGenToJson(dartClass); | ||
return this.createFromJson || this.createToJson; | ||
} | ||
|
||
public boolean doesClassContainFromJsonAndToJson(@NotNull DartClass dartClass) { | ||
boolean hasFromJson = false; | ||
DartFactoryConstructorDeclaration[] constructorDeclarationList = PsiTreeUtil.getChildrenOfType( | ||
DartResolveUtil.getBody(dartClass), | ||
DartFactoryConstructorDeclaration.class); | ||
protected boolean needGenFromJson(@NotNull DartClass dartClass) { | ||
DartFactoryConstructorDeclaration[] constructorDeclarationList = PsiTreeUtil.getChildrenOfType(DartResolveUtil.getBody(dartClass), DartFactoryConstructorDeclaration.class); | ||
if (constructorDeclarationList != null) { | ||
for (DartFactoryConstructorDeclaration constructor : constructorDeclarationList) { | ||
if (StringUtils.equals(constructor.getName(), "fromJson")) { | ||
hasFromJson = true; | ||
break; | ||
return false; | ||
} | ||
} | ||
} | ||
boolean hasToJson = doesClassContainMethod(dartClass, "toJson"); | ||
this.hasFromJson = hasFromJson; | ||
this.hasToJson = hasToJson; | ||
return hasFromJson && hasToJson; | ||
return true; | ||
} | ||
|
||
protected boolean needGenToJson(@NotNull DartClass dartClass) { | ||
return !doesClassContainMethod(dartClass, "toJson"); | ||
} | ||
|
||
@Override | ||
protected @NotNull BaseDartGenerateHandler getGenerateHandler() { | ||
return new DartGenerateJSONMethodHandler(hasFromJson, hasToJson); | ||
return new DartGenerateJSONMethodHandler(createFromJson, createToJson); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...va/com/xtu/plugin/flutter/action/generate/json/action/DartGenerateToJSONMethodAction.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,12 @@ | ||
package com.xtu.plugin.flutter.action.generate.json.action; | ||
|
||
import com.jetbrains.lang.dart.psi.DartClass; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class DartGenerateToJSONMethodAction extends DartGenerateJSONMethodAction { | ||
|
||
@Override | ||
protected boolean needGenFromJson(@NotNull DartClass dartClass) { | ||
return false; | ||
} | ||
} |
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