use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteral in project intellij-community by JetBrains.
the class ConvertToDollarSlashRegexIntention method processIntention.
@Override
protected void processIntention(@NotNull PsiElement element, @NotNull Project project, Editor editor) throws IncorrectOperationException {
if (!(element instanceof GrLiteral))
return;
String rawText = GrStringUtil.removeQuotes(element.getText());
GrExpression newRegexp = GroovyPsiElementFactory.getInstance(project).createExpressionFromText("$/" + rawText + "/$");
//don't use replaceWithExpression() since it can revert conversion if regexp brakes syntax
element.replace(newRegexp);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteral in project intellij-community by JetBrains.
the class RemoveUnnecessaryEscapeCharactersIntention method processIntention.
@Override
protected void processIntention(@NotNull PsiElement element, @NotNull Project project, Editor editor) throws IncorrectOperationException {
final Document document = editor.getDocument();
final TextRange range = element.getTextRange();
document.replaceString(range.getStartOffset(), range.getEndOffset(), removeUnnecessaryEscapeSymbols((GrLiteral) element));
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteral in project intellij-community by JetBrains.
the class ConvertIntegerToBinaryPredicate method satisfiedBy.
@Override
public boolean satisfiedBy(PsiElement element) {
if (!(element instanceof GrLiteral))
return false;
final GrLiteral expression = (GrLiteral) element;
final PsiType type = expression.getType();
if (type == null)
return false;
if (!PsiType.INT.equals(type) && !PsiType.LONG.equals(type) && !type.equalsToText("java.lang.Integer") && !type.equalsToText("java.lang.Long")) {
return false;
}
@NonNls final String text = expression.getText();
if (text == null || text.isEmpty()) {
return false;
}
if (text.startsWith("0x") || text.startsWith("0X")) {
return true;
}
if (text.startsWith("0b") || text.startsWith("0B")) {
return false;
}
if ("0".equals(text) || "0L".equals(text)) {
return true;
}
return text.charAt(0) != '0';
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteral in project intellij-community by JetBrains.
the class ConvertIntegerToDecimalIntention method processIntention.
@Override
public void processIntention(@NotNull PsiElement element, @NotNull Project project, Editor editor) throws IncorrectOperationException {
final GrLiteral exp = (GrLiteral) element;
@NonNls String textString = exp.getText().replaceAll("_", "");
final int textLength = textString.length();
final char lastChar = textString.charAt(textLength - 1);
final boolean isLong = lastChar == 'l' || lastChar == 'L';
if (isLong) {
textString = textString.substring(0, textLength - 1);
}
final BigInteger val;
if (textString.startsWith("0x") || textString.startsWith("0X")) {
final String rawIntString = textString.substring(2);
val = new BigInteger(rawIntString, 16);
} else if (textString.startsWith("0b") || textString.startsWith("0B")) {
final String rawString = textString.substring(2);
val = new BigInteger(rawString, 2);
} else {
final String rawIntString = textString.substring(1);
val = new BigInteger(rawIntString, 8);
}
String decimalString = val.toString(10);
if (isLong) {
decimalString += 'L';
}
PsiImplUtil.replaceExpression(decimalString, exp);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteral in project intellij-community by JetBrains.
the class GradleDocumentationProvider method findDoc.
@Nullable
private static String findDoc(@Nullable PsiElement element, Object argValue) {
String result = null;
if (element instanceof GrLiteral) {
GrLiteral grLiteral = (GrLiteral) element;
PsiElement stmt = PsiTreeUtil.findFirstParent(grLiteral, psiElement -> psiElement instanceof GrCall);
if (stmt instanceof GrCall) {
GrCall grCall = (GrCall) stmt;
PsiMethod psiMethod = grCall.resolveMethod();
if (psiMethod != null && psiMethod.getContainingClass() != null) {
//noinspection ConstantConditions
String qualifiedName = psiMethod.getContainingClass().getQualifiedName();
if (grLiteral.getParent() instanceof GrNamedArgument) {
GrNamedArgument namedArgument = (GrNamedArgument) grLiteral.getParent();
String key = StringUtil.join(new String[] { "gradle.documentation", qualifiedName, psiMethod.getName(), namedArgument.getLabelName(), String.valueOf(argValue) }, ".");
result = GradleDocumentationBundle.messageOrDefault(key, "");
}
}
}
}
return result;
}
Aggregations