use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression 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.path.GrMethodCallExpression in project android by JetBrains.
the class GradleDslParser method getExpressionElement.
@Nullable
private static GradleDslExpression getExpressionElement(@NotNull GradleDslElement parentElement, @NotNull GroovyPsiElement psiElement, @NotNull String propertyName, @NotNull GrExpression propertyExpression) {
if (propertyExpression instanceof GrLiteral) {
// ex: compileSdkVersion 23 or compileSdkVersion = "android-23"
return new GradleDslLiteral(parentElement, psiElement, propertyName, (GrLiteral) propertyExpression);
}
if (propertyExpression instanceof GrReferenceExpression) {
// ex: compileSdkVersion SDK_VERSION or sourceCompatibility = VERSION_1_5
return new GradleDslReference(parentElement, psiElement, propertyName, (GrReferenceExpression) propertyExpression);
}
if (propertyExpression instanceof GrMethodCallExpression) {
// ex: compile project("someProject")
GrMethodCallExpression methodCall = (GrMethodCallExpression) propertyExpression;
GrReferenceExpression callReferenceExpression = getChildOfType(methodCall, GrReferenceExpression.class);
if (callReferenceExpression != null) {
String referenceName = callReferenceExpression.getText();
if (!isEmpty(referenceName)) {
GrArgumentList argumentList = methodCall.getArgumentList();
if (argumentList.getAllArguments().length > 0) {
return getMethodCall(parentElement, methodCall, referenceName, argumentList);
} else {
return new GradleDslMethodCall(parentElement, methodCall, referenceName);
}
}
}
}
if (propertyExpression instanceof GrNewExpression) {
GrNewExpression newExpression = (GrNewExpression) propertyExpression;
GrCodeReferenceElement referenceElement = newExpression.getReferenceElement();
if (referenceElement != null) {
String objectName = referenceElement.getText();
if (!isEmpty(objectName)) {
GrArgumentList argumentList = newExpression.getArgumentList();
if (argumentList != null) {
if (argumentList.getAllArguments().length > 0) {
return getNewExpression(parentElement, newExpression, objectName, argumentList);
}
}
}
}
}
return null;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression in project android by JetBrains.
the class GradleDslMethodCall method create.
@Override
@Nullable
public GroovyPsiElement create() {
GroovyPsiElement psiElement = getPsiElement();
if (psiElement != null) {
return psiElement;
}
if (myParent == null) {
return null;
}
GroovyPsiElement parentPsiElement = myParent.create();
if (parentPsiElement == null) {
return null;
}
GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(parentPsiElement.getProject());
String statementText = (myStatementName != null ? myStatementName + " " : "") + myName + "()";
GrStatement statement = factory.createStatementFromText(statementText);
PsiElement addedElement = parentPsiElement.addBefore(statement, parentPsiElement.getLastChild());
if (addedElement instanceof GrApplicationStatement) {
GrExpression[] expressionArguments = ((GrApplicationStatement) addedElement).getArgumentList().getExpressionArguments();
if (expressionArguments.length == 1 && expressionArguments[0] instanceof GrMethodCallExpression) {
setPsiElement(expressionArguments[0]);
return getPsiElement();
}
}
if (addedElement instanceof GrMethodCallExpression) {
setPsiElement((GrMethodCallExpression) addedElement);
return getPsiElement();
}
return null;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression in project intellij-community by JetBrains.
the class ChangeToOperatorInspection method buildVisitor.
@NotNull
@Override
protected BaseInspectionVisitor buildVisitor() {
return new BaseInspectionVisitor() {
@Override
public void visitMethodCallExpression(@NotNull GrMethodCallExpression methodCall) {
final String methodName = getMethodName(methodCall);
if (methodName == null)
return;
Transformation transformation = TRANSFORMATIONS.get(methodName);
if (transformation == null)
return;
PsiElement highlightElement = getHighlightElement(methodCall);
if (highlightElement == null)
return;
if (transformation.couldApply(methodCall, getOptions())) {
registerError(highlightElement, message("replace.with.operator.message", methodName), new LocalQuickFix[] { getFix(transformation, methodName) }, GENERIC_ERROR_OR_WARNING);
}
}
};
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression in project intellij-community by JetBrains.
the class GroovyNameSuggestionUtil method generateNameByExpr.
private static void generateNameByExpr(GrExpression expr, Set<String> possibleNames, NameValidator validator, boolean forStaticVariable) {
if (expr instanceof GrReferenceExpression && ((GrReferenceExpression) expr).getReferenceName() != null) {
if (PsiUtil.isThisReference(expr)) {
possibleNames.add(validator.validateName("thisInstance", true));
}
if (PsiUtil.isSuperReference(expr)) {
possibleNames.add(validator.validateName("superInstance", true));
}
GrReferenceExpression refExpr = (GrReferenceExpression) expr;
String name = refExpr.getReferenceName();
if (name != null && name.toUpperCase().equals(name)) {
possibleNames.add(validator.validateName(name.toLowerCase(), true));
} else {
generateCamelNames(possibleNames, validator, name);
}
if (expr.getText().equals(name)) {
possibleNames.remove(name);
}
}
if (expr instanceof GrMethodCallExpression) {
generateNameByExpr(((GrMethodCallExpression) expr).getInvokedExpression(), possibleNames, validator, forStaticVariable);
}
if (expr instanceof GrLiteral) {
final Object value = ((GrLiteral) expr).getValue();
if (value instanceof String) {
generateNameByString(possibleNames, (String) value, validator, forStaticVariable, expr.getProject());
}
}
}
Aggregations