use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression in project intellij-community by JetBrains.
the class GroovyParameterInfoHandler method appendParameterText.
private static void appendParameterText(PsiParameter param, PsiSubstitutor substitutor, StringBuilder buffer) {
if (param instanceof GrParameter) {
GrParameter grParam = (GrParameter) param;
GroovyPresentationUtil.appendParameterPresentation(grParam, substitutor, TypePresentation.PRESENTABLE, buffer);
final GrExpression initializer = grParam.getInitializerGroovy();
if (initializer != null) {
buffer.append(" = ").append(initializer.getText());
} else if (grParam.isOptional()) {
buffer.append(" = null");
}
} else {
PsiType t = param.getType();
PsiType paramType = substitutor.substitute(t);
buffer.append(paramType.getPresentableText());
String name = param.getName();
if (name != null) {
buffer.append(" ");
buffer.append(name);
}
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression in project intellij-community by JetBrains.
the class NotAndParenthesesSurrounder method surroundExpression.
@Override
protected TextRange surroundExpression(@NotNull GrExpression expression, @Nullable PsiElement context) {
final GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(expression.getProject());
final GrUnaryExpression template = (GrUnaryExpression) factory.createExpressionFromText("!(a)", context);
assert template.getOperand() != null;
GroovyExpressionSurrounder.replaceToOldExpression(((GrParenthesizedExpression) template.getOperand()).getOperand(), expression);
final GrExpression result = expression.replaceWithExpression(template, true);
final int endOffset = result.getTextRange().getEndOffset();
return new TextRange(endOffset, endOffset);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression in project android by JetBrains.
the class GradleEditorValueExtractor method visitReferenceExpression.
@Override
public void visitReferenceExpression(GrReferenceExpression expression) {
if (expression.getParent() instanceof GrMethodCallExpression) {
// This is a reference expression which points to the method name. We're not interested in it, so, just return.
return;
}
GrExpression qualifier = expression.getQualifierExpression();
if (qualifier == null) {
myContext.addCachedVariable(expression.getText(), expression.getTextRange());
return;
}
myContext.rememberVariableQualifier(qualifier.getText());
PsiElement dotToken = expression.getDotToken();
if (dotToken == null) {
return;
}
ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.findSingle(GroovyLanguage.INSTANCE);
for (PsiElement e = dotToken.getNextSibling(); e != null; e = e.getNextSibling()) {
ASTNode node = e.getNode();
if (node == null) {
if (e instanceof PsiWhiteSpace) {
continue;
}
e.accept(myVisitor);
return;
}
IElementType type = node.getElementType();
if (type == GroovyTokenTypes.mIDENT) {
myContext.addCachedVariable(e.getText(), e.getTextRange());
} else if (parserDefinition.getWhitespaceTokens().contains(type) || parserDefinition.getCommentTokens().contains(type)) {
continue;
} else {
e.accept(myVisitor);
}
return;
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression in project android by JetBrains.
the class GradleEditorValueExtractor method visitGStringExpression.
@Override
public void visitGStringExpression(GrString expression) {
GroovyPsiElement[] parts = expression.getAllContentParts();
boolean registeredAssignment = false;
for (GroovyPsiElement part : parts) {
if (part instanceof GrStringContent) {
if (!myInterestedInReferencesOnly && !registeredAssignment && !part.getTextRange().isEmpty()) {
registeredAssignment = true;
String text = expression.getText();
TextRange range = expression.getTextRange();
if (text.startsWith("'") || text.startsWith("\"")) {
text = text.substring(1);
range = TextRange.create(range.getStartOffset() + 1, range.getEndOffset());
}
if (text.endsWith("'") || text.endsWith("\"")) {
text = text.substring(0, text.length() - 1);
range = TextRange.create(range.getStartOffset(), range.getEndOffset() - 1);
}
myContext.addCachedValue(text, range);
}
} else if (part instanceof GrStringInjection) {
GrExpression injectedExpression = ((GrStringInjection) part).getExpression();
if (injectedExpression != null) {
injectedExpression.accept(myVisitor);
}
}
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression in project android by JetBrains.
the class AndroidGradleSpellcheckingStrategy method isPrint.
private static boolean isPrint(PsiElement element) {
PsiElement parent0 = element.getParent();
if (parent0 == null) {
return false;
}
PsiElement parent1 = parent0.getParent();
if (parent1 == null) {
return false;
}
PsiElement parent2 = parent1.getParent();
if (parent2 == null) {
return false;
}
if (parent2 instanceof GrCommandArgumentList) {
parent2 = parent2.getParent();
}
if (parent2 instanceof GrApplicationStatement) {
GrApplicationStatement call = (GrApplicationStatement) parent2;
GrExpression propertyExpression = call.getInvokedExpression();
if (propertyExpression instanceof GrReferenceExpression) {
GrReferenceExpression propertyRef = (GrReferenceExpression) propertyExpression;
String property = propertyRef.getReferenceName();
if ("print".equals(property) || "println".equals(property)) {
return true;
}
}
}
return false;
}
Aggregations