Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: Modifier processors for different types
- Loading branch information
Showing
6 changed files
with
102 additions
and
2 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
13 changes: 13 additions & 0 deletions
13
src/main/java/de/plushnikov/intellij/plugin/processor/modifier/ModifierProcessor.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,13 @@ | |||
package de.plushnikov.intellij.plugin.processor.modifier; | |||
|
|||
import com.intellij.psi.PsiModifierList; | |||
import org.jetbrains.annotations.NotNull; | |||
|
|||
/** | |||
* @author Alexej Kubarev | |||
*/ | |||
public interface ModifierProcessor { | |||
|
|||
boolean isSupported(@NotNull PsiModifierList modifierList, @NotNull String name); | |||
Boolean hasModifierProperty(@NotNull PsiModifierList modifierList, @NotNull String name); | |||
} |
58 changes: 58 additions & 0 deletions
58
src/main/java/de/plushnikov/intellij/plugin/processor/modifier/ValueModifierProcessor.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,58 @@ | |||
package de.plushnikov.intellij.plugin.processor.modifier; | |||
|
|||
import com.intellij.psi.PsiAnnotation; | |||
import com.intellij.psi.PsiClass; | |||
import com.intellij.psi.PsiElement; | |||
import com.intellij.psi.PsiField; | |||
import com.intellij.psi.PsiModifier; | |||
import com.intellij.psi.PsiModifierList; | |||
import de.plushnikov.intellij.plugin.util.PsiAnnotationSearchUtil; | |||
import org.jetbrains.annotations.NotNull; | |||
|
|||
/** | |||
* @author Alexej Kubarev | |||
*/ | |||
public class ValueModifierProcessor implements ModifierProcessor { | |||
|
|||
|
|||
@Override | |||
public boolean isSupported(@NotNull PsiModifierList modifierList, @NotNull String name) { | |||
|
|||
// Fast check if the requested modifier is even supported | |||
if (!PsiModifier.FINAL.equals(name) || PsiModifier.PRIVATE.equals(name)) { | |||
return false; | |||
} | |||
|
|||
PsiElement parent = modifierList.getParent(); | |||
PsiClass searchableClass = null; | |||
|
|||
if (parent instanceof PsiClass) { | |||
searchableClass = (PsiClass) parent; | |||
} else if (parent instanceof PsiField) { | |||
searchableClass = ((PsiField) parent).getContainingClass(); | |||
} | |||
|
|||
if (null != searchableClass) { | |||
|
|||
return PsiAnnotationSearchUtil.isAnnotatedWith(searchableClass, lombok.Value.class, lombok.experimental.Value.class); | |||
} | |||
|
|||
return false; | |||
} | |||
|
|||
@Override | |||
public Boolean hasModifierProperty(@NotNull PsiModifierList modifierList, @NotNull String name) { | |||
|
|||
if (PsiModifier.FINAL.equals(name)) { | |||
return Boolean.TRUE; | |||
} | |||
|
|||
if (PsiModifier.PRIVATE.equals(name)) { | |||
if (modifierList.getParent() instanceof PsiField) { | |||
return Boolean.TRUE; | |||
} | |||
} | |||
|
|||
return null; | |||
} | |||
} |
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