use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression in project intellij-community by JetBrains.
the class ConvertConcatenationToGstringIntention method performIntention.
private static void performIntention(GrBinaryExpression expr, StringBuilder builder, boolean multiline) {
GrExpression left = (GrExpression) PsiUtil.skipParentheses(expr.getLeftOperand(), false);
GrExpression right = (GrExpression) PsiUtil.skipParentheses(expr.getRightOperand(), false);
getOperandText(left, builder, multiline);
getOperandText(right, builder, multiline);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression in project intellij-community by JetBrains.
the class ConvertStringToMultilineIntention method isAppropriateBinary.
private static boolean isAppropriateBinary(@NotNull GrBinaryExpression binary, @Nullable PsiElement prevChecked) {
if (binary.getOperationTokenType() == GroovyTokenTypes.mPLUS) {
final GrExpression left = binary.getLeftOperand();
final GrExpression right = binary.getRightOperand();
if ((left != prevChecked || containsOnlyLiterals(right)) && (right != prevChecked || containsOnlyLiterals(left))) {
return true;
}
}
return false;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression in project intellij-community by JetBrains.
the class MyPredicate method getParameterByArgument.
@Nullable
private static GrParameter getParameterByArgument(GrExpression arg) {
PsiElement parent = PsiUtil.skipParentheses(arg.getParent(), true);
if (!(parent instanceof GrArgumentList))
return null;
final GrArgumentList argList = (GrArgumentList) parent;
parent = parent.getParent();
if (!(parent instanceof GrMethodCall))
return null;
final GrMethodCall methodCall = (GrMethodCall) parent;
final GrExpression expression = methodCall.getInvokedExpression();
if (!(expression instanceof GrReferenceExpression))
return null;
final GroovyResolveResult resolveResult = ((GrReferenceExpression) expression).advancedResolve();
if (resolveResult == null)
return null;
GrClosableBlock[] closures = methodCall.getClosureArguments();
final Map<GrExpression, Pair<PsiParameter, PsiType>> mapToParams = GrClosureSignatureUtil.mapArgumentsToParameters(resolveResult, arg, false, false, argList.getNamedArguments(), argList.getExpressionArguments(), closures);
if (mapToParams == null)
return null;
final Pair<PsiParameter, PsiType> parameterPair = mapToParams.get(arg);
final PsiParameter parameter = parameterPair == null ? null : parameterPair.getFirst();
return parameter instanceof GrParameter ? ((GrParameter) parameter) : null;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression in project intellij-community by JetBrains.
the class MyPredicate method createClass.
public static GrTypeDefinition createClass(Project project, GrNamedArgument[] namedArguments, String packageName, String className) {
StringBuilder classText = new StringBuilder();
if (!packageName.isEmpty()) {
classText.append("package ").append(packageName).append('\n');
}
classText.append("class ").append(className).append(" {\n");
for (GrNamedArgument argument : namedArguments) {
final String fieldName = argument.getLabelName();
final GrExpression expression = argument.getExpression();
LOG.assertTrue(expression != null);
final PsiType type = TypesUtil.unboxPrimitiveTypeWrapper(expression.getType());
if (type != null) {
classText.append(type.getCanonicalText());
} else {
classText.append(GrModifier.DEF);
}
classText.append(' ').append(fieldName).append('\n');
}
classText.append('}');
return GroovyPsiElementFactory.getInstance(project).createTypeDefinition(classText.toString());
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression in project intellij-community by JetBrains.
the class ConvertSimpleGetterToPropertyIntention method getElementPredicate.
@NotNull
@Override
protected PsiElementPredicate getElementPredicate() {
return new PsiElementPredicate() {
@Override
public boolean satisfiedBy(PsiElement element) {
PsiElement parent = element.getParent();
if (!(parent instanceof GrMethod) || ((GrMethod) parent).getNameIdentifierGroovy() != element)
return false;
GrMethod method = (GrMethod) parent;
GrOpenBlock block = method.getBlock();
if (block == null)
return false;
GrStatement[] statements = block.getStatements();
if (statements.length != 1)
return false;
if (!GroovyPropertyUtils.isSimplePropertyGetter(method))
return false;
if (GroovyPropertyUtils.findFieldForAccessor(method, true) != null)
return false;
GrStatement statement = statements[0];
if (!(statement instanceof GrReturnStatement && ((GrReturnStatement) statement).getReturnValue() != null || statement instanceof GrExpression && !PsiType.VOID.equals(((GrExpression) statement).getType()))) {
return false;
}
return true;
}
};
}
Aggregations