-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move CodeAction provides next to MagikChecks/MagikTypedChecks
- Loading branch information
1 parent
79ce8b4
commit ec49533
Showing
18 changed files
with
473 additions
and
188 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
19 changes: 19 additions & 0 deletions
19
magik-checks/src/main/java/nl/ramsolutions/sw/magik/checks/MagikCheckFixer.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,19 @@ | ||
package nl.ramsolutions.sw.magik.checks; | ||
|
||
import java.util.List; | ||
import nl.ramsolutions.sw.magik.CodeAction; | ||
import nl.ramsolutions.sw.magik.MagikFile; | ||
import nl.ramsolutions.sw.magik.Range; | ||
|
||
/** | ||
* Base class to provide automatic fixes for Magik checks. | ||
*/ | ||
public abstract class MagikCheckFixer { | ||
|
||
/** | ||
* Provide automatic fixes for violations detected by the sibling check. | ||
* @return | ||
*/ | ||
public abstract List<CodeAction> provideCodeActions(MagikFile magikFile, Range range); | ||
|
||
} |
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
43 changes: 43 additions & 0 deletions
43
...va/nl/ramsolutions/sw/magik/languageserver/codeactions/MagikChecksCodeActionProvider.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,43 @@ | ||
package nl.ramsolutions.sw.magik.languageserver.codeactions; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import nl.ramsolutions.sw.magik.CodeAction; | ||
import nl.ramsolutions.sw.magik.MagikTypedFile; | ||
import nl.ramsolutions.sw.magik.Range; | ||
import nl.ramsolutions.sw.magik.checks.CheckList; | ||
import nl.ramsolutions.sw.magik.checks.MagikCheckFixer; | ||
import org.eclipse.lsp4j.CodeActionContext; | ||
|
||
/** | ||
* Provide {@link CodeAction}s for {@link MagikCheck}s. | ||
*/ | ||
public class MagikChecksCodeActionProvider { | ||
|
||
/** | ||
* Provide {@link CodeAction} for {@link MagikCheck} checks. | ||
* @param magikFile {@link MagikTypedFile{} to check on. | ||
* @param range {@link Range} to get {@link CodeAction}s for. | ||
* @param context Context, not used currently. | ||
* @return List of {@link CodeAction}s. | ||
* @throws ReflectiveOperationException | ||
*/ | ||
public List<CodeAction> provideCodeActions( | ||
final MagikTypedFile magikFile, | ||
final Range range, | ||
final CodeActionContext context) throws ReflectiveOperationException { | ||
// TODO: Only for enabled checks. | ||
|
||
final List<CodeAction> codeActions = new ArrayList<>(); | ||
for (final List<Class<?>> fixerClassses : CheckList.getFixers().values()) { | ||
for (final Class<?> fixerClass : fixerClassses) { | ||
final MagikCheckFixer fixer = | ||
(MagikCheckFixer) fixerClass.getDeclaredConstructor().newInstance(); | ||
List<CodeAction> fixerCodeActions = fixer.provideCodeActions(magikFile, range); | ||
codeActions.addAll(fixerCodeActions); | ||
} | ||
} | ||
return codeActions; | ||
} | ||
|
||
} |
53 changes: 53 additions & 0 deletions
53
.../ramsolutions/sw/magik/languageserver/codeactions/MagikTypedChecksCodeActionProvider.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,53 @@ | ||
package nl.ramsolutions.sw.magik.languageserver.codeactions; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map.Entry; | ||
import nl.ramsolutions.sw.magik.CodeAction; | ||
import nl.ramsolutions.sw.magik.MagikTypedFile; | ||
import nl.ramsolutions.sw.magik.Range; | ||
import nl.ramsolutions.sw.magik.typedchecks.CheckList; | ||
import nl.ramsolutions.sw.magik.typedchecks.MagikTypedCheck; | ||
import nl.ramsolutions.sw.magik.typedchecks.MagikTypedCheckFixer; | ||
import org.eclipse.lsp4j.CodeActionContext; | ||
|
||
/** | ||
* Provide {@link CodeAction}s for {@link MagikTypedCheck}s. | ||
*/ | ||
public class MagikTypedChecksCodeActionProvider { | ||
|
||
/** | ||
* Provide {@link CodeAction} for {@link MagikTypedCheck} checks. | ||
* @param magikFile {@link MagikTypedFile{} to check on. | ||
* @param range {@link Range} to get {@link CodeAction}s for. | ||
* @param context Context, not used currently. | ||
* @return List of {@link CodeAction}s. | ||
* @throws ReflectiveOperationException | ||
*/ | ||
public List<CodeAction> provideCodeActions( | ||
final MagikTypedFile magikFile, | ||
final Range range, | ||
final CodeActionContext context) throws ReflectiveOperationException { | ||
// TODO: Only for enabled checks. | ||
|
||
final List<CodeAction> codeActions = new ArrayList<>(); | ||
for (final Entry<Class<?>, List<Class<?>>> entry : CheckList.getFixers().entrySet()) { | ||
final Class<?> checkClass = entry.getKey(); | ||
final List<Class<?>> fixerClassses = entry.getValue(); | ||
for (final Class<?> fixerClass : fixerClassses) { | ||
|
||
|
||
final MagikTypedCheckFixer fixer = | ||
(MagikTypedCheckFixer) fixerClass.getDeclaredConstructor().newInstance(); | ||
List<CodeAction> fixerCodeActions = fixer.provideCodeActions(magikFile, range); | ||
codeActions.addAll(fixerCodeActions); | ||
} | ||
} | ||
return codeActions; | ||
} | ||
|
||
private boolean isCheckEnabled(final Class<?> checkClass) { | ||
return true; | ||
} | ||
|
||
} |
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.