generated from JetBrains/intellij-platform-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from jaksonlin/new-java-version
move to java code base
- Loading branch information
Showing
145 changed files
with
5,540 additions
and
4,444 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
30 changes: 30 additions & 0 deletions
30
src/main/java/com/github/jaksonlin/pitestintellij/MyBundle.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,30 @@ | ||
package com.github.jaksonlin.pitestintellij; | ||
|
||
import com.intellij.DynamicBundle; | ||
import org.jetbrains.annotations.NonNls; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.PropertyKey; | ||
|
||
import java.util.function.Supplier; | ||
|
||
public final class MyBundle extends DynamicBundle { | ||
@NonNls | ||
private static final String BUNDLE = "messages.MyBundle"; | ||
private static final MyBundle INSTANCE = new MyBundle(); | ||
|
||
private MyBundle() { | ||
super(BUNDLE); | ||
} | ||
|
||
public static @NotNull String message(@NotNull @PropertyKey(resourceBundle = BUNDLE) String key, Object... params) { | ||
return INSTANCE.getMessage(key, params); | ||
} | ||
|
||
public static @NotNull Supplier<String> messagePointer(@NotNull @PropertyKey(resourceBundle = BUNDLE) String key, Object... params) { | ||
return INSTANCE.getLazyMessage(key, params); | ||
} | ||
|
||
public static MyBundle getInstance() { | ||
return INSTANCE; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...ain/java/com/github/jaksonlin/pitestintellij/actions/GenerateAnnotationCommandAction.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.github.jaksonlin.pitestintellij.actions; | ||
|
||
import com.github.jaksonlin.pitestintellij.commands.unittestannotations.GenerateAnnotationCommand; | ||
import com.github.jaksonlin.pitestintellij.context.CaseCheckContext; | ||
import com.github.jaksonlin.pitestintellij.util.Pair; | ||
import com.github.jaksonlin.pitestintellij.util.PsiUtil; | ||
import com.intellij.openapi.actionSystem.AnAction; | ||
import com.intellij.openapi.actionSystem.AnActionEvent; | ||
import com.intellij.openapi.project.Project; | ||
import com.intellij.psi.PsiClass; | ||
import com.intellij.psi.PsiMethod; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class GenerateAnnotationCommandAction extends AnAction { | ||
|
||
@Override | ||
public void actionPerformed(@NotNull AnActionEvent e) { | ||
Pair<PsiMethod, PsiClass> psiMethodInfo = PsiUtil.findMethodAtCaret(e); // Call the static method | ||
if (psiMethodInfo == null) { | ||
return; | ||
} | ||
CaseCheckContext context = CaseCheckContext.create(psiMethodInfo.getKey(), psiMethodInfo.getValue()); | ||
Project project = e.getProject(); | ||
if (project != null) { | ||
GenerateAnnotationCommand command = new GenerateAnnotationCommand(project, context); | ||
command.execute(); | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/com/github/jaksonlin/pitestintellij/actions/RunCaseAnnoationCheckAction.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,31 @@ | ||
package com.github.jaksonlin.pitestintellij.actions; | ||
|
||
import com.github.jaksonlin.pitestintellij.commands.unittestannotations.CheckAnnotationCommand; | ||
import com.github.jaksonlin.pitestintellij.context.CaseCheckContext; | ||
import com.github.jaksonlin.pitestintellij.util.Pair; | ||
import com.github.jaksonlin.pitestintellij.util.PsiUtil; | ||
import com.intellij.openapi.actionSystem.AnAction; | ||
import com.intellij.openapi.actionSystem.AnActionEvent; | ||
import com.intellij.openapi.project.Project; | ||
import com.intellij.psi.PsiClass; | ||
import com.intellij.psi.PsiMethod; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
|
||
public class RunCaseAnnoationCheckAction extends AnAction { | ||
|
||
@Override | ||
public void actionPerformed(@NotNull AnActionEvent e) { | ||
Pair<PsiMethod, PsiClass> psiMethodInfo = PsiUtil.findMethodAtCaret(e); | ||
if (psiMethodInfo == null) { | ||
return; | ||
} | ||
CaseCheckContext context = CaseCheckContext.create(psiMethodInfo.getKey(), psiMethodInfo.getValue()); | ||
Project project = e.getProject(); | ||
if (project != null) { | ||
CheckAnnotationCommand command = new CheckAnnotationCommand(project, context); | ||
command.execute(); | ||
} | ||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/com/github/jaksonlin/pitestintellij/actions/RunPitestAction.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,34 @@ | ||
package com.github.jaksonlin.pitestintellij.actions; | ||
|
||
import com.github.jaksonlin.pitestintellij.services.PitestService; | ||
import com.intellij.openapi.actionSystem.AnAction; | ||
import com.intellij.openapi.actionSystem.AnActionEvent; | ||
import com.intellij.openapi.actionSystem.PlatformDataKeys; | ||
import com.intellij.openapi.application.ApplicationManager; | ||
import com.intellij.openapi.project.Project; | ||
import com.intellij.openapi.vfs.VirtualFile; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class RunPitestAction extends AnAction { | ||
|
||
private final PitestService pitestService; | ||
|
||
public RunPitestAction() { | ||
pitestService = ApplicationManager.getApplication().getService(PitestService.class); | ||
} | ||
|
||
@Override | ||
public void actionPerformed(@NotNull AnActionEvent e) { | ||
Project targetProject = e.getProject(); | ||
if (targetProject == null) { | ||
return; | ||
} | ||
|
||
VirtualFile testVirtualFile = e.getData(PlatformDataKeys.VIRTUAL_FILE); | ||
if (testVirtualFile == null) { | ||
return; | ||
} | ||
|
||
pitestService.runPitest(targetProject, testVirtualFile.getPath()); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
...ain/java/com/github/jaksonlin/pitestintellij/actions/RunTestFileAnnoationCheckAction.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,51 @@ | ||
package com.github.jaksonlin.pitestintellij.actions; | ||
|
||
import com.github.jaksonlin.pitestintellij.commands.unittestannotations.CheckAnnotationCommand; | ||
import com.github.jaksonlin.pitestintellij.context.CaseCheckContext; | ||
import com.intellij.openapi.actionSystem.AnAction; | ||
import com.intellij.openapi.actionSystem.AnActionEvent; | ||
import com.intellij.openapi.actionSystem.CommonDataKeys; | ||
import com.intellij.openapi.project.Project; | ||
import com.intellij.psi.*; | ||
import com.intellij.psi.util.PsiTreeUtil; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class RunTestFileAnnoationCheckAction extends AnAction { | ||
|
||
@Override | ||
public void actionPerformed(@NotNull AnActionEvent e) { | ||
batchCheckAnnotation(e); | ||
} | ||
|
||
private void batchCheckAnnotation(@NotNull AnActionEvent e) { | ||
PsiJavaFile psiJavaFile = (PsiJavaFile) e.getData(CommonDataKeys.PSI_FILE); | ||
if (psiJavaFile == null) { | ||
return; | ||
} | ||
|
||
psiJavaFile.accept(new JavaRecursiveElementVisitor() { | ||
@Override | ||
public void visitMethod(PsiMethod method) { | ||
super.visitMethod(method); | ||
// inspect the method annotations | ||
PsiAnnotation[] annotations = method.getAnnotations(); | ||
for (PsiAnnotation annotation : annotations) { | ||
// inspect the annotation | ||
String annotationName = annotation.getQualifiedName(); | ||
if (annotationName != null && | ||
(annotationName.equals("org.junit.Test") || annotationName.equals("org.junit.jupiter.api.Test") || annotationName.equals("Test"))) { | ||
PsiClass psiClass = PsiTreeUtil.getParentOfType(method, PsiClass.class); | ||
if (psiClass != null) { | ||
CaseCheckContext context = CaseCheckContext.create(method, psiClass); | ||
Project project = e.getProject(); | ||
if (project != null) { | ||
new CheckAnnotationCommand(project, context).execute(); | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}); | ||
} | ||
} |
84 changes: 84 additions & 0 deletions
84
src/main/java/com/github/jaksonlin/pitestintellij/annotations/AnnotationFieldConfig.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,84 @@ | ||
package com.github.jaksonlin.pitestintellij.annotations; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class AnnotationFieldConfig { | ||
private String name; | ||
private AnnotationFieldType type; | ||
private boolean required; | ||
private DefaultValue defaultValue; | ||
@Nullable | ||
private FieldValidation validation; | ||
@Nullable | ||
private ValueProvider valueProvider; | ||
|
||
public AnnotationFieldConfig() { | ||
this.required = false; | ||
this.defaultValue = new DefaultValue.NullValue(); | ||
} | ||
|
||
public AnnotationFieldConfig(String name, AnnotationFieldType type) { | ||
this.name = name; | ||
this.type = type; | ||
this.required = false; | ||
this.defaultValue = new DefaultValue.NullValue(); | ||
} | ||
|
||
public AnnotationFieldConfig(String name, AnnotationFieldType type, FieldValidation validation) { | ||
this.name = name; | ||
this.type = type; | ||
this.required = false; | ||
this.defaultValue = new DefaultValue.NullValue(); | ||
this.validation = validation; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public AnnotationFieldType getType() { | ||
return type; | ||
} | ||
|
||
public void setType(AnnotationFieldType type) { | ||
this.type = type; | ||
} | ||
|
||
public boolean isRequired() { | ||
return required; | ||
} | ||
|
||
public void setRequired(boolean required) { | ||
this.required = required; | ||
} | ||
|
||
public DefaultValue getDefaultValue() { | ||
return defaultValue; | ||
} | ||
|
||
public void setDefaultValue(DefaultValue defaultValue) { | ||
this.defaultValue = defaultValue; | ||
} | ||
|
||
@Nullable | ||
public FieldValidation getValidation() { | ||
return validation; | ||
} | ||
|
||
public void setValidation(@Nullable FieldValidation validation) { | ||
this.validation = validation; | ||
} | ||
|
||
@Nullable | ||
public ValueProvider getValueProvider() { | ||
return valueProvider; | ||
} | ||
|
||
public void setValueProvider(@Nullable ValueProvider valueProvider) { | ||
this.valueProvider = valueProvider; | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/java/com/github/jaksonlin/pitestintellij/annotations/AnnotationFieldType.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,6 @@ | ||
package com.github.jaksonlin.pitestintellij.annotations; | ||
|
||
public enum AnnotationFieldType { | ||
STRING, | ||
STRING_LIST | ||
} |
83 changes: 83 additions & 0 deletions
83
src/main/java/com/github/jaksonlin/pitestintellij/annotations/AnnotationParser.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,83 @@ | ||
package com.github.jaksonlin.pitestintellij.annotations; | ||
|
||
import com.github.jaksonlin.pitestintellij.context.UnittestCase; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
public class AnnotationParser { | ||
private final AnnotationSchema schema; | ||
private final AnnotationValidator validator; | ||
|
||
public AnnotationParser(AnnotationSchema schema) { | ||
this.schema = schema; | ||
this.validator = new AnnotationValidator(schema); | ||
} | ||
|
||
public UnittestCase parseAnnotation(Map<String, Object> annotationValues) { | ||
AnnotationValidator.ValidationResult result = validator.validate(annotationValues); | ||
|
||
if (result instanceof AnnotationValidator.ValidationResult.Valid) { | ||
Map<String, Object> parsedValues = new HashMap<>(); | ||
for (AnnotationFieldConfig field : schema.getFields()) { | ||
if (field.isRequired()) { | ||
if (!annotationValues.containsKey(field.getName())) { | ||
throw new IllegalArgumentException("Missing required field: " + field.getName()); | ||
} | ||
if (annotationValues.get(field.getName()) == null) { | ||
throw new IllegalArgumentException("Required field cannot be null: " + field.getName()); | ||
} | ||
} else { | ||
if (!annotationValues.containsKey(field.getName()) || annotationValues.get(field.getName()) == null) { | ||
parsedValues.put(field.getName(), field.getDefaultValue()); | ||
continue; | ||
} | ||
} | ||
Object rawValue = annotationValues.get(field.getName()); | ||
parsedValues.put(field.getName(), convertValue(rawValue, field)); | ||
} | ||
return new UnittestCase(parsedValues); | ||
} else if (result instanceof AnnotationValidator.ValidationResult.Invalid) { | ||
AnnotationValidator.ValidationResult.Invalid invalidResult = (AnnotationValidator.ValidationResult.Invalid) result; | ||
throw new IllegalArgumentException( | ||
"Invalid annotation values:\n" + String.join("\n", invalidResult.getErrors()) | ||
); | ||
} | ||
// Should not happen if ValidationResult is properly implemented | ||
throw new IllegalStateException("Unexpected ValidationResult type"); | ||
} | ||
|
||
@Nullable | ||
private Object convertValue(@Nullable Object value, AnnotationFieldConfig field) { | ||
if (value == null) { | ||
DefaultValue defaultValue = field.getDefaultValue(); | ||
if (defaultValue instanceof DefaultValue.StringValue) { | ||
return ((DefaultValue.StringValue) defaultValue).getValue(); | ||
} else if (defaultValue instanceof DefaultValue.StringListValue) { | ||
return ((DefaultValue.StringListValue) defaultValue).getValue(); | ||
} else if (defaultValue instanceof DefaultValue.NullValue) { | ||
return null; | ||
} | ||
return null; // Should ideally not reach here if DefaultValue is exhaustive | ||
} | ||
|
||
switch (field.getType()) { | ||
case STRING: | ||
return value instanceof String ? value : (field.getDefaultValue() instanceof DefaultValue.StringValue ? ((DefaultValue.StringValue) field.getDefaultValue()).getValue() : null); | ||
case STRING_LIST: | ||
if (value instanceof List<?>) { | ||
return ((List<?>) value).stream() | ||
.filter(String.class::isInstance) | ||
.map(String.class::cast) | ||
.collect(Collectors.toList()); | ||
} else { | ||
return java.util.Collections.emptyList(); | ||
} | ||
default: | ||
return null; // Should not happen if AnnotationFieldType is exhaustive | ||
} | ||
} | ||
} |
Oops, something went wrong.