Last active
April 22, 2020 17:48
-
-
Save pavi2410/6d5f4f3e7aeacc37bb834e9660defd79 to your computer and use it in GitHub Desktop.
IntelliJ Structural Replace for changing annotation value
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
import com.intellij.psi.impl.source.tree.java.* | |
import com.intellij.psi.* | |
import com.intellij.psi.impl.* | |
import java.util.stream.* | |
def str = "" | |
if (LString instanceof PsiLiteralExpressionImpl) { | |
str = LString.value | |
} else if (LString instanceof PsiPolyadicExpressionImpl) { | |
PsiPolyadicExpression parentExpression = LString | |
StringBuilder computedValue = new StringBuilder(); | |
for (PsiExpression operand : parentExpression.getOperands()) { | |
if (operand instanceof PsiReference) { | |
PsiElement probableDefinition = ((PsiReference) operand).resolve(); | |
if (probableDefinition instanceof PsiVariable) { | |
PsiExpression initializer = ((PsiVariable) probableDefinition).getInitializer(); | |
if (initializer != null) { | |
Object value = JavaConstantExpressionEvaluator.computeConstantExpression(initializer, true); | |
if (value instanceof String) { | |
computedValue.append(value); | |
} | |
} | |
} | |
} else { | |
Object value = JavaConstantExpressionEvaluator.computeConstantExpression(operand, true); | |
if (value instanceof String) { | |
computedValue.append(value); | |
} | |
} | |
} | |
str = computedValue.toString(); | |
} | |
return str.tokenize(",").stream().map { it.trim() }.map { "\"$it\"" }.collect(Collectors.joining(",\n ")) |
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
@UsesPermissions({ | |
$LList$ | |
}) |
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
@UsesPermissions(permissionNames = $LString$) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment