use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall in project intellij-community by JetBrains.
the class GeeseUtil method calculateRBraceAlignment.
static void calculateRBraceAlignment(PsiElement rBrace, AlignmentProvider alignments) {
int leadingBraceCount = 0;
PsiElement next;
if (!isClosureContainLF(rBrace))
return;
for (next = PsiUtil.getPreviousNonWhitespaceToken(rBrace); isClosureRBrace(next) && isClosureContainLF(next); next = PsiUtil.getPreviousNonWhitespaceToken(next)) {
leadingBraceCount++;
}
PsiElement cur = rBrace;
for (next = getNextNonWhitespaceToken(cur); isClosureRBrace(next); next = getNextNonWhitespaceToken(cur)) {
cur = next;
}
for (; leadingBraceCount > 0; leadingBraceCount--) {
cur = PsiUtil.getPreviousNonWhitespaceToken(cur);
}
PsiElement parent = cur.getParent();
LOG.assertTrue(parent instanceof GrClosableBlock);
//search for start of the line
cur = parent;
if (cur.getParent() instanceof GrMethodCall) {
GrMethodCall call = (GrMethodCall) cur.getParent();
GrExpression invoked = call.getInvokedExpression();
if (invoked instanceof GrReferenceExpression && ((GrReferenceExpression) invoked).getReferenceNameElement() != null) {
cur = ((GrReferenceExpression) invoked).getReferenceNameElement();
} else {
cur = call;
}
}
cur = PsiTreeUtil.getDeepestFirst(cur);
while (!PsiUtil.isNewLine(next = PsiTreeUtil.prevLeaf(cur, true))) {
if (next == null)
break;
if (next.getNode().getElementType() == TokenType.WHITE_SPACE && PsiTreeUtil.prevLeaf(next) == null) {
//if cur is first word in the text, whitespace could be before it
break;
}
cur = next;
}
int startOffset = cur.getTextRange().getStartOffset();
int endOffset = rBrace.getTextRange().getStartOffset();
if (rBrace.getContainingFile().getText().substring(startOffset, endOffset).indexOf('\n') < 0) {
return;
}
while (true) {
final PsiElement p = cur.getParent();
if (p != null && p.getTextOffset() == cur.getTextOffset()) {
cur = p;
} else {
break;
}
}
alignments.addPair(rBrace, cur, true);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall in project intellij-community by JetBrains.
the class GrMethodCallWithSingleClosureArgFixer method apply.
@Override
public void apply(@NotNull Editor editor, @NotNull GroovySmartEnterProcessor processor, @NotNull PsiElement psiElement) {
final PsiElement parent = psiElement.getParent();
if (parent instanceof GrReferenceExpression && !(parent.getParent() instanceof GrMethodCall) && hasOnlyClosureParam((GrReferenceExpression) parent)) {
final int endOffset = psiElement.getTextRange().getEndOffset();
editor.getDocument().insertString(endOffset, "{\n}");
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall in project intellij-community by JetBrains.
the class JavaStylePropertiesInvocationInspection method buildVisitor.
@NotNull
@Override
protected BaseInspectionVisitor buildVisitor() {
return new BaseInspectionVisitor() {
@Override
public void visitMethodCallExpression(@NotNull GrMethodCallExpression methodCallExpression) {
super.visitMethodCallExpression(methodCallExpression);
visitMethodCall(methodCallExpression);
}
@Override
public void visitApplicationStatement(@NotNull GrApplicationStatement applicationStatement) {
super.visitApplicationStatement(applicationStatement);
visitMethodCall(applicationStatement);
}
private void visitMethodCall(GrMethodCall methodCall) {
if (JavaStylePropertiesUtil.isPropertyAccessor(methodCall)) {
final String message = GroovyInspectionBundle.message("java.style.property.access");
final GrExpression expression = methodCall.getInvokedExpression();
if (expression instanceof GrReferenceExpression) {
PsiElement referenceNameElement = ((GrReferenceExpression) expression).getReferenceNameElement();
registerError(referenceNameElement, message, myFixes, ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
}
}
}
};
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall in project intellij-community by JetBrains.
the class ChangeToOperatorInspection method getFix.
@Nullable
protected GroovyFix getFix(@NotNull Transformation transformation, @NotNull String methodName) {
return new GroovyFix() {
@Nls
@NotNull
@Override
public String getFamilyName() {
return message("replace.with.operator.fix", methodName);
}
@Override
protected void doFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) throws IncorrectOperationException {
PsiElement call = descriptor.getPsiElement().getParent();
if (call == null)
return;
call = call.getParent();
if (!(call instanceof GrMethodCall))
return;
GrMethodCall methodCall = (GrMethodCall) call;
GrExpression invokedExpression = methodCall.getInvokedExpression();
if (!(invokedExpression instanceof GrReferenceExpression))
return;
Options options = getOptions();
if (!transformation.couldApply(methodCall, options))
return;
transformation.apply(methodCall, options);
}
};
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall in project intellij-community by JetBrains.
the class GroovyMapValueTypeEnhancer method getReferenceType.
@Override
public PsiType getReferenceType(GrReferenceExpression ref, @Nullable PsiElement resolved) {
if (resolved != null)
return null;
GrExpression qualifierExpression = ref.getQualifierExpression();
if (qualifierExpression == null)
return null;
PsiType mapType = qualifierExpression.getType();
if (!InheritanceUtil.isInheritor(mapType, CommonClassNames.JAVA_UTIL_MAP)) {
return null;
}
PsiElement qResolved;
if (qualifierExpression instanceof GrReferenceExpression) {
qResolved = ((GrReferenceExpression) qualifierExpression).resolve();
} else if (qualifierExpression instanceof GrMethodCall) {
qResolved = ((GrMethodCall) qualifierExpression).resolveMethod();
} else {
return null;
}
String key = ref.getReferenceName();
if (key == null)
return null;
for (GroovyMapContentProvider provider : GroovyMapContentProvider.EP_NAME.getExtensions()) {
PsiType type = provider.getValueType(qualifierExpression, qResolved, key);
if (type != null) {
return type;
}
}
if (mapType instanceof GrMapType) {
return ((GrMapType) mapType).getTypeByStringKey(key);
}
return null;
}
Aggregations